-
Notifications
You must be signed in to change notification settings - Fork 1
/
README.txt
314 lines (251 loc) · 11.9 KB
/
README.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
51
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
# Long Project LP4: PERT, Enumeration of Topological Orders
# Team: LP101
* Rahul Nalawade (https://github.com/rahul1947)
rsn170330@utdallas.edu
* Prateek Sarna (https://github.com/prateek5795)
pxs180012@utdallas.edu
* Bhavish Khanna Narayanan (https://github.com/bhavish14)
bxn170002@utdallas.edu
# End Date:
* Sunday, November 25, 2018
_______________________________________________________________________________
# PROBLEM STATEMENT:
1. Implement Enumeration of Permutations and Combinations in Enumerate.java.
It also contains methods for other Enumeration problem which is optional
for implementation.
2. Implement Enumeration of all Topological Orders of a given directed graph in
EnumerateTopological.java.
3. Implement PERT algorithm with all the methods in PERT.java.
Input:
1. G = (V,E), G must be a DAG
2. duration(u) = {0, 1, 2, ...}, where u is a node (task) in V.
Output:
1. Critical Path Length (Minimum time to complete Project)
2. slack(u): Slack available for each node (task)
3. EC(u): Earliest Completion Time for each node
4. LC(u): Latest Completion Time for each node
/**
* Implement PERT algorithm by computing all the necessary output values.
* Run PERT algorithm on graph g. Assume that vertex 1 is s and vertex n is t.
* You need to add edges from s to all vertices and from all vertices to t.
*/
public static PERT pert(Graph g, int[] duration) {...}
// non-static method called after calling the constructor
public boolean pert();
The following methods can be called to query the results, after running one
of the above methods:
public int ec(Vertex u); // Earliest completion time of u
public int lc(Vertex u); // Latest completion time of u
public int slack(Vertex u); // Slack of u
public int criticalPath(); // Length of critical path
public boolean critical(Vertex u); // Is vertex u on a critical path?
public int numCritical(); // Number of critical nodes in graph
_______________________________________________________________________________
# DESCRIPTION:
#1. Enumerate.java:
ATTRIBUTES:
-----------
- T[] arr: Array of elements on which enumeration is to be done.
n = arr.length
- k: number of elements to be selected (default = n). E.g nPk or nCk.
- count: counts the number of times visit has been called based on the
Approver.
APPROVER<T>:
------------
- Responsible for selection and de-selection (backtracking) of an
element based on certain precedence constraints coded in select() and
unselect() methods respectively.
- visit() is called by non-static visit() to print the k elements in the
arr[0...k-1]
METHODS:
--------
A. permute(c): recursive method to visit all valid permutations, where c
is number of elements yet to visit.
B. combine(i, c): recursive method to visit all valid combinations, where
c is the number of element we need to choose from arr[i...n-1].
C. heap(g): recursive method to visit all permutations by a single swap
from previous permutation, where first g elements are not frozen, i.e.
arr[g...n-1] are frozen, and arr[0..g-1] can only be changed.
D. algorithmL(Comparator c): Knuth's L Algorithm based on Comparator c.
-------------------------------------------------------------------------------
#2. EnumerateTopological.java:
ATTRIBUTES:
-----------
- print: boolean if true prints all enumerations, else no printing.
- selector: Approver of EnumerateTopological itself.
- Vertex[] A: array of vertices in the Graph.
SELECTOR extended from APPROVER<T>
----------------------------------
- select(u): selects u, if it has inDegrees = 0.
- unselect(u): do v.inDegrees++, where edge e = (u,v) exists.
METHODS:
--------
A. initialize(): initializes get(u).inDegrees = u.inDegree for all u.
B. enumerateTopological(): based on selector, enumerates all
permutations using permute() from Enumerate.
Returns count of enumerations from Enumerate itself.
NOTE:
Counting and Enumerating Topological Orders uses the same algorithm.
-------------------------------------------------------------------------------
#3. PERT.java:
PERTVertex:
-----------
- duration: duration of this vertex
- slack: slack available for this vertex
- earliestCT: earliest completion time (EC) for this vertex
- latestCT: latest completion time (LC) for this vertex
METHODS:
--------
A. initialize(): add edges from source (first vertex) to all vertices,
and all vertices to the sink (last vertex).
B. pert(): Implements PERT by computing slack, EC, LC for all vertices.
Returns true if Graph is not a DAG, false otherwise.
NOTE: it uses a topological order from DFS.java
_______________________________________________________________________________
# RESULTS:
# Enumerate:
$java rsn170330.Enumerate
Permutations: 4 3
1 2 3
1 2 4
1 3 2
...
4 1 3
4 1 2
Count: 24
_________________________
Combinations: 4 3
1 2 3
1 2 4
1 3 4
2 3 4
Count: 4
_________________________
Heap Permutations: 4
1 2 3 4
2 1 3 4
3 1 2 4
...
3 2 4 1
2 3 4 1
Count: 24
_________________________
Algorithm L Permutations:
1 2 2 3 3 4
1 2 2 3 4 3
1 2 2 4 3 3
...
4 3 3 2 1 2
4 3 3 2 2 1
Count: 180
_________________________
# Enumerate Topological:
$ java rsn170330.EnumerateTopological 0 rsn170330/lp4-test/enumtop-t08.txt
+-------------------------------------------------------------------------+
| File | |V| |E| | Output | Time (mSec) | Memory (used/avail) |
|-------------------------------------------------------------------------|
| enumtop-t01 | 7 6 | 105 | 2 | 1 MB / 117 MB |
|-------------------------------------------------------------------------|
| enumtop-t02 | 8 9 | 280 | 4 | 1 MB / 117 MB |
|-------------------------------------------------------------------------|
| enumtop-t03 | 8 11 | 118 | 3 | 1 MB / 117 MB |
|-------------------------------------------------------------------------|
| enumtop-t04 | 10 30 | 20 | 2 | 1 MB / 117 MB |
|-------------------------------------------------------------------------|
| enumtop-t05 | 20 100 | 3864 | 14 | 3 MB / 117 MB |
|-------------------------------------------------------------------------|
| enumtop-t06 | 30 300 | 107136 | 60 | 7 MB / 117 MB |
|-------------------------------------------------------------------------|
| enumtop-t07 | 40 500 | 38052 | 31 | 5 MB / 117 MB |
|-------------------------------------------------------------------------|
| enumtop-t08 | 50 800 | 6193152 | 1390 | 7 MB / 117 MB |
|-------------------------------------------------------------------------|
| enumtop-t09 | 50 900 | 552960 | 653 | 4 MB / 117 MB |
|-------------------------------------------------------------------------|
| enumtop-t10 | 100 4000 | 29160 | 612 | 12 MB / 117 MB |
|-------------------------------------------------------------------------|
| enumtop-t11 | 200 18000 | 768000 | 2512 | 22 MB / 147 MB |
+-------------------------------------------------------------------------+
NOTE:
|V|: Number of Vertices in the Graph
|E|: Number of Edges in the Graph
Output: Total number of all valid permutations of Topological Orderings
Refer Results/lp4-enumtop.txt as obtained from
$ ./lp4-enumtop.sh > lp4-enumtop.txt
_______________________________________________________________________________
# PERT:
$ java rsn170330.PERT false rsn170330/lp4-test/pert-t04.txt
+-------------------------------------------------------------------------+
| File | |V| |E| | Output | Time (mSec) | Memory (used/avail) |
|-------------------------------------------------------------------------|
| pert-t01 | 102 300 | 183 20 | 5 | 2 MB / 117 MB |
|-------------------------------------------------------------------------|
| pert-t02 | 52 1200 | 98 52 | 6 | 4 MB / 117 MB |
|-------------------------------------------------------------------------|
| pert-t03 | 102 1000 | 97 34 | 5 | 4 MB / 117 MB |
|-------------------------------------------------------------------------|
| pert-t04 | 502 675 | 89 64 | 9 | 3 MB / 117 MB |
|-------------------------------------------------------------------------|
| pert-t05 | 1002 1166 | 61 46 | 12 | 5 MB / 117 MB |
|-------------------------------------------------------------------------|
| pert-t06 | 502 6000 | 596 57 | 12 | 16 MB / 117 MB |
|-------------------------------------------------------------------------|
| pert-t07 | 502 6000 | 84 65 | 11 | 16 MB / 117 MB |
|-------------------------------------------------------------------------|
| pert-t08 | 1002 6000 | 99 26 | 12 | 17 MB / 117 MB |
|-------------------------------------------------------------------------|
| pert-t09 | 1002 6000 | 323 42 | 14 | 17 MB / 117 MB |
+-------------------------------------------------------------------------+
NOTE:
Output: x y
x: Minimum Time needed to complete the Project/ Critical Path Length
y: Number of Critical Nodes in the Graph
Refer Results/lp4-pert.txt as obtained from
$ ./lp4-pert.sh > lp4-pert.txt
NOTE:
- Time and Memory might change, as you run the test the program on a
different system, but they could be comparable to the above values.
Existing Processor: Intel® Core™ i5-8250U CPU @ 1.60GHz × 8
Memory: 7.5 GiB
- EnumeratePath.java consist of extended version of this project where
all paths from source (first vertex) to sink (last vertex) could be
enumerated using two algorithms - with and without Selector/ Approver.
NOTE: It uses VertexStack<T> of itself instead of java Stack.
_______________________________________________________________________________
# HOW TO RUN:
1. Extract the rsn170330.zip
2. Compile:
$ javac rsn170330/*.java
3. Run:
[a] Enumerate.java:
$ java rsn170330.Enumerate n k
where combinations = nCk, permutations = nPk, i.e.
n :- number of distinct elements
k :- number of elements to choose from n
NOTE: by default n = 4, k = 3
-----------------------------------------------------------------------------
[b] EnumerateTopological:
$ java rsn170330.EnumerateTopological [arg0] [arg1]
$ java rsn170330.EnumerateTopological 0 rsn170330/lp4-test/enumtop-t08.txt
[arg0] :- true for verbose i.e. to print all topological orders, otherwise no
enumeration of topological orders
[arg1] :- file containing the graph
NOTE: by default, verbose = false and it has a simple graph in it's main()
-----------------------------------------------------------------------------
[c] EnumeratePath:
$ java rsn170330.EnumeratePath [arg0] [arg1]
$ java rsn170330.EnumeratePath 1
[arg0] :- true for verbose i.e. to print all paths, otherwise no enumeration of
paths
[arg1] :- file containing the graph.
NOTE: by default, verbose = false and it has a simple graph in it's main()
-----------------------------------------------------------------------------
[d] PERT:
$ java rsn170330.PERT [arg0] [arg1]
$ java rsn170330.PERT false rsn170330/lp4-test/pert-t04.txt
[arg0] :- true for details i.e. to print the PERT chart, otherwise no chart
[arg1] :- file containing the graph.
NOTE: by default, details = false and it has a simple graph in it's main()
-----------------------------------------------------------------------------
NOTE: the current directory must contain rbk directory with rbk/Graph.java
_______________________________________________________________________________