The largest level represents the achieved production span.
You need to work out a number of implementation details in your scheduling algorithm. Make sure it runs in O(n+m) time. Your algorithm should be based on the following approach:
1 The vertices are considered in topological order. For each vertex v, assign v to a level p if (i) level p is at least one level higher than the largest level assigned to any of v’s incoming edges, and (ii) level p does not already have k vertices assigned to it. If more than one vertex qualifies for placement, an arbitrary one is chosen.
2 Repeat the process until all vertices have been scheduled.
3 Report the schedule and the achieved production span.
Summary of Tasks
This project asks you to implement the following tasks. Each task needs to have an O(n+m) time implementation.
1 For a given dag G, determine the topological number of each vertex using the degree-based topological sorting algorithm.
2 For a given dag G, determine for the length of the longest path.
3 For a given dag G, use the topological numbers and the longest paths entries to generate a schedule that completes all manufacturing steps in the shortest production span. Return the schedule.
4 For a given dag G and an integer k, 1< k < n, use the topological numbers to determine a schedule using at most k stations. Return the schedule.
For those interested in using graph visualization tools, we provide the following links to resources:
· Network Workbench - http://nwb.cns.iu.edu/index.html
· graphviz - http://www.linuxdevcenter.com/pub/a/linux/2004/05/06/graphviz_dot.html
· Cytoscape - http://www.cytoscape.org/
Programming Assignment
The skeleton code contains a number example dags. Each dag file has the following format:
vertices, edges
0:
In:
Out:
1:
In:
Out:
...
n:
In:
Out:
For example, for a 4-vertex dag the input can look like:
4 vertices, 6 edges
0:
In: 2
Out: 1 3
1:
In: 0 2
Out: 3
2:
In:
Out: 3 0 1
3:
In: 2 0 1
Out:
Represent each dag so that it maintains for each vertex the list of out-edges as well as in-edges. You need to define a class Digraph that you can adapt from the one given from Princeton library. Add additional entries as needed.
For tasks 3 and 4, the generated schedule is represented as described in Schedule.java. The data structure resembles the structure of adjacency lists: it is an array of lists. The size of the array equals the production span and the list at the j-th entry of the array contains the steps executing simultaneously at time j (listed in arbitrary order). Do not modify Schedule.java. You can use methods in Schedule.java to construct a schedule.
You must implement the following methods of the DagUtilities class:
· public static int[] topologicalSort(Digraph G)
· perform topological sort on dag G and assign topological numbers.
· public static int longestPath(Digraph G)
· return the length of the longest path in the dag G.
· public static Schedule minProdSpanSchedule(Digraph G)
· for dag G, return a schedule minimizing the production span.
· public static Schedule spanKStations(Digraph G, int k)
· for dag G and integer k, return a schedule using at most k stations.
· public static Digraph readGraphFromFile(File file)
· Read a dag from input file and return the dag
Testing
You have been provided with several example trees which you should use to test your code. To run our main function, use the following command:
$ java -cp Project5Test [Graph_File_Path]
If you want to specify the number of stations for task 4, use the following command:
$ java -cp Project5Test [Graph_File_Path] -s [Number_Of_Stations]
Analysis Questions
Your report must answer each question briefly and clearly.
1 State and explain the asymptotic performance of your algorithm determining the topological numbers.
2 State and explain the asymptotic performance of your algorithm determining the longest path in the dag.
3 State and explain the asymptotic performance of your algorithm determining a schedule achieving minimum production span.
4 State and explain the asymptotic performance of your algorithm determining a schedule using no more than k stations.
5 Give an example of a dag consisting of at least 15 vertices on which your k-station algorithm fails to find a schedule minimizing the production span for k>1. Explain at what point your algorithm makes the wrong decision.
6 Give an example of a dag consisting of at least 15 vertices on which your k-station algorithm generates a schedule achieving minimum production span, k>1.
7 For the dag you used in question 6: Does your algorithm produce a schedule achieving minimum production span when the topological ordering used is the one generated by executing a DFS on the dag? Explain and illustrate your answer.
For the dag in file dagQ8.txt(400 vertices, 850 edges) create a plot having k on the x-axis (starting with k=1) and the resulting production span on the y-axis. Note that the dag has a longest path length of 17 and thus the minimum production span possible is 18 (it requires 107 stations). Discuss your plot.
Project 5: Implement four tasks on dags, each having O(n+m) time performance.
1.For a given dag G, determine the topological number of each vertex using the degree-based topological sorting algorithm.
• Do not use the DFS approach, but the described degree-based approach
2.For a given dag G, determine for the length of the longest path.
• Use the topological numbers and edge relaxation(on max)
17
· Longest path of length is3
· Shortest production span is4
· Possible schedule:
A, (B, C, D), (E, F, G), H
· Possible schedules if only two
stations are available: A, (B,C), (D,E), (F,G), H A, (B,D), (C,F), (E,G, H
18
Project 5: implement four tasks on dags, each having O(n+m) time performance.
3. For a given dag G, use the topological numbers and the longest paths entries to generate a schedule that completes all manufacturing steps in the shortest production span. Return the schedule.
4. For a given dag G and an integer k, 1< k < n, use the topological numbers to determine a schedule using at most k stations. Return the schedule.
· The schedule for k=1 is the topological order
· No benefit when having more stations than long
·
About the dags and schedules
· Take a careful look at the input format
· Dags can have multiple sources, but have only one sink
· Determine what is needed in class Digraph on entries and methods
· Class schedule cannot be changed Size of the array corresponds to the production span Linked list at index j lists production steps executing at time j Longest linked list determines how many stations are used
· There are other representations of schedule, but you need to use the one given
20
Analysis question 5
Give an example of a dag consisting of at least 15 vertices on which your k-station algorithm fails to find a schedule minimizing the production span for k>1. Explain at what point your algorithm makes the wrong decision.
For small dags, you can check whether your schedule is feasible and whether it generates minimum production span.
For large dags, you can write a simple methods to check whether your schedule is feasible. However, determining whether it produces minimum production span is not easy.
Choose a k (2 or 3) and a dag such that your scheduling algorithm makes a mistake.You have to do more than find a counterexample. The example has to fool your algorithm!
21
About the schedules
· The graph were generated by a dag library and they seem to be “schedule friendly”
· For k>1, two students may generate schedules having a different production span.
· For every production span, there generally exist a number of valid schedules.
· Finding an example where your algorithm fails corresponds