Skip to content

Commit 0a21c86

Browse files
committed
added evolution class
1 parent 87bdb74 commit 0a21c86

12 files changed

+2699
-55
lines changed

Worm2D/Evolution.h

+6-42
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,16 @@
11
#include "TSearch.h"
22
#include "VectorMatrix.h"
3-
//#include "Worm2D.h"
3+
#include "../argUtils.h"
44

55
class Evolution
66
{
77
public:
8+
Evolution():supArgs1_ptr(nullptr){}
89
virtual void GenPhenMapping(TVector<double> &gen, TVector<double> &phen) = 0;
910
virtual double EvaluationFunction(TVector<double> &v, RandomState &rs) = 0;
1011

11-
};
12-
13-
class EvolutionRS18:public Evolution
14-
{
15-
public:
16-
void GenPhenMapping(TVector<double> &gen, TVector<double> &phen);
17-
double EvaluationFunction(TVector<double> &v, RandomState &rs);
18-
19-
private:
20-
21-
double Duration = 50.0; // Seconds
22-
double Transient = 10.0; //
23-
double StepSize = 0.01;
24-
int N_curvs = 23; // Number of cuvature points
25-
26-
// Used for Dumping: Frame rate for recording datais set to 50 frames per second
27-
double fps = 25.0;
28-
int skip = (int) (1/(StepSize*fps));
12+
13+
protected:
14+
SuppliedArgs* supArgs1_ptr;
2915

30-
// Genotype -> Phenotype Mapping (Ventral cord)
31-
double BiasRange = 15.0;
32-
double SCRange = 15.0;
33-
double CSRange = 15.0;
34-
double TauMin = 0.5; //
35-
double TauMax = 2.0;
36-
37-
double ESRange = 2.0;
38-
39-
double SRmax = 200.0;
40-
double NMJmax = 1.0;
41-
42-
// (Head)
43-
double HCSRange = 15.0;
44-
45-
// Fitness
46-
double AvgSpeed = 0.00022; // Average speed of the worm in meters per seconds
47-
double BBCfit = AvgSpeed*Duration;
48-
49-
// Size of genotype (VC)
50-
int VectSize = 30;
51-
52-
};
16+
};

Worm2D/EvolutionRS18.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "Evolution.h"
1+
#include "EvolutionRS18.h"
22
#include <math.h>
33
#include "WormRS18.h"
44

