From 2723624a67e454540cff46760f2080c6fbb45058 Mon Sep 17 00:00:00 2001 From: Dario Izzo Date: Wed, 17 Dec 2008 00:24:45 +0100 Subject: [PATCH] DiGMO simulateor case added --- SolversThreads/SolversThreads.cpp | 6 +- main.cpp | 320 +++++++++++++++++++++----------------- 2 files changed, 179 insertions(+), 147 deletions(-) diff --git a/SolversThreads/SolversThreads.cpp b/SolversThreads/SolversThreads.cpp index 88ed117..7e558f2 100644 --- a/SolversThreads/SolversThreads.cpp +++ b/SolversThreads/SolversThreads.cpp @@ -254,7 +254,7 @@ void *ASAthread(void *data) vector picks; vector LB,UB; ASAalgorithm ASA; - Pk::Random32 rng; + Pk::Random32 rng; GOProblem* problem; @@ -264,8 +264,8 @@ void *ASAthread(void *data) pthread_mutex_lock (PtrTP->TPmutex); rng = Pk::Random32(PtrTP->randomSeed); deme=PtrTP->Ptr_pop->extractRandomDeme(PtrTP->NP,picks, rng); - problem = PtrTP->problem; - problem->getBounds(LB, UB); + problem = PtrTP->problem; + problem->getBounds(LB, UB); unsigned int temp; temp = rng.next(); ASA.initASA(PtrTP->generations,LB.size(),PtrTP->Ts,PtrTP->Tf, rng.next()); diff --git a/main.cpp b/main.cpp index 5ebc81c..f24e312 100644 --- a/main.cpp +++ b/main.cpp @@ -53,7 +53,7 @@ while (choice != -1) { //we choose the algorithm - cout << "Choose: 1-ASA, 2-PSO, 3-MPSO, 4-DE, 5-SGA, 6-IslandModel(ring), Default-DiGMO: "; + cout << "Choose: 1-ASA, 2-PSO, 3-MPSO, 4-DE, 5-SGA, 6-IslandModel(ring), 7-DiGMO(simulator): "; cin >> choice; switch (choice){ @@ -696,190 +696,222 @@ while (choice != -1) { } break; - case 9: - { - Individual x; - x.createRandomIndividual(LB,UB,rng); - cout << x << endl; - x[0]=666; - cout << x << endl; - - Population pop; - pop.createRandomPopulation(LB,UB,5,rng); - pop.evaluatePopulation(problem); - cout << pop[3] << endl; - pop[3][0]=666; - cout << pop[3] << endl; - cout << pop << endl; - - } - break; - - default: - { - int NUM_THREADS=2; - //We create a random population and evaluate its fitness (this is done by the main thread - i.e. no parallelization here) - pop.createRandomPopulation(LB,UB,20*5, rng); - pop.evaluatePopulation(problem); + case 7: + { - //We instanciate the objects needed for pthreads allocating memory for the threads array - pthread_t *threads; - threads = new pthread_t [NUM_THREADS]; - //pthread_attr_t attr; - //pthread_attr_init(&attr); - //pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); - pthread_mutex_t mutex; - pthread_cond_t exitcond; - pthread_mutex_init(&mutex, NULL); - pthread_cond_init (&exitcond, NULL); + //Experiment Settings + int NP = 200; //main population size + int trials = 20; //number of trials + int gen = 500; //generations per algorithm call + double F = 0.8; //F in DE + double CR = 0.8; //CR in DE + int strategy = 2; //DE startegy + int islandsN = 1; //Number of Islands + //stopping criteria + int itermax = 120; //Maximum number of iterations allowed (i.e. output printed on the screen) + //Experiment Outputs + double mean = 0, dev= 0, max = 0, min = 200000000; + vector results; + //Main cycle creating threads + for (int i=0;i parallelProblems(islandsN); + for (int i=0;i max) max = results[i]; + if (results[i] < min) min = results[i]; } - pthread_mutex_unlock (&mutex); + mean /= results.size(); - //The main cycle has finished: we wait for all threads to finish - for (int i=0; i