Skip to content

Commit

Permalink
Merge branch 'master' into SGP-GPTP-2018
Browse files Browse the repository at this point in the history
  • Loading branch information
amlalejini committed Jul 3, 2018
2 parents 842819c + bcb32f5 commit eabb8cb
Show file tree
Hide file tree
Showing 37 changed files with 941 additions and 375 deletions.
4 changes: 4 additions & 0 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[bumpversion]
current_version = 0.0.2
commit = True
tag = True
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "third-party/Catch"]
path = third-party/Catch
url = https://github.com/philsquared/Catch.git
[submodule "third-party/force-cover"]
path = third-party/force-cover
url = https://github.com/emilydolson/force-cover.git
61 changes: 53 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ notifications:
on_success: always
rooms:
- secure: UC8Bsb6n2WAnKdUwzGo/QwDEhSyKbJFUZCVYem11o8JpXz/PB/vLTNIt/0xhbkoAwGMivAH6i6AeLx4HhMShnt5iWq1GK5Toh+uScp1BqT3M4XnoQbmiuhKKeFJhcoFaASGIoylURXAd65fVaojSul0Lx/pztkYzNQ1FUvcwtpA/guxJ9TE5M2Vmp81T5h74InJCW8eh30UJUlWkHdChK4RxnBgDic9vmn6/DGMWBIdGDbceF3PtOHQUk3E363LFDF6Ij0rOx5oXCm0YsSblvNRxFR9MOVX2YAKPy+dM5Kx0IRlIH+yYG9heH207+cfDg4LP7PiV0eCPh5gw8s7FHr89/fM8Mubh6X+l6Wbjla4waAdMhfSdI1vGxxq5uYTEtpfzsaNNQpfMnxe4eLEpdw3FgUA6xUdSS00dkBG1RoLTtqYSGCfEkKBwzmwwbEU77SYCKu+cjtjgBJSiwC0+Dxje4Y3tb5gDLCKbDArbPWiaqaqVPtRtUbSSP7qIt9e1DaAbcJO2nun+G8y1EdHoUNWbCVqZ/70l33Oo4ssm4d38xuAqFcKv1PH+7zv8Yql4uZIDBJz8G8aVvHMlBfrKRghDakWBrKX9rFbNen5IxuV/vMF051tHc0CWlO3HQjphH5ST1/eNjywGl107VLP9HzkZzqDBKcxcSGMLi7QC7F0=

compiler:
- g++-5
- clang++-5.0
Expand Down Expand Up @@ -44,11 +45,55 @@ before_script:
- sleep 3 # give xvfb some time to start
- git fetch origin master:refs/remotes/origin/master
- npm install source-map
- make install-dependencies
- cd third-party
- bash install_emscripten.sh
- make install-npm-deps
- . emsdk_portable_repo/emsdk_portable/emsdk_env.sh
- cd ..
script:
- make travis
- make install-test-dependencies
- . ./third-party/emsdk_portable_repo/emsdk_portable/emsdk_env.sh
script: make test

jobs:
include:
- stage: test
compiler: clang++-5.0
install:
- if [ "$CXX" = "clang++" ]; then export CXX="clang++-5.0" CC="clang-5.0"; fi
addons:
apt:
sources:
- kalakris-cmake
- llvm-toolchain-trusty-5.0
packages:
- clang-5.0
- cmake
- build-essential
- bison
- python-virtualenv
- python-pip
- tar
- gzip
before_script:
- git fetch origin master:refs/remotes/origin/master
- make install-doc-dependencies
script: make doc
- stage: test
compiler: clang++
install:
- if [ "$CXX" = "clang++" ]; then export CXX="clang++-5.0" CC="clang-5.0"; fi
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-trusty-5.0
packages:
- clang-5.0
- libclang-5.0-dev
- llvm-5.0
- g++-5
- build-essential
- tar
- gzip
before_script:
- git fetch origin master:refs/remotes/origin/master
- make install-test-dependencies
- make install-coverage-dependencies
script: make coverage
after_success:
- curl -s https://codecov.io/bash | bash
22 changes: 13 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,27 @@ test:
doc: build-doxygen-xml
cd doc && ./make_docs.sh

coverage:
cd tests && make test-coverage

build-doxygen-xml:
./third-party/doxygen/build/bin/doxygen Doxyfile

travis:
make install-dependencies
cd third-party && bash install_emscripten.sh
cd third-party && make install-npm-deps
make test
make doc

install-dependencies:
git submodule init
git submodule update
cd third-party && make

install-testing-dependencies:
cd third-party && make install-testing-dependencies
install-doc-dependencies:
git submodule init
git submodule update
cd third-party && make install-doc-dependencies

install-test-dependencies:
cd third-party && make install-test-dependencies

install-coverage-dependencies:
cd third-party && make install-coverage-dependencies

clean:
rm -rf build/*
Expand Down
63 changes: 47 additions & 16 deletions apps/OpenWorld/source/OpenOrg.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
#include "geometry/Point2D.h"
#include "hardware/EventDrivenGP.h"

struct OpenOrg {
class OpenOrg {
public:
static constexpr size_t TAG_WIDTH = 16;
using hardware_t = emp::EventDrivenGP_AW<TAG_WIDTH>;
using event_lib_t = hardware_t::event_lib_t;
Expand All @@ -16,37 +17,67 @@ struct OpenOrg {

enum class Trait { ORG_ID };

private:
size_t id;

size_t color_id;
hardware_t brain;

emp::Point center;
double radius;
emp::Angle facing;

double energy;
double size;
double time_born;
double time_dead;

emp::CircleBody2D body;

static size_t NextID() {
static size_t next_id = 0;
return next_id++;
}
/// Values calculated from the above:
double base_cost; /// How much energy is spent each update?

public:
OpenOrg(inst_lib_t & inst_lib, event_lib_t & event_lib, emp::Ptr<emp::Random> random_ptr)
: id(NextID()), brain(inst_lib, event_lib, random_ptr), energy(0.0), size(0.0)
, time_born(0.0), time_dead(-1.0), body({100.0,100.0,5.0})
{
brain.SetTrait((size_t)Trait::ORG_ID, id);
}
: id(0), color_id(0), brain(inst_lib, event_lib, random_ptr)
, center(1.0, 1.0), radius(5.0), facing()
, energy(0.0), time_born(0.0), time_dead(-1.0), base_cost(radius*radius*0.01)
{ ; }
OpenOrg(const OpenOrg &) = default;
OpenOrg(OpenOrg &&) = default;
~OpenOrg() { ; }

OpenOrg & operator=(const OpenOrg &) = default;
OpenOrg & operator=(OpenOrg &&) = default;

void Setup(emp::WorldPosition pos) {
std::cerr << "Seting up at pos " << pos.GetIndex() << std::endl;
size_t GetID() const { return id; }
size_t GetColorID() const { return color_id; }
hardware_t & GetBrain() { return brain; }
const hardware_t & GetBrain() const { return brain; }
emp::Point GetCenter() const { return center; }
double GetRadius() const { return radius; }
emp::Angle GetFacing() const { return facing; }
double GetEnergy() const { return energy; }
double GetTimeBorn() const { return time_born; }
double GetTimeDead() const { return time_dead; }
double GetBaseCost() const { return base_cost; }

double GetMass() const { return radius * radius; }

OpenOrg & SetID(size_t _in) { id = _in; return *this; }
OpenOrg & GetColorID(size_t _in) { color_id = _in; return *this; }
// OpenOrg & SetBrain(const hardware_t & _in) { brain = _in; return *this; }
OpenOrg & SetCenter(emp::Point _in) { center = _in; return *this; }
OpenOrg & SetRadius(double _in) { radius = _in; return *this; }
OpenOrg & SetFacing(emp::Angle _in) { facing = _in; return *this; }
OpenOrg & SetEnergy(double _in) { energy = _in; return *this; }
OpenOrg & SetTimeBorn(double _in) { time_born = _in; return *this; }
OpenOrg & SetTimeDead(double _in) { time_dead = _in; return *this; }
OpenOrg & SetBaseCost(double _in) { base_cost = _in; return *this; }

OpenOrg & RotateDegrees(double degrees) { facing.RotateDegrees(degrees); return *this; }
OpenOrg & Translate(emp::Point shift) { center += shift; return *this; }

void Setup(emp::WorldPosition pos, emp::Random & random) {
// std::cerr << "Seting up at pos " << pos.GetIndex() << std::endl;
base_cost = GetMass() * 0.01;
RotateDegrees(random.GetDouble(360.0));
}

void Process(size_t exe_count) {
Expand Down
106 changes: 96 additions & 10 deletions apps/OpenWorld/source/OpenWorld.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,142 @@
#define OPEN_WORLD_H

#include "Evolve/World.h"
#include "geometry/Surface2D.h"
#include "geometry/Surface.h"

#include "config.h"
#include "OpenOrg.h"

class OpenWorld : public emp::World<OpenOrg> {
private:
static constexpr size_t TAG_WIDTH = 16;
using hardware_t = emp::EventDrivenGP_AW<TAG_WIDTH>;
using hardware_t = OpenOrg::hardware_t;
using program_t = hardware_t::Program;
using prog_fun_t = hardware_t::Function;
using prog_tag_t = hardware_t::affinity_t;
using event_lib_t = hardware_t::event_lib_t;
using inst_t = hardware_t::inst_t;
using inst_lib_t = hardware_t::inst_lib_t;
using hw_state_t = hardware_t::State;

using surface_t = emp::Surface2D<emp::CircleBody2D>;
using surface_t = emp::Surface<OpenOrg>;

OpenWorldConfig & config;
inst_lib_t inst_lib;
event_lib_t event_lib;
surface_t surface;
size_t next_id;

// double pop_pressure = 1.0; // How much pressure before an organism dies?

std::unordered_map<size_t, emp::Ptr<OpenOrg>> id_map;


public:
OpenWorld(OpenWorldConfig & _config)
: config(_config), inst_lib(), event_lib(), surface(config.WORLD_X(), config.WORLD_Y())
: config(_config), inst_lib(), event_lib(),
surface({config.WORLD_X(), config.WORLD_Y()}),
next_id(1), id_map()
{
OnPlacement( [this](size_t pos){ id_map[ GetOrg(pos).id ] = &GetOrg(pos); } );
OnOrgDeath( [this](size_t pos){ id_map.erase( GetOrg(pos).id ); } );
SetPopStruct_Grow(false); // Don't automatically delete organism when new ones are born.

// Make sure that we are tracking organisms by their IDs.
OnPlacement( [this](size_t pos){
size_t id = next_id++;
GetOrg(pos).GetBrain().SetTrait((size_t)OpenOrg::Trait::ORG_ID, id);
id_map[id] = &GetOrg(pos);
});
OnOrgDeath( [this](size_t pos){ id_map.erase( GetOrg(pos).GetID() ); } );

// Setup new instructions for the instruction set.
inst_lib.AddInst("Vroom", [this](hardware_t & hw, const inst_t & inst) {
const size_t id = (size_t) hw.GetTrait((size_t) OpenOrg::Trait::ORG_ID);
emp::Ptr<OpenOrg> org_ptr = id_map[id];
emp::Angle facing = org_ptr->body.GetOrientation();
facing.GetPoint(10.0);
emp::Angle facing = org_ptr->GetFacing();
org_ptr->Translate( facing.GetPoint(1.0) );
}, 1, "Move forward.");

inst_lib.AddInst("SpinRight", [this](hardware_t & hw, const inst_t & inst) mutable {
const size_t id = (size_t) hw.GetTrait((size_t) OpenOrg::Trait::ORG_ID);
emp::Ptr<OpenOrg> org_ptr = id_map[id];
org_ptr->RotateDegrees(-5.0);
}, 1, "Rotate -5 degrees.");

inst_lib.AddInst("SpinLeft", [this](hardware_t & hw, const inst_t & inst) mutable {
const size_t id = (size_t) hw.GetTrait((size_t) OpenOrg::Trait::ORG_ID);
emp::Ptr<OpenOrg> org_ptr = id_map[id];
org_ptr->RotateDegrees(5.0);
}, 1, "Rotate 5 degrees.");

// On each update, run organisms and make sure they stay on the surface.
OnUpdate([this](size_t){
Process(5);
for (auto & org : *this) {
double x = org.GetCenter().GetX();
double y = org.GetCenter().GetY();
if (x < 0.0) x += config.WORLD_X();
if (y < 0.0) y += config.WORLD_Y();
if (x >= config.WORLD_X()) x -= config.WORLD_X();
if (y >= config.WORLD_Y()) y -= config.WORLD_Y();
org.SetCenter({x,y});
}
});

// Setup a mutation function.
SetMutFun( [this](OpenOrg & org, emp::Random & random){
org.SetRadius(org.GetRadius() * random.GetDouble(0.96, 1.05));
return 1;
});

// Initialize a populaton of random organisms.
Inject(OpenOrg(inst_lib, event_lib, random_ptr), config.INIT_POP_SIZE());
for (size_t i = 0; i < config.INIT_POP_SIZE(); i++) {
double x = random_ptr->GetDouble(config.WORLD_X());
double y = random_ptr->GetDouble(config.WORLD_Y());
GetOrg(i).body.SetPosition({x,y});
surface.AddBody(&GetOrg(i).body);
GetOrg(i).SetCenter({x,y});
surface.AddBody(&GetOrg(i));
GetOrg(i).GetBrain().SetProgram(GenerateRandomProgram());
}
}
~OpenWorld() { ; }

surface_t & GetSurface() { return surface; }

program_t GenerateRandomProgram() {
program_t prog(&inst_lib);
size_t fcnt = random_ptr->GetUInt(config.PROGRAM_MIN_FUN_CNT(), config.PROGRAM_MAX_FUN_CNT());
for (size_t fID = 0; fID < fcnt; ++fID) {
prog_fun_t new_fun;
new_fun.affinity.Randomize(*random_ptr);
size_t icnt = random_ptr->GetUInt(config.PROGRAM_MIN_INST_CNT(), config.PROGRAM_MAX_INST_CNT());
for (size_t iID = 0; iID < icnt; ++iID) {
new_fun.PushInst(random_ptr->GetUInt(prog.GetInstLib()->GetSize()),
random_ptr->GetInt(config.PROGRAM_MAX_ARG_VAL()),
random_ptr->GetInt(config.PROGRAM_MAX_ARG_VAL()),
random_ptr->GetInt(config.PROGRAM_MAX_ARG_VAL()),
prog_tag_t());
new_fun.inst_seq.back().affinity.Randomize(*random_ptr);
}
prog.PushFunction(new_fun);
}
return prog;
}

/// Test if two bodies have collided and act accordingly if they have.
bool TestPairCollision(OpenOrg & body1, OpenOrg & body2) {
// if (body1.IsLinked(body2)) return false; // Linked bodies can overlap.

const emp::Point dist = body1.GetCenter() - body2.GetCenter();
const double sq_pair_dist = dist.SquareMagnitude();
const double radius_sum = body1.GetRadius() + body2.GetRadius();
const double sq_min_dist = radius_sum * radius_sum;

// If there was no collision, return false.
if (sq_pair_dist >= sq_min_dist) { return false; }

// If we made it this far, there was a collision!

return true;
}
};

#endif
7 changes: 7 additions & 0 deletions apps/OpenWorld/source/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ EMP_BUILD_CONFIG( OpenWorldConfig,
VALUE(POINT_MUTATE_PROB, double, 0.001, "Probability of instructions being mutated"),
VALUE(BIT_FLIP_PROB, double, 0.00001, "Probability of each tag bit toggling"),

GROUP(PROGRAM, "Various configuration options for SignalGP programs."),
VALUE(PROGRAM_MAX_FUN_CNT, size_t, 8, "Maximum number of functions in a SignalGP program."),
VALUE(PROGRAM_MIN_FUN_CNT, size_t, 1, "Minimum number of functions in a SignalGP program."),
VALUE(PROGRAM_MAX_INST_CNT, size_t, 16, "Maximum number of instructions in a SignalGP function."),
VALUE(PROGRAM_MIN_INST_CNT, size_t, 1, "Minimum number of instructions in a SignalGP function."),
VALUE(PROGRAM_MAX_ARG_VAL, size_t, 16, "Maximum argument value in a SignalGP program instruction."),

GROUP(OUTPUT, "Output rates for OpenWorld"),
VALUE(PRINT_INTERVAL, size_t, 100, "How many updates between prints?")
)
Expand Down
2 changes: 1 addition & 1 deletion apps/OpenWorld/source/native/OpenWorld.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
int main(int argc, char* argv[])
{
OpenWorldConfig config;
config.Read("OpenWorld.cfg");
config.Read("OpenWorld.cfg", false);
auto args = emp::cl::ArgManager(argc, argv);
if (args.ProcessConfigOptions(config, std::cout, "OpenWorld.cfg", "OpenWorld-macros.h") == false) exit(0);
if (args.TestUnknown() == false) exit(0); // If there are leftover args, throw an error.
Expand Down
Loading

0 comments on commit eabb8cb

Please sign in to comment.