示例#1
0
  public void run() {
    if (!checkRealizeable()) {
      System.out.println("Project is not realizeable, quitting");
      System.exit(1);
    }

    int t = 0;
    ArrayList<Task> active_tasks = findTaskWithIndegreeZero();
    System.out.println("---------------- Starting project from");
    for (Task task : active_tasks) {
      System.out.println(task.toString());
      task.start(t);
    }
    boolean finished = false;
    while (true) {

      ArrayList<Task> to_be_removed = new ArrayList<>();
      ArrayList<Task> to_be_added = new ArrayList<>();
      for (Task task : active_tasks) {

        if (task.isFinished(t)) {
          for (Edge edge : task.outEdges) {
            if (edge.w.tell_finished_prerequisite(t)) {
              to_be_added.add(edge.w);
            }
          }
          to_be_removed.add(task);
        }
      }
      active_tasks.removeAll(to_be_removed);
      active_tasks.addAll(to_be_added);
      int current_staff = 0;

      for (Task task : active_tasks) {
        current_staff += task.staff;
      }
      System.out.println("Current staff: " + Integer.toString(current_staff));

      if (active_tasks.size() == 0) {
        for (Task task : tasks) {
          if (task.finished_at == -1) {
            System.out.println("Task " + Integer.toString(task.id) + " was not able to finish!");
          }
        }
        break;
      }
      t++;
      System.out.println(" ");
      System.out.println("t: " + Integer.toString(t));
    }
    minimum_completion_time = t;
    System.out.println(
        "*** Shortest possible execution time is "
            + Integer.toString(minimum_completion_time)
            + " ***");

    setSlack();
  }
示例#2
0
 public String _toString() {
   if (runtime == null) return StringUtil.lastSubstring(super.toString(), ".") + "," + "<orphan>";
   else
     return StringUtil.lastSubstring(super.toString(), ".")
         + "--"
         + state
         + (sleepOn == null || sleepOn == this
             ? ""
             : " on "
                 + sleepOn
                 + (waitPack != null && waitPack.target != null ? "(waiting/locking)" : ""))
         + (state == State_SLEEPING ? " until " + wakeUpTime : "")
         + "--"
         + "context="
         + mainContext()
         + "--"
         + "next_task="
         + (nextTask != null ? nextTask.toString() : "<null>")
         + "--"
         + (currentContext == mainContext ? "" : "--currentContext=" + _currentContext())
         + (returnPort == null ? "" : "--return_port=" + returnPort)
         + (sendingPort == null ? "" : "--sending_port=" + sendingPort);
 }
示例#3
0
 public String info(String prefix_) {
   if (runtime == null)
     return StringUtil.lastSubstring(prefix_ + super.toString(), ".") + "," + "<orphan>";
   StringBuffer sb_ =
       new StringBuffer(
           prefix_
               + StringUtil.lastSubstring(super.toString(), ".")
               + ", "
               + state
               + (sleepOn == null || sleepOn == this
                   ? ""
                   : " on "
                       + sleepOn
                       + (waitPack != null && waitPack.target != null ? "(waiting/locking)" : ""))
               + (state == State_SLEEPING ? " until " + wakeUpTime : "")
               + "\n"
               + prefix_
               + "Context="
               + mainContext()
               + (mainContext == null ? ", " : "\n" + prefix_)
               + "Next_Task="
               + (nextTask != null ? nextTask.toString() : "<null>")
               + "\n");
   if (currentContext != mainContext)
     sb_.append(prefix_ + "CurrentContext: " + _currentContext() + "\n");
   if (returnPort != null) sb_.append(prefix_ + "return_port: " + returnPort + "\n");
   if (sendingPort != null) sb_.append(prefix_ + "sending_port: " + sendingPort + "\n");
   sb_.append(prefix_ + "Locks: " + locks());
   sb_.append(prefix_ + "#arrivals: " + totalNumEvents + "\n");
   sb_.append(prefix_ + "last_sleepOn: " + lastsleepon + "\n");
   sb_.append(
       prefix_
           + "last_wkUp_thread: "
           + (lastwakeupthread == null ? null : currentThread(lastwakeupthread))
           + "\n");
   return sb_.toString();
 }
示例#4
0
 public void printAllTasks() {
   for (Task task : tasks) {
     System.out.println(task.toString());
   }
 }