Example #1
0
        public String run_next(Time time, int tick)
        {
            String log_text = "";

            if (cur_process != null){
                cur_process.running(tick);
                if (cur_process.complexity.ToMsec() == cur_process.time_worked.ToMsec())
                {
                    log_text = log_text + " Process " + cur_process.id + " done! Time worked: " + cur_process.time_worked.ToString() + ".\n";
                    cur_process.solve(time);
                    done_processes.Add(cur_process);
                    processes_quiue.Remove(cur_process);
                    cur_process = null;
                    return log_text;
                }
            }
            else
            {
                if (processes_quiue.Count > 0){
                    cur_process = processes_quiue[0];
                    cur_process.run(time);
                    cur_process.running(tick);
                    log_text = log_text + " Process " + cur_process.id + " starts.\n";
                }
                else
                {
                    log_text = log_text + " Waiting for processes.\n";
                }
            }
            return log_text;
        }
Example #2
0
 public Process(int id, Time complexity, Time start)
 {
     this.id = id;
     this.complexity = complexity;
     this.state = 0;
     this.deleyed = new Time();
     this.start = start;
     this.time_worked = new Time();
     this.finish = new Time();
 }
Example #3
0
        public String run_next(Time time, int tick)
        {
            String log_text = "";

            if (cur_process != null){
                cur_process.running(tick);
                if (cur_process.complexity.ToMsec() == cur_process.time_worked.ToMsec())
                {
                    log_text = log_text + " Process " + cur_process.id + " done! Time worked: " + cur_process.time_worked.ToString() + ".\n";
                    cur_process.solve(time);
                    done_processes.Add(cur_process);
                    processes_quiue.Remove(cur_process);
                    cur_process = null;
                    return log_text;
                }
            }

            if (cur_process == null){
                if (processes_quiue.Count > 0){
                    cur_process = processes_quiue[0];
                }
            }

            if (processes_quiue.Count > 0)
            {
                Process next_proc = processes_quiue.OrderBy((x) => (x.complexity.ToMsec() - x.time_worked.ToMsec())).First();

                if (cur_process.id != next_proc.id)
                {
                    log_text = log_text + " Process " + cur_process.id + " paused.\n";
                    cur_process.pause();
                    cur_process = next_proc;
                    if (next_proc.state == 0)
                    {
                        next_proc.run(time);
                        next_proc.running(tick);
                        log_text = log_text + " NEXT: new task " + next_proc.id + " remain work: " + (cur_process.complexity - cur_process.time_worked).ToString() + ".\n";
                    }
                    else
                    {
                        if (next_proc.state == 2)
                        {
                            next_proc.resume(time);
                            log_text = log_text + " NEXT: paused task " + next_proc.id + " remain work: " + (cur_process.complexity - cur_process.time_worked).ToString() + ".\n";
                        }
                        else
                        {
                            log_text = log_text + " Unexpected state detected.\n";
                        }
                    }
                }
            }
            return log_text;
        }
Example #4
0
 public String gen_next(int min_time, int max_time, int tick, Time time, int max_processes, double chance)
 {
     String log_text = "";
     Random rand = new Random();
     if (chance * 100 > rand.Next(0, 100)){
         if (max_processes > (done_processes.Count + processes_quiue.Count))
         {
             processes_quiue.Add(proc_gen.gen_process(min_time, max_time, tick, time));
             log_text = log_text + " Process " + processes_quiue.Last().id + " added.\n";
         }
     }
     return log_text;
 }
Example #5
0
 public Time(Time t)
 {
     this.min = t.min;
     this.sec = t.sec;
     this.msec = t.msec;
 }
Example #6
0
 public Process gen_process(int min_time, int max_time, int tick, Time time)
 {
     cur_id++;
     int rand = random.Next(min_time, max_time);
     return new Process(cur_id - 1, new Time(rand - (rand % tick)), new Time(time));
 }
Example #7
0
 public void solve(Time time)
 {
     finish = time;
     deleyed = (finish - start) - complexity;
     state = 3;
 }
Example #8
0
 public void run(Time time)
 {
     state = 1;
 }
Example #9
0
 public void resume(Time time)
 {
     state = 1;
 }