1 | package simulator.stats; |
---|
2 | |
---|
3 | |
---|
4 | |
---|
5 | import java.io.File; |
---|
6 | import java.io.FileOutputStream; |
---|
7 | import java.io.IOException; |
---|
8 | import java.io.PrintStream; |
---|
9 | import java.util.ArrayList; |
---|
10 | import java.util.List; |
---|
11 | |
---|
12 | import gridsim.Accumulator; |
---|
13 | |
---|
14 | |
---|
15 | public class AccumulatedStatistics { |
---|
16 | |
---|
17 | protected static final String ACCUMULATED_SIMULATIONS_STATISTICS_OUTPUT_FILE_NAME = "Stats_Accumulated_Simulations.txt"; |
---|
18 | |
---|
19 | protected List<SimulationStatistics> simulations; |
---|
20 | |
---|
21 | public AccumulatedStatistics(int noOfSimulations) { |
---|
22 | simulations = new ArrayList<SimulationStatistics>(noOfSimulations); |
---|
23 | } |
---|
24 | |
---|
25 | public AccumulatedStatistics() { |
---|
26 | simulations = new ArrayList<SimulationStatistics>(); |
---|
27 | } |
---|
28 | |
---|
29 | public void add(SimulationStatistics simulationStatistics) { |
---|
30 | simulations.add(simulationStatistics); |
---|
31 | } |
---|
32 | |
---|
33 | public void saveStatistics() { |
---|
34 | |
---|
35 | SimulationStatistics simulationStatisticsNew = simulations.get(0); |
---|
36 | |
---|
37 | if(!simulationStatisticsNew.accumulatedStats()) |
---|
38 | return; |
---|
39 | String dirName = simulationStatisticsNew.getOutputFolderName(); |
---|
40 | if(dirName == null) |
---|
41 | return; |
---|
42 | |
---|
43 | PrintStream out = null; |
---|
44 | try { |
---|
45 | File file = new File(dirName + ACCUMULATED_SIMULATIONS_STATISTICS_OUTPUT_FILE_NAME); |
---|
46 | out = new PrintStream(new FileOutputStream(file)); |
---|
47 | } catch (IOException e) { |
---|
48 | e.printStackTrace(); |
---|
49 | } |
---|
50 | |
---|
51 | DCwormsAccumulator resourceLoad = getAccumulatedResourceLoad(); |
---|
52 | DCwormsAccumulator reservationLoad = getAccumulatedReservationLoad(); |
---|
53 | DCwormsAccumulator makespan = getAccumulatedMakespan(); |
---|
54 | DCwormsAccumulator taskExecutionTime = getAccumulatedJobExecutionTime(); |
---|
55 | DCwormsAccumulator taskQueueLength = getAccumulatedQueueJobCount(); |
---|
56 | DCwormsAccumulator taskCompletionTime = getAccumulatedCompletionTime(); |
---|
57 | DCwormsAccumulator taskWaitingTime = getAccumulatedWaitingTime(); |
---|
58 | DCwormsAccumulator taskFlowTime = getAccumulatedJobFlowTime(); |
---|
59 | DCwormsAccumulator taskLateness = getAccumulatedLateness(); |
---|
60 | DCwormsAccumulator delayedTasks = getAccumulatedDelayedTasks(); |
---|
61 | DCwormsAccumulator taskTardiness = getAccumulatedTardiness(); |
---|
62 | DCwormsAccumulator failedRequests = getAccumulatedFailedRequests(); |
---|
63 | |
---|
64 | out.print("Delayed tasks (accumulated)"); |
---|
65 | out.println(delayedTasks); |
---|
66 | out.print("Failed requests (accumulated)"); |
---|
67 | out.println(failedRequests); |
---|
68 | out.print("Makespan (accumulated)"); |
---|
69 | out.println(makespan); |
---|
70 | out.print("Resources queue length (accumulated)"); |
---|
71 | out.println(taskQueueLength); |
---|
72 | out.print("Mean (accumulated) resource load"); |
---|
73 | out.println(resourceLoad); |
---|
74 | out.print("Mean (accumulated) reservation load"); |
---|
75 | out.println(reservationLoad); |
---|
76 | out.print("Task completion time (accumulated)"); |
---|
77 | out.println(taskCompletionTime); |
---|
78 | out.print("Task execution time (accumulated)"); |
---|
79 | out.println(taskExecutionTime); |
---|
80 | out.print("Task flow time (accumulated)"); |
---|
81 | out.println(taskFlowTime); |
---|
82 | out.print("Task waiting time (accumulated)"); |
---|
83 | out.println(taskWaitingTime); |
---|
84 | out.print("Task lateness (accumulated)"); |
---|
85 | out.println(taskLateness); |
---|
86 | out.print("Task tardiness (accumulated)"); |
---|
87 | out.println(taskTardiness); |
---|
88 | out.println(); |
---|
89 | out.close(); |
---|
90 | } |
---|
91 | |
---|
92 | public DCwormsAccumulator getAccumulatedResourceLoad() { |
---|
93 | DCwormsAccumulator resourceMeanLoad = new DCwormsAccumulator(); |
---|
94 | for (SimulationStatistics simStat : simulations) { |
---|
95 | DCwormsAccumulator simulationResTotalLoad = simStat.getStats(SimulationStatistics.RESOURCES_TOTAL_LOAD); |
---|
96 | resourceMeanLoad.add(simulationResTotalLoad.getMean()); |
---|
97 | } |
---|
98 | return resourceMeanLoad; |
---|
99 | } |
---|
100 | |
---|
101 | public DCwormsAccumulator getAccumulatedReservationLoad(){ |
---|
102 | DCwormsAccumulator reservationMean = new DCwormsAccumulator(); |
---|
103 | for (SimulationStatistics simStat : simulations) { |
---|
104 | Accumulator simulationResvTotalLoad = simStat.getStats(SimulationStatistics.RESOURCES_RESERVATION_LOAD); |
---|
105 | reservationMean.add(simulationResvTotalLoad.getMean()); |
---|
106 | } |
---|
107 | return reservationMean; |
---|
108 | } |
---|
109 | |
---|
110 | /*public GSSAccumulator getAccumulatedBokrerThroughput() { |
---|
111 | GSSAccumulator meanThroughput = new GSSAccumulator(); |
---|
112 | |
---|
113 | for (SimulationStatisticsNew simStat : simulations) { |
---|
114 | double simulationMeanThroughput = simStat.getBrokerStats().average(Sim_stat.THROUGHPUT); |
---|
115 | meanThroughput.add(simulationMeanThroughput); |
---|
116 | } |
---|
117 | return meanThroughput; |
---|
118 | }*/ |
---|
119 | |
---|
120 | public DCwormsAccumulator getAccumulatedJobFlowTime() { |
---|
121 | DCwormsAccumulator meanJobFlowTime = new DCwormsAccumulator(); |
---|
122 | for (SimulationStatistics simStat : simulations) { |
---|
123 | Accumulator simulationJobFlowTime = simStat.getStats(SimulationStatistics.TASK_FLOW_TIME); |
---|
124 | meanJobFlowTime.add(simulationJobFlowTime.getMean()); |
---|
125 | } |
---|
126 | return meanJobFlowTime; |
---|
127 | } |
---|
128 | |
---|
129 | public DCwormsAccumulator getAccumulatedLateness() { |
---|
130 | DCwormsAccumulator meanLateness = new DCwormsAccumulator(); |
---|
131 | for (SimulationStatistics simStat : simulations) { |
---|
132 | Accumulator simulationLateness = simStat.getStats(SimulationStatistics.TASK_LATENESS); |
---|
133 | meanLateness.add(simulationLateness.getMean()); |
---|
134 | } |
---|
135 | return meanLateness; |
---|
136 | } |
---|
137 | |
---|
138 | public DCwormsAccumulator getAccumulatedFailedRequests() { |
---|
139 | DCwormsAccumulator meanFailedRequests = new DCwormsAccumulator(); |
---|
140 | for (SimulationStatistics simStat : simulations) { |
---|
141 | Accumulator simulationFailedRequestes = simStat.getStats(SimulationStatistics.FAILED_REQUESTS); |
---|
142 | meanFailedRequests.add(simulationFailedRequestes.getMean()); |
---|
143 | } |
---|
144 | return meanFailedRequests; |
---|
145 | } |
---|
146 | |
---|
147 | public DCwormsAccumulator getAccumulatedTardiness() { |
---|
148 | DCwormsAccumulator meanTardiness = new DCwormsAccumulator(); |
---|
149 | for (SimulationStatistics simStat : simulations) { |
---|
150 | Accumulator simulationJobTardiness = simStat.getStats(SimulationStatistics.TASK_TARDINESS); |
---|
151 | meanTardiness.add(simulationJobTardiness.getMean()); |
---|
152 | } |
---|
153 | return meanTardiness; |
---|
154 | } |
---|
155 | |
---|
156 | public DCwormsAccumulator getAccumulatedDelayedTasks() { |
---|
157 | DCwormsAccumulator delayedTasks = new DCwormsAccumulator(); |
---|
158 | for (SimulationStatistics simStat : simulations) { |
---|
159 | Accumulator simulationDelayedTasks = simStat.getStats(SimulationStatistics.DELAYED_TASKS); |
---|
160 | delayedTasks.add(simulationDelayedTasks.getMean()); |
---|
161 | } |
---|
162 | return delayedTasks; |
---|
163 | } |
---|
164 | |
---|
165 | public DCwormsAccumulator getAccumulatedCompletionTime() { |
---|
166 | DCwormsAccumulator meanJobCompletionTime = new DCwormsAccumulator(); |
---|
167 | |
---|
168 | for (SimulationStatistics simStat : simulations) { |
---|
169 | Accumulator simulationJobTurnaroundTime = simStat.getStats(SimulationStatistics.TASK_COMPLETION_TIME); |
---|
170 | meanJobCompletionTime.add(simulationJobTurnaroundTime.getMean()); |
---|
171 | } |
---|
172 | return meanJobCompletionTime; |
---|
173 | } |
---|
174 | |
---|
175 | public DCwormsAccumulator getAccumulatedMakespan() { |
---|
176 | DCwormsAccumulator meanMakespan = new DCwormsAccumulator(); |
---|
177 | for (SimulationStatistics simStat : simulations) { |
---|
178 | meanMakespan.add(simStat.getStats(SimulationStatistics.MAKESPAN).getMean()); |
---|
179 | } |
---|
180 | return meanMakespan; |
---|
181 | } |
---|
182 | |
---|
183 | public DCwormsAccumulator getAccumulatedWaitingTime() { |
---|
184 | DCwormsAccumulator meanWaitingTime = new DCwormsAccumulator(); |
---|
185 | for (SimulationStatistics simStat : simulations) |
---|
186 | meanWaitingTime.add(simStat.getStats(SimulationStatistics.TASK_WAITING_TIME).getMean()); |
---|
187 | return meanWaitingTime; |
---|
188 | } |
---|
189 | |
---|
190 | public DCwormsAccumulator getAccumulatedJobExecutionTime() { |
---|
191 | DCwormsAccumulator meanJobExecutionTime = new DCwormsAccumulator(); |
---|
192 | for (SimulationStatistics simStat : simulations) |
---|
193 | meanJobExecutionTime.add(simStat.getStats(SimulationStatistics.TASK_EXECUTION_TIME).getMean()); |
---|
194 | return meanJobExecutionTime; |
---|
195 | } |
---|
196 | |
---|
197 | public DCwormsAccumulator getAccumulatedQueueJobCount() { |
---|
198 | DCwormsAccumulator meanQueuJobCount = new DCwormsAccumulator(); |
---|
199 | for (SimulationStatistics simStat : simulations) |
---|
200 | meanQueuJobCount.add(simStat.getStats(SimulationStatistics.RESOURCES_QUEUE_LENGTH).getMean()); |
---|
201 | return meanQueuJobCount; |
---|
202 | } |
---|
203 | |
---|
204 | } |
---|