Skip to content

Commit

Permalink
Main
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennedeg committed Feb 23, 2018
1 parent 3b30278 commit ea1e0ab
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 147 deletions.
163 changes: 89 additions & 74 deletions .cproject

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions .project
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,10 @@
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
<variableList>
<variable>
<name>SDL</name>
<value>file:/usr/include/SDL</value>
</variable>
</variableList>
</projectDescription>
4 changes: 2 additions & 2 deletions .settings/language.settings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project>
<configuration id="cdt.managedbuild.config.gnu.cross.exe.debug.1952959546" name="Debug">
<configuration id="cdt.managedbuild.config.gnu.cross.exe.debug.1357481319" name="Debug">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
Expand All @@ -11,7 +11,7 @@
</provider>
</extension>
</configuration>
<configuration id="cdt.managedbuild.config.gnu.cross.exe.release.1157127818" name="Release">
<configuration id="cdt.managedbuild.config.gnu.cross.exe.release.374768704" name="Release">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
Expand Down
12 changes: 12 additions & 0 deletions .settings/org.eclipse.cdt.managedbuilder.core.prefs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,19 @@ environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.
environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.1952959546/C_INCLUDE_PATH/operation=remove
environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.1952959546/append=true
environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.1952959546/appendContributed=true
environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.so.debug.1300268500/CPATH/delimiter=\:
environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.so.debug.1300268500/CPATH/operation=remove
environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.so.debug.1300268500/CPLUS_INCLUDE_PATH/delimiter=\:
environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.so.debug.1300268500/CPLUS_INCLUDE_PATH/operation=remove
environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.so.debug.1300268500/C_INCLUDE_PATH/delimiter=\:
environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.so.debug.1300268500/C_INCLUDE_PATH/operation=remove
environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.so.debug.1300268500/append=true
environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.so.debug.1300268500/appendContributed=true
environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.cross.exe.debug.1952959546/LIBRARY_PATH/delimiter=;
environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.cross.exe.debug.1952959546/LIBRARY_PATH/operation=remove
environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.cross.exe.debug.1952959546/append=true
environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.cross.exe.debug.1952959546/appendContributed=true
environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.cross.so.debug.1300268500/LIBRARY_PATH/delimiter=\:
environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.cross.so.debug.1300268500/LIBRARY_PATH/operation=remove
environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.cross.so.debug.1300268500/append=true
environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.cross.so.debug.1300268500/appendContributed=true
3 changes: 2 additions & 1 deletion src/AGContreStratFixe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ void AGContreStratFixe::selection(){
individu->setGain(eval.at(0));
}
sort(m_population.begin(), m_population.end(), Individu<GeneDouble>::comparaisonIndividu);
affichage();
//affichage();
addMoyenne();
m_population.erase(m_population.begin(), m_population.begin() + getTaillePop()/2);
}
1 change: 1 addition & 0 deletions src/AGNoStrat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ void AGNoStrat::selection(){
}
sort(m_population.begin(), m_population.end(), Individu<GeneDouble>::comparaisonIndividu);
//affichage();
addMoyenne();
m_population.erase(m_population.begin(), m_population.begin() + getTaillePop()/2);
}
63 changes: 15 additions & 48 deletions src/AlgoGenetiqueTDJ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,8 @@
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <SDL/SDL.h>
#define POINTS_COUNT 4
static SDL_Point points[POINTS_COUNT] = {
{320, 200},
{300, 240},
{340, 240},
{320, 200}
};
//#include <SDL/SDL.h>


#include "AlgoGenetiqueTDJ.h"

Expand Down Expand Up @@ -81,8 +75,8 @@ std::vector<double> AlgoGenetiqueTDJ::fitnessFunction(Strategie &unJoueur1, Stra
unJoueur1.reinitialiser();
unJoueur2.reinitialiser();
std::vector<double> resultat;
resultat.push_back(gainJoueur1);
resultat.push_back(gainJoueur2);
resultat.push_back( gainJoueur1 + 0*gainJoueur2);
resultat.push_back( 0*gainJoueur1 + gainJoueur2);
return resultat;
}

