DagTask.java 2.35 KB
Newer Older
1 2 3 4 5
package mvd.jester.model;

import java.util.Set;
import org.jgrapht.experimental.dag.DirectedAcyclicGraph;
import org.jgrapht.graph.DefaultEdge;
6
import mvd.jester.utils.DagUtils;
7 8 9 10 11 12 13 14 15 16 17

public class DagTask implements Task {

    private DirectedAcyclicGraph<Job, DefaultEdge> jobDag;
    private final Set<Segment> workloadDistribution;
    private final long workload;
    private final long criticalPath;
    private final long period;
    private final long deadline;
    private final long numberOfThreads;

18 19
    public DagTask(final DirectedAcyclicGraph<Job, DefaultEdge> jobDag, final long period,
            final long numberOfThreads) {
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
        this.jobDag = jobDag;
        this.period = period;
        this.deadline = period;
        this.numberOfThreads = numberOfThreads;
        this.workload = DagUtils.calculateWorkload(this.jobDag);
        this.criticalPath = DagUtils.calculateCriticalPath(this.jobDag);
        this.workloadDistribution =
                DagUtils.calculateWorkloadDistribution(this.jobDag, this.criticalPath);
    }

    public double getUtilization() {
        return (double) workload / period;
    }

    /**
     * @return the deadline
     */
    public long getDeadline() {
        return deadline;
    }

    /**
     * @return the jobDag
     */
    public DirectedAcyclicGraph<Job, DefaultEdge> getJobDag() {
        return jobDag;
    }

    /**
     * @param jobDag the jobDag to set
     */
51
    public void setJobDag(final DirectedAcyclicGraph<Job, DefaultEdge> jobDag) {
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
        this.jobDag = jobDag;
    }

    /**
     * @return the period
     */
    public long getPeriod() {
        return period;
    }

    /**
     * @return the workload
     */
    public long getWorkload() {
        return workload;
    }

    /**
     * @return the criticalPath
     */
    public long getCriticalPath() {
        return criticalPath;
    }


    /**
     * @return the workloadDistribution
     */
    public Set<Segment> getWorkloadDistribution() {
        return workloadDistribution;
    }

    @Override
    public long getMaximumParallelism() {
        long max = 0;
87
        for (final Segment s : workloadDistribution) {
88 89 90 91 92 93 94 95 96 97 98 99 100 101
            if (max < s.getNumberOfJobs()) {
                max = s.getNumberOfJobs();
            }
        }
        return max;
    }


    @Override
    public long getNumberOfThreads() {
        return numberOfThreads;
    }

}