Skip to content
Snippets Groups Projects
Commit 75901cfe authored by Gontier Antonin's avatar Gontier Antonin :fox:
Browse files

Merge branch 'dev' into 'doc'

Fresh population : dev to doc
parents d7508135 cc38c66f
No related branches found
No related tags found
No related merge requests found
22 serialization::archive 12 0 0 0 0 1344 18 8 32 10 320 0 6049672149429310496 2717439154472801824 4542198347308291164 3343219490040042730 4650051781416015241 1856754989365220584 505103489031919047 3752275180256122228 4866562513946170770 1173696855371502905 1221235317429195779 4149028308603131404 2045123101683307753 4370964611481162791 5180541057765791173 5360174911826974081 1031380308188190072 986689177400759733 244646298477975040 5613465412490089847 1101584513098536432 5138775896008905857 1975027673560012312 2943252523251979602 5609952642960053260 4242433772309534060 1464183846434788512 6176289965319312768 3348519309541659812 2415134792122487964 1749226692266513655 4292581514350220540 5296981249972852171 4801146528766088433 4906398327628289264 3607813114610865705 4492704583126635751 4977274474607891944 1307210215102633018 5689839102085649841 2195435566988121212 1261411206850205111 3189328583410963748 4419674356490688027 1725218012350862746 3253992298913715628 712825117784954428 60711758615008752 3265820516429387162 150734821684630820 1288835612192134442 2619388701849441350 149173853513077780 5550078548389876828 5774758385601664405 5922290998424097892 1676168994112919074 240114440515802268 403847628644570412 2987042424101295397 3517994605086135354 4887770529355650102 5794233604833859067 6201596650888844684 4940778008349889812 5141238640968160492 2789721588238701601 2243858380260595113 5684313945636558055 5999160644685354264 4478432442508596294 4618046577256814119 1988078672666252408 5366154769481716944 3734088965401826849 1948406257025471852 5672079549746205739 4256709455491519708 2585289048641951040 6154653257523614763 4779898830966510695 5934204258459571642 2154500200789431413 3135014335045424163 3907309520854930632 1578184627366614360 5456650074359485604 4409922396939146466 739959689624540251 4722120227146880263 339520761619994129 2308392431710786944 398813243614451068 2094403005923513475 3442214806611186849 795471459778713129 3992954702894224715 4018991195254379641 5643341043383718971 2238459908227880011 615522142202549718 5216532768547853636 6004446655284106395 2227711113423410288 2401272653985174908 4419351966442345849 166640283012748842 2366998613361743321 2499860968941147196 5315238655502177828 646912115091100768 1789120035053884661 3472566632482952715 4866826186478802000 4306344277624083570 3158299811933639920 3271602627864613968 5737953905554511366 1586208830773122244 5500691002220729787 1009555507893556448 1164253977787684380 5725898468284650953 295270747991102906 2091492576358093973 3603513509994550599 1925384312699016566 4195018748123632756 6059732164279326156 4636336333956109782 5586857176976283016 4900521625284400306 713109599796418043 81096444815660425 4424899822738167173 3166382552191161440 3339881225150027320 36065283526612187 1266426615475263015 3329711751798871606 4154273995042215228 3164304929131255169 1509122089984382266 1689821091237123174 3481854417543026011 4892931543583610130 2419687323797181713 1997089436006372628 3581081089713395158 5326021474418808166 4242897239609726027 5652071071275406804 2423583276671391184 3996226577354216656 59957791805920423 5630850348164732137 85659558395237750 4541436909570643131 1655570553002382725 4988060018564519217 3519693436362184201 3842387585058559378 4742454708527060082 1348424792733668899 1074602257184806248 4555779448750363899 5600838312124536343 2267470657488901434 5045937174893483383 4447446380045260097 4058248427948430890 2838930530572850316 1092155094879589834 3556128768482530473 6144590556205405506 4740759214095586648 1397766705404204232 3847775207555454059 1772752811174548644 1920214744332916096 2216255541792200038 5202727327269115223 1726646061727175884 5283022070303544794 5679400489692484876 3288650762843673944 5432450443244754307 3172700462739215554 664000485982819755 5468773425855976901 6203671254615413859 99566493837808935 4874699586408404192 4892773023111665109 337876666119148793 1486219830960510432 6185868524739548620 3488491639005042194 3806841881076815237 4145379758128518529 4887253050698487190 5240268378521097697 4659221279540499906 5973500246476281187 367178749618443504 4607648935203296407 5104714356152522067 1331502610585572844 1635741531911214246 5402181004246275210 3762049697678972156 4235715043702691080 2447969596034307605 1844647117969970460 4321077696752801003 3065421971346478389 1061025706978203051 2987508251016254656 4850720269404034306 3396390681384932791 470004688238826996 2635822850546456040 4729578050852705538 586677594841240736 2630572139878471063 5345834689260410073 1792458235146097836 6130290714535024160 1837902317009622568 4092277601138726185 604539265829328059 5138814793928627521 5474716263476647112 3774348862809626025 132254553917576662 1091757247422944450 4520025371387647249 2930235108131886556 2387035792495597105 5453927503221314741 4936064519962317963 659111879222056282 3999584348179289560 4644907427869185462 3364733463772517941 1925903519247652167 5613520375554724982 5014455356164298234 2679655609691133409 1200878829738481088 3306553670964761915 1925417711061030151 3486729994083521680 4464543103296099850 2681212457358611611 3317403489440519511 960794158243370289 752911226520491569 4222158119498110437 4731777627327452625 3643520876911744449 135401861024732465 1984077667628537361 3626308923920962919 5425222311632655890 1086619469971838129 2630384085404177852 5332810507822126636 1428418306431407446 5103945492104566117 5292049560820700656 2504778092092544307 4109951000505898451 1582239844294776201 4401847461164799288 3679663169400264182 1254055149932729525 2684954789064562200 2918931031364228470 2686965627898352945 2411888891135808812 4835067485841872072 2518957847561754123 2938898423050491299 5987136049634301301 1995629186928071987 3605714522884134119 74950277428041162 5423881458824107372 5753219561068483737 3095271144878462364 6035008388049819048 1840168442611029153 2978364729108878614 2108611878324950516 716273575294129452 5609725005375657132 446758238279325089 6145540644665382050 331409245627667957 3772499767042200849 4179849676765418725 4536396585817265333 6126956996541306184 3817391262573188562 234457956308112549 3247681587464000688 3167075685668509228 64821880834020887 4157931881027032457 4288361918031320264 4320512305029797033 1392202071580005924 2371715512327689498 3312028537265313336 2883771495815468468 2085503916919870800 3645466214169957930 1072187055370589610 5069414034035430595 36 0 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00
22 serialization::archive 15 0 0 0 0 1344 9 8 32 10 320 0 3388319928575251848 430654736042415468 180930603063890987 3401401125914072409 4657215175349163049 5067933328885273938 4857449326118360265 4305842184363333004 3691168448014800066 1797369816877225380 5125460791601124738 38115850159215699 186524887755347237 4771798085606298789 2319862488682714473 2218636981596247258 4504572320697996409 465602380698899865 699410549606863988 2685742024720733323 1925215458276332945 3982827680882480151 1528490849895044307 4262385551596278939 3738346682090607692 3867058342936761713 5591919270153180163 3315974250437825570 2641495664301561004 4797937958954849334 4102807985354233192 2938503427947943333 6040045404633027715 1790507846221157520 3437733930066072867 1847892987425051987 5307270535516902530 5337503074073826530 435159088806843498 4694909572018099584 2914351640157246886 402046393103570240 1113322545420129675 993525653271205121 820227641625269442 1105759899982583063 3123163220811764880 4555004141242864956 3596659098162812211 5450130842865390677 3740697052749124965 4433874587347539256 2164558981325739138 3542165581432149249 1492003659999696139 1618290275829208412 1906219738228806724 2599233153389548904 4168423277322556476 6054965925511976339 4118632784241153398 4154193127656576280 5916011386118362248 2256911875030111281 3695219366714823927 1050760659418600695 5548814087562122529 4833788496614872332 1392628850299327864 1294986561486116188 3396597482949661908 4302177150454092906 2622375564032923047 5781050804741297364 2555524649526908053 4024608532876809489 1009310223122650202 3866110758326752393 5145454313923728481 3049996251374900508 6153780390223172652 1636604506862245000 3662566081299731760 3802452913586459818 2107923385828398235 4355834631461885179 3555130686679209093 5166357779766334775 5931301658093999169 2430013411529413980 3013540119728084325 748831637105136732 4702796282237703553 4068227154309010678 1209972037210526770 2272042269502395562 4469785876738069779 5643961012048942475 5267594653941060790 1234209514758362486 5481931146695038194 4961103604168447402 3895852206143329434 108487087626671236 257187605069256057 5681913817897358577 978749312176936345 856267406761612459 3743246823837553894 5744105021059388584 3432741686633813192 1279265735244240076 24183378844177459 4807173312968119497 5897055602596107312 2699684712431932726 2963402659300463761 3626735208783926634 4460860648599016648 4785638164690949371 948168453966550192 2216422404379596097 698152950579582180 2659792322923287896 5815766575038453092 4144010157604132210 139750891299657093 2452090294049232067 3582795079996822908 784676180168561794 16297669978543397 3735934117676504438 1077016662852654347 552296189335459129 2911710523836290132 5068094602978743524 2567055403317417027 1785480352315987351 1892416780978148458 3364814576798323993 5770332616081986851 1862453050538284243 5847731030594508120 5102640776068552023 281686703387333771 2965419572792481000 3537303345249244327 3171845997179557250 4127865121740477843 4316584595700700235 3603296699554845803 2031640648833160602 3878049453182473408 6147592753312650533 3519801642119058534 6127358754851902667 5900571782334436651 3661985605107209322 1590411636059558979 2209075760422573239 5819969064313836731 2077634061836113035 5017376572243367028 1225145410881606747 4801915826271376714 1335676481027331185 4774783606526629254 930453239849276582 365929070980191564 3981648458985854083 722909673151255896 1987031555891287322 3492594579410933048 3036159034827134180 200932626278601889 5226060338115892312 4828864755743708517 508935544142419072 3063773946963317995 5779824923549029605 2851518176370414920 3920920347985007824 2024291668093555942 5316843375992689831 6098128322900186308 991999389577172197 1460968686390563976 3847193678910838086 5699281730545243234 6127671406170035324 2090304687872103648 5909719702820672902 1902604291603584217 2434957900686283942 3132095400234079376 281396018408969332 1357888380709000439 4344478630321312936 6073810153832207612 5091915632153810089 3536866274163184979 2446149847406663076 2369628986544968859 5906612005427205465 3963621222012081520 4708301695874651477 185873218309510467 2597049663117710646 1531894884922053911 4202588836448228544 5766752682769405031 5508846721111512425 4015347527636833638 1162845875433887043 4999506660213642515 4392378876158891412 2253958574994838900 1830575721699955845 4923993974531282278 3407506384690959632 592180115041080520 2256405402146428282 3745003748257289601 5941229543166760235 1799495102277244107 419660293050553712 3943378960991901084 5019579892901828003 4244688206068012156 3564171131677529500 78756704182588600 5175957907994924297 1974384646461576535 160549195093071236 3046389391921468683 380954871584281954 1375184227027244406 2126109636445197686 6081598185218036987 1996199424891835564 2182043551463626055 4879149857426593147 537691225609852277 2244579488699667641 2694137121327535431 3712398250916435280 1981784150716503284 5837130078594290955 2902932135144084825 5154516217280615590 986956988406879601 2311447153113945366 1185117824809882997 4702046707291411841 2441576133346088120 2015506657960940796 6134662213994337554 828852225874285804 2425524987343721824 3548911872849499299 1203154354973562131 1387875354703746375 3801799976166774049 2825442311769511319 4784684211105879362 1384525193151632630 1924637251505411297 343791730161145252 6104427759834191221 4045308966626153724 906367758778127675 10683830956545398 2188958951063541044 2616697831881069796 4927099122899146115 803559168213832836 2513921916022609116 5023550625068995803 518294828175185274 675599741802271978 5800902623548331296 3401737805859312777 2366159345932195136 6054842232454927556 4220420764681491591 2177649898361672953 415158613148390820 5212603347020207435 608477776470561961 2978533917877818648 1252615335703729382 605289030959944923 2292971498783331731 529080771728725329 1316184551605130394 5562539562775565639 2235651507911546083 5676726640238974209 5911058552980886793 3432146352229635379 3487641442522027394 2171494835701273825 5667048079410943286 1484111349753664666 182805637757981988 4690229658271274347 3869991504710653224 4316115801506010389 4419885219914995041 4216707550706488704 4287489163428713874 953273594818450764 4222160443744081113 4170863531704440041 2047252187042272401 3221185232623621426 1667601884169131222 681522698084930707 534424911483032949 1288129010314171669 27 0 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00
This diff is collapsed.
//This is a config file
//The syntax should be : parameter=value
//WARNING : DO NOT WRITE ANY SPACE CHARACTER
//ALE settings
romPath=../ale/roms/Frostbite.bin
displayScreen=true
displayScreen=false
enableSound=false
repeatActionProb=0.25
//Valeur de la colour palette : SECAM / PAL / standard
//Value of the color palette : SECAM / PAL / standard
colourPalette=SECAM
//Algo gen
algoGen=true
freshPop=false
//Launch parameters
nEvalP=1
nEvalS=3
mutRate=0.6
crossRate=0.6
tournSize=3
popSize=30
nbIter=100
crossRate=0
tournSize=2
popSize=3
nbIter=1
......@@ -24,6 +24,24 @@ void ga::init_population()
}
}
void ga::fill_population()
{
std::vector<agent> current_population_retrieved;
std::ifstream ifpop("best_pop.txt", std::ios::binary);
boost::archive::text_iarchive ipop(ifpop);
ipop >> current_population_retrieved;
int sp = (int)current_population_retrieved.size();
for(int i = 0; i < params.population_size; ++i)
{
if(i >= sp){
genetic_operators::initialize(current_population[i]);
}else{
current_population[i] = current_population_retrieved[i];
}
}
}
int ga::selection() const
{
int best_agent = 0;
......@@ -52,7 +70,8 @@ void ga::select_population()
void ga::crossover_population()
{
std::uniform_real_distribution<float> r(0, 1);
for (int i = 0; i < params.population_size; i += 2)
int sp = std::nearbyint(params.population_size * 0.5f) * 2.0f;
for (int i = 0; i < sp; i += 2)
{
if (r(Utils::Random::get_Rng()) < params.crossover_rate)
genetic_operators::crossover(new_population[i], new_population[i + 1]);
......
......@@ -10,6 +10,8 @@
#include "Random.h"
#include <fstream>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/vector.hpp>
#include "agent.hpp"
/**
......@@ -57,6 +59,8 @@ class ga{
*
*/
void init_population();
void fill_population();
/**
* @fn select_population
......@@ -78,6 +82,7 @@ class ga{
*
*/
void mutate_population();
public:
/**
* @fn ga(const parameters& params, const agent::parameters& agent_params)
......@@ -92,19 +97,24 @@ class ga{
/**
* @fn run
* @brief Executes the genetic algorithm
* @details First of all, the algorithm initializes the population with random agent.\n
* @details First of all, the algorithm initializes the population with random agent or the last population saved.\n
* Then, the agents are tested and their fitness calculated. If one of them is better than the current best agent, the best agent is saved.\n
* Finally, a new population is generated by selecting best agents among pools of current agents. They are also crossed and mutated.\n
* The algorithm loops on these newly generated populations until all iterations are done.\n
*
* @param fresh If true, initializes the population with random agents. If false, initializes the populations with the last population saved.
* @param fitness Tool used to processed results
*/
void run(Fitness fitness);
void run(bool fresh, Fitness fitness);
};
template <typename Fitness>
void ga::run(Fitness fitness){
init_population();
void ga::run(bool fresh, Fitness fitness){
if(fresh){
init_population();
}else{
fill_population();
}
double best_value = 0;
agent best_agent;
for (int i = 1; i <= params.nb_iterations; ++i){
......@@ -134,5 +144,12 @@ void ga::run(Fitness fitness){
// std::cout << population_fitness[i] << " | ";
// }
// std::cout << std::endl;
}
}
std::ofstream ofpop("best_pop.txt");
boost::archive::text_oarchive opop(ofpop);
opop << current_population;
ofpop.close();
auto sp = current_population.size();
std::cout << sp << " agents archived successfully" << std::endl;
}
......@@ -58,6 +58,7 @@ namespace master_slave{
int tournSize = 2;
int popSize = 30;
int nbIter = 100;
bool fresh = true;
//Lecture de la config
vector<vector<string>> config = Utils::read_Config();
......@@ -77,6 +78,12 @@ namespace master_slave{
popSize = stoi(config.at(i).at(1));
}else if(config.at(i).at(0) == "nbIter"){
nbIter = stoi(config.at(i).at(1));
}else if(config.at(i).at(0) == "freshPop"){
if(config.at(i).at(1) == "true"){
fresh = true;
}else if(config.at(i).at(1) == "false"){
fresh = false;
}
}
}
......@@ -102,7 +109,7 @@ namespace master_slave{
(port,
genetic_algorithms::accumulate::mean_score<double>,
np, ns);
ga.run(fitness);
ga.run(fresh, fitness);
return;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment