-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDriver.java
More file actions
161 lines (116 loc) · 5.04 KB
/
Copy pathDriver.java
File metadata and controls
161 lines (116 loc) · 5.04 KB
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
/*
Driver
Bruk Mulatu
COSC 2203
Assignment : Can It Be Done?
Due Date: November 18, 2020
Approved by: Robel Tadele
*/
import java.util.Scanner;
public class Driver {
public static void main(String [] args) {
Scanner input = new Scanner(System.in);// Scanner
//Setting boolean value
boolean feasibility = true;
//Declaring matrix array
int[][] matrix;
int numStages = 0; // Node number
int stageColumn = 0; // Store adjacency size
int outgoingEdges = 0;// Store outgoing edges
String critical; // String for critical activities
int[] stageValue; // Declare current node or vertices
int [] earlyActivity;
int [] lateActivity;
int[] edgesIn; //Store the number of edges going into a stage
int [] topArray;
int [] est;
int [] lst;
int edgesInCount = 0; //Count the number of edges in a column
int activityCount = 0;
int currentColumn = 0;
System.out.println("This program creates an Activity on Edge digraph");
System.out.println("Enter the input as specified in the programming guidelines: ");
numStages = input.nextInt(); // Input the number of stages(vertices)
//Array to store value of nodes
stageValue = new int[numStages];
//Setting the matrix size
matrix = new int[numStages][numStages];
//Store the number of edges going into a stage
edgesIn = new int[numStages];
//Input a value that makes all values negative before replacing them later
for (int i = 0; i < numStages; i++) {
for (int j = 0; j < numStages; j++) {
matrix[i][j] = -1; //Random negative value to replicate infinity
}
}
//For loop that runs for the number of stages
for (int i = 0; i < numStages; i++) {
//Store the stage values in an array
stageValue[i] = input.nextInt();
outgoingEdges = input.nextInt();
//for loop that runs for the number of edges
for (int j = 0; j < outgoingEdges; j++) {
stageColumn = input.nextInt();
//Store value in stage column minus 1 since array starts at 0
matrix[i][stageColumn-1] = input.nextInt();
}
}
for (currentColumn = 0; currentColumn < numStages; currentColumn++){
edgesInCount = 0;
int j = currentColumn;
for (int i = 0; i < numStages; i++) {
if (!(matrix[i][j] == -1)) {
edgesInCount++;
activityCount++;
}
}
edgesIn[j] = edgesInCount;
}
GraphClass graph = new GraphClass(matrix,edgesIn); // Create graph object
//Calling topological method and storing it in an array
topArray = graph.topOrder(stageValue);
//Check if graph is feasible
feasibility = graph.isFeasible();
System.out.println();
//Print feasibility statements
if (feasibility){
System.out.println("Project is Feasible");
} else {
System.out.println("Project is not feasible");
System.exit(0);
}
//Set early stage time
est = graph.setEarlyStage(topArray, stageValue);
// Set late stage time and pass the total weight
lst = graph.setLateStage(est[est.length-1],topArray,stageValue);
earlyActivity = graph.setEarlyActivity(activityCount, stageValue.length, est);
lateActivity = graph.setLateActivity(lst,stageValue.length ,activityCount );
critical = graph.criticalActivities(lateActivity, earlyActivity);
/*--- Output ---*/
// Print topological order
System.out.println();
System.out.print("Ordering: ");
for (int i = 0; i <topArray.length; i++) {
System.out.print(topArray[i] + " ");
}
System.out.println();
System.out.println();
System.out.println("Stage Early Late");
for (int i = 0; i < lst.length; i++) {
//System.out.println(i+1 + " " + est[topArray[i]]);
if(i+1 == topArray[i])
System.out.println(i+1 + " " + est[topArray[i]-1] + " " + lst[topArray[i]-1]);
else
System.out.println(i+1 + " " + est[i] + " " + lst[i]);
}
System.out.println();
System.out.println("Total Project Time: " + est[est.length-1]);
System.out.println();
System.out.println("Activity Early Late");
for (int i = 0; i <earlyActivity.length ; i++) {
System.out.println(i+1 + " " + earlyActivity[i] + " " + lateActivity[i]);
}
System.out.println();
System.out.println("Critical Activities: " + critical);
}
}