@@ -25,7 +25,7 @@ public class SimulatorBenchmark implements Simulator, Runnable {
2525 private SimulationCache mySimulationCache = null ;
2626 private ArrayList <SimulationType > myListOfSimulations = null ;
2727//private int simulationCounter=0;
28- private String logFileName ;
28+ private final String logFileName ;
2929 private typeOfBenchmarkFunction benchmarkFunction = typeOfBenchmarkFunction .Sphere ;
3030 int status = 0 ;
3131 boolean log = true ;
@@ -42,8 +42,9 @@ public SimulatorBenchmark() {
4242
4343 /**
4444 * inits and starts the simulation, this is neccessary and must be
45- * implemented In Benchmark we don`t use a local cache Ackley, Rosenbrock,
46- * Schwefel, Rastrigin: source from Le Minh Nghia, NTU-Singapore Parts of
45+ * implemented
46+ * In Benchmark we don`t use a local cache
47+ * Ackley, Rosenbrock, Schwefel, Rastrigin: source from Le Minh Nghia, NTU-Singapore Parts of
4748 * other functions are isp. by http://fossies.org/dox/cilib-0.7.6
4849 *
4950 * @param listOfParameterSetsTMP List of Parametersets to be simulated
@@ -52,6 +53,7 @@ public SimulatorBenchmark() {
5253 * @param log write special log file for this simulator. true: write log
5354 * file, false: dont write log file
5455 */
56+ @ Override
5557 public void initSimulator (ArrayList <ArrayList <parameter >> listOfParameterSetsTMP , int simulationCounterTMP , boolean log ) {
5658 this .log = log ;
5759 //this.simulationCounter=simulationCounterTMP;
@@ -65,6 +67,7 @@ public void initSimulator(ArrayList<ArrayList<parameter>> listOfParameterSetsTMP
6567 *
6668 * @return % of simulatiions that are finished
6769 */
70+ @ Override
6871 public int getStatus () {
6972 return this .status ;
7073 }
@@ -74,6 +77,7 @@ public int getStatus() {
7477 *
7578 * @return actual simulation counter
7679 */
80+ @ Override
7781 public int getSimulationCounter () {
7882 return support .getGlobalSimulationCounter ();
7983 }
@@ -85,6 +89,7 @@ public int getSimulationCounter() {
8589 * @return list of completed simulations (parsers) which contain all data
8690 * from the log-files
8791 */
92+ @ Override
8893 public ArrayList <SimulationType > getListOfCompletedSimulationParsers () {
8994 return this .myListOfSimulations ;
9095 }
@@ -149,8 +154,9 @@ public static double getCPUTime(double confidenceIntervall, double maxRelError)
149154 /**
150155 * Main Method for thread, called with Thread.start()
151156 */
157+ @ Override
152158 public void run () {
153- myListOfSimulations = new ArrayList <SimulationType >();
159+ myListOfSimulations = new ArrayList <>();
154160 support .log ("Number of Benchmark-Simulations to do: " + listOfParameterSetsTMP .size ());
155161 for (int i = 0 ; i < this .listOfParameterSetsTMP .size (); i ++) {
156162 support .setStatusText ("Simulating: " + (i + 1 ) + "/" + listOfParameterSetsTMP .size ());
@@ -163,191 +169,7 @@ public void run() {
163169 //Print out a log file
164170 support .addLinesToLogFileFromListOfParser (myListOfSimulations , logFileName );
165171 }
166- this .status = 100 ;
167-
168- // /*
169- // double limitLower = -5.0, limitUpper = 5.0;//The limits of the used benchmark function
170- //
171- // switch (benchmarkFunction) {
172- // case Ackley:
173- // limitLower = support.DEFAULT_ACKLEY_limitLower;
174- // limitUpper = support.DEFAULT_ACKLEY_limitupper;
175- // break;
176- // /*case Rosenbrock:
177- // limitLower=-5.0;
178- // limitUpper=5.0;
179- // break;*/
180- // case Sphere:
181- // limitLower = support.DEFAULT_Sphere_limitLower;
182- // limitUpper = support.DEFAULT_Sphere_limitupper;
183- // break;
184- // case Matya:
185- // limitUpper = support.DEFAULT_Matya_limitLower;
186- // limitLower = support.DEFAULT_Matya_limitupper;
187- // break;
188- // /*case Easom:
189- // limitUpper=100.0;
190- // limitLower=-100.0;
191- // break;*/
192- // case Schwefel:
193- // limitUpper = support.DEFAULT_Schwefel_limitLower;
194- // limitLower = support.DEFAULT_Schwefel_limitupper;
195- // break;
196- // case Rastrigin:
197- // limitLower = support.DEFAULT_Rastrigin_limitLower;
198- // limitUpper = support.DEFAULT_Rastrigin_limitupper;
199- // break;
200- //
201- // default:
202- // break;
203- // }
204- //
205- // myListOfSimulations = new ArrayList<SimulationType>();
206- //
207- // for (int i = 0; i < listOfParameterSetsTMP.size(); i++) {
208- // SimulationType tmpSimulation = new SimulationType();
209- // ArrayList<parameter> tmpParameterList = listOfParameterSetsTMP.get(i);
210- // ArrayList<parameter> tmpListOfChangableParameter = support.getListOfChangableParameters(tmpParameterList);
211- //
212- // //set indicator
213- // support.setStatusText("Simulating: " + (i + 1) + "/" + listOfParameterSetsTMP.size());
214- //
215- // double sum;
216- // int dimension = tmpListOfChangableParameter.size();
217- // double xNew;
218- // double x[] = new double[dimension];
219- // double value;
220- // for (int c = 0; c < dimension; c++) {
221- // parameter p = tmpListOfChangableParameter.get(c);
222- // value = p.getValue();
223- // p = support.getParameterByName(support.getOriginalParameterBase(), p.getName());
224- // //Check Range and align the value to map constraints
225- // //p.printInfo();
226- // xNew = (value - p.getStartValue()) / (p.getEndValue() - p.getStartValue());
227- // x[c] = xNew * (limitUpper - limitLower) + limitLower;
228- // }
229- //
230- // //support.log(dimension+" parameter out of "+tmpParameterList.size()+" are changable.");
231- // /*if(dimension<2){
232- // support.log("New Dimension is smaller, check details of Paramaters.");
233- // for(int ci=0;ci<tmpParameterList.size();ci++){
234- // parameter p=tmpParameterList.get(ci);
235- // p.printInfo();
236- // }
237- // }*/
238- // switch (benchmarkFunction) {
239- // case Ackley:
240- // //source of this part is from Le Minh Nghia, NTU-Singapore
241- // double sum1 = 0.0;
242- // double sum2 = 0.0;
243- // for (int d = 0; d < x.length; d++) {
244- // sum1 += (x[d] * x[d]);
245- // sum2 += (Math.cos(2 * Math.PI * x[d]));
246- // }//end of for-d-loop
247- // sum = (-20.0 * Math.exp(-0.2 * Math.sqrt(sum1 / ((double) x.length))) - Math.exp(sum2 / ((double) x.length)) + 20.0 + Math.E);
248- // break;
249- // /*case Rosenbrock:
250- // //source of this part is from Le Minh Nghia, NTU-Singapore
251- // double [] v = new double[x.length];
252- // for (int i1 = 0; i1 < x.length; i1++) v[i1] = x[i1] + 1;
253- // for (int i1 = 0 ; i1 < (x.length-1) ; i1 ++) {
254- // double temp1 = (v[i1] * v[i1]) - v[i1+1];
255- // double temp2 = v[i1] - 1.0;
256- // sum += (100.0 * temp1 * temp1) + (temp2 * temp2);
257- // }
258- // break;*/
259- // case Sphere:
260- // sum = 0.0;
261- // for (int c = 0; c < dimension; c++) {
262- // parameter p = tmpListOfChangableParameter.get(c);
263- // value = p.getValue();
264- // p = support.getParameterByName(support.getOriginalParameterBase(), p.getName());
265- // //Check Range and align the value to map constraints
266- // xNew = (value - p.getStartValue()) / (p.getEndValue() - p.getStartValue());
267- // xNew = xNew * (limitUpper - limitLower) + limitLower;
268- // sum += (xNew * xNew);
269- // }//End of for-c-loop
270- // break;
271- //
272- // case Matya:
273- // if (dimension != 2) {
274- // support.log("Matya is only defined for 2 dimensions");
275- // return;
276- // }
277- // double x0 = x[0];
278- // double x1 = x[1];
279- // sum = 0.26 * (x0 * x0 + x1 * x1) - 0.48 * x0 * x1;
280- // break;
281- //
282- // case Schwefel:
283- // //source of this part is from Le Minh Nghia, NTU-Singapore
284- // //Schwefel's problem 1.2 - Unimodal
285- // //Global optimum: f = 0 at x[] = 0
286- // double prev_sum,
287- // curr_sum,
288- // outer_sum;
289- // curr_sum = x[0];
290- // outer_sum = (curr_sum * curr_sum);
291- // for (int i1 = 1; i1 < x.length; i1++) {
292- // prev_sum = curr_sum;
293- // curr_sum = prev_sum + x[i1];
294- // outer_sum += (curr_sum * curr_sum);
295- // }
296- // sum = outer_sum;
297- // break;
298- //
299- // case Rastrigin:
300- // //source of this part is from Le Minh Nghia, NTU-Singapore
301- // //Multimodal - x [-5,5], global - 0 at x[] = 0
302- // double res = 10 * x.length;
303- // for (int i1 = 0; i1 < x.length; i1++) {
304- // res += x[i1] * x[i1]
305- // - 10 * Math.cos(2 * Math.PI * x[i1]);
306- // }
307- // sum = res;
308- // break;
309- //
310- // /*case Easom:
311- // if(dimension!=2){
312- // support.log("Easom is only defined for 2 dimensions");
313- // return;
314- // }
315- // double powerTerm1 = -((x[0]-Math.PI)*(x[0]-Math.PI));
316- // double powerTerm2 = -((x[1]-Math.PI)*(x[1]-Math.PI));
317- // double power = powerTerm1 + powerTerm2;
318- // sum = -Math.cos(x[0]) * Math.cos(x[1]) * Math.exp(power);
319- // break;
320- // */
321- // default:
322- // sum = 0.0;
323- // break;
324- // }
325- //
326- // ArrayList<MeasureType> tmpListOfMeasurements = ((MeasurementForm) support.getMeasureFormPane().getComponentAt(0)).getMeasurements();
327- // //All Measure will have the same result value
328- //
329- // ArrayList<MeasureType> newListOfMeasurements = new ArrayList<MeasureType>();
330- //
331- // for (int d = 0; d < tmpListOfMeasurements.size(); d++) {
332- // //make deep copy of old Measurement
333- // MeasureType tmpMeasurement = new MeasureType(tmpListOfMeasurements.get(d));
334- // tmpMeasurement.setAccuraryReached(true);
335- // tmpMeasurement.setMeanValue(sum);
336- // //TODO fill out all other imformation
337- // newListOfMeasurements.add(tmpMeasurement);
338- // tmpMeasurement.setCPUTime(2.22);
339- //
340- // }//end of for-d-loop
341- //
342- // tmpSimulation.setListOfParameters(tmpParameterList);
343- // tmpSimulation.setMeasures(newListOfMeasurements);
344- // myListOfSimulations.add(tmpSimulation);
345- // support.incGlobalSimulationCounter();
346- //
347- // this.status = (100 / listOfParameterSetsTMP.size()) * i;
348- // }//End of for-i-loop
349- // this.status = 100;
350- //
172+ this .status = 100 ;
351173 }
352174
353175 /**
@@ -357,89 +179,10 @@ public void run() {
357179 * @param targetMeasure Measure that should be optimized
358180 * @return calculated optimum (for given measure)
359181 */
182+ @ Override
360183 public SimulationType getCalculatedOptimum (MeasureType targetMeasure ) {
361184
362185 return BenchmarkFactory .getBenchmarkFunction ().getOptimumSimulation ();
363-
364- // support.log("SimulatorBenchmark: Getting absolute optimum simulation from Benchmark-Function.");
365- // ArrayList<parameter> optimumParameterlist = support.getCopyOfParameterSet(support.getOriginalParameterBase());
366- // ArrayList<parameter> optimumChangableParameterset = support.getListOfChangableParameters(optimumParameterlist);
367- //
368- // //Create dummy-Simulation with optimum-Measure
369- // SimulationType myOptimumSimulation = new SimulationType();
370- //
371- // ArrayList<MeasureType> tmpListOfMeasurements = support.getMainFrame().getListOfActiveMeasureMentsToOptimize();
372- // //All Measure will have the same result value
373- //
374- // ArrayList<MeasureType> newListOfMeasurements = new ArrayList<MeasureType>();
375- // for (int d = 0; d < tmpListOfMeasurements.size(); d++) {
376- // //make deep copy of old Measurement
377- // MeasureType tmpMeasurement = new MeasureType(tmpListOfMeasurements.get(d));
378- // tmpMeasurement.setAccuraryReached(true);
379- // //Meanvalue is given by original Measure
380- // tmpMeasurement.setCPUTime(0);
381- // newListOfMeasurements.add(tmpMeasurement);
382- // }//end of for-d-loop
383- // switch (benchmarkFunction) {
384- // case Ackley:
385- // //Optimum is in the middle of each parameter, its exact at 0,0
386- // for (int i = 0; i < optimumChangableParameterset.size(); i++) {
387- // parameter p = optimumChangableParameterset.get(i);
388- // p.setValue(p.getEndValue() - ((p.getEndValue() - p.getStartValue()) / 2));
389- // }
390- //
391- // break;
392- // /*case Rosenbrock:
393- // //TODO remove this function
394- // support.log("No Optimum is calculated for Rosenbrock!");
395- // break;
396- // */
397- // case Sphere:
398- // //Optimum is in the middle of each parameter, its exact at 0,0
399- // for (int i = 0; i < optimumChangableParameterset.size(); i++) {
400- // parameter p = optimumChangableParameterset.get(i);
401- // p.setValue(p.getEndValue() - ((p.getEndValue() - p.getStartValue()) / 2));
402- // }
403- // break;
404- //
405- // case Matya:
406- // //Optimum is in the middle of each parameter, its exact at 0,0
407- // for (int i = 0; i < optimumChangableParameterset.size(); i++) {
408- // parameter p = optimumChangableParameterset.get(i);
409- // p.setValue(p.getEndValue() - ((p.getEndValue() - p.getStartValue()) / 2));
410- // }
411- // break;
412- //
413- // case Schwefel:
414- // //Optimum is in the middle of each parameter, its exact at 0,0
415- // for (int i = 0; i < optimumChangableParameterset.size(); i++) {
416- // parameter p = optimumChangableParameterset.get(i);
417- // p.setValue(p.getEndValue() - ((p.getEndValue() - p.getStartValue()) / 2));
418- // }
419- // break;
420- //
421- // case Rastrigin:
422- // //Optimum is in the middle of each parameter, its exact at 0,0
423- // for (int i = 0; i < optimumChangableParameterset.size(); i++) {
424- // parameter p = optimumChangableParameterset.get(i);
425- // p.setValue(p.getEndValue() - ((p.getEndValue() - p.getStartValue()) / 2));
426- // }
427- // break;
428- //
429- // /*case Easom:
430- // //TODO remove this function
431- // support.log("No Optimum is calculated for Easom!");
432- // break;
433- // */
434- // default:
435- //
436- // break;
437- // }
438- //
439- // myOptimumSimulation.setListOfParameters(optimumParameterlist);
440- // myOptimumSimulation.setMeasures(newListOfMeasurements);
441- //
442- // return myOptimumSimulation;
443186 }
444187
445188 @ Override
0 commit comments