Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
/fitness.dat
/phenotype.dat
/seed.dat
build/
out/
.vs/
60 changes: 60 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
"files.associations": {
".fantomasignore": "ignore",
"cmath": "cpp",
"atomic": "cpp",
"bit": "cpp",
"cctype": "cpp",
"charconv": "cpp",
"clocale": "cpp",
"compare": "cpp",
"concepts": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"exception": "cpp",
"format": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"ios": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"iterator": "cpp",
"limits": "cpp",
"locale": "cpp",
"memory": "cpp",
"new": "cpp",
"ostream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"typeinfo": "cpp",
"utility": "cpp",
"xfacet": "cpp",
"xiosbase": "cpp",
"xlocale": "cpp",
"xlocbuf": "cpp",
"xlocinfo": "cpp",
"xlocmes": "cpp",
"xlocmon": "cpp",
"xlocnum": "cpp",
"xloctime": "cpp",
"xmemory": "cpp",
"xstring": "cpp",
"xtr1common": "cpp",
"xutility": "cpp",
"cerrno": "c",
"cfloat": "c",
"climits": "c"
}
}
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.5)
project(CE_Locomotion)

file(GLOB locomotion_src Muscles.cpp NervousSystem.cpp random.cpp StretchReceptor.cpp TSearch.cpp Worm.cpp WormBody.cpp)

add_executable(locomotion ${locomotion_src} main.cpp)

if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_compile_options(locomotion PUBLIC /O2 /LTCG)
else()
target_compile_options(locomotion PUBLIC -O3 -flto)
endif()
26 changes: 26 additions & 0 deletions CMakeSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"configurations": [
{
"name": "x64-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [ "msvc_x64_x64" ],
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": ""
},
{
"name": "x64-Release",
"generator": "Ninja",
"configurationType": "RelWithDebInfo",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "msvc_x64_x64" ]
}
]
}
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ main: main.o Worm.o WormBody.o NervousSystem.o StretchReceptor.o Muscles.o TSear
random.o: random.cpp random.h VectorMatrix.h
g++ -c -O3 -flto random.cpp
TSearch.o: TSearch.cpp TSearch.h
g++ -c -O3 -flto TSearch.cpp
g++ -c -O3 -flto -DTHREADED_SEARCH TSearch.cpp
Worm.o: Worm.cpp Worm.h
g++ -c -O3 -flto Worm.cpp
WormBody.o: WormBody.cpp WormBody.h
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ We are using this to better understand how the same neural circuit can produce m

Work in collaboration with Dr. Erick Olivares and Prof. Randall Beer.

## Dependencies

```
python -m venv openworm
source openworm/Scripts/activate
# or Windows
# openworm\Scripts\activate.bat
```
Then install the dependencies using pip:
```
pip install -r .\requirements.txt
```

## Instructions for use

1. Compile using the Makefile:
Expand Down
5 changes: 4 additions & 1 deletion TSearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,10 @@ void *EvaluatePopulationRange(void *arg)
TSearch *s = prs->search;
for (int i = prs->start; i <= prs->end; i++)
s->Perf[i] = s->EvaluateVector(s->Population[i], s->RandomStates[i]);
pthread_exit(NULL);
#ifdef THREADED_SEARCH
pthread_exit(NULL);
#endif
return NULL;
}


Expand Down
3 changes: 1 addition & 2 deletions TSearch.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
// "Evolutionary" search classes
// *****************************

// Uncomment the following line to enable multithreading
#define THREADED_SEARCH
// Define THREADED_SEARCH via Makefile or CMakeLists.txt
#define THREAD_COUNT 16

#pragma once
Expand Down
12 changes: 6 additions & 6 deletions Worm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,10 @@ void Worm::Curvature(TVector<double> &c)
a1 = atan2(dy1,dx1);
a2 = atan2(dy2,dx2);

if (a1 > PI/2 and a2 < -PI/2)
if (a1 > PI/2 && a2 < -PI/2)
a = (a1 - 2*PI) - a2;
else
if (a1 < -PI/2 and a2 > PI/2)
if (a1 < -PI/2 && a2 > PI/2)
a = a1 - (a2 - 2*PI);
else
a = a1-a2;
Expand All @@ -305,10 +305,10 @@ void Worm::AngleCurvature(TVector<double> &c)
a1 = atan2(dy1,dx1);
a2 = atan2(dy2,dx2);

if (a1 > PI/2 and a2 < -PI/2)
if (a1 > PI/2 && a2 < -PI/2)
a = (a1 - 2*PI) - a2;
else
if (a1 < -PI/2 and a2 > PI/2)
if (a1 < -PI/2 && a2 > PI/2)
a = a1 - (a2 - 2*PI);
else
a = a1-a2;
Expand Down Expand Up @@ -391,10 +391,10 @@ void Worm::DumpCurvature(ofstream &ofs, int skips)
a1 = atan2(dy1,dx1);
a2 = atan2(dy2,dx2);

if (a1 > PI/2 and a2 < -PI/2)
if (a1 > PI/2 && a2 < -PI/2)
a = (a1 - 2*PI) - a2;
else
if (a1 < -PI/2 and a2 > PI/2)
if (a1 < -PI/2 && a2 > PI/2)
a = a1 - (a2 - 2*PI);
else
a = a1-a2;
Expand Down
4 changes: 4 additions & 0 deletions WormBody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@

#include "WormBody.h"
#include <cfloat>
#if _MSC_VER
#define _USE_MATH_DEFINES
#include <math.h>
#endif

using namespace std;

Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
numpy
matplotlib