Expand Down Expand Up @@ -127,7 +121,7 @@ void AlgoGenetiqueTDJ::mutation(){
for (int i = 0; i < t; ++i){
for(int j = 0; j < getIndividu(i)->getTailleChromosome(); ++j){
double valeurGene = getIndividu(i)->getGene(j)->getValeur();
double r = rand()/(double)RAND_MAX*0.1 - 0.05;
double r = rand()/(double)RAND_MAX*0.01 - 0.005;
getIndividu(i)->getGene(j)->setValeur( std::max(0., std::min(1., valeurGene + r)));
}
}
Expand Down Expand Up @@ -163,41 +157,14 @@ void AlgoGenetiqueTDJ::addMoyenne(){
m_moyenne.push_back(moyenne);
}

void AlgoGenetiqueTDJaffichageMoyenne(){
if (SDL_Init(SDL_INIT_VIDEO) == 0) {
SDL_Window* window = NULL;
SDL_Renderer* renderer = NULL;

if (SDL_CreateWindowAndRenderer(640, 480, 0, &window, &renderer) == 0) {
SDL_bool done = SDL_FALSE;

while (!done) {
SDL_Event event;

SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
SDL_RenderClear(renderer);

SDL_SetRenderDrawColor(renderer, 255, 255, 255, SDL_ALPHA_OPAQUE);
SDL_RenderDrawLines(renderer, points, POINTS_COUNT);
SDL_RenderPresent(renderer);

while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
done = SDL_TRUE;
}
}
}
}

if (renderer) {
SDL_DestroyRenderer(renderer);
}
if (window) {
SDL_DestroyWindow(window);
}
}
SDL_Quit();
return 0;
}

void AlgoGenetiqueTDJ::affichageMoyenne(){
int t = m_moyenne.size();
int g = pow(2, getMemoirePop());
for(int i = 0; i < t; ++i){
std::cout << i << ": " << m_moyenne.at(i).at(0) << " ";
for(int j = 0; j < g; ++j){
std::cout << m_moyenne.at(i).at(j+1) << " ";
}
std::cout << std::endl;
}
}
51 changes: 29 additions & 22 deletions src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <vector>
#include <iostream>
#include <time.h>

#include "StratChoix1.h"
#include "Strat01.h"
Expand All @@ -20,7 +21,29 @@


int main(int argc, char *argv[]) {
if (0){

srand(time(NULL));
if (argv[1]){
std::vector<int> matriceGains;
matriceGains.push_back(-5);
matriceGains.push_back(-5);
matriceGains.push_back(0);
matriceGains.push_back(-8);
matriceGains.push_back(-8);
matriceGains.push_back(0);
matriceGains.push_back(-7);
matriceGains.push_back(-7);
Jeu jeu(matriceGains);
StratRep strat;
AGContreStratFixe algo(strat, jeu, atoi(argv[2]), atoi(argv[3]), atoi(argv[4]));
algo.doOneGeneration();
algo.doGenerations(1000);
algo.affichageMoyenne();
//algo.affichage();
return 0;
}

else{
std::vector<int> matriceGains;
matriceGains.push_back(-1);
matriceGains.push_back(-1);
Expand All @@ -31,29 +54,13 @@ int main(int argc, char *argv[]) {
matriceGains.push_back(-5);
matriceGains.push_back(-5);
Jeu jeu(matriceGains);
StratOpport strat;
AGContreStratFixe algo(strat, jeu, 20, 20, 4);
AGNoStrat algo(jeu, atoi(argv[1]), atoi(argv[2]), atoi(argv[3]));
algo.doOneGeneration();
algo.doGenerations(800);
algo.doGenerations(10000);
algo.affichageMoyenne();
algo.affichage();
return 0;
}

if (1){
std::vector<int> matriceGains;
matriceGains.push_back(-1);
matriceGains.push_back(-1);
matriceGains.push_back(0);
matriceGains.push_back(-10);
matriceGains.push_back(-10);
matriceGains.push_back(0);
matriceGains.push_back(-5);
matriceGains.push_back(-5);
Jeu jeu(matriceGains);
AGNoStrat algo(jeu, 20, 20, 4);
algo.doOneGeneration();
algo.doGenerations(10000);
algo.affichage();
return 0;
}
return 1;
}

0 comments on commit ea1e0ab

Please sign in to comment.