You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Function which computes the cost of process scheduling to a number of VMs.
37
+
*/
38
+
publicvoidexecute(){
39
+
this.calculateCost();
40
+
this.showResults();
41
+
}
42
+
43
+
/**
44
+
* Function which computes the cost of running each Process to each and every Machine
45
+
*/
46
+
privatevoidcalculateCost(){
47
+
48
+
for (inti=0; i < numberProcesses; i++){ //for each Process
49
+
50
+
for (intj=0; j < numberMachines; j++) { //for each Machine
51
+
52
+
Cost[i][j] = runningCost(i, j);
53
+
}
54
+
}
55
+
}
56
+
57
+
/**
58
+
* Function which returns the minimum cost of running a certain Process to a certain Machine.In order for the Machine to execute the Process ,he requires the output
59
+
* of the previously executed Process, which may have been executed to the same Machine or some other.If the previous Process has been executed to another Machine,we
60
+
* have to transfer her result, which means extra cost for transferring the data from one Machine to another(if the previous Process has been executed to the same
61
+
* Machine, there is no transport cost).
62
+
*
63
+
* @param process ,refers to the Process
64
+
* @param machine ,refers to the Machine
65
+
* @return the minimum cost of executing the process to the certain machine.
66
+
*/
67
+
privateintrunningCost(intprocess, intmachine) {
68
+
69
+
if (process==0) //refers to the first process,which does not require for a previous one to have been executed
70
+
returnRun[process][machine];
71
+
else {
72
+
73
+
int[] runningCosts = newint[numberMachines]; //stores the costs of executing our Process depending on the Machine the previous one was executed
74
+
75
+
for (intk=0; k < numberMachines; k++) //computes the cost of executing the previous process to each and every Machine
76
+
runningCosts[k] = Cost[process-1][k] + Transfer[k][machine] + Run[process][machine]; //transferring the result to our Machine and executing the Process to our Machine
77
+
78
+
returnfindMin(runningCosts); //returns the minimum running cost
79
+
}
80
+
}
81
+
82
+
/**
83
+
* Function used in order to return the minimum Cost.
84
+
* @param cost ,an Array of size M which refers to the costs of executing a Process to each Machine
85
+
* @return the minimum cost
86
+
*/
87
+
privateintfindMin(int[] cost) {
88
+
89
+
intmin=0;
90
+
91
+
for (inti=1;i<cost.length;i++){
92
+
93
+
if (cost[i]<cost[min])
94
+
min=i;
95
+
}
96
+
returncost[min];
97
+
}
98
+
99
+
/**
100
+
* Method used in order to present the overall costs.
101
+
*/
102
+
privatevoidshowResults(){
103
+
104
+
for (inti=0; i < numberProcesses; i++){
105
+
106
+
for (intj=0; j < numberMachines; j++) {
107
+
System.out.print(Cost[i][j]);
108
+
System.out.print(" ");
109
+
}
110
+
111
+
System.out.println();
112
+
}
113
+
System.out.println();
114
+
}
115
+
116
+
/**
117
+
* Getter for the running Cost of i process on j machine.
0 commit comments