Subversion Repositories programming

Rev

Rev 413 | Rev 415 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 413 Rev 414
Line 87... Line 87...
87
    {
87
    {
88
        cur_proc.time_left--;
88
        cur_proc.time_left--;
89
        cur_time++;
89
        cur_time++;
90
    }
90
    }
91
 
91
 
-
 
92
    protected void printGanttChart ()
-
 
93
    {
-
 
94
        Vector<String> t = new Vector<String> ();
-
 
95
        Vector<String> l = new Vector<String> ();
-
 
96
 
-
 
97
        String timeline = new String();
-
 
98
        String labels = new String();
-
 
99
        String add1 = new String();
-
 
100
        String add2 = new String();
-
 
101
 
-
 
102
        int exptime = 0;
-
 
103
        int templen;
-
 
104
 
-
 
105
        for (LogEntry e : log)
-
 
106
        {
-
 
107
            if (e.msg == LogEntry.MsgType.EXPIRE || e.msg == LogEntry.MsgType.COMPLETE)
-
 
108
            {
-
 
109
                exptime = e.time;
-
 
110
                continue;
-
 
111
            }
-
 
112
 
-
 
113
            add1 = "|---" + e.proc.name + "---";
-
 
114
            add2 = "" + e.time;
-
 
115
 
-
 
116
            for (int i=0; add2.length() < add1.length(); i++)
-
 
117
                add2 += " ";
-
 
118
 
-
 
119
            if (timeline.length() + add1.length() > 79)
-
 
120
            {
-
 
121
                t.add (timeline + "|");
-
 
122
 
-
 
123
                templen = labels.length() - String.valueOf(exptime).length();
-
 
124
                labels = labels.substring (0, templen+1) + String.valueOf(exptime);
-
 
125
                
-
 
126
                l.add (labels);
-
 
127
                timeline = new String();
-
 
128
                labels = new String();
-
 
129
            }
-
 
130
 
-
 
131
            timeline += add1;
-
 
132
            labels += add2;
-
 
133
        }
-
 
134
 
-
 
135
        /* Done, add the last values of timeline and labels to the Vectors */
-
 
136
        t.add (timeline + "|");
-
 
137
 
-
 
138
        templen = labels.length() - String.valueOf(exptime).length();
-
 
139
        labels = labels.substring (0, templen+1) + String.valueOf(exptime);
-
 
140
        l.add (labels);
-
 
141
 
-
 
142
        assert (l.size() == t.size());
-
 
143
 
-
 
144
        for (int i=0; i<l.size(); i++)
-
 
145
        {
-
 
146
            System.out.println (t.elementAt (i));
-
 
147
            System.out.println (l.elementAt (i));
-
 
148
            System.out.println ();
-
 
149
        }
-
 
150
    }
-
 
151
 
92
    public Scheduler ()
152
    public Scheduler ()
93
    {
153
    {
94
        this.run_queue = new Vector<Process> ();
154
        this.run_queue = new Vector<Process> ();
95
        this.log = new Vector<LogEntry> ();
155
        this.log = new Vector<LogEntry> ();
96
    }
156
    }
Line 99... Line 159...
99
    {
159
    {
100
        /* Keep step()ing until we're done */
160
        /* Keep step()ing until we're done */
101
        while (step ())
161
        while (step ())
102
            ; // do nothing
162
            ; // do nothing
103
 
163
 
-
 
164
        /* Verbose print of each log entry */
104
        for (LogEntry e : log)
165
        //for (LogEntry e : log)
105
            System.out.println (e);
166
        //   System.out.println (e);
-
 
167
 
-
 
168
        /* Gantt Chart */
-
 
169
        printGanttChart ();
106
 
170
 
107
        /* Print time taken */
171
        /* Print time taken */
108
        System.out.println ("\nSimulation took " + cur_time + " time units to complete!");
172
        System.out.println ("\nSimulation took " + cur_time + " time units to complete!");
109
    }
173
    }
110
}
174
}