Example #1
0
  @Override
  void solve(Set<? extends Job> jobs) {
    Job[] sortedJobs = jobs.toArray(new Job[jobs.size()]);
    Arrays.sort(sortedJobs, Job::compareArrivalTime);

    processTime = totWT = 0;
    long usefulTime = 0;
    int jobCount = jobs.size();
    PriorityQueue<Job> queue = new PriorityQueue<>(Job::compareBurstTime);
    for (Job job : sortedJobs) {
      if (job == null) {
        jobCount--;
        continue;
      }

      while (!queue.isEmpty() && processTime < job.getArrivalTime()) {
        Job nextJob = queue.poll();
        long arrivalTime = nextJob.getArrivalTime();
        long burstTime = nextJob.getBurstTime();

        if (processTime < nextJob.getArrivalTime()) {
          processList.add(new RunningProcess("Idle", arrivalTime - processTime));
          processTime = arrivalTime;
        }

        processList.add(new RunningProcess("P" + nextJob.getId(), burstTime));
        usefulTime += burstTime;
        totWT += processTime - arrivalTime;
        processTime += burstTime;
      }

      queue.add(job);
    }

    while (!queue.isEmpty()) {
      Job nextJob = queue.poll();
      long arrivalTime = nextJob.getArrivalTime();
      long burstTime = nextJob.getBurstTime();

      if (processTime < nextJob.getArrivalTime()) {
        processList.add(new RunningProcess("Idle", arrivalTime - processTime));
        processTime = arrivalTime;
      }

      processList.add(new RunningProcess("P" + nextJob.getId(), burstTime));
      usefulTime += burstTime;
      totWT += processTime - arrivalTime;
      processTime += burstTime;
    }

    totRT = totWT;
    totTAT = totWT + usefulTime;

    avgRT = avgWT = (double) totWT / (double) jobCount;
    avgTAT = (double) totTAT / (double) jobCount;

    utilization = usefulTime * 100.0 / processTime;
  }
 /**
  * Helper method to easily execute a job.
  *
  * @param job Job to be executed.
  */
 public static void execute(Job job) {
   if (job == null)
     throw new IllegalArgumentException(
         format("Illegal call of execute(job = '%s') - must not be null!", job));
   Job current = jobQuery().jobId(job.getId()).singleResult();
   if (current == null)
     throw new IllegalStateException(
         format(
             "Illegal state when calling execute(job = '%s') - job does not exist anymore!", job));
   managementService().executeJob(job.getId());
 }
Example #3
0
 @Override
 public Job getJob(String Id) {
   synchronized (this.lock) {
     for (Job j : this.nonSubmitted) if (j.getId().equals(Id)) return j;
   }
   return null;
 }
Example #4
0
  private void identifyVacantJobsByZone() {
    // populate HashMap with Jobs by zone

    logger.info("  Identifying vacant jobs by zone");
    vacantJobsByZone = new HashMap<>();
    Job[] jobs = Job.getJobArray();
    for (Job jj : jobs) {
      if (jj.getWorkerId() == -1) {
        int id = jj.getId();
        int zone = jj.getZone();
        if (vacantJobsByZone.containsKey(zone)) {
          int[] vacancies = vacantJobsByZone.get(zone);
          int[] newVacancies = SiloUtil.expandArrayByOneElement(vacancies, id);
          vacantJobsByZone.put(zone, newVacancies);
        } else {
          vacantJobsByZone.put(zone, new int[] {id});
        }
      }
    }
  }