@@ -81,6 +81,8 @@ double EvolutionRS18::EvaluationFunction(TVector<double> &v, RandomState &rs)
8181
{
8282
double fitness;
8383
ofstream fitfile;
84+
85+
8486
if (supArgs1.speedoutput)
8587
{
8688

@@ -116,17 +118,19 @@ if (supArgs1.output){
116118

117119
if (supArgs1.output){
118120
w.DumpParams(paramsfile);
119-
writeParsToJson(w);
121+
//writeParsToJson(w);
120122
}
121123

122124

123125
w.InitializeState(rs);
124126

127+
128+
125129
// Transient
126130
for (double t = 0.0; t <= Transient; t += StepSize)
127131
{
128132
w.Step(StepSize, 1);
129-
if (supArgs1.output)
133+
130134

131135
if (supArgs1.output)
132136
{

Worm2D/EvolutionRS18.h

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include "TSearch.h"
2+
#include "VectorMatrix.h"
3+
#include "Evolution.h"
4+
5+
class EvolutionRS18:public Evolution
6+
{
7+
public:
8+
EvolutionRS18(){
9+
10+
supArgs1_ptr = new SuppliedArgs2018();
11+
12+
}
13+
void GenPhenMapping(TVector<double> &gen, TVector<double> &phen);
14+
double EvaluationFunction(TVector<double> &v, RandomState &rs);
15+
16+
SuppliedArgs2018& supArgs1 = static_cast<SuppliedArgs2018&>(*supArgs1_ptr);
17+
18+
private:
19+
20+
double Duration = 50.0; // Seconds
21+
double Transient = 10.0; //
22+
double StepSize = 0.01;
23+
int N_curvs = 23; // Number of cuvature points
24+
25+
// Used for Dumping: Frame rate for recording datais set to 50 frames per second
26+
double fps = 25.0;
27+
int skip = (int) (1/(StepSize*fps));
28+
29+
// Genotype -> Phenotype Mapping (Ventral cord)
30+
double BiasRange = 15.0;
31+
double SCRange = 15.0;
32+
double CSRange = 15.0;
33+
double TauMin = 0.5; //
34+
double TauMax = 2.0;
35+
36+
double ESRange = 2.0;
37+
38+
double SRmax = 200.0;
39+
double NMJmax = 1.0;
40+
41+
// (Head)
42+
double HCSRange = 15.0;
43+
44+
// Fitness
45+
double AvgSpeed = 0.00022; // Average speed of the worm in meters per seconds
46+
double BBCfit = AvgSpeed*Duration;
47+
48+
// Size of genotype (VC)
49+
int VectSize = 30;
50+
51+
};

Worm2D/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ TSearch.o: TSearch.cpp TSearch.h
99
argUtils.o: ../argUtils.cpp ../argUtils.h
1010
g++ -c -O3 -flto ../argUtils.cpp
1111
Worm2D.o: Worm2D.cpp Worm2D.h
12-
g++ -c -O3 -flto Worm2D.cpp
12+
g++ -c -O3 -std=c++11 -flto Worm2D.cpp
1313
WormRS18.o: WormRS18.cpp WormRS18.h
14-
g++ -c -O3 -flto WormRS18.cpp
14+
g++ -c -O3 -std=c++11 -flto WormRS18.cpp
1515
WormBody.o: WormBody.cpp WormBody.h
1616
g++ -c -O3 -flto WormBody.cpp
1717
NervousSystem.o: NervousSystem.cpp NervousSystem.h VectorMatrix.h random.h

Worm2D/Worm2D.cpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "Worm2D.h"
2-
2+
#include <iomanip>
33

44
WormIzq::WormIzq(wormIzqParams par1_):par1(par1_),n_ptr(new NervousSystem)
55
{
@@ -14,7 +14,6 @@ WormIzq::WormIzq(wormIzqParams par1_):par1(par1_),n_ptr(new NervousSystem)
1414
void WormIzq::setUp()
1515
{
1616
m.SetMuscleParams(par1.N_muscles, par1.T_muscle);
17-
1817
}
1918

2019
int WormIzq::nn(int neuronNumber, int unitNumber)
@@ -126,6 +125,18 @@ void WormIzq::DumpBodyState(ofstream &ofs, int skips)
126125
}
127126
}
128127

128+
void WormIzq::writeJsonFile()
129+
{
130+
131+
json j;
132+
addParsToJson(j);
133+
//ofstream json_out(supArgs1.rename_file("worm_data.json"));
134+
ofstream json_out("worm_data.json");
135+
json_out << std::setw(4) << j << std::endl;
136+
json_out.close();
137+
138+
}
139+
129140
void WormIzq::addParsToJson(json & j)
130141
{
131142
// addwormIzqParams

Worm2D/Worm2D.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
#include "Muscles.h"
44
#include "WormBody.h"
55
#include "NervousSystem.h"
6-
#include <nlohmann/json.hpp>
6+
//#include <nlohmann/json.hpp>
77
#include "jsonUtils.h"
88

99

10-
using json = nlohmann::json;
10+
//using json = nlohmann::json;
1111

1212
#define PI 3.14159265
1313

@@ -48,7 +48,7 @@ class WormIzq: public Worm2D
4848
virtual void InitializeState(RandomState &rs) = 0;
4949
virtual void Step(double StepSize, double output) = 0;
5050
void addParsToJson(json & j);
51-
51+
void writeJsonFile();
5252

5353
double CoMx();
5454
double CoMy();

Worm2D/WormRS18.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
#define HEADSR
1313
#define VNCSR
1414

15-
//extern SuppliedArgs2018 supArgs1;
15+
extern SuppliedArgs2018 supArgs1;
16+
1617

1718
RS18Macros Worm18::setMacros()
1819
{
@@ -30,7 +31,7 @@ return {headsr,vncsr};
3031
// The constructor
3132
Worm18::Worm18(TVector<double> &v,double output):WormIzq({6,24,0.1,6}),rS18Macros(setMacros())
3233
{
33-
34+
supArgs1.writeMessage();
3435
// Nervous system // Ventral cord
3536
n_ptr->SetCircuitSize(par1.N_units*par1.N_neuronsperunit, 4, 4);
3637

@@ -309,7 +310,7 @@ void Worm18::addExtraParsToJson(json & j)
309310
string nsHead = "Head Nervous system";
310311
appendAllNSJson(j[nsHead], h);
311312
vector<string> cell_names = {"SMDD", "RMDD", "SMDV", "RMDV"};
312-
appendCellNamesToJson(j[nsHead], cell_names, par1.N_units);
313+
appendCellNamesToJson(j[nsHead], cell_names, 1);
313314
Params<double> par = sr.getStretchReceptorParams();
314315
appendToJson<double>(j["Stretch receptor"], par);
315316
}

0 commit comments

Comments
 (0)