From ede1373bbb7fdef55118cc747023a9242984ed3d Mon Sep 17 00:00:00 2001 From: raki123 Date: Wed, 16 Nov 2016 21:39:51 +0100 Subject: [PATCH 01/10] done --- .kdev4/tol-revolve.kdev4 | 10 + cpp/CMakeLists.txt | 1 + cpp/tol/plugin/ExtendedNeuralNetwork.cpp | 348 +++++++++ cpp/tol/plugin/ExtendedNeuralNetwork.h | 69 ++ cpp/tol/plugin/RobotController.cpp | 3 +- cpp/tol/plugin/RobotController.h | 2 + cpp/tol/plugin/helper.h | 1 + scripts/offline-evolve/run-experiments.sh | 2 +- scripts/offline-evolve2/gait-learning.world | 43 ++ .../offline-evolve2/input-15/baseline.conf | 6 + .../input-15/baseline_no_fitness.conf | 7 + scripts/offline-evolve2/input-15/comma.conf | 7 + .../input-15/comma_aggressive.conf | 12 + scripts/offline-evolve2/input-15/plus.conf | 5 + .../input-15/plus_aggressive.conf | 11 + .../input-15/plus_gradual.conf | 6 + .../input-15/plus_less_aggressive.conf | 4 + .../input-15/plus_more_aggressive.conf | 11 + .../offline-evolve2/input-20/baseline.conf | 7 + scripts/offline-evolve2/input-20/plus.conf | 5 + .../input-20/plus_aggressive.conf | 10 + .../input-20/plus_more_aggressive.conf | 10 + scripts/offline-evolve2/input/baseline.conf | 5 + scripts/offline-evolve2/input/comma.conf | 4 + .../input/comma_aggressive.conf | 9 + scripts/offline-evolve2/input/plus.conf | 3 + .../input/plus_aggressive.conf | 8 + .../input/plus_more_aggressive.conf | 8 + scripts/offline-evolve2/make.sh | 3 + scripts/offline-evolve2/offline-evolve.world | 39 ++ scripts/offline-evolve2/offline_evolve.py | 437 ++++++++++++ scripts/offline-evolve2/rlpower.cfg | 12 + scripts/offline-evolve2/robots/babyA.yaml | 89 +++ scripts/offline-evolve2/robots/babyB.yaml | 101 +++ scripts/offline-evolve2/robots/babyC.yaml | 171 +++++ scripts/offline-evolve2/robots/gecko12.yaml | 124 ++++ scripts/offline-evolve2/robots/gecko17.yaml | 176 +++++ scripts/offline-evolve2/robots/gecko7.yaml | 73 ++ scripts/offline-evolve2/robots/snake5.yaml | 41 ++ scripts/offline-evolve2/robots/snake7.yaml | 63 ++ scripts/offline-evolve2/robots/snake9.yaml | 83 +++ scripts/offline-evolve2/robots/spider13.yaml | 121 ++++ scripts/offline-evolve2/robots/spider17.yaml | 161 +++++ scripts/offline-evolve2/robots/spider9.yaml | 659 ++++++++++++++++++ scripts/offline-evolve2/run-experiments.sh | 83 +++ .../offline-evolve2/single_robot_manager.py | 101 +++ scripts/offline-evolve2/start.py | 57 ++ scripts/offline-evolve2/summarize.R | 103 +++ tol-revolve.kdev4 | 3 + tol/build/builder.py | 4 +- tol/spec/__init__.py | 1 + tol/spec/extended_brain.py | 118 ++++ 52 files changed, 3436 insertions(+), 4 deletions(-) create mode 100644 .kdev4/tol-revolve.kdev4 create mode 100644 cpp/tol/plugin/ExtendedNeuralNetwork.cpp create mode 100644 cpp/tol/plugin/ExtendedNeuralNetwork.h create mode 100644 scripts/offline-evolve2/gait-learning.world create mode 100644 scripts/offline-evolve2/input-15/baseline.conf create mode 100644 scripts/offline-evolve2/input-15/baseline_no_fitness.conf create mode 100644 scripts/offline-evolve2/input-15/comma.conf create mode 100644 scripts/offline-evolve2/input-15/comma_aggressive.conf create mode 100644 scripts/offline-evolve2/input-15/plus.conf create mode 100644 scripts/offline-evolve2/input-15/plus_aggressive.conf create mode 100644 scripts/offline-evolve2/input-15/plus_gradual.conf create mode 100644 scripts/offline-evolve2/input-15/plus_less_aggressive.conf create mode 100644 scripts/offline-evolve2/input-15/plus_more_aggressive.conf create mode 100644 scripts/offline-evolve2/input-20/baseline.conf create mode 100644 scripts/offline-evolve2/input-20/plus.conf create mode 100644 scripts/offline-evolve2/input-20/plus_aggressive.conf create mode 100644 scripts/offline-evolve2/input-20/plus_more_aggressive.conf create mode 100644 scripts/offline-evolve2/input/baseline.conf create mode 100644 scripts/offline-evolve2/input/comma.conf create mode 100644 scripts/offline-evolve2/input/comma_aggressive.conf create mode 100644 scripts/offline-evolve2/input/plus.conf create mode 100644 scripts/offline-evolve2/input/plus_aggressive.conf create mode 100644 scripts/offline-evolve2/input/plus_more_aggressive.conf create mode 100755 scripts/offline-evolve2/make.sh create mode 100644 scripts/offline-evolve2/offline-evolve.world create mode 100644 scripts/offline-evolve2/offline_evolve.py create mode 100644 scripts/offline-evolve2/rlpower.cfg create mode 100644 scripts/offline-evolve2/robots/babyA.yaml create mode 100644 scripts/offline-evolve2/robots/babyB.yaml create mode 100644 scripts/offline-evolve2/robots/babyC.yaml create mode 100644 scripts/offline-evolve2/robots/gecko12.yaml create mode 100644 scripts/offline-evolve2/robots/gecko17.yaml create mode 100644 scripts/offline-evolve2/robots/gecko7.yaml create mode 100644 scripts/offline-evolve2/robots/snake5.yaml create mode 100644 scripts/offline-evolve2/robots/snake7.yaml create mode 100644 scripts/offline-evolve2/robots/snake9.yaml create mode 100644 scripts/offline-evolve2/robots/spider13.yaml create mode 100644 scripts/offline-evolve2/robots/spider17.yaml create mode 100644 scripts/offline-evolve2/robots/spider9.yaml create mode 100755 scripts/offline-evolve2/run-experiments.sh create mode 100644 scripts/offline-evolve2/single_robot_manager.py create mode 100644 scripts/offline-evolve2/start.py create mode 100644 scripts/offline-evolve2/summarize.R create mode 100644 tol-revolve.kdev4 create mode 100644 tol/spec/extended_brain.py diff --git a/.kdev4/tol-revolve.kdev4 b/.kdev4/tol-revolve.kdev4 new file mode 100644 index 0000000..8947d13 --- /dev/null +++ b/.kdev4/tol-revolve.kdev4 @@ -0,0 +1,10 @@ +[CMake] +ProjectRootRelative=./ + +[Defines And Includes][Compiler] +Name=GCC +Path=gcc +Type=GCC + +[Project] +VersionControlSupport=kdevgit diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 1fff715..77e1898 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -65,6 +65,7 @@ file(GLOB_RECURSE tol/plugin/fakebrain.cpp tol/plugin/helper.cpp tol/plugin/rlpower.cpp + tol/plugin/ExtendedNeuralNetwork.cpp ) add_library(tolworldcontrol SHARED ${TOL_WORLD_SRC}) diff --git a/cpp/tol/plugin/ExtendedNeuralNetwork.cpp b/cpp/tol/plugin/ExtendedNeuralNetwork.cpp new file mode 100644 index 0000000..0e390b7 --- /dev/null +++ b/cpp/tol/plugin/ExtendedNeuralNetwork.cpp @@ -0,0 +1,348 @@ +#include "ExtendedNeuralNetwork.h" +#include "helper.h" +#include "sensor.h" +#include "actuator.h" +#include "revolve/gazebo/motors/Motor.h" +#include "revolve/gazebo/sensors/Sensor.h" + + +namespace tol { + + ExtendedNeuralNetwork::ExtendedNeuralNetwork(std::string modelName, + tol::EvaluatorPtr evaluator, + sdf::ElementPtr node, + const std::vector &actuators, + const std::vector &sensors) : + revolve::brain::ExtendedNeuralNetwork( + modelName, + parseSDF(node, actuators, sensors), + evaluator, + Helper::createWrapper(actuators), + Helper::createWrapper(sensors)) { } + + ExtendedNeuralNetwork::~ExtendedNeuralNetwork() + { + + } + + + void ExtendedNeuralNetwork::update(const std::vector &actuators, + const std::vector &sensors, + double t, + double step) { + //std::cout << "yay" << std::endl; + revolve::brain::ExtendedNeuralNetwork::update( + Helper::createWrapper(actuators), + Helper::createWrapper(sensors), + t, step + ); + } + + +ExtendedNeuralNetwork::ExtNNConfig ExtendedNeuralNetwork::parseSDF(sdf::ElementPtr node, + const std::vector< revolve::gazebo::MotorPtr > & motors, + const std::vector< revolve::gazebo::SensorPtr > & sensors) { + ExtNNConfig ret; + + // Map neuron sdf elements to their id's + std::map neuronDescriptions; + + // List of all hidden neuron id's + std::vector hiddenIds; + + // Number of input neurons for mapping them to the input buffer + ret.numInputNeurons_ = 0; + + // Number of output neurons for mapping them to the output buffer + ret.numOutputNeurons_ = 0; + + // Number of hidden neurons + ret.numHiddenNeurons_ = 0; + + // Get the first sdf neuron element + auto neuron = node->HasElement("rv:neuron") ? node->GetElement("rv:neuron") : sdf::ElementPtr(); + + while (neuron) { + if (!neuron->HasAttribute("layer") || !neuron->HasAttribute("id")) { + std::cerr << "Missing required neuron attributes (id or layer). '" << std::endl; + throw std::runtime_error("Robot brain error"); + } + auto layer = neuron->GetAttribute("layer")->GetAsString(); + auto neuronId = neuron->GetAttribute("id")->GetAsString(); + + + // check if a neuron with this id has been already added + if (neuronDescriptions.count(neuronId)) { + std::cerr << "Duplicate neuron ID '" + << neuronId << "'" << std::endl; + throw std::runtime_error("Robot brain error"); + } + + // add this neuron to the id->sdf map + neuronDescriptions[neuronId] = neuron; + + // add the neuron id to the appropriate list of id's + if ("input" == layer) { + // inputIds.push_back(neuronId); + } + + else if ("output" == layer) { + // outputIds.push_back(neuronId); + } + + else if ("hidden" == layer) { + hiddenIds.push_back(neuronId); + } + + else { + std::cerr << "Unknown neuron layer '" << layer << "'." << std::endl; + throw std::runtime_error("Robot brain error"); + } + + neuron = neuron->GetNextElement("rv:neuron"); + } + + + // Add output neurons for motors: + + // map of numbers of output neurons for each body part + std::map outputCountMap; + + for (auto it = motors.begin(); it != motors.end(); ++it) { + auto motor = *it; + auto partId = motor->partId(); + + if (!outputCountMap.count(partId)) { + outputCountMap[partId] = 0; + } + + for (unsigned int i = 0, l = motor->outputs(); i < l; ++i) { + std::stringstream neuronId; + neuronId << partId << "-out-" << outputCountMap[partId]; + outputCountMap[partId]++; + + auto neuronDescription = neuronDescriptions.find(neuronId.str()); + if (neuronDescription == neuronDescriptions.end()) { + std::cerr << "Required output neuron " << neuronId.str() << + " for motor could not be located" + << std::endl; + throw std::runtime_error("Robot brain error"); + } + + auto newNeuron = neuronHelper(neuronDescription->second, ret); + ret.idToNeuron_[neuronId.str()] = newNeuron; + + } + } + // Add input neurons for sensors: + + // map of number of input neurons for each part: + + std::map inputCountMap; + + for (auto it = sensors.begin(); it != sensors.end(); ++it) { + auto sensor = *it; + auto partId = sensor->partId(); + + if (!inputCountMap.count(partId)) { + inputCountMap[partId] = 0; + } + + for (unsigned int i = 0, l = sensor->inputs(); i < l; ++i) { + std::stringstream neuronId; + neuronId << partId << "-in-" << inputCountMap[partId]; + inputCountMap[partId]++; + + auto neuronDescription = neuronDescriptions.find(neuronId.str()); + if (neuronDescription == neuronDescriptions.end()) { + std::cerr << "Required input neuron " << neuronId.str() << + " for sensor could not be located" + << std::endl; + throw std::runtime_error("Robot brain error"); + } + + auto newNeuron = neuronHelper(neuronDescription->second,ret); + ret.idToNeuron_[neuronId.str()] = newNeuron; + } + } + + // initialize the array for sensor inputs: + ret.inputs_ = new double[ret.numInputNeurons_]; + ret.outputs_ = new double[ret.numOutputNeurons_]; + + + // Add hidden neurons: + for (auto it = hiddenIds.begin(); it != hiddenIds.end(); ++it) { + auto neuronDescription = neuronDescriptions.find(*it); + auto newNeuron = neuronHelper(neuronDescription->second,ret); + ret.idToNeuron_[*it] = newNeuron; + } + + + // Add connections: + auto connection = node->HasElement("rv:neural_connection") ? node->GetElement("rv:neural_connection") : sdf::ElementPtr(); + while (connection) { + if (!connection->HasAttribute("src") || !connection->HasAttribute("dst") + || !connection->HasAttribute("weight")) { + std::cerr << "Missing required connection attributes (`src`, `dst` or `weight`)." << std::endl; + throw std::runtime_error("Robot brain error"); + } + + auto src = connection->GetAttribute("src")->GetAsString(); + auto dst = connection->GetAttribute("dst")->GetAsString(); + + + std::string dstSocketName; + if (connection->HasAttribute("socket")) { + dstSocketName = connection->GetAttribute("socket")->GetAsString(); + } + else { + dstSocketName = "None"; // this is the default socket name + } + + double weight; + connection->GetAttribute("weight")->Get(weight); + + // Use connection helper to set the weight + connectionHelper(src, dst, dstSocketName, weight, ret.idToNeuron_, ret); + + // Load the next connection + connection = connection->GetNextElement("rv:neural_connection"); + } + return ret; +} + +std::map ExtendedNeuralNetwork::parseSDFElement(sdf::ElementPtr elem) +{ + std::map params; + + auto subElem = elem->GetFirstElement(); + while (subElem) { + auto elName = subElem->GetName(); + double elValue = subElem->Get(); + params[elName] = elValue; + subElem = subElem->GetNextElement(); + } + + return params; +} + +void ExtendedNeuralNetwork::connectionHelper(const std::string &src, + const std::string &dst, + const std::string &socket, + double weight, + const std::map &idToNeuron, + ExtNNConfig &ret) +{ + std::cout << "connection from " + src + " to " + dst + " was added with weight: " << weight << std::endl; + auto srcNeuron = idToNeuron.find(src); + if (srcNeuron == idToNeuron.end()) { + std::cerr << "Could not find source neuron '" << src << "'" << std::endl; + throw std::runtime_error("Robot brain error"); + } + auto dstNeuron = idToNeuron.find(dst); + if (dstNeuron == idToNeuron.end()) { + std::cerr << "Could not find destination neuron '" << dst << "'" << std::endl; + throw std::runtime_error("Robot brain error"); + } + + revolve::brain::NeuralConnectionPtr newConnection(new revolve::brain::NeuralConnection( + srcNeuron->second, + dstNeuron->second, + weight + )); + + // Add reference to this connection to the destination neuron + (dstNeuron->second)->AddIncomingConnection(socket, newConnection); + ret.connections_.push_back(newConnection); +} + + +revolve::brain::NeuronPtr ExtendedNeuralNetwork::neuronHelper(sdf::ElementPtr neuron, + ExtNNConfig &ret) +{ + if (!neuron->HasAttribute("type")) { + std::cerr << "Missing required `type` attribute for neuron." << std::endl; + throw std::runtime_error("Robot brain error"); + } + + if (!neuron->HasAttribute("layer")) { + std::cerr << "Missing required `layer` attribute for neuron." << std::endl; + throw std::runtime_error("Robot brain error"); + } + + auto type = neuron->GetAttribute("type")->GetAsString(); + auto layer = neuron->GetAttribute("layer")->GetAsString(); + auto id = neuron->GetAttribute("id")->GetAsString(); + + // map of parameter names and values + auto params = parseSDFElement(neuron); + + return addNeuron(id, type, layer, params, ret); +} + + + +revolve::brain::NeuronPtr ExtendedNeuralNetwork::addNeuron(const std::string &neuronId, + const std::string &neuronType, + const std::string &neuronLayer, // can be 'hidden', 'input' or 'output' + const std::map ¶ms, + ExtNNConfig &ret) +{ + revolve::brain::NeuronPtr newNeuron; + std::cout << neuronType + " " + neuronId + " was added in"+ " "+ neuronLayer << std::endl; + if ("input" == neuronLayer) { + newNeuron.reset(new revolve::brain::InputNeuron(neuronId, params)); + + ret.inputNeurons_.push_back(newNeuron); + ret.inputPositionMap_[newNeuron] = ret.numInputNeurons_; + ret.numInputNeurons_++; + } + + else { + + if ("Sigmoid" == neuronType) { + newNeuron.reset(new revolve::brain::SigmoidNeuron(neuronId, params)); + } + else if ("Simple" == neuronType) { + newNeuron.reset(new revolve::brain::LinearNeuron(neuronId, params)); + } + else if ("Oscillator" == neuronType) { + newNeuron.reset(new revolve::brain::OscillatorNeuron(neuronId, params)); + } + else if ("V-Neuron" == neuronType) { + newNeuron.reset(new revolve::brain::VOscillator(neuronId, params)); + } + else if ("X-Neuron" == neuronType) { + newNeuron.reset(new revolve::brain::XOscillator(neuronId, params)); + } + else if ("Bias" == neuronType) { + newNeuron.reset(new revolve::brain::BiasNeuron(neuronId, params)); + } + else if ("Leaky" == neuronType) { + newNeuron.reset(new revolve::brain::LeakyIntegrator(neuronId, params)); + } + else if ("DifferentialCPG" == neuronType) { + newNeuron.reset(new revolve::brain::DifferentialCPG(neuronId, params)); + } + else { + std::cerr << "Unsupported neuron type `" << neuronType << '`' << std::endl; + throw std::runtime_error("Robot brain error"); + } + + if ("output" == neuronLayer) { + ret.outputNeurons_.push_back(newNeuron); + ret.outputPositionMap_[newNeuron] = ret.numOutputNeurons_; + ret.numOutputNeurons_++; + } + else { + ret.hiddenNeurons_.push_back(newNeuron); + ret.numHiddenNeurons_++; + } + } + + ret.allNeurons_.push_back(newNeuron); + return newNeuron; +} +} /* namespace tol */ + diff --git a/cpp/tol/plugin/ExtendedNeuralNetwork.h b/cpp/tol/plugin/ExtendedNeuralNetwork.h new file mode 100644 index 0000000..23a3c46 --- /dev/null +++ b/cpp/tol/plugin/ExtendedNeuralNetwork.h @@ -0,0 +1,69 @@ +#ifndef REVOLVE_GAZEBO_BRAIN_DIFFERENTIAL_NEAT_H +#define REVOLVE_GAZEBO_BRAIN_DIFFERENTIAL_NEAT_H + +#include "brain/ccpg/ExtendedNeuralNetwork.h" +#include "evaluator.h" +#include "revolve/gazebo/brain/Brain.h" + + +#include +#include + +#include +#include + +namespace tol { + + class ExtendedNeuralNetwork : public revolve::gazebo::Brain, private revolve::brain::ExtendedNeuralNetwork { + + public: + ExtendedNeuralNetwork(std::string modelName, + tol::EvaluatorPtr evaluator, + sdf::ElementPtr node, + const std::vector &actuators, + const std::vector &sensors); + + virtual ~ExtendedNeuralNetwork(); + + /** + * Method for updating sensors readings, actuators positions, ranked list of policies and generating new policy + * @param actuators: vector list of robot's actuators + * @param sensors: vector list of robot's sensors + * @param t: + * @param step: + */ + virtual void update(const std::vector &actuators, + const std::vector &sensors, + double t, + double step); + + static ExtNNConfig parseSDF(sdf::ElementPtr node, + const std::vector & motors, + const std::vector & sensors); + + static std::map parseSDFElement(sdf::ElementPtr elem); + + static void connectionHelper(const std::string &src, + const std::string &dst, + const std::string &socket, + double weight, + const std::map &idToNeuron, + ExtNNConfig& ret); + + static revolve::brain::NeuronPtr neuronHelper(sdf::ElementPtr neuron, + ExtNNConfig& ret); + + static revolve::brain::NeuronPtr addNeuron(const std::string &neuronId, + const std::string &neuronType, + const std::string &neuronLayer, // can be 'hidden', 'input' or 'output' + const std::map ¶ms, + ExtNNConfig& ret); + + + }; + +} /* namespace tol */ + +#endif //REVOLVE_GAZEBO_BRAIN_REINFORCEDLEARNING_H + + diff --git a/cpp/tol/plugin/RobotController.cpp b/cpp/tol/plugin/RobotController.cpp index a16660b..24a4144 100644 --- a/cpp/tol/plugin/RobotController.cpp +++ b/cpp/tol/plugin/RobotController.cpp @@ -7,6 +7,7 @@ #include "RobotController.h" #include "rlpower.h" +#include "ExtendedNeuralNetwork.h" #include @@ -37,7 +38,7 @@ void RobotController::LoadBrain(sdf::ElementPtr sdf) } if (brain->GetAttribute("algorithm")->GetAsString() == "rlpower") { - brain_.reset(new tol::RLPower(this->model->GetName(), brain, evaluator_, motors_, sensors_)); + brain_.reset(new tol::ExtendedNeuralNetwork(this->model->GetName(), evaluator_, brain, motors_, sensors_)); } else { std::cout << "Calling default ANN brain." << std::endl; revolve::gazebo::RobotController::LoadBrain(sdf); diff --git a/cpp/tol/plugin/RobotController.h b/cpp/tol/plugin/RobotController.h index 70a956a..4e47a88 100644 --- a/cpp/tol/plugin/RobotController.h +++ b/cpp/tol/plugin/RobotController.h @@ -12,6 +12,8 @@ #include "rlpower.h" #include "evaluator.h" +#include + namespace tol { class RobotController: public revolve::gazebo::RobotController { diff --git a/cpp/tol/plugin/helper.h b/cpp/tol/plugin/helper.h index 93ce423..41d9521 100644 --- a/cpp/tol/plugin/helper.h +++ b/cpp/tol/plugin/helper.h @@ -24,6 +24,7 @@ #include "sensor.h" #include +#include namespace tol { diff --git a/scripts/offline-evolve/run-experiments.sh b/scripts/offline-evolve/run-experiments.sh index bc7a171..adf1981 100755 --- a/scripts/offline-evolve/run-experiments.sh +++ b/scripts/offline-evolve/run-experiments.sh @@ -10,7 +10,7 @@ robot_list=( spider9 spider13 spider17 gecko7 gecko12 gecko17 snake5 snake7 snak config=rlpower.cfg gz_command=gzserver -load_controller= +#load_controller= manager=single_robot_manager.py no_experiments=10 output=output diff --git a/scripts/offline-evolve2/gait-learning.world b/scripts/offline-evolve2/gait-learning.world new file mode 100644 index 0000000..fa159af --- /dev/null +++ b/scripts/offline-evolve2/gait-learning.world @@ -0,0 +1,43 @@ + + + + + 0 + 0 + + + + 0.005 + + + 0.0 + + + + + 0.1 + 10e-6 + + + 100 + 1e-8 + + + world + + + + + + + + + model://sun + + + model://tol_ground + + + + + \ No newline at end of file diff --git a/scripts/offline-evolve2/input-15/baseline.conf b/scripts/offline-evolve2/input-15/baseline.conf new file mode 100644 index 0000000..6483a30 --- /dev/null +++ b/scripts/offline-evolve2/input-15/baseline.conf @@ -0,0 +1,6 @@ +output_directory=/media/expdata/output +restore_directory=baseline-selection +disable_selection=1 +disable_fitness=1 +population_size=15 +num_children=15 diff --git a/scripts/offline-evolve2/input-15/baseline_no_fitness.conf b/scripts/offline-evolve2/input-15/baseline_no_fitness.conf new file mode 100644 index 0000000..95b27ec --- /dev/null +++ b/scripts/offline-evolve2/input-15/baseline_no_fitness.conf @@ -0,0 +1,7 @@ +output_directory=output +restore_directory=baseline-no-fitness-15 +disable_fitness=1 +disable_selection=1 +keep_parents=0 +population_size=15 +num_children=15 \ No newline at end of file diff --git a/scripts/offline-evolve2/input-15/comma.conf b/scripts/offline-evolve2/input-15/comma.conf new file mode 100644 index 0000000..251b434 --- /dev/null +++ b/scripts/offline-evolve2/input-15/comma.conf @@ -0,0 +1,7 @@ +output_directory=comma-output +restore_directory=comma-1000 +population_size=15 +num_children=15 +keep_parents=False +num_generations=1000 +num_evolutions=32 diff --git a/scripts/offline-evolve2/input-15/comma_aggressive.conf b/scripts/offline-evolve2/input-15/comma_aggressive.conf new file mode 100644 index 0000000..70818c4 --- /dev/null +++ b/scripts/offline-evolve2/input-15/comma_aggressive.conf @@ -0,0 +1,12 @@ +output_directory=comma-output +restore_directory=comma-aggressive-15-2000 +keep_parents=0 +enable_light_sensor=0 +body_mutation_epsilon=0.3 +brain_mutation_epsilon=0.3 +p_delete_subtree=0.25 +p_duplicate_subtree=0.25 +p_swap_subtree=0.25 +population_size=15 +num_children=15 +num_generations=2000 diff --git a/scripts/offline-evolve2/input-15/plus.conf b/scripts/offline-evolve2/input-15/plus.conf new file mode 100644 index 0000000..48d810c --- /dev/null +++ b/scripts/offline-evolve2/input-15/plus.conf @@ -0,0 +1,5 @@ +output_directory=/media/expdata/output +restore_directory=plus +population_size=15 +num_children=15 +world_step_size=0.003 \ No newline at end of file diff --git a/scripts/offline-evolve2/input-15/plus_aggressive.conf b/scripts/offline-evolve2/input-15/plus_aggressive.conf new file mode 100644 index 0000000..c8fedad --- /dev/null +++ b/scripts/offline-evolve2/input-15/plus_aggressive.conf @@ -0,0 +1,11 @@ +output_directory=population-output +restore_directory=plus-aggressive-15 +enable_light_sensor=0 +body_mutation_epsilon=0.3 +brain_mutation_epsilon=0.3 +p_delete_subtree=0.25 +p_duplicate_subtree=0.25 +p_swap_subtree=0.25 +population_size=15 +num_children=15 +num_evolutions=32 diff --git a/scripts/offline-evolve2/input-15/plus_gradual.conf b/scripts/offline-evolve2/input-15/plus_gradual.conf new file mode 100644 index 0000000..8339971 --- /dev/null +++ b/scripts/offline-evolve2/input-15/plus_gradual.conf @@ -0,0 +1,6 @@ +output_directory=/media/expdata/output +restore_directory=plus-gradual-new +population_size=15 +num_children=1 +num_generations=2991 +world_step_size=0.003 \ No newline at end of file diff --git a/scripts/offline-evolve2/input-15/plus_less_aggressive.conf b/scripts/offline-evolve2/input-15/plus_less_aggressive.conf new file mode 100644 index 0000000..d6833ba --- /dev/null +++ b/scripts/offline-evolve2/input-15/plus_less_aggressive.conf @@ -0,0 +1,4 @@ +output_directory=output +restore_directory=plus-less-aggressive-size-discount-3 +population_size=15 +num_children=15 diff --git a/scripts/offline-evolve2/input-15/plus_more_aggressive.conf b/scripts/offline-evolve2/input-15/plus_more_aggressive.conf new file mode 100644 index 0000000..02dce3e --- /dev/null +++ b/scripts/offline-evolve2/input-15/plus_more_aggressive.conf @@ -0,0 +1,11 @@ +output_directory=population-output +restore_directory=plus-more-aggressive-15 +enable_light_sensor=0 +body_mutation_epsilon=0.4 +brain_mutation_epsilon=0.4 +p_delete_subtree=0.4 +p_duplicate_subtree=0.4 +p_swap_subtree=0.4 +population_size=15 +num_children=15 +num_evolutions=32 diff --git a/scripts/offline-evolve2/input-20/baseline.conf b/scripts/offline-evolve2/input-20/baseline.conf new file mode 100644 index 0000000..7f80d63 --- /dev/null +++ b/scripts/offline-evolve2/input-20/baseline.conf @@ -0,0 +1,7 @@ +output_directory=output +restore_directory=baseline-20 +enable_light_sensor=0 +disable_evolution=1 +keep_parents=1 +population_size=20 +num_children=20 \ No newline at end of file diff --git a/scripts/offline-evolve2/input-20/plus.conf b/scripts/offline-evolve2/input-20/plus.conf new file mode 100644 index 0000000..79ed5cf --- /dev/null +++ b/scripts/offline-evolve2/input-20/plus.conf @@ -0,0 +1,5 @@ +output_directory=output +restore_directory=plus-20 +enable_light_sensor=0 +population_size=20 +num_children=20 diff --git a/scripts/offline-evolve2/input-20/plus_aggressive.conf b/scripts/offline-evolve2/input-20/plus_aggressive.conf new file mode 100644 index 0000000..7ee964d --- /dev/null +++ b/scripts/offline-evolve2/input-20/plus_aggressive.conf @@ -0,0 +1,10 @@ +output_directory=debug-output +restore_directory=plus-aggressive-20 +enable_light_sensor=0 +body_mutation_epsilon=0.3 +brain_mutation_epsilon=0.3 +p_delete_subtree=0.25 +p_duplicate_subtree=0.25 +p_swap_subtree=0.25 +population_size=20 +num_children=20 diff --git a/scripts/offline-evolve2/input-20/plus_more_aggressive.conf b/scripts/offline-evolve2/input-20/plus_more_aggressive.conf new file mode 100644 index 0000000..285e6d2 --- /dev/null +++ b/scripts/offline-evolve2/input-20/plus_more_aggressive.conf @@ -0,0 +1,10 @@ +output_directory=output +restore_directory=plus-more-aggressive-20 +enable_light_sensor=0 +body_mutation_epsilon=0.4 +brain_mutation_epsilon=0.4 +p_delete_subtree=0.4 +p_duplicate_subtree=0.4 +p_swap_subtree=0.4 +population_size=20 +num_children=20 \ No newline at end of file diff --git a/scripts/offline-evolve2/input/baseline.conf b/scripts/offline-evolve2/input/baseline.conf new file mode 100644 index 0000000..e3cf3e3 --- /dev/null +++ b/scripts/offline-evolve2/input/baseline.conf @@ -0,0 +1,5 @@ +output_directory=output +restore_directory=baseline +enable_light_sensor=0 +disable_evolution=1 +keep_parents=1 diff --git a/scripts/offline-evolve2/input/comma.conf b/scripts/offline-evolve2/input/comma.conf new file mode 100644 index 0000000..6e21d0d --- /dev/null +++ b/scripts/offline-evolve2/input/comma.conf @@ -0,0 +1,4 @@ +output_directory=output +restore_directory=comma +enable_light_sensor=0 +keep_parents=False diff --git a/scripts/offline-evolve2/input/comma_aggressive.conf b/scripts/offline-evolve2/input/comma_aggressive.conf new file mode 100644 index 0000000..7a913ef --- /dev/null +++ b/scripts/offline-evolve2/input/comma_aggressive.conf @@ -0,0 +1,9 @@ +output_directory=output +restore_directory=comma-aggressive +enable_light_sensor=0 +keep_parents=False +body_mutation_epsilon=0.3 +brain_mutation_epsilon=0.3 +p_delete_subtree=0.25 +p_duplicate_subtree=0.25 +p_swap_subtree=0.25 diff --git a/scripts/offline-evolve2/input/plus.conf b/scripts/offline-evolve2/input/plus.conf new file mode 100644 index 0000000..d615657 --- /dev/null +++ b/scripts/offline-evolve2/input/plus.conf @@ -0,0 +1,3 @@ +output_directory=output +restore_directory=plus +enable_light_sensor=0 diff --git a/scripts/offline-evolve2/input/plus_aggressive.conf b/scripts/offline-evolve2/input/plus_aggressive.conf new file mode 100644 index 0000000..62357f0 --- /dev/null +++ b/scripts/offline-evolve2/input/plus_aggressive.conf @@ -0,0 +1,8 @@ +output_directory=output +restore_directory=plus-aggressive +enable_light_sensor=0 +body_mutation_epsilon=0.3 +brain_mutation_epsilon=0.3 +p_delete_subtree=0.25 +p_duplicate_subtree=0.25 +p_swap_subtree=0.25 diff --git a/scripts/offline-evolve2/input/plus_more_aggressive.conf b/scripts/offline-evolve2/input/plus_more_aggressive.conf new file mode 100644 index 0000000..d96df1a --- /dev/null +++ b/scripts/offline-evolve2/input/plus_more_aggressive.conf @@ -0,0 +1,8 @@ +output_directory=output +restore_directory=plus-more-aggressive +enable_light_sensor=0 +body_mutation_epsilon=0.4 +brain_mutation_epsilon=0.4 +p_delete_subtree=0.4 +p_duplicate_subtree=0.4 +p_swap_subtree=0.4 diff --git a/scripts/offline-evolve2/make.sh b/scripts/offline-evolve2/make.sh new file mode 100755 index 0000000..57f317a --- /dev/null +++ b/scripts/offline-evolve2/make.sh @@ -0,0 +1,3 @@ +#!/bin/bash +cd ../../build/ +make -j4 diff --git a/scripts/offline-evolve2/offline-evolve.world b/scripts/offline-evolve2/offline-evolve.world new file mode 100644 index 0000000..8d48748 --- /dev/null +++ b/scripts/offline-evolve2/offline-evolve.world @@ -0,0 +1,39 @@ + + + + + 0 + 0 + + + 0.003 + + + 0.0 + + + + 0.1 + 10e-6 + + + 100 + 1e-8 + + + quick + + + + + + + model://sun + + + model://tol_ground + + + + + diff --git a/scripts/offline-evolve2/offline_evolve.py b/scripts/offline-evolve2/offline_evolve.py new file mode 100644 index 0000000..1715c35 --- /dev/null +++ b/scripts/offline-evolve2/offline_evolve.py @@ -0,0 +1,437 @@ +# Offline evolution scheme +# - We use a population of constant size 10 +# - Each robot is evaluated for 20 seconds, though we may vary this number +# - The average speed during this evaluation is the fitness +# - We do parent selection using a binary tournament: select two parents at +# random, the one with the best fitness is parent 1, repeat for parent 2. +# - Using this mechanism, we generate 10 children +# - After evaluation of the children, we either do: +# -- Plus scheme, sort *all* robots by fitness +# -- Comma scheme, get rid of the parents and continue with children only +from __future__ import absolute_import +import sys +import time +import os +import shutil +import random +import csv +import itertools +import logging +import trollius +from trollius import From, Return + +sys.path.append(os.path.dirname(os.path.abspath(__file__))+'/../../') + +from sdfbuilder import Pose +from sdfbuilder.math import Vector3 + +from revolve.util import wait_for + +from tol.manage.robot import Robot +from tol.config import parser +from tol.manage import World +from tol.logging import logger, output_console +from tol.util.analyze import list_extremities, count_joints, count_motors, count_extremities, count_connections + +# Log output to console +output_console() +logger.setLevel(logging.DEBUG) + +# Add offline evolve arguments +parser.add_argument( + '--population-size', + default=10, type=int, + help="Population size in each generation." +) + +parser.add_argument( + '--num-children', + default=10, type=int, + help="The number of children produced in each generation." +) + + +def str2bool(v): + return v.lower() == "true" or v == "1" + +parser.add_argument( + '--keep-parents', + default=True, type=str2bool, + help="Whether or not to discard the parents after each generation. This determines the strategy, + or ,." +) + +parser.add_argument( + '--num-generations', + default=200, type=int, + help="The number of generations to simulate." +) + +parser.add_argument( + '--disable-evolution', + default=False, type=str2bool, + help="Useful as a baseline test - if set to true, new robots are generated" + " every time rather than evolving them." +) + +parser.add_argument( + '--disable-selection', + default=False, type=str2bool, + help="Useful as a different baseline test - if set to true, robots reproduce," + " but parents are selected completely random." +) + +parser.add_argument( + '--disable-fitness', + default=False, type=str2bool, + help="Another baseline testing option, sorts robots randomly rather " + "than selecting the top pairs. This only matters if parents are kept." +) + +parser.add_argument( + '--num-evolutions', + default=30, type=int, + help="The number of times to repeat the experiment." +) + +parser.add_argument( + '--evaluation-threshold', + default=10.0, type=float, + help="Maximum number of seconds one evaluation can take before the " + "decision is made to restart from snapshot. The assumption is " + "that the world may have become slow and restarting will help." +) + + +class OfflineEvoManager(World): + """ + Extended world manager for the offline evolution script + """ + + def __init__(self, conf, _private): + """ + + :param conf: + :param _private: + :return: + """ + super(OfflineEvoManager, self).__init__(conf, _private) + + self._snapshot_data = {} + + # Output files + csvs = { + 'generations': ['run', 'gen', 'robot_id', 'vel', 'dvel', 'fitness', 't_eval'], + 'robot_details': ['robot_id', 'extremity_id', 'extremity_size', + 'joint_count', 'motor_count'] + } + self.csv_files = {k: {'filename': None, 'file': None, 'csv': None, + 'header': csvs[k]} + for k in csvs} + + self.current_run = 0 + + if self.output_directory: + for k in self.csv_files: + fname = os.path.join(self.output_directory, k + '.csv') + self.csv_files[k]['filename'] = fname + if self.do_restore: + shutil.copy(fname + '.snapshot', fname) + f = open(fname, 'ab', buffering=1) + else: + f = open(fname, 'wb', buffering=1) + + self.csv_files[k]['file'] = f + self.csv_files[k]['csv'] = csv.writer(f, delimiter=',') + + if not self.do_restore: + self.csv_files[k]['csv'].writerow(self.csv_files[k]['header']) + + def robots_header(self): + return Robot.header() + + @classmethod + @trollius.coroutine + def create(cls, conf): + """ + Coroutine to instantiate a Revolve.Angle WorldManager + :param conf: + :return: + """ + self = cls(_private=cls._PRIVATE, conf=conf) + yield From(self._init()) + raise Return(self) + + @trollius.coroutine + def create_snapshot(self): + """ + Copy the generations file in the snapshot + :return: + """ + ret = yield From(super(OfflineEvoManager, self).create_snapshot()) + if not ret: + raise Return(ret) + + for k in self.csv_files: + entry = self.csv_files[k] + if entry['file']: + entry['file'].flush() + shutil.copy(entry['filename'], entry['filename'] + '.snapshot') + + @trollius.coroutine + def get_snapshot_data(self): + """ + :return: + """ + data = yield From(super(OfflineEvoManager, self).get_snapshot_data()) + data.update(self._snapshot_data) + raise Return(data) + + @trollius.coroutine + def evaluate_pair(self, tree, bbox, parents=None): + """ + Evaluates a single robot tree. + :param tree: + :param bbox: + :param parents: + :return: Evaluated Robot object + """ + # Pause the world just in case it wasn't already + yield From(wait_for(self.pause(True))) + + pose = Pose(position=Vector3(0, 0, -bbox.min.z)) + fut = yield From(self.insert_robot(tree, pose, parents=parents)) + robot = yield From(fut) + + max_age = self.conf.evaluation_time + self.conf.warmup_time + + # Unpause the world to start evaluation + yield From(wait_for(self.pause(False))) + + before = time.time() + + while True: + if robot.age() >= max_age: + break + + # Sleep for the pose update frequency, which is about when + # we expect a new age update. + yield From(trollius.sleep(1.0 / self.state_update_frequency)) + + yield From(wait_for(self.delete_robot(robot))) + yield From(wait_for(self.pause(True))) + + diff = time.time() - before + if diff > self.conf.evaluation_threshold: + sys.stderr.write("Evaluation threshold exceeded, shutting down with nonzero status code.\n") + sys.stderr.flush() + sys.exit(15) + + raise Return(robot) + + @trollius.coroutine + def evaluate_population(self, trees, bboxes, parents=None): + """ + :param trees: + :param bboxes: + :param parents: + :return: + """ + if parents is None: + parents = [None for _ in trees] + + pairs = [] + print("Evaluating population...") + for tree, bbox, par in itertools.izip(trees, bboxes, parents): + print("Evaluating individual...") + before = time.time() + robot = yield From(self.evaluate_pair(tree, bbox, par)) + pairs.append((robot, time.time() - before)) + print("Done.") + + print("Done evaluating population.") + raise Return(pairs) + + @trollius.coroutine + def produce_generation(self, parents): + """ + Produce the next generation of robots from + the current. + :param parents: + :return: + """ + print("Producing generation...") + trees = [] + bboxes = [] + parent_pairs = [] + + while len(trees) < self.conf.num_children: + print("Producing individual...") + if self.conf.disable_selection: + p1, p2 = random.sample(parents, 2) + else: + p1, p2 = select_parents(parents, self.conf) + + for j in xrange(self.conf.max_mating_attempts): + pair = yield From(self.attempt_mate(p1, p2)) + if pair: + trees.append(pair[0]) + bboxes.append(pair[1]) + parent_pairs.append((p1, p2)) + break + + print("Done.") + + print("Done producing generation.") + raise Return(trees, bboxes, parent_pairs) + + def log_generation(self, evo, generation, pairs): + """ + :param evo: The evolution run + :param generation: + :param pairs: List of tuples (robot, evaluation wallclock time) + :return: + """ + print("================== GENERATION %d ==================" % generation) + if not self.output_directory: + return + + go = self.csv_files['generations']['csv'] + do = self.csv_files['robot_details']['csv'] + for robot, t_eval in pairs: + robot_id = robot.robot.id + root = robot.tree.root + go.writerow([evo, generation, robot.robot.id, robot.velocity(), + robot.displacement_velocity(), robot.fitness(), t_eval]) + + # TODO Write this once when robot is written instead + counter = 0 + for extr in list_extremities(root): + num_joints = count_joints(extr) + num_motors = count_motors(extr) + do.writerow((robot_id, counter, len(extr), num_joints, num_motors)) + counter += 1 + + @trollius.coroutine + def run(self): + """ + :return: + """ + conf = self.conf + + if self.do_restore: + # Recover from a previously cancelled / crashed experiment + data = self.do_restore + evo_start = data['evo_start'] + gen_start = data['gen_start'] + pairs = data['local_pairs'] + else: + # Start at the first experiment + evo_start = 1 + gen_start = 1 + pairs = None + + for evo in range(evo_start, conf.num_evolutions + 1): + self.current_run = evo + + if not pairs: + # Only create initial population if we are not restoring from + # a previous experiment. + trees, bboxes = yield From(self.generate_population(conf.population_size)) + pairs = yield From(self.evaluate_population(trees, bboxes)) + self.log_generation(evo, 0, pairs) + + for generation in xrange(gen_start, conf.num_generations): + if (generation % 10) == 0: + # Snapshot every 10 generations + self._snapshot_data = { + "local_pairs": pairs, + "gen_start": generation, + "evo_start": evo + } + yield From(self.create_snapshot()) + print("Created snapshot of experiment state.") + + # Produce the next generation and evaluate them + robots = [p[0] for p in pairs] + if conf.disable_evolution: + child_trees, child_bboxes = yield From( + self.generate_population(conf.population_size)) + parent_pairs = None + else: + child_trees, child_bboxes, parent_pairs = yield From(self.produce_generation(robots)) + + child_pairs = yield From(self.evaluate_population(child_trees, child_bboxes, parent_pairs)) + + if conf.keep_parents: + pairs += child_pairs + else: + pairs = child_pairs + + # Sort the bots and reduce to population size + if conf.disable_fitness: + random.shuffle(pairs) + else: + pairs = sorted(pairs, key=lambda r: r[0].fitness(), reverse=True) + + pairs = pairs[:conf.population_size] + self.log_generation(evo, generation, pairs) + + # Clear "restore" parameters + gen_start = 1 + pairs = None + + yield From(self.teardown()) + + @trollius.coroutine + def teardown(self): + """ + :return: + """ + yield From(super(OfflineEvoManager, self).teardown()) + for k in self.csv_files: + if self.csv_files[k]['file']: + self.csv_files[k]['file'].close() + + +def select_parent(parents, conf): + """ + Select a parent using a binary tournament. + :param parents: + :param conf: Configuration object + :return: + """ + return sorted(random.sample(parents, conf.tournament_size), key=lambda r: r.fitness())[-1] + + +def select_parents(parents, conf): + """ + :param parents: + :param conf: Configuration object + :return: + """ + p1 = select_parent(parents, conf) + p2 = select_parent(list(parent for parent in parents if parent != p1), conf) + return p1, p2 + + +@trollius.coroutine +def run(): + """ + :return: + """ + conf = parser.parse_args() + world = yield From(OfflineEvoManager.create(conf)) + yield From(world.run()) + + +def main(): + try: + loop = trollius.get_event_loop() + loop.run_until_complete(run()) + except KeyboardInterrupt: + print("Got Ctrl+C, shutting down.") + + +if __name__ == '__main__': + main() + diff --git a/scripts/offline-evolve2/rlpower.cfg b/scripts/offline-evolve2/rlpower.cfg new file mode 100644 index 0000000..6b9f00b --- /dev/null +++ b/scripts/offline-evolve2/rlpower.cfg @@ -0,0 +1,12 @@ +{ + 'algorithm': 'rlpower', + 'type': 'A', # original rlpower + 'evaluation_rate': '30.0', + 'max_evaluations': '1000', + 'max_ranked_policies': '10', + 'init_spline_size': '3', + 'interpolation_spline_size': '100', + 'init_sigma': '0.8', +# 'policy_load_path': 'spider.policy', # Used to load policy + 'sigma_tau_correction': '0.2' +} \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/babyA.yaml b/scripts/offline-evolve2/robots/babyA.yaml new file mode 100644 index 0000000..c0e0b45 --- /dev/null +++ b/scripts/offline-evolve2/robots/babyA.yaml @@ -0,0 +1,89 @@ +--- +body: + id : Core + type : Core + children : + 2: + slot : 0 + id : Leg00Joint + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Leg00 + type : FixedBrick + orientation : 0 + 3: + slot : 0 + id : Leg01Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg011Joint + type : ActiveHinge + orientation : 90 + children : + 1: + slot : 0 + id : Leg01 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg021Joint + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Leg02 + type : FixedBrick + orientation : 0 + 1: + slot : 0 + id : BodyJoint0 + type : ActiveHinge + orientation : 90 + children : + 1: + slot : 0 + id : Body0 + type : FixedBrick + orientation : -90 + children : + 1: + slot : 0 + id : BodyJoint1 + type : ActiveHinge + orientation : 90 + children : + 1: + slot : 0 + id : Body1 + type : FixedBrick + orientation : -90 + children: + 2: + slot : 0 + id : Leg10Joint + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Leg10 + type : FixedBrick + orientation : 0 + 3: + slot : 0 + id : Leg11Joint + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Leg11 + type : FixedBrick + orientation : 0 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/babyB.yaml b/scripts/offline-evolve2/robots/babyB.yaml new file mode 100644 index 0000000..4508b99 --- /dev/null +++ b/scripts/offline-evolve2/robots/babyB.yaml @@ -0,0 +1,101 @@ +--- +body: + id : Core + type : Core + children : + 0: + id : Leg00Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg00 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg01Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg01 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg02Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg02 + type : FixedBrick + orientation : -90 + 1: + id : Leg10Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg10 + type : FixedBrick + orientation : -90 + 2: + id : Leg20Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg20 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg21Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg21 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg22Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg22 + type : FixedBrick + orientation : -90 + 3: + id : Leg30Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg30 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg31Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg31 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg32Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg32 + type : FixedBrick + orientation : -90 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/babyC.yaml b/scripts/offline-evolve2/robots/babyC.yaml new file mode 100644 index 0000000..4667693 --- /dev/null +++ b/scripts/offline-evolve2/robots/babyC.yaml @@ -0,0 +1,171 @@ +--- +body: + id : Core + type : Core + children : + 2: + slot : 0 + id : Leg00Joint + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Leg00 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg001Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg001 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg002Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg002 + type : FixedBrick + orientation : 0 + 3: + slot : 0 + id : Leg01Joint + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Leg01 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg011Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg011 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg012Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg012 + type : FixedBrick + orientation : 0 + 1: + slot : 0 + id : BodyJoint0 + type : ActiveHinge + orientation : 90 + children : + 1: + slot : 0 + id : Body0 + type : FixedBrick + orientation : -90 + children : + 1: + slot : 0 + id : BodyJoint1 + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Body1 + type : FixedBrick + orientation : 0 + children : + 1: + slot : 0 + id : BodyJoint2 + type : ActiveHinge + orientation : 90 + children : + 1: + slot : 0 + id : Body2 + type : FixedBrick + orientation : -90 + children : + 1: + id : BodyJoint3 + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Body3 + type : FixedBrick + orientation : 0 + children: + 2: + slot : 0 + id : Leg10Joint + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Leg10 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg101Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg101 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg102Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg102 + type : FixedBrick + orientation : 0 + 3: + slot : 0 + id : Leg11Joint + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Leg11 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg111Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg112Joint + type : ActiveHinge + orientation : -90 + children : + 1: + id : Leg112 + type : FixedBrick + orientation : 0 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/gecko12.yaml b/scripts/offline-evolve2/robots/gecko12.yaml new file mode 100644 index 0000000..9c138ad --- /dev/null +++ b/scripts/offline-evolve2/robots/gecko12.yaml @@ -0,0 +1,124 @@ +--- +body: + id : Core + type : Core + children : + 2: + slot : 0 + id : Leg00Joint + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Leg00 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg001Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg001 + type : FixedBrick + orientation : -90 + 3: + slot : 0 + id : Leg01Joint + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Leg01 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg011Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg011 + type : FixedBrick + orientation : -90 + 1: + slot : 0 + id : BodyJoint0 + type : ActiveHinge + orientation : 90 + children : + 1: + slot : 0 + id : Body0 + type : FixedBrick + orientation : -90 + children : + 1: + slot : 0 + id : BodyJoint1 + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Body1 + type : FixedBrick + orientation : 0 + children : + 1: + id : BodyJoint2 + type : ActiveHinge + orientation : 90 + children : + 1: + slot : 0 + id : Body2 + type : FixedBrick + orientation : -90 + children: + 2: + slot : 0 + id : Leg10Joint + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Leg10 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg101Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg101 + type : FixedBrick + orientation : -90 + 3: + slot : 0 + id : Leg11Joint + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Leg11 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg111Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg111 + type : FixedBrick + orientation : -90 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/gecko17.yaml b/scripts/offline-evolve2/robots/gecko17.yaml new file mode 100644 index 0000000..5e11c4f --- /dev/null +++ b/scripts/offline-evolve2/robots/gecko17.yaml @@ -0,0 +1,176 @@ +--- +body: + id : Core + type : Core + children : + 2: + slot : 0 + id : Leg00Joint + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Leg00 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg001Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg001 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg002Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg002 + type : FixedBrick + orientation : 0 + 3: + slot : 0 + id : Leg01Joint + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Leg01 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg011Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg011 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg012Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg012 + type : FixedBrick + orientation : 0 + 1: + slot : 0 + id : BodyJoint0 + type : ActiveHinge + orientation : 90 + children : + 1: + slot : 0 + id : Body0 + type : FixedBrick + orientation : -90 + children : + 1: + slot : 0 + id : BodyJoint1 + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Body1 + type : FixedBrick + orientation : 0 + children : + 1: + slot : 0 + id : BodyJoint2 + type : ActiveHinge + orientation : 90 + children : + 1: + slot : 0 + id : Body2 + type : FixedBrick + orientation : -90 + children : + 1: + id : BodyJoint3 + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Body3 + type : FixedBrick + orientation : 0 + children: + 2: + slot : 0 + id : Leg10Joint + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Leg10 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg101Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg101 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg102Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg102 + type : FixedBrick + orientation : 0 + 3: + slot : 0 + id : Leg11Joint + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Leg11 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg111Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg111 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg112Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg112 + type : FixedBrick + orientation : 0 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/gecko7.yaml b/scripts/offline-evolve2/robots/gecko7.yaml new file mode 100644 index 0000000..806b736 --- /dev/null +++ b/scripts/offline-evolve2/robots/gecko7.yaml @@ -0,0 +1,73 @@ +--- +body: + id : Core + type : Core + children : + 2: + slot : 0 + id : Leg00Joint + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Leg00 + type : FixedBrick + orientation : 0 + 3: + slot : 0 + id : Leg01Joint + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Leg01 + type : FixedBrick + orientation : 0 + 1: + slot : 0 + id : BodyJoint0 + type : ActiveHinge + orientation : 90 + children : + 1: + slot : 0 + id : Body0 + type : FixedBrick + orientation : -90 + children : + 1: + slot : 0 + id : BodyJoint1 + type : ActiveHinge + orientation : 90 + children : + 1: + slot : 0 + id : Body1 + type : FixedBrick + orientation : -90 + children: + 2: + slot : 0 + id : Leg10Joint + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Leg10 + type : FixedBrick + orientation : 0 + 3: + slot : 0 + id : Leg11Joint + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Leg11 + type : FixedBrick + orientation : 0 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/snake5.yaml b/scripts/offline-evolve2/robots/snake5.yaml new file mode 100644 index 0000000..d09976a --- /dev/null +++ b/scripts/offline-evolve2/robots/snake5.yaml @@ -0,0 +1,41 @@ +--- +body: + id : Core + type : Core + children : + 0: + id : Leg00Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg00 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg01Joint + type : ActiveHinge + children : + 1: + id : Leg01 + type : FixedBrick + orientation : 0 + 1: + id : Leg10Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg10 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg11Joint + type : ActiveHinge + children : + 1: + id : Leg11 + type : FixedBrick + orientation : 0 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/snake7.yaml b/scripts/offline-evolve2/robots/snake7.yaml new file mode 100644 index 0000000..123bbed --- /dev/null +++ b/scripts/offline-evolve2/robots/snake7.yaml @@ -0,0 +1,63 @@ +--- +body: + id : Core + type : Core + children : + 0: + id : Leg00Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg00 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg01Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg01 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg02Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg02 + type : FixedBrick + orientation : -90 + 1: + id : Leg10Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg10 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg11Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg11 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg12Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg12 + type : FixedBrick + orientation : -90 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/snake9.yaml b/scripts/offline-evolve2/robots/snake9.yaml new file mode 100644 index 0000000..6ecf5a0 --- /dev/null +++ b/scripts/offline-evolve2/robots/snake9.yaml @@ -0,0 +1,83 @@ +--- +body: + id : Core + type : Core + children : + 0: + id : Leg00Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg00 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg01Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg01 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg02Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg02 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg03Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg03 + type : FixedBrick + orientation : 0 + 1: + id : Leg10Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg10 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg11Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg11 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg12Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg12 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg13Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg13 + type : FixedBrick + orientation : 0 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/spider13.yaml b/scripts/offline-evolve2/robots/spider13.yaml new file mode 100644 index 0000000..bce3693 --- /dev/null +++ b/scripts/offline-evolve2/robots/spider13.yaml @@ -0,0 +1,121 @@ +--- +body: + id : Core + type : Core + children : + 0: + id : Leg00Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg00 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg01Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg01 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg02Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg02 + type : FixedBrick + orientation : -90 + 1: + id : Leg10Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg10 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg11Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg11 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg12Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg12 + type : FixedBrick + orientation : -90 + 2: + id : Leg20Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg20 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg21Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg21 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg22Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg22 + type : FixedBrick + orientation : -90 + 3: + id : Leg30Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg30 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg31Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg31 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg32Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg32 + type : FixedBrick + orientation : -90 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/spider17.yaml b/scripts/offline-evolve2/robots/spider17.yaml new file mode 100644 index 0000000..8def37b --- /dev/null +++ b/scripts/offline-evolve2/robots/spider17.yaml @@ -0,0 +1,161 @@ +--- +body: + id : Core + type : Core + children : + 0: + id : Leg00Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg00 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg01Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg01 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg02Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg02 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg03Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg03 + type : FixedBrick + orientation : 0 + 1: + id : Leg10Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg10 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg11Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg11 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg12Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg12 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg13Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg13 + type : FixedBrick + orientation : 0 + 2: + id : Leg20Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg20 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg21Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg21 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg22Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg22 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg23Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg23 + type : FixedBrick + orientation : 0 + 3: + id : Leg30Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg30 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg31Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg31 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg32Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg32 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg33Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg33 + type : FixedBrick + orientation : 0 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/spider9.yaml b/scripts/offline-evolve2/robots/spider9.yaml new file mode 100644 index 0000000..53bab38 --- /dev/null +++ b/scripts/offline-evolve2/robots/spider9.yaml @@ -0,0 +1,659 @@ +body: + children: + 0: + children: + 1: + children: + 1: + children: + 1: + id: Leg01 + label: '' + orientation: 0 + params: + blue: 0.5 + green: 0.5 + red: 0.5 + slot: 0 + type: FixedBrick + id: Leg01Joint + label: '' + orientation: 0 + params: + blue: 0.5 + green: 0.5 + red: 0.5 + slot: 0 + type: ActiveHinge + id: Leg00 + label: '' + orientation: -90 + params: + blue: 0.5 + green: 0.5 + red: 0.5 + slot: 0 + type: FixedBrick + id: Leg00Joint + label: '' + orientation: 90 + params: + blue: 0.5 + green: 0.5 + red: 0.5 + slot: 0 + type: ActiveHinge + 1: + children: + 1: + children: + 1: + children: + 1: + id: Leg11 + label: '' + orientation: 0 + params: + blue: 0.5 + green: 0.5 + red: 0.5 + slot: 0 + type: FixedBrick + id: Leg11Joint + label: '' + orientation: 0 + params: + blue: 0.5 + green: 0.5 + red: 0.5 + slot: 0 + type: ActiveHinge + id: Leg10 + label: '' + orientation: -90 + params: + blue: 0.5 + green: 0.5 + red: 0.5 + slot: 0 + type: FixedBrick + id: Leg10Joint + label: '' + orientation: 90 + params: + blue: 0.5 + green: 0.5 + red: 0.5 + slot: 0 + type: ActiveHinge + 2: + children: + 1: + children: + 1: + children: + 1: + id: Leg21 + label: '' + orientation: 0 + params: + blue: 0.5 + green: 0.5 + red: 0.5 + slot: 0 + type: FixedBrick + id: Leg21Joint + label: '' + orientation: 0 + params: + blue: 0.5 + green: 0.5 + red: 0.5 + slot: 0 + type: ActiveHinge + id: Leg20 + label: '' + orientation: -90 + params: + blue: 0.5 + green: 0.5 + red: 0.5 + slot: 0 + type: FixedBrick + id: Leg20Joint + label: '' + orientation: 90 + params: + blue: 0.5 + green: 0.5 + red: 0.5 + slot: 0 + type: ActiveHinge + 3: + children: + 1: + children: + 1: + children: + 1: + id: Leg31 + label: '' + orientation: 0 + params: + blue: 0.5 + green: 0.5 + red: 0.5 + slot: 0 + type: FixedBrick + id: Leg31Joint + label: '' + orientation: 0 + params: + blue: 0.5 + green: 0.5 + red: 0.5 + slot: 0 + type: ActiveHinge + id: Leg30 + label: '' + orientation: -90 + params: + blue: 0.5 + green: 0.5 + red: 0.5 + slot: 0 + type: FixedBrick + id: Leg30Joint + label: '' + orientation: 90 + params: + blue: 0.5 + green: 0.5 + red: 0.5 + slot: 0 + type: ActiveHinge + id: Core + label: '' + orientation: 0 + params: + blue: 0.5 + green: 0.5 + red: 0.5 + type: Core +brain: + connections: + - dst: Leg00Joint-cpg-0 + socket: from_x + src: Leg00Joint-cpg-1 + weight: 1.0 + - dst: Leg00Joint-cpg-1 + socket: from_v + src: Leg00Joint-cpg-0 + weight: 1.0 + - dst: Leg00Joint-out-0 + src: Leg00Joint-cpg-0 + weight: 1.0 + - dst: Leg01Joint-cpg-2 + socket: from_x + src: Leg01Joint-cpg-3 + weight: 1.0 + - dst: Leg01Joint-cpg-3 + socket: from_v + src: Leg01Joint-cpg-2 + weight: 1.0 + - dst: Leg01Joint-out-0 + src: Leg01Joint-cpg-2 + weight: 1.0 + - dst: Leg00Joint-cpg-0 + socket: from_x_ext + src: Leg01Joint-cpg-3 + weight: 1.0 + - dst: Leg01Joint-cpg-2 + socket: from_x_ext + src: Leg00Joint-cpg-1 + weight: 1.0 + - dst: Leg00Joint-cpg-0 + socket: from_v_ext + src: Leg01Joint-cpg-2 + weight: 1.0 + - dst: Leg01Joint-cpg-2 + socket: from_v_ext + src: Leg00Joint-cpg-0 + weight: 1.0 + - dst: Leg10Joint-cpg-4 + socket: from_x + src: Leg10Joint-cpg-5 + weight: 1.0 + - dst: Leg10Joint-cpg-5 + socket: from_v + src: Leg10Joint-cpg-4 + weight: 1.0 + - dst: Leg10Joint-out-0 + src: Leg10Joint-cpg-4 + weight: 1.0 + - dst: Leg11Joint-cpg-6 + socket: from_x + src: Leg11Joint-cpg-7 + weight: 1.0 + - dst: Leg11Joint-cpg-7 + socket: from_v + src: Leg11Joint-cpg-6 + weight: 1.0 + - dst: Leg11Joint-out-0 + src: Leg11Joint-cpg-6 + weight: 1.0 + - dst: Leg10Joint-cpg-4 + socket: from_x_ext + src: Leg11Joint-cpg-7 + weight: 1.0 + - dst: Leg11Joint-cpg-6 + socket: from_x_ext + src: Leg10Joint-cpg-5 + weight: 1.0 + - dst: Leg10Joint-cpg-4 + socket: from_v_ext + src: Leg11Joint-cpg-6 + weight: 1.0 + - dst: Leg11Joint-cpg-6 + socket: from_v_ext + src: Leg10Joint-cpg-4 + weight: 1.0 + - dst: Leg20Joint-cpg-8 + socket: from_x + src: Leg20Joint-cpg-9 + weight: 1.0 + - dst: Leg20Joint-cpg-9 + socket: from_v + src: Leg20Joint-cpg-8 + weight: 1.0 + - dst: Leg20Joint-out-0 + src: Leg20Joint-cpg-8 + weight: 1.0 + - dst: Leg21Joint-cpg-10 + socket: from_x + src: Leg21Joint-cpg-11 + weight: 1.0 + - dst: Leg21Joint-cpg-11 + socket: from_v + src: Leg21Joint-cpg-10 + weight: 1.0 + - dst: Leg21Joint-out-0 + src: Leg21Joint-cpg-10 + weight: 1.0 + - dst: Leg20Joint-cpg-8 + socket: from_x_ext + src: Leg21Joint-cpg-11 + weight: 1.0 + - dst: Leg21Joint-cpg-10 + socket: from_x_ext + src: Leg20Joint-cpg-9 + weight: 1.0 + - dst: Leg20Joint-cpg-8 + socket: from_v_ext + src: Leg21Joint-cpg-10 + weight: 1.0 + - dst: Leg21Joint-cpg-10 + socket: from_v_ext + src: Leg20Joint-cpg-8 + weight: 1.0 + - dst: Leg30Joint-cpg-12 + socket: from_x + src: Leg30Joint-cpg-13 + weight: 1.0 + - dst: Leg30Joint-cpg-13 + socket: from_v + src: Leg30Joint-cpg-12 + weight: 1.0 + - dst: Leg30Joint-out-0 + src: Leg30Joint-cpg-12 + weight: 1.0 + - dst: Leg31Joint-cpg-14 + socket: from_x + src: Leg31Joint-cpg-15 + weight: 1.0 + - dst: Leg31Joint-cpg-15 + socket: from_v + src: Leg31Joint-cpg-14 + weight: 1.0 + - dst: Leg31Joint-out-0 + src: Leg31Joint-cpg-14 + weight: 1.0 + - dst: Leg30Joint-cpg-12 + socket: from_x_ext + src: Leg31Joint-cpg-15 + weight: 1.0 + - dst: Leg31Joint-cpg-14 + socket: from_x_ext + src: Leg30Joint-cpg-13 + weight: 1.0 + - dst: Leg30Joint-cpg-12 + socket: from_v_ext + src: Leg31Joint-cpg-14 + weight: 1.0 + - dst: Leg31Joint-cpg-14 + socket: from_v_ext + src: Leg30Joint-cpg-12 + weight: 1.0 + - dst: Leg00Joint-cpg-0 + src: Core-in-5 + weight: 1.0 + - dst: Leg00Joint-cpg-0 + src: Core-in-4 + weight: 1.0 + - dst: Leg00Joint-cpg-0 + src: Core-in-0 + weight: 1.0 + - dst: Leg00Joint-cpg-0 + src: Core-in-3 + weight: 1.0 + - dst: Leg00Joint-cpg-0 + src: Core-in-2 + weight: 1.0 + - dst: Leg00Joint-cpg-0 + src: Core-in-1 + weight: 1.0 + - dst: Leg10Joint-cpg-4 + src: Core-in-5 + weight: 1.0 + - dst: Leg10Joint-cpg-4 + src: Core-in-4 + weight: 1.0 + - dst: Leg10Joint-cpg-4 + src: Core-in-0 + weight: 1.0 + - dst: Leg10Joint-cpg-4 + src: Core-in-3 + weight: 1.0 + - dst: Leg10Joint-cpg-4 + src: Core-in-2 + weight: 1.0 + - dst: Leg10Joint-cpg-4 + src: Core-in-1 + weight: 1.0 + - dst: Leg20Joint-cpg-8 + src: Core-in-5 + weight: 1.0 + - dst: Leg20Joint-cpg-8 + src: Core-in-4 + weight: 1.0 + - dst: Leg20Joint-cpg-8 + src: Core-in-0 + weight: 1.0 + - dst: Leg20Joint-cpg-8 + src: Core-in-3 + weight: 1.0 + - dst: Leg20Joint-cpg-8 + src: Core-in-2 + weight: 1.0 + - dst: Leg20Joint-cpg-8 + src: Core-in-1 + weight: 1.0 + - dst: Leg30Joint-cpg-12 + src: Core-in-5 + weight: 1.0 + - dst: Leg30Joint-cpg-12 + src: Core-in-4 + weight: 1.0 + - dst: Leg30Joint-cpg-12 + src: Core-in-0 + weight: 1.0 + - dst: Leg30Joint-cpg-12 + src: Core-in-3 + weight: 1.0 + - dst: Leg30Joint-cpg-12 + src: Core-in-2 + weight: 1.0 + - dst: Leg30Joint-cpg-12 + src: Core-in-1 + weight: 1.0 + - dst: Leg10Joint-cpg-4 + socket: from_x_ext + src: Leg00Joint-cpg-1 + weight: 1.0 + - dst: Leg00Joint-cpg-0 + socket: from_x_ext + src: Leg10Joint-cpg-5 + weight: 1.0 + - dst: Leg10Joint-cpg-4 + socket: from_v_ext + src: Leg00Joint-cpg-0 + weight: 1.0 + - dst: Leg00Joint-cpg-0 + socket: from_v_ext + src: Leg10Joint-cpg-4 + weight: 1.0 + - dst: Leg20Joint-cpg-8 + socket: from_x_ext + src: Leg00Joint-cpg-1 + weight: 1.0 + - dst: Leg00Joint-cpg-0 + socket: from_x_ext + src: Leg20Joint-cpg-9 + weight: 1.0 + - dst: Leg20Joint-cpg-8 + socket: from_v_ext + src: Leg00Joint-cpg-0 + weight: 1.0 + - dst: Leg00Joint-cpg-0 + socket: from_v_ext + src: Leg20Joint-cpg-8 + weight: 1.0 + - dst: Leg30Joint-cpg-12 + socket: from_x_ext + src: Leg00Joint-cpg-1 + weight: 1.0 + - dst: Leg00Joint-cpg-0 + socket: from_x_ext + src: Leg30Joint-cpg-13 + weight: 1.0 + - dst: Leg30Joint-cpg-12 + socket: from_v_ext + src: Leg00Joint-cpg-0 + weight: 1.0 + - dst: Leg00Joint-cpg-0 + socket: from_v_ext + src: Leg30Joint-cpg-12 + weight: 1.0 + - dst: Leg20Joint-cpg-8 + socket: from_x_ext + src: Leg10Joint-cpg-5 + weight: 1.0 + - dst: Leg10Joint-cpg-4 + socket: from_x_ext + src: Leg20Joint-cpg-9 + weight: 1.0 + - dst: Leg20Joint-cpg-8 + socket: from_v_ext + src: Leg10Joint-cpg-4 + weight: 1.0 + - dst: Leg10Joint-cpg-4 + socket: from_v_ext + src: Leg20Joint-cpg-8 + weight: 1.0 + - dst: Leg30Joint-cpg-12 + socket: from_x_ext + src: Leg10Joint-cpg-5 + weight: 1.0 + - dst: Leg10Joint-cpg-4 + socket: from_x_ext + src: Leg30Joint-cpg-13 + weight: 1.0 + - dst: Leg30Joint-cpg-12 + socket: from_v_ext + src: Leg10Joint-cpg-4 + weight: 1.0 + - dst: Leg10Joint-cpg-4 + socket: from_v_ext + src: Leg30Joint-cpg-12 + weight: 1.0 + - dst: Leg30Joint-cpg-12 + socket: from_x_ext + src: Leg20Joint-cpg-9 + weight: 1.0 + - dst: Leg20Joint-cpg-8 + socket: from_x_ext + src: Leg30Joint-cpg-13 + weight: 1.0 + - dst: Leg30Joint-cpg-12 + socket: from_v_ext + src: Leg20Joint-cpg-8 + weight: 1.0 + - dst: Leg20Joint-cpg-8 + socket: from_v_ext + src: Leg30Joint-cpg-12 + weight: 1.0 + neurons: + Leg00Joint-cpg-0: + id: Leg00Joint-cpg-0 + layer: hidden + part_id: Leg00Joint + type: V-Neuron + Leg00Joint-cpg-1: + id: Leg00Joint-cpg-1 + layer: hidden + part_id: Leg00Joint + type: X-Neuron + Leg01Joint-cpg-2: + id: Leg01Joint-cpg-2 + layer: hidden + part_id: Leg01Joint + type: V-Neuron + Leg01Joint-cpg-3: + id: Leg01Joint-cpg-3 + layer: hidden + part_id: Leg01Joint + type: X-Neuron + Leg10Joint-cpg-4: + id: Leg10Joint-cpg-4 + layer: hidden + part_id: Leg10Joint + type: V-Neuron + Leg10Joint-cpg-5: + id: Leg10Joint-cpg-5 + layer: hidden + part_id: Leg10Joint + type: X-Neuron + Leg11Joint-cpg-6: + id: Leg11Joint-cpg-6 + layer: hidden + part_id: Leg11Joint + type: V-Neuron + Leg11Joint-cpg-7: + id: Leg11Joint-cpg-7 + layer: hidden + part_id: Leg11Joint + type: X-Neuron + Leg20Joint-cpg-8: + id: Leg20Joint-cpg-8 + layer: hidden + part_id: Leg20Joint + type: V-Neuron + Leg20Joint-cpg-9: + id: Leg20Joint-cpg-9 + layer: hidden + part_id: Leg20Joint + type: X-Neuron + Leg21Joint-cpg-10: + id: Leg21Joint-cpg-10 + layer: hidden + part_id: Leg21Joint + type: V-Neuron + Leg21Joint-cpg-11: + id: Leg21Joint-cpg-11 + layer: hidden + part_id: Leg21Joint + type: X-Neuron + Leg30Joint-cpg-12: + id: Leg30Joint-cpg-12 + layer: hidden + part_id: Leg30Joint + type: V-Neuron + Leg30Joint-cpg-13: + id: Leg30Joint-cpg-13 + layer: hidden + part_id: Leg30Joint + type: X-Neuron + Leg31Joint-cpg-14: + id: Leg31Joint-cpg-14 + layer: hidden + part_id: Leg31Joint + type: V-Neuron + Leg31Joint-cpg-15: + id: Leg31Joint-cpg-15 + layer: hidden + part_id: Leg31Joint + type: X-Neuron + params: + Leg00Joint-cpg-0: + alpha: 1.0 + energy: 1.0 + tau: 1.0 + Leg00Joint-cpg-1: + tau: 1.0 + Leg00Joint-out-0: + bias: 0.0 + gain: 0.5 + Leg01Joint-cpg-2: + alpha: 1.0 + energy: 1.0 + tau: 1.0 + Leg01Joint-cpg-3: + tau: 1.0 + Leg01Joint-out-0: + bias: 0.0 + gain: 0.5 + Leg10Joint-cpg-4: + alpha: 1.0 + energy: 1.0 + tau: 1.0 + Leg10Joint-cpg-5: + tau: 1.0 + Leg10Joint-out-0: + bias: 0.0 + gain: 0.5 + Leg11Joint-cpg-6: + alpha: 1.0 + energy: 1.0 + tau: 1.0 + Leg11Joint-cpg-7: + tau: 1.0 + Leg11Joint-out-0: + bias: 0.0 + gain: 0.5 + Leg20Joint-cpg-8: + alpha: 1.0 + energy: 1.0 + tau: 1.0 + Leg20Joint-cpg-9: + tau: 1.0 + Leg20Joint-out-0: + bias: 0.0 + gain: 0.5 + Leg21Joint-cpg-10: + alpha: 1.0 + energy: 1.0 + tau: 1.0 + Leg21Joint-cpg-11: + tau: 1.0 + Leg21Joint-out-0: + bias: 0.0 + gain: 0.5 + Leg30Joint-cpg-12: + alpha: 1.0 + energy: 1.0 + tau: 1.0 + Leg30Joint-cpg-13: + tau: 1.0 + Leg30Joint-out-0: + bias: 0.0 + gain: 0.5 + Leg31Joint-cpg-14: + alpha: 1.0 + energy: 1.0 + tau: 1.0 + Leg31Joint-cpg-15: + tau: 1.0 + Leg31Joint-out-0: + bias: 0.0 + gain: 0.5 +id: 0 diff --git a/scripts/offline-evolve2/run-experiments.sh b/scripts/offline-evolve2/run-experiments.sh new file mode 100755 index 0000000..ddf01fd --- /dev/null +++ b/scripts/offline-evolve2/run-experiments.sh @@ -0,0 +1,83 @@ +#!/usr/bin/env bash + +# Handle keyboard interrupt +trap " exit " INT + +PROGNAME=$(basename $0) + +# Default argument list +robot_list=( spider9 spider13 spider17 gecko7 gecko12 gecko17 snake5 snake7 snake9 babyA babyB babyC ) + +config=rlpower.cfg +manager=single_robot_manager.py +world=gait-learning.world +output=output +restore=restore +gz_command=gzserver +no_experiments=10 + +function error_exit() { + echo "${PROGNAME}: ${1:-"Unknown Error"}" 1 >&2 + exit 1 +} + +function help() { + echo "Usage: ${PROGNAME} [args...]" + echo "Arguments:" + echo " -c | --config Path to robot brain config file" + echo " -g | --gzcommand Gazebo command [gzserver|gazebo] Default: gzserver" + echo " -h | --help Help page" + echo " -m | --manager Name of script that controls robots and the environment" + echo " -n | --no-experiments Number of experiment repetitions" + echo " -o | --output Name of the output directory" + echo " -r | --restore Name of the restore directory" + echo " -w | --world Name of world file" + + exit 0 +} + +function main() { + + # Read out the argument list + if [ $# -gt 0 ]; then + while [ "$1" != "" ] + do + local argument="$1"; + shift + local parameter="$1"; + shift + case ${argument} in + -c | --config) local config=${parameter} ;; + -g | --gzcommand) local gz_command=${parameter} ;; + -h | --help) help ;; + -m | --manager) local manager=${parameter} ;; + -n | --no-experiments) local no_experiments=${parameter} ;; + -o | --output) local output=${parameter} ;; + -r | --restore) local restore=${parameter} ;; + -w | --world) local world=${parameter} ;; + *) error_exit "${LINENO}: In ${FUNCNAME}() unknown argument ${argument}." ;; + esac + done + fi + + # For each name in 'robot_list' run 'no_experiments' experiments + for index in ${!robot_list[*]} + do + for (( i = 1; i <= ${no_experiments}; ++ i )) + do + python start.py \ + --manager ${manager} \ + --world ${world} \ + --output ${output} \ + --restore ${restore} \ + --robot-name robots/${robot_list[$index]} \ + --experiment-round ${i} \ + --brain-conf-path ${config} \ + --gazebo-cmd ${gz_command} + done + done + + exit 0 +} + +main $@ diff --git a/scripts/offline-evolve2/single_robot_manager.py b/scripts/offline-evolve2/single_robot_manager.py new file mode 100644 index 0000000..633c4f7 --- /dev/null +++ b/scripts/offline-evolve2/single_robot_manager.py @@ -0,0 +1,101 @@ +import ast +import os +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..')) + +from pygazebo.pygazebo import DisconnectError +from trollius.py33_exceptions import ConnectionResetError + +import trollius +from trollius import From + +from tol.config import parser +from tol.manage import World + +from sdfbuilder import Pose +from sdfbuilder.math import Vector3 + +from revolve.convert.yaml import yaml_to_robot +from revolve.angle import Tree +from revolve.util import wait_for + +from tol.spec import get_extended_brain_spec + + +@trollius.coroutine +def run(): + """ + The main coroutine, which is started below. + """ + # Parse command line / file input arguments + conf = parser.parse_args() + + # Adding brain configuration + with open(conf.brain_conf_path, 'r') as f: + s = f.read() + brain_conf = ast.literal_eval(s) + brain_conf["policy_load_path"] = conf.load_controller + conf.brain_conf = brain_conf + + # This disables the analyzer; enable it if you want to generate valid robots + # Can also do this using arguments of course, just pass an empty string + # conf.analyzer_address = None + + with open("{}.yaml".format(conf.robot_name), 'r') as yamlfile: + bot_yaml = yamlfile.read() + + # Create the world, this connects to the Gazebo world + world = yield From(World.create(conf)) + + # These are useful when working with YAML + body_spec = world.builder.body_builder.spec + brain_spec = get_extended_brain_spec(conf) + + # Create a robot from YAML + robot = yaml_to_robot(body_spec, brain_spec, bot_yaml) + + # Create a revolve.angle `Tree` representation from the robot, which + # is what is used in the world manager. + robot_tree = Tree.from_body_brain(robot.body, robot.brain, body_spec) + + # Insert the robot into the world. `insert_robot` resolves when the insert + # request is sent, the future it returns resolves when the robot insert + # is actually confirmed and a robot manager object has been created + pose = Pose(position=Vector3(0, 0, 0.05)) + future = yield From(world.insert_robot(robot_tree, pose, "{}-{}".format(conf.robot_name, conf.experiment_round))) + robot_manager = yield From(future) + + # I usually start the world paused, un-pause it here. Note that + # pause again returns a future for when the request is sent, + # that future in turn resolves when a response has been received. + # This is the general convention for all message actions in the + # world manager. `wait_for` saves the hassle of grabbing the + # intermediary future in this case. + yield From(wait_for(world.pause(False))) + + # Start a run loop to do some stuff + while True: + # Print robot fitness every second + print("Robot fitness: %f" % robot_manager.fitness()) + yield From(trollius.sleep(1.0)) + + +def main(): + def handler(loop, context): + exc = context['exception'] + if isinstance(exc, DisconnectError) or isinstance(exc, ConnectionResetError): + print("Got disconnect / connection reset - shutting down.") + sys.exit(0) + raise context['exception'] + + try: + loop = trollius.get_event_loop() + loop.set_exception_handler(handler) + loop.run_until_complete(run()) + except KeyboardInterrupt: + print("Got CtrlC, shutting down.") + + +if __name__ == '__main__': + main() diff --git a/scripts/offline-evolve2/start.py b/scripts/offline-evolve2/start.py new file mode 100644 index 0000000..285a737 --- /dev/null +++ b/scripts/offline-evolve2/start.py @@ -0,0 +1,57 @@ +import os +import sys + +here = os.path.dirname(os.path.abspath(__file__)) +tol_path = os.path.abspath(os.path.join(here, '..', '..')) +rv_path = os.path.abspath(os.path.join(tol_path, '..', 'revolve')) +sys.path.append(os.path.dirname(os.path.abspath(__file__))) + +from revolve.util import Supervisor +from offline_evolve import parser + + +class OfflineEvolutionSupervisor(Supervisor): + """ + Supervisor class that adds some output filtering for ODE errors + """ + + def __init__(self, *args, **kwargs): + super(OfflineEvolutionSupervisor, self).__init__(*args, **kwargs) + self.ode_errors = 0 + + def write_stderr(self, data): + """ + :param data: + :return: + """ + if 'ODE Message 3' in data: + self.ode_errors += 1 + elif data.strip(): + sys.stderr.write(data) + + if self.ode_errors >= 100: + self.ode_errors = 0 + sys.stderr.write('ODE Message 3 (100)\n') + + +args = parser.parse_args() + +os.environ['GAZEBO_PLUGIN_PATH'] = os.path.join(tol_path, 'build') +os.environ['GAZEBO_MODEL_PATH'] = os.path.join(tol_path, 'tools', 'models') + \ + ':' + os.path.join(rv_path, 'tools', 'models') + +supervisor = OfflineEvolutionSupervisor( + manager_cmd=[sys.executable, args.manager, + "--load-controller", args.load_controller, + "--robot-name", args.robot_name, + "--experiment-round", args.experiment_round, + "--brain-conf-path", args.brain_conf_path], + analyzer_cmd=os.path.join(rv_path, 'tools', 'analyzer', 'run-analyzer'), + world_file=os.path.join(here, args.world), + output_directory=args.output_directory, + restore_directory=args.restore_directory, + gazebo_cmd=args.gazebo_cmd, + manager_args=sys.argv[1:] +) + +supervisor.launch() diff --git a/scripts/offline-evolve2/summarize.R b/scripts/offline-evolve2/summarize.R new file mode 100644 index 0000000..a83d9a0 --- /dev/null +++ b/scripts/offline-evolve2/summarize.R @@ -0,0 +1,103 @@ +# Use this script to summarize one or multiple concatenated +# runs of evolution data. +# This post helps here: +# http://stackoverflow.com/a/10349375/358873 + +library(ggplot2) +library(plyr) +library(reshape) + +read_dir_data <- function(odir) { + tdata = read.csv(paste(odir, "/generations.csv", sep=""), head=TRUE); + tdata$exp = as.factor(odir); + if (tdata[1,]$exp == "plus-gradual") { + tdata$births = tdata$gen + 15; + } else { + tdata$births = tdata$gen * 15 + 15; + } + + rdata = read.csv(paste(odir, "/robots.csv", sep=""), head=TRUE); + + return(merge(tdata[tdata$births<=3000,], rdata, by.x=c("robot_id", "run"), by.y=c("id", "run"))); +} + +dirs = list.files("."); +data = do.call(rbind, lapply(dirs, read_dir_data)); + +# Unify fitness calculation +data$fitness = 5*data$dvel + data$vel; + +# Remove outliers +data = data[data$fitness<1,]; + +cdata = ddply(data, c("births", "exp"), summarise, + fit=mean(fitness), fsd=sd(fitness), + ext=mean(extremity_count), esd=sd(extremity_count), + joints=mean(joint_count), jsd=sd(joint_count), + motors=mean(motor_count), msd=sd(motor_count), + sz=mean(nparts), ssd=sd(nparts), + inp=mean(inputs), isd=sd(inputs), + hid=mean(hidden), hsd=sd(hidden), + con=mean(conn), csd=sd(conn) + ); + +cdata$plot = as.factor("Fitness"); +cdata1 = cdata; +cdata2 = cdata; +cdata3 = cdata; +cdata4 = cdata; +cdata5 = cdata; +cdata6 = cdata; +cdata7 = cdata; + +cdata1$plot = as.factor("# of joints"); +cdata2$plot = as.factor("# of active joints"); +cdata3$plot = as.factor("Total size"); +cdata4$plot = as.factor("# of extremities"); +cdata5$plot = as.factor("# of inputs"); +cdata6$plot = as.factor("# of hidden neurons"); +cdata7$plot = as.factor("# of connections"); + +# Fitness over generations +ggplot(cdata, aes(births)) + + facet_grid(plot~., scale="free") + + geom_line(aes(y=fit, colour=exp)) + + geom_ribbon(aes(ymin=fit-fsd, ymax=fit+fsd, fill=exp), alpha=0.1, linetype=0) + + + geom_line(data=cdata1, aes(y=joints, colour=exp)) + + geom_ribbon(data=cdata1, aes(ymin=joints-jsd, ymax=joints+jsd, fill=exp), alpha=0.1, linetype=0) + + + geom_line(data=cdata2, aes(y=motors, colour=exp)) + + geom_ribbon(data=cdata2, aes(ymin=motors-jsd, ymax=motors+jsd, fill=exp), alpha=0.1, linetype=0) + + + geom_line(data=cdata3, aes(y=sz, colour=exp)) + + geom_ribbon(data=cdata3, aes(ymin=sz-ssd, ymax=sz+ssd, fill=exp), alpha=0.1, linetype=0) + + + geom_line(data=cdata4, aes(y=ext, colour=exp)) + + geom_ribbon(data=cdata4, aes(ymin=ext-esd, ymax=ext+esd, fill=exp), alpha=0.1, linetype=0) + + + geom_line(data=cdata5, aes(y=inp, colour=exp)) + + geom_ribbon(data=cdata5, aes(ymin=inp-isd, ymax=inp+isd, fill=exp), alpha=0.1, linetype=0) + + + geom_line(data=cdata6, aes(y=hid, colour=exp)) + + geom_ribbon(data=cdata6, aes(ymin=hid-hsd, ymax=hid+hsd, fill=exp), alpha=0.1, linetype=0) + + + geom_line(data=cdata7, aes(y=con, colour=exp)) + + geom_ribbon(data=cdata7, aes(ymin=con-csd, ymax=con+csd, fill=exp), alpha=0.1, linetype=0) + + + scale_fill_discrete(name="Experiment") + + scale_colour_discrete(name="Experiment") + + xlab("# of births") + + ylab(""); + +#last_gens = cdata[cdata$gen==max(cdata$gen),]; + +# Retrieve all the best robots per experiment +# See http://stackoverflow.com/questions/6289538/aggregate-a-dataframe-on-a-given-column-and-display-another-column +exp_maxes = do.call(rbind,lapply(split(data, list(data$exp, data$run)),function(chunk) chunk[which.max(chunk$fitness),])) +exp_maxes = exp_maxes[order(-exp_maxes$fitness),] + +exp_states = ddply(data, ~exp+run, summarise, cur_gen=max(gen)); +exp_states = exp_states[order(exp_states$exp, -exp_states$run),]; + +exp_states diff --git a/tol-revolve.kdev4 b/tol-revolve.kdev4 new file mode 100644 index 0000000..401c4b8 --- /dev/null +++ b/tol-revolve.kdev4 @@ -0,0 +1,3 @@ +[Project] +Manager=KDevCMakeManager +Name=tol-revolve diff --git a/tol/build/builder.py b/tol/build/builder.py index c48a35f..7797117 100644 --- a/tol/build/builder.py +++ b/tol/build/builder.py @@ -1,7 +1,7 @@ from revolve.build.sdf import RobotBuilder, BodyBuilder, NeuralNetBuilder, BasicBattery from revolve.angle.robogen.util import apply_surface_parameters from sdfbuilder import SDF -from ..spec import get_body_spec, get_brain_spec +from ..spec import get_body_spec, get_brain_spec, get_extended_brain_spec def get_builder(conf): @@ -10,7 +10,7 @@ def get_builder(conf): :return: """ body_spec = get_body_spec(conf) - brain_spec = get_brain_spec(conf) + brain_spec = get_extended_brain_spec(conf) return RobotBuilder(BodyBuilder(body_spec, conf), NeuralNetBuilder(brain_spec)) diff --git a/tol/spec/__init__.py b/tol/spec/__init__.py index aa043df..3f7a09a 100644 --- a/tol/spec/__init__.py +++ b/tol/spec/__init__.py @@ -1,5 +1,6 @@ from .body import get_body_spec, get_body_generator from .brain import get_brain_spec, get_brain_generator +from .extended_brain import get_extended_brain_spec from .robot import get_tree_generator __author__ = 'Elte Hupkes' diff --git a/tol/spec/extended_brain.py b/tol/spec/extended_brain.py new file mode 100644 index 0000000..4da2a91 --- /dev/null +++ b/tol/spec/extended_brain.py @@ -0,0 +1,118 @@ +from __future__ import absolute_import + +from revolve.generate import NeuralNetworkGenerator +from revolve.spec import default_neural_net, NeuralNetImplementation, NeuronSpec, ParamSpec + +from ..config import constants + + +def get_extended_brain_spec(conf): + """ + Returns the brain specification corresponding to the + given config. + :param conf: + :return: + """ + epsilon = conf.brain_mutation_epsilon + + return NeuralNetImplementation({ + "Input": NeuronSpec( + layers=["input"] + ), + + "Sigmoid": NeuronSpec( + params=[ + ParamSpec("bias", min_value=-1, max_value=1, default=0, epsilon=epsilon), + ParamSpec("gain", min_value=0, max_value=1, default=.5, epsilon=epsilon) + ], + layers=["output", "hidden"] + ), + + "Simple": NeuronSpec( + params=[ + ParamSpec("bias", min_value=-1, max_value=1, epsilon=epsilon), + ParamSpec("gain", min_value=0, max_value=1, default=.5, epsilon=epsilon) + ], + layers=["output", "hidden"] + ), + + # "Gain": NeuronSpec( + # params=[ + # ParamSpec("gain", min_value=0, max_value=1, default=.5, epsilon=epsilon) + # ], + # layers=["output", "hidden"] + # ), + + "Bias": NeuronSpec( + params=[ + ParamSpec("bias", min_value=-1.0, max_value=1.0, epsilon=epsilon), + ], + layers=["output", "hidden"] + ), + + "Oscillator": NeuronSpec( + params=[ + ParamSpec("period", min_value=0, max_value=10, epsilon=epsilon), + ParamSpec("phase_offset", min_value=0, max_value=3.14, epsilon=epsilon), + ParamSpec("amplitude", min_value=0, default=1, max_value=10000, epsilon=epsilon) + ], + layers=["output", "hidden"] + ), + + + # these neurons are for the nonlinear oscillator CPG model found in Ijspeert (2005): + "V-Neuron": NeuronSpec( + params=[ + ParamSpec("alpha", min_value = 0.05, max_value = 10.0, epsilon = epsilon), + ParamSpec("tau", min_value = 1.0, max_value = 50.0, epsilon = epsilon), + ParamSpec("energy", min_value = 0.0, max_value = 25.0, epsilon = epsilon) + ], + layers = ["output", "hidden"] + ), + + "X-Neuron": NeuronSpec( + params=[ + ParamSpec("tau", min_value = 0.01, max_value = 5.0, epsilon = epsilon), + ], + layers = ["output", "hidden"] + ), + + "DifferentialCPG": NeuronSpec( + params=[ + ParamSpec("bias", min_value = -1.0, max_value = 1.0, epsilon = epsilon), + ], + layers = ["output", "hidden"] + ), + + # # Leaky integrator + # "Leaky": NeuronSpec( + # params=[ + # ParamSpec("bias", min_value = 0.01, max_value = 10.0, epsilon = epsilon), + # ParamSpec("tau", min_value = 0.01, max_value = 10.0, epsilon = epsilon), + # ], + # layers = ["output", "hidden"] + # ), + + # "NL-Main": NeuronSpec( + # params=[ + # ParamSpec("a", min_value = 0.01, max_value = 10.0, epsilon = epsilon), + # ParamSpec("amplitude", min_value = 0.01, max_value = 10.0, epsilon = epsilon) + # ], + # layers = ["output", "hidden"] + # ) + + # "NL-Theta": NeuronSpec( + # params=[ + # ParamSpec("freq", min_value = 0.01, max_value = 10.0, epsilon = epsilon) + # ], + # layers = ["output", "hidden"] + # ) + + # "QuadNeuron": NeuronSpec( + # params=[], + # layers = ["output", "hidden"] + # ) + + }) + + From 0d18ccc73ff323f28f8d665fdc438f74e3ecea43 Mon Sep 17 00:00:00 2001 From: raki123 Date: Thu, 17 Nov 2016 18:51:52 +0100 Subject: [PATCH 02/10] changed according to info from revolve-brain --- .gitignore | 3 + .kdev4/tol-revolve.kdev4 | 10 -- cpp/CMakeLists.txt | 2 +- cpp/tol/plugin/ExtendedNeuralNetwork.h | 69 ----------- cpp/tol/plugin/RobotController.cpp | 2 +- ...etwork.cpp => extended_neural_network.cpp} | 2 +- cpp/tol/plugin/extended_neural_network.h | 111 ++++++++++++++++++ 7 files changed, 117 insertions(+), 82 deletions(-) delete mode 100644 .kdev4/tol-revolve.kdev4 delete mode 100644 cpp/tol/plugin/ExtendedNeuralNetwork.h rename cpp/tol/plugin/{ExtendedNeuralNetwork.cpp => extended_neural_network.cpp} (99%) create mode 100644 cpp/tol/plugin/extended_neural_network.h diff --git a/.gitignore b/.gitignore index b0ba6e5..1d93be6 100644 --- a/.gitignore +++ b/.gitignore @@ -63,6 +63,9 @@ target/ # PyCharm project files .idea +#kdev files +*.kdev4 + # Virtual env .venv diff --git a/.kdev4/tol-revolve.kdev4 b/.kdev4/tol-revolve.kdev4 deleted file mode 100644 index 8947d13..0000000 --- a/.kdev4/tol-revolve.kdev4 +++ /dev/null @@ -1,10 +0,0 @@ -[CMake] -ProjectRootRelative=./ - -[Defines And Includes][Compiler] -Name=GCC -Path=gcc -Type=GCC - -[Project] -VersionControlSupport=kdevgit diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 77e1898..0f8b35e 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -65,7 +65,7 @@ file(GLOB_RECURSE tol/plugin/fakebrain.cpp tol/plugin/helper.cpp tol/plugin/rlpower.cpp - tol/plugin/ExtendedNeuralNetwork.cpp + tol/plugin/extended_neural_network.cpp ) add_library(tolworldcontrol SHARED ${TOL_WORLD_SRC}) diff --git a/cpp/tol/plugin/ExtendedNeuralNetwork.h b/cpp/tol/plugin/ExtendedNeuralNetwork.h deleted file mode 100644 index 23a3c46..0000000 --- a/cpp/tol/plugin/ExtendedNeuralNetwork.h +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef REVOLVE_GAZEBO_BRAIN_DIFFERENTIAL_NEAT_H -#define REVOLVE_GAZEBO_BRAIN_DIFFERENTIAL_NEAT_H - -#include "brain/ccpg/ExtendedNeuralNetwork.h" -#include "evaluator.h" -#include "revolve/gazebo/brain/Brain.h" - - -#include -#include - -#include -#include - -namespace tol { - - class ExtendedNeuralNetwork : public revolve::gazebo::Brain, private revolve::brain::ExtendedNeuralNetwork { - - public: - ExtendedNeuralNetwork(std::string modelName, - tol::EvaluatorPtr evaluator, - sdf::ElementPtr node, - const std::vector &actuators, - const std::vector &sensors); - - virtual ~ExtendedNeuralNetwork(); - - /** - * Method for updating sensors readings, actuators positions, ranked list of policies and generating new policy - * @param actuators: vector list of robot's actuators - * @param sensors: vector list of robot's sensors - * @param t: - * @param step: - */ - virtual void update(const std::vector &actuators, - const std::vector &sensors, - double t, - double step); - - static ExtNNConfig parseSDF(sdf::ElementPtr node, - const std::vector & motors, - const std::vector & sensors); - - static std::map parseSDFElement(sdf::ElementPtr elem); - - static void connectionHelper(const std::string &src, - const std::string &dst, - const std::string &socket, - double weight, - const std::map &idToNeuron, - ExtNNConfig& ret); - - static revolve::brain::NeuronPtr neuronHelper(sdf::ElementPtr neuron, - ExtNNConfig& ret); - - static revolve::brain::NeuronPtr addNeuron(const std::string &neuronId, - const std::string &neuronType, - const std::string &neuronLayer, // can be 'hidden', 'input' or 'output' - const std::map ¶ms, - ExtNNConfig& ret); - - - }; - -} /* namespace tol */ - -#endif //REVOLVE_GAZEBO_BRAIN_REINFORCEDLEARNING_H - - diff --git a/cpp/tol/plugin/RobotController.cpp b/cpp/tol/plugin/RobotController.cpp index 24a4144..1389dd8 100644 --- a/cpp/tol/plugin/RobotController.cpp +++ b/cpp/tol/plugin/RobotController.cpp @@ -7,7 +7,7 @@ #include "RobotController.h" #include "rlpower.h" -#include "ExtendedNeuralNetwork.h" +#include "extended_neural_network.h" #include diff --git a/cpp/tol/plugin/ExtendedNeuralNetwork.cpp b/cpp/tol/plugin/extended_neural_network.cpp similarity index 99% rename from cpp/tol/plugin/ExtendedNeuralNetwork.cpp rename to cpp/tol/plugin/extended_neural_network.cpp index 0e390b7..8cd13cd 100644 --- a/cpp/tol/plugin/ExtendedNeuralNetwork.cpp +++ b/cpp/tol/plugin/extended_neural_network.cpp @@ -1,4 +1,4 @@ -#include "ExtendedNeuralNetwork.h" +#include "extended_neural_network.h" #include "helper.h" #include "sensor.h" #include "actuator.h" diff --git a/cpp/tol/plugin/extended_neural_network.h b/cpp/tol/plugin/extended_neural_network.h new file mode 100644 index 0000000..740daf6 --- /dev/null +++ b/cpp/tol/plugin/extended_neural_network.h @@ -0,0 +1,111 @@ +#ifndef REVOLVE_GAZEBO_BRAIN_DIFFERENTIAL_NEAT_H +#define REVOLVE_GAZEBO_BRAIN_DIFFERENTIAL_NEAT_H + +#include "brain/ccpg/extended_neural_network.h" +#include "evaluator.h" +#include "revolve/gazebo/brain/Brain.h" + + +#include +#include + +#include +#include + +namespace tol { + + class ExtendedNeuralNetwork : public revolve::gazebo::Brain, private revolve::brain::ExtendedNeuralNetwork { + + public: + /** + * Constructor for a neural network including neurons that are of a different type than the usual ones. + * @param modelName: name of the model + * @param evaluator: pointer to the evaluator that is used + * @param node: the sdf file containing the necessary information to build the network + * @param actuators: vector list of robot's actuators + * @param sensors: vector list of robot's sensors + * @return pointer to the neural network + */ + ExtendedNeuralNetwork(std::string modelName, + tol::EvaluatorPtr evaluator, + sdf::ElementPtr node, + const std::vector &actuators, + const std::vector &sensors); + + virtual ~ExtendedNeuralNetwork(); + + /** + * Method for updating sensors readings, actuators positions, ranked list of policies and generating new policy + * @param actuators: vector list of robot's actuators + * @param sensors: vector list of robot's sensors + * @param t: + * @param step: + */ + virtual void update(const std::vector &actuators, + const std::vector &sensors, + double t, + double step); + + /** + * Method to transform the sdf file to a configuration + * @param node: sdf file to be transformed + * @param motors: vector list of robot's motors + * @param sensors: vector list of robot's sensors + * @return configuration needed for the neural network + */ + static ExtNNConfig parseSDF(sdf::ElementPtr node, + const std::vector & motors, + const std::vector & sensors); + + /** + * Method to get the parameters of neurons from an sdf ElementPtr + * @param elem: sdf that includes the parameters + * @return string to parameter mapping + */ + static std::map parseSDFElement(sdf::ElementPtr elem); + + /** + * Helpermethod for getting the configuration + * adds a new connection to the configuration + * @param src: the beginning of the connetion + * @param dst: the end of the connection + * @param weight: weighting factor of the connection + * @param idToNeuron: mapping between the neurons and their ids + * @param ret: configuration for the network where the connection should be included + */ + static void connectionHelper(const std::string &src, + const std::string &dst, + const std::string &socket, + double weight, + const std::map &idToNeuron, + ExtNNConfig& ret); + /** + * Helpermethod for getting the configuration + * @param neuron: sdf for the neuron to be added + * @param ret: configuration for the network where the neuron should be added + */ + static revolve::brain::NeuronPtr neuronHelper(sdf::ElementPtr neuron, + ExtNNConfig& ret); + + /** + * Helpermethod for getting the configuration + * This function creates neurons and adds them to the configuration + * @param neuronId: id of the neuron + * @param neuronType: type of the neuron + * @param neuronLayer: layer the neuron should be added to, can be 'hidden', 'input' or 'output' + * @param params: parameters of the new neuron + */ + static revolve::brain::NeuronPtr addNeuron(const std::string &neuronId, + const std::string &neuronType, + const std::string &neuronLayer, + const std::map ¶ms, + ExtNNConfig& ret); + + + }; + +} /* namespace tol */ + +#endif //REVOLVE_GAZEBO_BRAIN_REINFORCEDLEARNING_H + + From 7eee209253639b1c93988336709c4c70bfc506d3 Mon Sep 17 00:00:00 2001 From: raki123 Date: Thu, 17 Nov 2016 18:53:00 +0100 Subject: [PATCH 03/10] some common sense changes --- scripts/offline-evolve2/gait-learning.world | 43 -- .../offline-evolve2/input-15/baseline.conf | 6 - .../input-15/baseline_no_fitness.conf | 7 - scripts/offline-evolve2/input-15/comma.conf | 7 - .../input-15/comma_aggressive.conf | 12 - scripts/offline-evolve2/input-15/plus.conf | 5 - .../input-15/plus_aggressive.conf | 11 - .../input-15/plus_gradual.conf | 6 - .../input-15/plus_less_aggressive.conf | 4 - .../input-15/plus_more_aggressive.conf | 11 - .../offline-evolve2/input-20/baseline.conf | 7 - scripts/offline-evolve2/input-20/plus.conf | 5 - .../input-20/plus_aggressive.conf | 10 - .../input-20/plus_more_aggressive.conf | 10 - scripts/offline-evolve2/input/baseline.conf | 5 - scripts/offline-evolve2/input/comma.conf | 4 - .../input/comma_aggressive.conf | 9 - scripts/offline-evolve2/input/plus.conf | 3 - .../input/plus_aggressive.conf | 8 - .../input/plus_more_aggressive.conf | 8 - scripts/offline-evolve2/make.sh | 3 - scripts/offline-evolve2/offline-evolve.world | 39 -- scripts/offline-evolve2/offline_evolve.py | 437 ------------ scripts/offline-evolve2/rlpower.cfg | 12 - scripts/offline-evolve2/robots/babyA.yaml | 89 --- scripts/offline-evolve2/robots/babyB.yaml | 101 --- scripts/offline-evolve2/robots/babyC.yaml | 171 ----- scripts/offline-evolve2/robots/gecko12.yaml | 124 ---- scripts/offline-evolve2/robots/gecko17.yaml | 176 ----- scripts/offline-evolve2/robots/gecko7.yaml | 73 -- scripts/offline-evolve2/robots/snake5.yaml | 41 -- scripts/offline-evolve2/robots/snake7.yaml | 63 -- scripts/offline-evolve2/robots/snake9.yaml | 83 --- scripts/offline-evolve2/robots/spider13.yaml | 121 ---- scripts/offline-evolve2/robots/spider17.yaml | 161 ----- scripts/offline-evolve2/robots/spider9.yaml | 659 ------------------ scripts/offline-evolve2/run-experiments.sh | 83 --- .../offline-evolve2/single_robot_manager.py | 101 --- scripts/offline-evolve2/start.py | 57 -- scripts/offline-evolve2/summarize.R | 103 --- 40 files changed, 2878 deletions(-) delete mode 100644 scripts/offline-evolve2/gait-learning.world delete mode 100644 scripts/offline-evolve2/input-15/baseline.conf delete mode 100644 scripts/offline-evolve2/input-15/baseline_no_fitness.conf delete mode 100644 scripts/offline-evolve2/input-15/comma.conf delete mode 100644 scripts/offline-evolve2/input-15/comma_aggressive.conf delete mode 100644 scripts/offline-evolve2/input-15/plus.conf delete mode 100644 scripts/offline-evolve2/input-15/plus_aggressive.conf delete mode 100644 scripts/offline-evolve2/input-15/plus_gradual.conf delete mode 100644 scripts/offline-evolve2/input-15/plus_less_aggressive.conf delete mode 100644 scripts/offline-evolve2/input-15/plus_more_aggressive.conf delete mode 100644 scripts/offline-evolve2/input-20/baseline.conf delete mode 100644 scripts/offline-evolve2/input-20/plus.conf delete mode 100644 scripts/offline-evolve2/input-20/plus_aggressive.conf delete mode 100644 scripts/offline-evolve2/input-20/plus_more_aggressive.conf delete mode 100644 scripts/offline-evolve2/input/baseline.conf delete mode 100644 scripts/offline-evolve2/input/comma.conf delete mode 100644 scripts/offline-evolve2/input/comma_aggressive.conf delete mode 100644 scripts/offline-evolve2/input/plus.conf delete mode 100644 scripts/offline-evolve2/input/plus_aggressive.conf delete mode 100644 scripts/offline-evolve2/input/plus_more_aggressive.conf delete mode 100755 scripts/offline-evolve2/make.sh delete mode 100644 scripts/offline-evolve2/offline-evolve.world delete mode 100644 scripts/offline-evolve2/offline_evolve.py delete mode 100644 scripts/offline-evolve2/rlpower.cfg delete mode 100644 scripts/offline-evolve2/robots/babyA.yaml delete mode 100644 scripts/offline-evolve2/robots/babyB.yaml delete mode 100644 scripts/offline-evolve2/robots/babyC.yaml delete mode 100644 scripts/offline-evolve2/robots/gecko12.yaml delete mode 100644 scripts/offline-evolve2/robots/gecko17.yaml delete mode 100644 scripts/offline-evolve2/robots/gecko7.yaml delete mode 100644 scripts/offline-evolve2/robots/snake5.yaml delete mode 100644 scripts/offline-evolve2/robots/snake7.yaml delete mode 100644 scripts/offline-evolve2/robots/snake9.yaml delete mode 100644 scripts/offline-evolve2/robots/spider13.yaml delete mode 100644 scripts/offline-evolve2/robots/spider17.yaml delete mode 100644 scripts/offline-evolve2/robots/spider9.yaml delete mode 100755 scripts/offline-evolve2/run-experiments.sh delete mode 100644 scripts/offline-evolve2/single_robot_manager.py delete mode 100644 scripts/offline-evolve2/start.py delete mode 100644 scripts/offline-evolve2/summarize.R diff --git a/scripts/offline-evolve2/gait-learning.world b/scripts/offline-evolve2/gait-learning.world deleted file mode 100644 index fa159af..0000000 --- a/scripts/offline-evolve2/gait-learning.world +++ /dev/null @@ -1,43 +0,0 @@ - - - - - 0 - 0 - - - - 0.005 - - - 0.0 - - - - - 0.1 - 10e-6 - - - 100 - 1e-8 - - - world - - - - - - - - - model://sun - - - model://tol_ground - - - - - \ No newline at end of file diff --git a/scripts/offline-evolve2/input-15/baseline.conf b/scripts/offline-evolve2/input-15/baseline.conf deleted file mode 100644 index 6483a30..0000000 --- a/scripts/offline-evolve2/input-15/baseline.conf +++ /dev/null @@ -1,6 +0,0 @@ -output_directory=/media/expdata/output -restore_directory=baseline-selection -disable_selection=1 -disable_fitness=1 -population_size=15 -num_children=15 diff --git a/scripts/offline-evolve2/input-15/baseline_no_fitness.conf b/scripts/offline-evolve2/input-15/baseline_no_fitness.conf deleted file mode 100644 index 95b27ec..0000000 --- a/scripts/offline-evolve2/input-15/baseline_no_fitness.conf +++ /dev/null @@ -1,7 +0,0 @@ -output_directory=output -restore_directory=baseline-no-fitness-15 -disable_fitness=1 -disable_selection=1 -keep_parents=0 -population_size=15 -num_children=15 \ No newline at end of file diff --git a/scripts/offline-evolve2/input-15/comma.conf b/scripts/offline-evolve2/input-15/comma.conf deleted file mode 100644 index 251b434..0000000 --- a/scripts/offline-evolve2/input-15/comma.conf +++ /dev/null @@ -1,7 +0,0 @@ -output_directory=comma-output -restore_directory=comma-1000 -population_size=15 -num_children=15 -keep_parents=False -num_generations=1000 -num_evolutions=32 diff --git a/scripts/offline-evolve2/input-15/comma_aggressive.conf b/scripts/offline-evolve2/input-15/comma_aggressive.conf deleted file mode 100644 index 70818c4..0000000 --- a/scripts/offline-evolve2/input-15/comma_aggressive.conf +++ /dev/null @@ -1,12 +0,0 @@ -output_directory=comma-output -restore_directory=comma-aggressive-15-2000 -keep_parents=0 -enable_light_sensor=0 -body_mutation_epsilon=0.3 -brain_mutation_epsilon=0.3 -p_delete_subtree=0.25 -p_duplicate_subtree=0.25 -p_swap_subtree=0.25 -population_size=15 -num_children=15 -num_generations=2000 diff --git a/scripts/offline-evolve2/input-15/plus.conf b/scripts/offline-evolve2/input-15/plus.conf deleted file mode 100644 index 48d810c..0000000 --- a/scripts/offline-evolve2/input-15/plus.conf +++ /dev/null @@ -1,5 +0,0 @@ -output_directory=/media/expdata/output -restore_directory=plus -population_size=15 -num_children=15 -world_step_size=0.003 \ No newline at end of file diff --git a/scripts/offline-evolve2/input-15/plus_aggressive.conf b/scripts/offline-evolve2/input-15/plus_aggressive.conf deleted file mode 100644 index c8fedad..0000000 --- a/scripts/offline-evolve2/input-15/plus_aggressive.conf +++ /dev/null @@ -1,11 +0,0 @@ -output_directory=population-output -restore_directory=plus-aggressive-15 -enable_light_sensor=0 -body_mutation_epsilon=0.3 -brain_mutation_epsilon=0.3 -p_delete_subtree=0.25 -p_duplicate_subtree=0.25 -p_swap_subtree=0.25 -population_size=15 -num_children=15 -num_evolutions=32 diff --git a/scripts/offline-evolve2/input-15/plus_gradual.conf b/scripts/offline-evolve2/input-15/plus_gradual.conf deleted file mode 100644 index 8339971..0000000 --- a/scripts/offline-evolve2/input-15/plus_gradual.conf +++ /dev/null @@ -1,6 +0,0 @@ -output_directory=/media/expdata/output -restore_directory=plus-gradual-new -population_size=15 -num_children=1 -num_generations=2991 -world_step_size=0.003 \ No newline at end of file diff --git a/scripts/offline-evolve2/input-15/plus_less_aggressive.conf b/scripts/offline-evolve2/input-15/plus_less_aggressive.conf deleted file mode 100644 index d6833ba..0000000 --- a/scripts/offline-evolve2/input-15/plus_less_aggressive.conf +++ /dev/null @@ -1,4 +0,0 @@ -output_directory=output -restore_directory=plus-less-aggressive-size-discount-3 -population_size=15 -num_children=15 diff --git a/scripts/offline-evolve2/input-15/plus_more_aggressive.conf b/scripts/offline-evolve2/input-15/plus_more_aggressive.conf deleted file mode 100644 index 02dce3e..0000000 --- a/scripts/offline-evolve2/input-15/plus_more_aggressive.conf +++ /dev/null @@ -1,11 +0,0 @@ -output_directory=population-output -restore_directory=plus-more-aggressive-15 -enable_light_sensor=0 -body_mutation_epsilon=0.4 -brain_mutation_epsilon=0.4 -p_delete_subtree=0.4 -p_duplicate_subtree=0.4 -p_swap_subtree=0.4 -population_size=15 -num_children=15 -num_evolutions=32 diff --git a/scripts/offline-evolve2/input-20/baseline.conf b/scripts/offline-evolve2/input-20/baseline.conf deleted file mode 100644 index 7f80d63..0000000 --- a/scripts/offline-evolve2/input-20/baseline.conf +++ /dev/null @@ -1,7 +0,0 @@ -output_directory=output -restore_directory=baseline-20 -enable_light_sensor=0 -disable_evolution=1 -keep_parents=1 -population_size=20 -num_children=20 \ No newline at end of file diff --git a/scripts/offline-evolve2/input-20/plus.conf b/scripts/offline-evolve2/input-20/plus.conf deleted file mode 100644 index 79ed5cf..0000000 --- a/scripts/offline-evolve2/input-20/plus.conf +++ /dev/null @@ -1,5 +0,0 @@ -output_directory=output -restore_directory=plus-20 -enable_light_sensor=0 -population_size=20 -num_children=20 diff --git a/scripts/offline-evolve2/input-20/plus_aggressive.conf b/scripts/offline-evolve2/input-20/plus_aggressive.conf deleted file mode 100644 index 7ee964d..0000000 --- a/scripts/offline-evolve2/input-20/plus_aggressive.conf +++ /dev/null @@ -1,10 +0,0 @@ -output_directory=debug-output -restore_directory=plus-aggressive-20 -enable_light_sensor=0 -body_mutation_epsilon=0.3 -brain_mutation_epsilon=0.3 -p_delete_subtree=0.25 -p_duplicate_subtree=0.25 -p_swap_subtree=0.25 -population_size=20 -num_children=20 diff --git a/scripts/offline-evolve2/input-20/plus_more_aggressive.conf b/scripts/offline-evolve2/input-20/plus_more_aggressive.conf deleted file mode 100644 index 285e6d2..0000000 --- a/scripts/offline-evolve2/input-20/plus_more_aggressive.conf +++ /dev/null @@ -1,10 +0,0 @@ -output_directory=output -restore_directory=plus-more-aggressive-20 -enable_light_sensor=0 -body_mutation_epsilon=0.4 -brain_mutation_epsilon=0.4 -p_delete_subtree=0.4 -p_duplicate_subtree=0.4 -p_swap_subtree=0.4 -population_size=20 -num_children=20 \ No newline at end of file diff --git a/scripts/offline-evolve2/input/baseline.conf b/scripts/offline-evolve2/input/baseline.conf deleted file mode 100644 index e3cf3e3..0000000 --- a/scripts/offline-evolve2/input/baseline.conf +++ /dev/null @@ -1,5 +0,0 @@ -output_directory=output -restore_directory=baseline -enable_light_sensor=0 -disable_evolution=1 -keep_parents=1 diff --git a/scripts/offline-evolve2/input/comma.conf b/scripts/offline-evolve2/input/comma.conf deleted file mode 100644 index 6e21d0d..0000000 --- a/scripts/offline-evolve2/input/comma.conf +++ /dev/null @@ -1,4 +0,0 @@ -output_directory=output -restore_directory=comma -enable_light_sensor=0 -keep_parents=False diff --git a/scripts/offline-evolve2/input/comma_aggressive.conf b/scripts/offline-evolve2/input/comma_aggressive.conf deleted file mode 100644 index 7a913ef..0000000 --- a/scripts/offline-evolve2/input/comma_aggressive.conf +++ /dev/null @@ -1,9 +0,0 @@ -output_directory=output -restore_directory=comma-aggressive -enable_light_sensor=0 -keep_parents=False -body_mutation_epsilon=0.3 -brain_mutation_epsilon=0.3 -p_delete_subtree=0.25 -p_duplicate_subtree=0.25 -p_swap_subtree=0.25 diff --git a/scripts/offline-evolve2/input/plus.conf b/scripts/offline-evolve2/input/plus.conf deleted file mode 100644 index d615657..0000000 --- a/scripts/offline-evolve2/input/plus.conf +++ /dev/null @@ -1,3 +0,0 @@ -output_directory=output -restore_directory=plus -enable_light_sensor=0 diff --git a/scripts/offline-evolve2/input/plus_aggressive.conf b/scripts/offline-evolve2/input/plus_aggressive.conf deleted file mode 100644 index 62357f0..0000000 --- a/scripts/offline-evolve2/input/plus_aggressive.conf +++ /dev/null @@ -1,8 +0,0 @@ -output_directory=output -restore_directory=plus-aggressive -enable_light_sensor=0 -body_mutation_epsilon=0.3 -brain_mutation_epsilon=0.3 -p_delete_subtree=0.25 -p_duplicate_subtree=0.25 -p_swap_subtree=0.25 diff --git a/scripts/offline-evolve2/input/plus_more_aggressive.conf b/scripts/offline-evolve2/input/plus_more_aggressive.conf deleted file mode 100644 index d96df1a..0000000 --- a/scripts/offline-evolve2/input/plus_more_aggressive.conf +++ /dev/null @@ -1,8 +0,0 @@ -output_directory=output -restore_directory=plus-more-aggressive -enable_light_sensor=0 -body_mutation_epsilon=0.4 -brain_mutation_epsilon=0.4 -p_delete_subtree=0.4 -p_duplicate_subtree=0.4 -p_swap_subtree=0.4 diff --git a/scripts/offline-evolve2/make.sh b/scripts/offline-evolve2/make.sh deleted file mode 100755 index 57f317a..0000000 --- a/scripts/offline-evolve2/make.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -cd ../../build/ -make -j4 diff --git a/scripts/offline-evolve2/offline-evolve.world b/scripts/offline-evolve2/offline-evolve.world deleted file mode 100644 index 8d48748..0000000 --- a/scripts/offline-evolve2/offline-evolve.world +++ /dev/null @@ -1,39 +0,0 @@ - - - - - 0 - 0 - - - 0.003 - - - 0.0 - - - - 0.1 - 10e-6 - - - 100 - 1e-8 - - - quick - - - - - - - model://sun - - - model://tol_ground - - - - - diff --git a/scripts/offline-evolve2/offline_evolve.py b/scripts/offline-evolve2/offline_evolve.py deleted file mode 100644 index 1715c35..0000000 --- a/scripts/offline-evolve2/offline_evolve.py +++ /dev/null @@ -1,437 +0,0 @@ -# Offline evolution scheme -# - We use a population of constant size 10 -# - Each robot is evaluated for 20 seconds, though we may vary this number -# - The average speed during this evaluation is the fitness -# - We do parent selection using a binary tournament: select two parents at -# random, the one with the best fitness is parent 1, repeat for parent 2. -# - Using this mechanism, we generate 10 children -# - After evaluation of the children, we either do: -# -- Plus scheme, sort *all* robots by fitness -# -- Comma scheme, get rid of the parents and continue with children only -from __future__ import absolute_import -import sys -import time -import os -import shutil -import random -import csv -import itertools -import logging -import trollius -from trollius import From, Return - -sys.path.append(os.path.dirname(os.path.abspath(__file__))+'/../../') - -from sdfbuilder import Pose -from sdfbuilder.math import Vector3 - -from revolve.util import wait_for - -from tol.manage.robot import Robot -from tol.config import parser -from tol.manage import World -from tol.logging import logger, output_console -from tol.util.analyze import list_extremities, count_joints, count_motors, count_extremities, count_connections - -# Log output to console -output_console() -logger.setLevel(logging.DEBUG) - -# Add offline evolve arguments -parser.add_argument( - '--population-size', - default=10, type=int, - help="Population size in each generation." -) - -parser.add_argument( - '--num-children', - default=10, type=int, - help="The number of children produced in each generation." -) - - -def str2bool(v): - return v.lower() == "true" or v == "1" - -parser.add_argument( - '--keep-parents', - default=True, type=str2bool, - help="Whether or not to discard the parents after each generation. This determines the strategy, + or ,." -) - -parser.add_argument( - '--num-generations', - default=200, type=int, - help="The number of generations to simulate." -) - -parser.add_argument( - '--disable-evolution', - default=False, type=str2bool, - help="Useful as a baseline test - if set to true, new robots are generated" - " every time rather than evolving them." -) - -parser.add_argument( - '--disable-selection', - default=False, type=str2bool, - help="Useful as a different baseline test - if set to true, robots reproduce," - " but parents are selected completely random." -) - -parser.add_argument( - '--disable-fitness', - default=False, type=str2bool, - help="Another baseline testing option, sorts robots randomly rather " - "than selecting the top pairs. This only matters if parents are kept." -) - -parser.add_argument( - '--num-evolutions', - default=30, type=int, - help="The number of times to repeat the experiment." -) - -parser.add_argument( - '--evaluation-threshold', - default=10.0, type=float, - help="Maximum number of seconds one evaluation can take before the " - "decision is made to restart from snapshot. The assumption is " - "that the world may have become slow and restarting will help." -) - - -class OfflineEvoManager(World): - """ - Extended world manager for the offline evolution script - """ - - def __init__(self, conf, _private): - """ - - :param conf: - :param _private: - :return: - """ - super(OfflineEvoManager, self).__init__(conf, _private) - - self._snapshot_data = {} - - # Output files - csvs = { - 'generations': ['run', 'gen', 'robot_id', 'vel', 'dvel', 'fitness', 't_eval'], - 'robot_details': ['robot_id', 'extremity_id', 'extremity_size', - 'joint_count', 'motor_count'] - } - self.csv_files = {k: {'filename': None, 'file': None, 'csv': None, - 'header': csvs[k]} - for k in csvs} - - self.current_run = 0 - - if self.output_directory: - for k in self.csv_files: - fname = os.path.join(self.output_directory, k + '.csv') - self.csv_files[k]['filename'] = fname - if self.do_restore: - shutil.copy(fname + '.snapshot', fname) - f = open(fname, 'ab', buffering=1) - else: - f = open(fname, 'wb', buffering=1) - - self.csv_files[k]['file'] = f - self.csv_files[k]['csv'] = csv.writer(f, delimiter=',') - - if not self.do_restore: - self.csv_files[k]['csv'].writerow(self.csv_files[k]['header']) - - def robots_header(self): - return Robot.header() - - @classmethod - @trollius.coroutine - def create(cls, conf): - """ - Coroutine to instantiate a Revolve.Angle WorldManager - :param conf: - :return: - """ - self = cls(_private=cls._PRIVATE, conf=conf) - yield From(self._init()) - raise Return(self) - - @trollius.coroutine - def create_snapshot(self): - """ - Copy the generations file in the snapshot - :return: - """ - ret = yield From(super(OfflineEvoManager, self).create_snapshot()) - if not ret: - raise Return(ret) - - for k in self.csv_files: - entry = self.csv_files[k] - if entry['file']: - entry['file'].flush() - shutil.copy(entry['filename'], entry['filename'] + '.snapshot') - - @trollius.coroutine - def get_snapshot_data(self): - """ - :return: - """ - data = yield From(super(OfflineEvoManager, self).get_snapshot_data()) - data.update(self._snapshot_data) - raise Return(data) - - @trollius.coroutine - def evaluate_pair(self, tree, bbox, parents=None): - """ - Evaluates a single robot tree. - :param tree: - :param bbox: - :param parents: - :return: Evaluated Robot object - """ - # Pause the world just in case it wasn't already - yield From(wait_for(self.pause(True))) - - pose = Pose(position=Vector3(0, 0, -bbox.min.z)) - fut = yield From(self.insert_robot(tree, pose, parents=parents)) - robot = yield From(fut) - - max_age = self.conf.evaluation_time + self.conf.warmup_time - - # Unpause the world to start evaluation - yield From(wait_for(self.pause(False))) - - before = time.time() - - while True: - if robot.age() >= max_age: - break - - # Sleep for the pose update frequency, which is about when - # we expect a new age update. - yield From(trollius.sleep(1.0 / self.state_update_frequency)) - - yield From(wait_for(self.delete_robot(robot))) - yield From(wait_for(self.pause(True))) - - diff = time.time() - before - if diff > self.conf.evaluation_threshold: - sys.stderr.write("Evaluation threshold exceeded, shutting down with nonzero status code.\n") - sys.stderr.flush() - sys.exit(15) - - raise Return(robot) - - @trollius.coroutine - def evaluate_population(self, trees, bboxes, parents=None): - """ - :param trees: - :param bboxes: - :param parents: - :return: - """ - if parents is None: - parents = [None for _ in trees] - - pairs = [] - print("Evaluating population...") - for tree, bbox, par in itertools.izip(trees, bboxes, parents): - print("Evaluating individual...") - before = time.time() - robot = yield From(self.evaluate_pair(tree, bbox, par)) - pairs.append((robot, time.time() - before)) - print("Done.") - - print("Done evaluating population.") - raise Return(pairs) - - @trollius.coroutine - def produce_generation(self, parents): - """ - Produce the next generation of robots from - the current. - :param parents: - :return: - """ - print("Producing generation...") - trees = [] - bboxes = [] - parent_pairs = [] - - while len(trees) < self.conf.num_children: - print("Producing individual...") - if self.conf.disable_selection: - p1, p2 = random.sample(parents, 2) - else: - p1, p2 = select_parents(parents, self.conf) - - for j in xrange(self.conf.max_mating_attempts): - pair = yield From(self.attempt_mate(p1, p2)) - if pair: - trees.append(pair[0]) - bboxes.append(pair[1]) - parent_pairs.append((p1, p2)) - break - - print("Done.") - - print("Done producing generation.") - raise Return(trees, bboxes, parent_pairs) - - def log_generation(self, evo, generation, pairs): - """ - :param evo: The evolution run - :param generation: - :param pairs: List of tuples (robot, evaluation wallclock time) - :return: - """ - print("================== GENERATION %d ==================" % generation) - if not self.output_directory: - return - - go = self.csv_files['generations']['csv'] - do = self.csv_files['robot_details']['csv'] - for robot, t_eval in pairs: - robot_id = robot.robot.id - root = robot.tree.root - go.writerow([evo, generation, robot.robot.id, robot.velocity(), - robot.displacement_velocity(), robot.fitness(), t_eval]) - - # TODO Write this once when robot is written instead - counter = 0 - for extr in list_extremities(root): - num_joints = count_joints(extr) - num_motors = count_motors(extr) - do.writerow((robot_id, counter, len(extr), num_joints, num_motors)) - counter += 1 - - @trollius.coroutine - def run(self): - """ - :return: - """ - conf = self.conf - - if self.do_restore: - # Recover from a previously cancelled / crashed experiment - data = self.do_restore - evo_start = data['evo_start'] - gen_start = data['gen_start'] - pairs = data['local_pairs'] - else: - # Start at the first experiment - evo_start = 1 - gen_start = 1 - pairs = None - - for evo in range(evo_start, conf.num_evolutions + 1): - self.current_run = evo - - if not pairs: - # Only create initial population if we are not restoring from - # a previous experiment. - trees, bboxes = yield From(self.generate_population(conf.population_size)) - pairs = yield From(self.evaluate_population(trees, bboxes)) - self.log_generation(evo, 0, pairs) - - for generation in xrange(gen_start, conf.num_generations): - if (generation % 10) == 0: - # Snapshot every 10 generations - self._snapshot_data = { - "local_pairs": pairs, - "gen_start": generation, - "evo_start": evo - } - yield From(self.create_snapshot()) - print("Created snapshot of experiment state.") - - # Produce the next generation and evaluate them - robots = [p[0] for p in pairs] - if conf.disable_evolution: - child_trees, child_bboxes = yield From( - self.generate_population(conf.population_size)) - parent_pairs = None - else: - child_trees, child_bboxes, parent_pairs = yield From(self.produce_generation(robots)) - - child_pairs = yield From(self.evaluate_population(child_trees, child_bboxes, parent_pairs)) - - if conf.keep_parents: - pairs += child_pairs - else: - pairs = child_pairs - - # Sort the bots and reduce to population size - if conf.disable_fitness: - random.shuffle(pairs) - else: - pairs = sorted(pairs, key=lambda r: r[0].fitness(), reverse=True) - - pairs = pairs[:conf.population_size] - self.log_generation(evo, generation, pairs) - - # Clear "restore" parameters - gen_start = 1 - pairs = None - - yield From(self.teardown()) - - @trollius.coroutine - def teardown(self): - """ - :return: - """ - yield From(super(OfflineEvoManager, self).teardown()) - for k in self.csv_files: - if self.csv_files[k]['file']: - self.csv_files[k]['file'].close() - - -def select_parent(parents, conf): - """ - Select a parent using a binary tournament. - :param parents: - :param conf: Configuration object - :return: - """ - return sorted(random.sample(parents, conf.tournament_size), key=lambda r: r.fitness())[-1] - - -def select_parents(parents, conf): - """ - :param parents: - :param conf: Configuration object - :return: - """ - p1 = select_parent(parents, conf) - p2 = select_parent(list(parent for parent in parents if parent != p1), conf) - return p1, p2 - - -@trollius.coroutine -def run(): - """ - :return: - """ - conf = parser.parse_args() - world = yield From(OfflineEvoManager.create(conf)) - yield From(world.run()) - - -def main(): - try: - loop = trollius.get_event_loop() - loop.run_until_complete(run()) - except KeyboardInterrupt: - print("Got Ctrl+C, shutting down.") - - -if __name__ == '__main__': - main() - diff --git a/scripts/offline-evolve2/rlpower.cfg b/scripts/offline-evolve2/rlpower.cfg deleted file mode 100644 index 6b9f00b..0000000 --- a/scripts/offline-evolve2/rlpower.cfg +++ /dev/null @@ -1,12 +0,0 @@ -{ - 'algorithm': 'rlpower', - 'type': 'A', # original rlpower - 'evaluation_rate': '30.0', - 'max_evaluations': '1000', - 'max_ranked_policies': '10', - 'init_spline_size': '3', - 'interpolation_spline_size': '100', - 'init_sigma': '0.8', -# 'policy_load_path': 'spider.policy', # Used to load policy - 'sigma_tau_correction': '0.2' -} \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/babyA.yaml b/scripts/offline-evolve2/robots/babyA.yaml deleted file mode 100644 index c0e0b45..0000000 --- a/scripts/offline-evolve2/robots/babyA.yaml +++ /dev/null @@ -1,89 +0,0 @@ ---- -body: - id : Core - type : Core - children : - 2: - slot : 0 - id : Leg00Joint - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Leg00 - type : FixedBrick - orientation : 0 - 3: - slot : 0 - id : Leg01Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg011Joint - type : ActiveHinge - orientation : 90 - children : - 1: - slot : 0 - id : Leg01 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg021Joint - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Leg02 - type : FixedBrick - orientation : 0 - 1: - slot : 0 - id : BodyJoint0 - type : ActiveHinge - orientation : 90 - children : - 1: - slot : 0 - id : Body0 - type : FixedBrick - orientation : -90 - children : - 1: - slot : 0 - id : BodyJoint1 - type : ActiveHinge - orientation : 90 - children : - 1: - slot : 0 - id : Body1 - type : FixedBrick - orientation : -90 - children: - 2: - slot : 0 - id : Leg10Joint - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Leg10 - type : FixedBrick - orientation : 0 - 3: - slot : 0 - id : Leg11Joint - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Leg11 - type : FixedBrick - orientation : 0 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/babyB.yaml b/scripts/offline-evolve2/robots/babyB.yaml deleted file mode 100644 index 4508b99..0000000 --- a/scripts/offline-evolve2/robots/babyB.yaml +++ /dev/null @@ -1,101 +0,0 @@ ---- -body: - id : Core - type : Core - children : - 0: - id : Leg00Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg00 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg01Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg01 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg02Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg02 - type : FixedBrick - orientation : -90 - 1: - id : Leg10Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg10 - type : FixedBrick - orientation : -90 - 2: - id : Leg20Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg20 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg21Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg21 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg22Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg22 - type : FixedBrick - orientation : -90 - 3: - id : Leg30Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg30 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg31Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg31 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg32Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg32 - type : FixedBrick - orientation : -90 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/babyC.yaml b/scripts/offline-evolve2/robots/babyC.yaml deleted file mode 100644 index 4667693..0000000 --- a/scripts/offline-evolve2/robots/babyC.yaml +++ /dev/null @@ -1,171 +0,0 @@ ---- -body: - id : Core - type : Core - children : - 2: - slot : 0 - id : Leg00Joint - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Leg00 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg001Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg001 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg002Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg002 - type : FixedBrick - orientation : 0 - 3: - slot : 0 - id : Leg01Joint - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Leg01 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg011Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg011 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg012Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg012 - type : FixedBrick - orientation : 0 - 1: - slot : 0 - id : BodyJoint0 - type : ActiveHinge - orientation : 90 - children : - 1: - slot : 0 - id : Body0 - type : FixedBrick - orientation : -90 - children : - 1: - slot : 0 - id : BodyJoint1 - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Body1 - type : FixedBrick - orientation : 0 - children : - 1: - slot : 0 - id : BodyJoint2 - type : ActiveHinge - orientation : 90 - children : - 1: - slot : 0 - id : Body2 - type : FixedBrick - orientation : -90 - children : - 1: - id : BodyJoint3 - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Body3 - type : FixedBrick - orientation : 0 - children: - 2: - slot : 0 - id : Leg10Joint - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Leg10 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg101Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg101 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg102Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg102 - type : FixedBrick - orientation : 0 - 3: - slot : 0 - id : Leg11Joint - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Leg11 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg111Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg112Joint - type : ActiveHinge - orientation : -90 - children : - 1: - id : Leg112 - type : FixedBrick - orientation : 0 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/gecko12.yaml b/scripts/offline-evolve2/robots/gecko12.yaml deleted file mode 100644 index 9c138ad..0000000 --- a/scripts/offline-evolve2/robots/gecko12.yaml +++ /dev/null @@ -1,124 +0,0 @@ ---- -body: - id : Core - type : Core - children : - 2: - slot : 0 - id : Leg00Joint - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Leg00 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg001Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg001 - type : FixedBrick - orientation : -90 - 3: - slot : 0 - id : Leg01Joint - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Leg01 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg011Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg011 - type : FixedBrick - orientation : -90 - 1: - slot : 0 - id : BodyJoint0 - type : ActiveHinge - orientation : 90 - children : - 1: - slot : 0 - id : Body0 - type : FixedBrick - orientation : -90 - children : - 1: - slot : 0 - id : BodyJoint1 - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Body1 - type : FixedBrick - orientation : 0 - children : - 1: - id : BodyJoint2 - type : ActiveHinge - orientation : 90 - children : - 1: - slot : 0 - id : Body2 - type : FixedBrick - orientation : -90 - children: - 2: - slot : 0 - id : Leg10Joint - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Leg10 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg101Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg101 - type : FixedBrick - orientation : -90 - 3: - slot : 0 - id : Leg11Joint - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Leg11 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg111Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg111 - type : FixedBrick - orientation : -90 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/gecko17.yaml b/scripts/offline-evolve2/robots/gecko17.yaml deleted file mode 100644 index 5e11c4f..0000000 --- a/scripts/offline-evolve2/robots/gecko17.yaml +++ /dev/null @@ -1,176 +0,0 @@ ---- -body: - id : Core - type : Core - children : - 2: - slot : 0 - id : Leg00Joint - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Leg00 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg001Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg001 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg002Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg002 - type : FixedBrick - orientation : 0 - 3: - slot : 0 - id : Leg01Joint - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Leg01 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg011Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg011 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg012Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg012 - type : FixedBrick - orientation : 0 - 1: - slot : 0 - id : BodyJoint0 - type : ActiveHinge - orientation : 90 - children : - 1: - slot : 0 - id : Body0 - type : FixedBrick - orientation : -90 - children : - 1: - slot : 0 - id : BodyJoint1 - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Body1 - type : FixedBrick - orientation : 0 - children : - 1: - slot : 0 - id : BodyJoint2 - type : ActiveHinge - orientation : 90 - children : - 1: - slot : 0 - id : Body2 - type : FixedBrick - orientation : -90 - children : - 1: - id : BodyJoint3 - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Body3 - type : FixedBrick - orientation : 0 - children: - 2: - slot : 0 - id : Leg10Joint - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Leg10 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg101Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg101 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg102Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg102 - type : FixedBrick - orientation : 0 - 3: - slot : 0 - id : Leg11Joint - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Leg11 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg111Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg111 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg112Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg112 - type : FixedBrick - orientation : 0 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/gecko7.yaml b/scripts/offline-evolve2/robots/gecko7.yaml deleted file mode 100644 index 806b736..0000000 --- a/scripts/offline-evolve2/robots/gecko7.yaml +++ /dev/null @@ -1,73 +0,0 @@ ---- -body: - id : Core - type : Core - children : - 2: - slot : 0 - id : Leg00Joint - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Leg00 - type : FixedBrick - orientation : 0 - 3: - slot : 0 - id : Leg01Joint - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Leg01 - type : FixedBrick - orientation : 0 - 1: - slot : 0 - id : BodyJoint0 - type : ActiveHinge - orientation : 90 - children : - 1: - slot : 0 - id : Body0 - type : FixedBrick - orientation : -90 - children : - 1: - slot : 0 - id : BodyJoint1 - type : ActiveHinge - orientation : 90 - children : - 1: - slot : 0 - id : Body1 - type : FixedBrick - orientation : -90 - children: - 2: - slot : 0 - id : Leg10Joint - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Leg10 - type : FixedBrick - orientation : 0 - 3: - slot : 0 - id : Leg11Joint - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Leg11 - type : FixedBrick - orientation : 0 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/snake5.yaml b/scripts/offline-evolve2/robots/snake5.yaml deleted file mode 100644 index d09976a..0000000 --- a/scripts/offline-evolve2/robots/snake5.yaml +++ /dev/null @@ -1,41 +0,0 @@ ---- -body: - id : Core - type : Core - children : - 0: - id : Leg00Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg00 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg01Joint - type : ActiveHinge - children : - 1: - id : Leg01 - type : FixedBrick - orientation : 0 - 1: - id : Leg10Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg10 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg11Joint - type : ActiveHinge - children : - 1: - id : Leg11 - type : FixedBrick - orientation : 0 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/snake7.yaml b/scripts/offline-evolve2/robots/snake7.yaml deleted file mode 100644 index 123bbed..0000000 --- a/scripts/offline-evolve2/robots/snake7.yaml +++ /dev/null @@ -1,63 +0,0 @@ ---- -body: - id : Core - type : Core - children : - 0: - id : Leg00Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg00 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg01Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg01 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg02Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg02 - type : FixedBrick - orientation : -90 - 1: - id : Leg10Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg10 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg11Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg11 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg12Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg12 - type : FixedBrick - orientation : -90 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/snake9.yaml b/scripts/offline-evolve2/robots/snake9.yaml deleted file mode 100644 index 6ecf5a0..0000000 --- a/scripts/offline-evolve2/robots/snake9.yaml +++ /dev/null @@ -1,83 +0,0 @@ ---- -body: - id : Core - type : Core - children : - 0: - id : Leg00Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg00 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg01Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg01 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg02Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg02 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg03Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg03 - type : FixedBrick - orientation : 0 - 1: - id : Leg10Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg10 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg11Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg11 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg12Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg12 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg13Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg13 - type : FixedBrick - orientation : 0 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/spider13.yaml b/scripts/offline-evolve2/robots/spider13.yaml deleted file mode 100644 index bce3693..0000000 --- a/scripts/offline-evolve2/robots/spider13.yaml +++ /dev/null @@ -1,121 +0,0 @@ ---- -body: - id : Core - type : Core - children : - 0: - id : Leg00Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg00 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg01Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg01 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg02Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg02 - type : FixedBrick - orientation : -90 - 1: - id : Leg10Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg10 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg11Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg11 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg12Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg12 - type : FixedBrick - orientation : -90 - 2: - id : Leg20Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg20 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg21Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg21 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg22Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg22 - type : FixedBrick - orientation : -90 - 3: - id : Leg30Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg30 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg31Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg31 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg32Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg32 - type : FixedBrick - orientation : -90 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/spider17.yaml b/scripts/offline-evolve2/robots/spider17.yaml deleted file mode 100644 index 8def37b..0000000 --- a/scripts/offline-evolve2/robots/spider17.yaml +++ /dev/null @@ -1,161 +0,0 @@ ---- -body: - id : Core - type : Core - children : - 0: - id : Leg00Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg00 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg01Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg01 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg02Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg02 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg03Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg03 - type : FixedBrick - orientation : 0 - 1: - id : Leg10Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg10 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg11Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg11 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg12Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg12 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg13Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg13 - type : FixedBrick - orientation : 0 - 2: - id : Leg20Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg20 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg21Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg21 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg22Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg22 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg23Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg23 - type : FixedBrick - orientation : 0 - 3: - id : Leg30Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg30 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg31Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg31 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg32Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg32 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg33Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg33 - type : FixedBrick - orientation : 0 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/spider9.yaml b/scripts/offline-evolve2/robots/spider9.yaml deleted file mode 100644 index 53bab38..0000000 --- a/scripts/offline-evolve2/robots/spider9.yaml +++ /dev/null @@ -1,659 +0,0 @@ -body: - children: - 0: - children: - 1: - children: - 1: - children: - 1: - id: Leg01 - label: '' - orientation: 0 - params: - blue: 0.5 - green: 0.5 - red: 0.5 - slot: 0 - type: FixedBrick - id: Leg01Joint - label: '' - orientation: 0 - params: - blue: 0.5 - green: 0.5 - red: 0.5 - slot: 0 - type: ActiveHinge - id: Leg00 - label: '' - orientation: -90 - params: - blue: 0.5 - green: 0.5 - red: 0.5 - slot: 0 - type: FixedBrick - id: Leg00Joint - label: '' - orientation: 90 - params: - blue: 0.5 - green: 0.5 - red: 0.5 - slot: 0 - type: ActiveHinge - 1: - children: - 1: - children: - 1: - children: - 1: - id: Leg11 - label: '' - orientation: 0 - params: - blue: 0.5 - green: 0.5 - red: 0.5 - slot: 0 - type: FixedBrick - id: Leg11Joint - label: '' - orientation: 0 - params: - blue: 0.5 - green: 0.5 - red: 0.5 - slot: 0 - type: ActiveHinge - id: Leg10 - label: '' - orientation: -90 - params: - blue: 0.5 - green: 0.5 - red: 0.5 - slot: 0 - type: FixedBrick - id: Leg10Joint - label: '' - orientation: 90 - params: - blue: 0.5 - green: 0.5 - red: 0.5 - slot: 0 - type: ActiveHinge - 2: - children: - 1: - children: - 1: - children: - 1: - id: Leg21 - label: '' - orientation: 0 - params: - blue: 0.5 - green: 0.5 - red: 0.5 - slot: 0 - type: FixedBrick - id: Leg21Joint - label: '' - orientation: 0 - params: - blue: 0.5 - green: 0.5 - red: 0.5 - slot: 0 - type: ActiveHinge - id: Leg20 - label: '' - orientation: -90 - params: - blue: 0.5 - green: 0.5 - red: 0.5 - slot: 0 - type: FixedBrick - id: Leg20Joint - label: '' - orientation: 90 - params: - blue: 0.5 - green: 0.5 - red: 0.5 - slot: 0 - type: ActiveHinge - 3: - children: - 1: - children: - 1: - children: - 1: - id: Leg31 - label: '' - orientation: 0 - params: - blue: 0.5 - green: 0.5 - red: 0.5 - slot: 0 - type: FixedBrick - id: Leg31Joint - label: '' - orientation: 0 - params: - blue: 0.5 - green: 0.5 - red: 0.5 - slot: 0 - type: ActiveHinge - id: Leg30 - label: '' - orientation: -90 - params: - blue: 0.5 - green: 0.5 - red: 0.5 - slot: 0 - type: FixedBrick - id: Leg30Joint - label: '' - orientation: 90 - params: - blue: 0.5 - green: 0.5 - red: 0.5 - slot: 0 - type: ActiveHinge - id: Core - label: '' - orientation: 0 - params: - blue: 0.5 - green: 0.5 - red: 0.5 - type: Core -brain: - connections: - - dst: Leg00Joint-cpg-0 - socket: from_x - src: Leg00Joint-cpg-1 - weight: 1.0 - - dst: Leg00Joint-cpg-1 - socket: from_v - src: Leg00Joint-cpg-0 - weight: 1.0 - - dst: Leg00Joint-out-0 - src: Leg00Joint-cpg-0 - weight: 1.0 - - dst: Leg01Joint-cpg-2 - socket: from_x - src: Leg01Joint-cpg-3 - weight: 1.0 - - dst: Leg01Joint-cpg-3 - socket: from_v - src: Leg01Joint-cpg-2 - weight: 1.0 - - dst: Leg01Joint-out-0 - src: Leg01Joint-cpg-2 - weight: 1.0 - - dst: Leg00Joint-cpg-0 - socket: from_x_ext - src: Leg01Joint-cpg-3 - weight: 1.0 - - dst: Leg01Joint-cpg-2 - socket: from_x_ext - src: Leg00Joint-cpg-1 - weight: 1.0 - - dst: Leg00Joint-cpg-0 - socket: from_v_ext - src: Leg01Joint-cpg-2 - weight: 1.0 - - dst: Leg01Joint-cpg-2 - socket: from_v_ext - src: Leg00Joint-cpg-0 - weight: 1.0 - - dst: Leg10Joint-cpg-4 - socket: from_x - src: Leg10Joint-cpg-5 - weight: 1.0 - - dst: Leg10Joint-cpg-5 - socket: from_v - src: Leg10Joint-cpg-4 - weight: 1.0 - - dst: Leg10Joint-out-0 - src: Leg10Joint-cpg-4 - weight: 1.0 - - dst: Leg11Joint-cpg-6 - socket: from_x - src: Leg11Joint-cpg-7 - weight: 1.0 - - dst: Leg11Joint-cpg-7 - socket: from_v - src: Leg11Joint-cpg-6 - weight: 1.0 - - dst: Leg11Joint-out-0 - src: Leg11Joint-cpg-6 - weight: 1.0 - - dst: Leg10Joint-cpg-4 - socket: from_x_ext - src: Leg11Joint-cpg-7 - weight: 1.0 - - dst: Leg11Joint-cpg-6 - socket: from_x_ext - src: Leg10Joint-cpg-5 - weight: 1.0 - - dst: Leg10Joint-cpg-4 - socket: from_v_ext - src: Leg11Joint-cpg-6 - weight: 1.0 - - dst: Leg11Joint-cpg-6 - socket: from_v_ext - src: Leg10Joint-cpg-4 - weight: 1.0 - - dst: Leg20Joint-cpg-8 - socket: from_x - src: Leg20Joint-cpg-9 - weight: 1.0 - - dst: Leg20Joint-cpg-9 - socket: from_v - src: Leg20Joint-cpg-8 - weight: 1.0 - - dst: Leg20Joint-out-0 - src: Leg20Joint-cpg-8 - weight: 1.0 - - dst: Leg21Joint-cpg-10 - socket: from_x - src: Leg21Joint-cpg-11 - weight: 1.0 - - dst: Leg21Joint-cpg-11 - socket: from_v - src: Leg21Joint-cpg-10 - weight: 1.0 - - dst: Leg21Joint-out-0 - src: Leg21Joint-cpg-10 - weight: 1.0 - - dst: Leg20Joint-cpg-8 - socket: from_x_ext - src: Leg21Joint-cpg-11 - weight: 1.0 - - dst: Leg21Joint-cpg-10 - socket: from_x_ext - src: Leg20Joint-cpg-9 - weight: 1.0 - - dst: Leg20Joint-cpg-8 - socket: from_v_ext - src: Leg21Joint-cpg-10 - weight: 1.0 - - dst: Leg21Joint-cpg-10 - socket: from_v_ext - src: Leg20Joint-cpg-8 - weight: 1.0 - - dst: Leg30Joint-cpg-12 - socket: from_x - src: Leg30Joint-cpg-13 - weight: 1.0 - - dst: Leg30Joint-cpg-13 - socket: from_v - src: Leg30Joint-cpg-12 - weight: 1.0 - - dst: Leg30Joint-out-0 - src: Leg30Joint-cpg-12 - weight: 1.0 - - dst: Leg31Joint-cpg-14 - socket: from_x - src: Leg31Joint-cpg-15 - weight: 1.0 - - dst: Leg31Joint-cpg-15 - socket: from_v - src: Leg31Joint-cpg-14 - weight: 1.0 - - dst: Leg31Joint-out-0 - src: Leg31Joint-cpg-14 - weight: 1.0 - - dst: Leg30Joint-cpg-12 - socket: from_x_ext - src: Leg31Joint-cpg-15 - weight: 1.0 - - dst: Leg31Joint-cpg-14 - socket: from_x_ext - src: Leg30Joint-cpg-13 - weight: 1.0 - - dst: Leg30Joint-cpg-12 - socket: from_v_ext - src: Leg31Joint-cpg-14 - weight: 1.0 - - dst: Leg31Joint-cpg-14 - socket: from_v_ext - src: Leg30Joint-cpg-12 - weight: 1.0 - - dst: Leg00Joint-cpg-0 - src: Core-in-5 - weight: 1.0 - - dst: Leg00Joint-cpg-0 - src: Core-in-4 - weight: 1.0 - - dst: Leg00Joint-cpg-0 - src: Core-in-0 - weight: 1.0 - - dst: Leg00Joint-cpg-0 - src: Core-in-3 - weight: 1.0 - - dst: Leg00Joint-cpg-0 - src: Core-in-2 - weight: 1.0 - - dst: Leg00Joint-cpg-0 - src: Core-in-1 - weight: 1.0 - - dst: Leg10Joint-cpg-4 - src: Core-in-5 - weight: 1.0 - - dst: Leg10Joint-cpg-4 - src: Core-in-4 - weight: 1.0 - - dst: Leg10Joint-cpg-4 - src: Core-in-0 - weight: 1.0 - - dst: Leg10Joint-cpg-4 - src: Core-in-3 - weight: 1.0 - - dst: Leg10Joint-cpg-4 - src: Core-in-2 - weight: 1.0 - - dst: Leg10Joint-cpg-4 - src: Core-in-1 - weight: 1.0 - - dst: Leg20Joint-cpg-8 - src: Core-in-5 - weight: 1.0 - - dst: Leg20Joint-cpg-8 - src: Core-in-4 - weight: 1.0 - - dst: Leg20Joint-cpg-8 - src: Core-in-0 - weight: 1.0 - - dst: Leg20Joint-cpg-8 - src: Core-in-3 - weight: 1.0 - - dst: Leg20Joint-cpg-8 - src: Core-in-2 - weight: 1.0 - - dst: Leg20Joint-cpg-8 - src: Core-in-1 - weight: 1.0 - - dst: Leg30Joint-cpg-12 - src: Core-in-5 - weight: 1.0 - - dst: Leg30Joint-cpg-12 - src: Core-in-4 - weight: 1.0 - - dst: Leg30Joint-cpg-12 - src: Core-in-0 - weight: 1.0 - - dst: Leg30Joint-cpg-12 - src: Core-in-3 - weight: 1.0 - - dst: Leg30Joint-cpg-12 - src: Core-in-2 - weight: 1.0 - - dst: Leg30Joint-cpg-12 - src: Core-in-1 - weight: 1.0 - - dst: Leg10Joint-cpg-4 - socket: from_x_ext - src: Leg00Joint-cpg-1 - weight: 1.0 - - dst: Leg00Joint-cpg-0 - socket: from_x_ext - src: Leg10Joint-cpg-5 - weight: 1.0 - - dst: Leg10Joint-cpg-4 - socket: from_v_ext - src: Leg00Joint-cpg-0 - weight: 1.0 - - dst: Leg00Joint-cpg-0 - socket: from_v_ext - src: Leg10Joint-cpg-4 - weight: 1.0 - - dst: Leg20Joint-cpg-8 - socket: from_x_ext - src: Leg00Joint-cpg-1 - weight: 1.0 - - dst: Leg00Joint-cpg-0 - socket: from_x_ext - src: Leg20Joint-cpg-9 - weight: 1.0 - - dst: Leg20Joint-cpg-8 - socket: from_v_ext - src: Leg00Joint-cpg-0 - weight: 1.0 - - dst: Leg00Joint-cpg-0 - socket: from_v_ext - src: Leg20Joint-cpg-8 - weight: 1.0 - - dst: Leg30Joint-cpg-12 - socket: from_x_ext - src: Leg00Joint-cpg-1 - weight: 1.0 - - dst: Leg00Joint-cpg-0 - socket: from_x_ext - src: Leg30Joint-cpg-13 - weight: 1.0 - - dst: Leg30Joint-cpg-12 - socket: from_v_ext - src: Leg00Joint-cpg-0 - weight: 1.0 - - dst: Leg00Joint-cpg-0 - socket: from_v_ext - src: Leg30Joint-cpg-12 - weight: 1.0 - - dst: Leg20Joint-cpg-8 - socket: from_x_ext - src: Leg10Joint-cpg-5 - weight: 1.0 - - dst: Leg10Joint-cpg-4 - socket: from_x_ext - src: Leg20Joint-cpg-9 - weight: 1.0 - - dst: Leg20Joint-cpg-8 - socket: from_v_ext - src: Leg10Joint-cpg-4 - weight: 1.0 - - dst: Leg10Joint-cpg-4 - socket: from_v_ext - src: Leg20Joint-cpg-8 - weight: 1.0 - - dst: Leg30Joint-cpg-12 - socket: from_x_ext - src: Leg10Joint-cpg-5 - weight: 1.0 - - dst: Leg10Joint-cpg-4 - socket: from_x_ext - src: Leg30Joint-cpg-13 - weight: 1.0 - - dst: Leg30Joint-cpg-12 - socket: from_v_ext - src: Leg10Joint-cpg-4 - weight: 1.0 - - dst: Leg10Joint-cpg-4 - socket: from_v_ext - src: Leg30Joint-cpg-12 - weight: 1.0 - - dst: Leg30Joint-cpg-12 - socket: from_x_ext - src: Leg20Joint-cpg-9 - weight: 1.0 - - dst: Leg20Joint-cpg-8 - socket: from_x_ext - src: Leg30Joint-cpg-13 - weight: 1.0 - - dst: Leg30Joint-cpg-12 - socket: from_v_ext - src: Leg20Joint-cpg-8 - weight: 1.0 - - dst: Leg20Joint-cpg-8 - socket: from_v_ext - src: Leg30Joint-cpg-12 - weight: 1.0 - neurons: - Leg00Joint-cpg-0: - id: Leg00Joint-cpg-0 - layer: hidden - part_id: Leg00Joint - type: V-Neuron - Leg00Joint-cpg-1: - id: Leg00Joint-cpg-1 - layer: hidden - part_id: Leg00Joint - type: X-Neuron - Leg01Joint-cpg-2: - id: Leg01Joint-cpg-2 - layer: hidden - part_id: Leg01Joint - type: V-Neuron - Leg01Joint-cpg-3: - id: Leg01Joint-cpg-3 - layer: hidden - part_id: Leg01Joint - type: X-Neuron - Leg10Joint-cpg-4: - id: Leg10Joint-cpg-4 - layer: hidden - part_id: Leg10Joint - type: V-Neuron - Leg10Joint-cpg-5: - id: Leg10Joint-cpg-5 - layer: hidden - part_id: Leg10Joint - type: X-Neuron - Leg11Joint-cpg-6: - id: Leg11Joint-cpg-6 - layer: hidden - part_id: Leg11Joint - type: V-Neuron - Leg11Joint-cpg-7: - id: Leg11Joint-cpg-7 - layer: hidden - part_id: Leg11Joint - type: X-Neuron - Leg20Joint-cpg-8: - id: Leg20Joint-cpg-8 - layer: hidden - part_id: Leg20Joint - type: V-Neuron - Leg20Joint-cpg-9: - id: Leg20Joint-cpg-9 - layer: hidden - part_id: Leg20Joint - type: X-Neuron - Leg21Joint-cpg-10: - id: Leg21Joint-cpg-10 - layer: hidden - part_id: Leg21Joint - type: V-Neuron - Leg21Joint-cpg-11: - id: Leg21Joint-cpg-11 - layer: hidden - part_id: Leg21Joint - type: X-Neuron - Leg30Joint-cpg-12: - id: Leg30Joint-cpg-12 - layer: hidden - part_id: Leg30Joint - type: V-Neuron - Leg30Joint-cpg-13: - id: Leg30Joint-cpg-13 - layer: hidden - part_id: Leg30Joint - type: X-Neuron - Leg31Joint-cpg-14: - id: Leg31Joint-cpg-14 - layer: hidden - part_id: Leg31Joint - type: V-Neuron - Leg31Joint-cpg-15: - id: Leg31Joint-cpg-15 - layer: hidden - part_id: Leg31Joint - type: X-Neuron - params: - Leg00Joint-cpg-0: - alpha: 1.0 - energy: 1.0 - tau: 1.0 - Leg00Joint-cpg-1: - tau: 1.0 - Leg00Joint-out-0: - bias: 0.0 - gain: 0.5 - Leg01Joint-cpg-2: - alpha: 1.0 - energy: 1.0 - tau: 1.0 - Leg01Joint-cpg-3: - tau: 1.0 - Leg01Joint-out-0: - bias: 0.0 - gain: 0.5 - Leg10Joint-cpg-4: - alpha: 1.0 - energy: 1.0 - tau: 1.0 - Leg10Joint-cpg-5: - tau: 1.0 - Leg10Joint-out-0: - bias: 0.0 - gain: 0.5 - Leg11Joint-cpg-6: - alpha: 1.0 - energy: 1.0 - tau: 1.0 - Leg11Joint-cpg-7: - tau: 1.0 - Leg11Joint-out-0: - bias: 0.0 - gain: 0.5 - Leg20Joint-cpg-8: - alpha: 1.0 - energy: 1.0 - tau: 1.0 - Leg20Joint-cpg-9: - tau: 1.0 - Leg20Joint-out-0: - bias: 0.0 - gain: 0.5 - Leg21Joint-cpg-10: - alpha: 1.0 - energy: 1.0 - tau: 1.0 - Leg21Joint-cpg-11: - tau: 1.0 - Leg21Joint-out-0: - bias: 0.0 - gain: 0.5 - Leg30Joint-cpg-12: - alpha: 1.0 - energy: 1.0 - tau: 1.0 - Leg30Joint-cpg-13: - tau: 1.0 - Leg30Joint-out-0: - bias: 0.0 - gain: 0.5 - Leg31Joint-cpg-14: - alpha: 1.0 - energy: 1.0 - tau: 1.0 - Leg31Joint-cpg-15: - tau: 1.0 - Leg31Joint-out-0: - bias: 0.0 - gain: 0.5 -id: 0 diff --git a/scripts/offline-evolve2/run-experiments.sh b/scripts/offline-evolve2/run-experiments.sh deleted file mode 100755 index ddf01fd..0000000 --- a/scripts/offline-evolve2/run-experiments.sh +++ /dev/null @@ -1,83 +0,0 @@ -#!/usr/bin/env bash - -# Handle keyboard interrupt -trap " exit " INT - -PROGNAME=$(basename $0) - -# Default argument list -robot_list=( spider9 spider13 spider17 gecko7 gecko12 gecko17 snake5 snake7 snake9 babyA babyB babyC ) - -config=rlpower.cfg -manager=single_robot_manager.py -world=gait-learning.world -output=output -restore=restore -gz_command=gzserver -no_experiments=10 - -function error_exit() { - echo "${PROGNAME}: ${1:-"Unknown Error"}" 1 >&2 - exit 1 -} - -function help() { - echo "Usage: ${PROGNAME} [args...]" - echo "Arguments:" - echo " -c | --config Path to robot brain config file" - echo " -g | --gzcommand Gazebo command [gzserver|gazebo] Default: gzserver" - echo " -h | --help Help page" - echo " -m | --manager Name of script that controls robots and the environment" - echo " -n | --no-experiments Number of experiment repetitions" - echo " -o | --output Name of the output directory" - echo " -r | --restore Name of the restore directory" - echo " -w | --world Name of world file" - - exit 0 -} - -function main() { - - # Read out the argument list - if [ $# -gt 0 ]; then - while [ "$1" != "" ] - do - local argument="$1"; - shift - local parameter="$1"; - shift - case ${argument} in - -c | --config) local config=${parameter} ;; - -g | --gzcommand) local gz_command=${parameter} ;; - -h | --help) help ;; - -m | --manager) local manager=${parameter} ;; - -n | --no-experiments) local no_experiments=${parameter} ;; - -o | --output) local output=${parameter} ;; - -r | --restore) local restore=${parameter} ;; - -w | --world) local world=${parameter} ;; - *) error_exit "${LINENO}: In ${FUNCNAME}() unknown argument ${argument}." ;; - esac - done - fi - - # For each name in 'robot_list' run 'no_experiments' experiments - for index in ${!robot_list[*]} - do - for (( i = 1; i <= ${no_experiments}; ++ i )) - do - python start.py \ - --manager ${manager} \ - --world ${world} \ - --output ${output} \ - --restore ${restore} \ - --robot-name robots/${robot_list[$index]} \ - --experiment-round ${i} \ - --brain-conf-path ${config} \ - --gazebo-cmd ${gz_command} - done - done - - exit 0 -} - -main $@ diff --git a/scripts/offline-evolve2/single_robot_manager.py b/scripts/offline-evolve2/single_robot_manager.py deleted file mode 100644 index 633c4f7..0000000 --- a/scripts/offline-evolve2/single_robot_manager.py +++ /dev/null @@ -1,101 +0,0 @@ -import ast -import os -import sys - -sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..')) - -from pygazebo.pygazebo import DisconnectError -from trollius.py33_exceptions import ConnectionResetError - -import trollius -from trollius import From - -from tol.config import parser -from tol.manage import World - -from sdfbuilder import Pose -from sdfbuilder.math import Vector3 - -from revolve.convert.yaml import yaml_to_robot -from revolve.angle import Tree -from revolve.util import wait_for - -from tol.spec import get_extended_brain_spec - - -@trollius.coroutine -def run(): - """ - The main coroutine, which is started below. - """ - # Parse command line / file input arguments - conf = parser.parse_args() - - # Adding brain configuration - with open(conf.brain_conf_path, 'r') as f: - s = f.read() - brain_conf = ast.literal_eval(s) - brain_conf["policy_load_path"] = conf.load_controller - conf.brain_conf = brain_conf - - # This disables the analyzer; enable it if you want to generate valid robots - # Can also do this using arguments of course, just pass an empty string - # conf.analyzer_address = None - - with open("{}.yaml".format(conf.robot_name), 'r') as yamlfile: - bot_yaml = yamlfile.read() - - # Create the world, this connects to the Gazebo world - world = yield From(World.create(conf)) - - # These are useful when working with YAML - body_spec = world.builder.body_builder.spec - brain_spec = get_extended_brain_spec(conf) - - # Create a robot from YAML - robot = yaml_to_robot(body_spec, brain_spec, bot_yaml) - - # Create a revolve.angle `Tree` representation from the robot, which - # is what is used in the world manager. - robot_tree = Tree.from_body_brain(robot.body, robot.brain, body_spec) - - # Insert the robot into the world. `insert_robot` resolves when the insert - # request is sent, the future it returns resolves when the robot insert - # is actually confirmed and a robot manager object has been created - pose = Pose(position=Vector3(0, 0, 0.05)) - future = yield From(world.insert_robot(robot_tree, pose, "{}-{}".format(conf.robot_name, conf.experiment_round))) - robot_manager = yield From(future) - - # I usually start the world paused, un-pause it here. Note that - # pause again returns a future for when the request is sent, - # that future in turn resolves when a response has been received. - # This is the general convention for all message actions in the - # world manager. `wait_for` saves the hassle of grabbing the - # intermediary future in this case. - yield From(wait_for(world.pause(False))) - - # Start a run loop to do some stuff - while True: - # Print robot fitness every second - print("Robot fitness: %f" % robot_manager.fitness()) - yield From(trollius.sleep(1.0)) - - -def main(): - def handler(loop, context): - exc = context['exception'] - if isinstance(exc, DisconnectError) or isinstance(exc, ConnectionResetError): - print("Got disconnect / connection reset - shutting down.") - sys.exit(0) - raise context['exception'] - - try: - loop = trollius.get_event_loop() - loop.set_exception_handler(handler) - loop.run_until_complete(run()) - except KeyboardInterrupt: - print("Got CtrlC, shutting down.") - - -if __name__ == '__main__': - main() diff --git a/scripts/offline-evolve2/start.py b/scripts/offline-evolve2/start.py deleted file mode 100644 index 285a737..0000000 --- a/scripts/offline-evolve2/start.py +++ /dev/null @@ -1,57 +0,0 @@ -import os -import sys - -here = os.path.dirname(os.path.abspath(__file__)) -tol_path = os.path.abspath(os.path.join(here, '..', '..')) -rv_path = os.path.abspath(os.path.join(tol_path, '..', 'revolve')) -sys.path.append(os.path.dirname(os.path.abspath(__file__))) - -from revolve.util import Supervisor -from offline_evolve import parser - - -class OfflineEvolutionSupervisor(Supervisor): - """ - Supervisor class that adds some output filtering for ODE errors - """ - - def __init__(self, *args, **kwargs): - super(OfflineEvolutionSupervisor, self).__init__(*args, **kwargs) - self.ode_errors = 0 - - def write_stderr(self, data): - """ - :param data: - :return: - """ - if 'ODE Message 3' in data: - self.ode_errors += 1 - elif data.strip(): - sys.stderr.write(data) - - if self.ode_errors >= 100: - self.ode_errors = 0 - sys.stderr.write('ODE Message 3 (100)\n') - - -args = parser.parse_args() - -os.environ['GAZEBO_PLUGIN_PATH'] = os.path.join(tol_path, 'build') -os.environ['GAZEBO_MODEL_PATH'] = os.path.join(tol_path, 'tools', 'models') + \ - ':' + os.path.join(rv_path, 'tools', 'models') - -supervisor = OfflineEvolutionSupervisor( - manager_cmd=[sys.executable, args.manager, - "--load-controller", args.load_controller, - "--robot-name", args.robot_name, - "--experiment-round", args.experiment_round, - "--brain-conf-path", args.brain_conf_path], - analyzer_cmd=os.path.join(rv_path, 'tools', 'analyzer', 'run-analyzer'), - world_file=os.path.join(here, args.world), - output_directory=args.output_directory, - restore_directory=args.restore_directory, - gazebo_cmd=args.gazebo_cmd, - manager_args=sys.argv[1:] -) - -supervisor.launch() diff --git a/scripts/offline-evolve2/summarize.R b/scripts/offline-evolve2/summarize.R deleted file mode 100644 index a83d9a0..0000000 --- a/scripts/offline-evolve2/summarize.R +++ /dev/null @@ -1,103 +0,0 @@ -# Use this script to summarize one or multiple concatenated -# runs of evolution data. -# This post helps here: -# http://stackoverflow.com/a/10349375/358873 - -library(ggplot2) -library(plyr) -library(reshape) - -read_dir_data <- function(odir) { - tdata = read.csv(paste(odir, "/generations.csv", sep=""), head=TRUE); - tdata$exp = as.factor(odir); - if (tdata[1,]$exp == "plus-gradual") { - tdata$births = tdata$gen + 15; - } else { - tdata$births = tdata$gen * 15 + 15; - } - - rdata = read.csv(paste(odir, "/robots.csv", sep=""), head=TRUE); - - return(merge(tdata[tdata$births<=3000,], rdata, by.x=c("robot_id", "run"), by.y=c("id", "run"))); -} - -dirs = list.files("."); -data = do.call(rbind, lapply(dirs, read_dir_data)); - -# Unify fitness calculation -data$fitness = 5*data$dvel + data$vel; - -# Remove outliers -data = data[data$fitness<1,]; - -cdata = ddply(data, c("births", "exp"), summarise, - fit=mean(fitness), fsd=sd(fitness), - ext=mean(extremity_count), esd=sd(extremity_count), - joints=mean(joint_count), jsd=sd(joint_count), - motors=mean(motor_count), msd=sd(motor_count), - sz=mean(nparts), ssd=sd(nparts), - inp=mean(inputs), isd=sd(inputs), - hid=mean(hidden), hsd=sd(hidden), - con=mean(conn), csd=sd(conn) - ); - -cdata$plot = as.factor("Fitness"); -cdata1 = cdata; -cdata2 = cdata; -cdata3 = cdata; -cdata4 = cdata; -cdata5 = cdata; -cdata6 = cdata; -cdata7 = cdata; - -cdata1$plot = as.factor("# of joints"); -cdata2$plot = as.factor("# of active joints"); -cdata3$plot = as.factor("Total size"); -cdata4$plot = as.factor("# of extremities"); -cdata5$plot = as.factor("# of inputs"); -cdata6$plot = as.factor("# of hidden neurons"); -cdata7$plot = as.factor("# of connections"); - -# Fitness over generations -ggplot(cdata, aes(births)) + - facet_grid(plot~., scale="free") + - geom_line(aes(y=fit, colour=exp)) + - geom_ribbon(aes(ymin=fit-fsd, ymax=fit+fsd, fill=exp), alpha=0.1, linetype=0) + - - geom_line(data=cdata1, aes(y=joints, colour=exp)) + - geom_ribbon(data=cdata1, aes(ymin=joints-jsd, ymax=joints+jsd, fill=exp), alpha=0.1, linetype=0) + - - geom_line(data=cdata2, aes(y=motors, colour=exp)) + - geom_ribbon(data=cdata2, aes(ymin=motors-jsd, ymax=motors+jsd, fill=exp), alpha=0.1, linetype=0) + - - geom_line(data=cdata3, aes(y=sz, colour=exp)) + - geom_ribbon(data=cdata3, aes(ymin=sz-ssd, ymax=sz+ssd, fill=exp), alpha=0.1, linetype=0) + - - geom_line(data=cdata4, aes(y=ext, colour=exp)) + - geom_ribbon(data=cdata4, aes(ymin=ext-esd, ymax=ext+esd, fill=exp), alpha=0.1, linetype=0) + - - geom_line(data=cdata5, aes(y=inp, colour=exp)) + - geom_ribbon(data=cdata5, aes(ymin=inp-isd, ymax=inp+isd, fill=exp), alpha=0.1, linetype=0) + - - geom_line(data=cdata6, aes(y=hid, colour=exp)) + - geom_ribbon(data=cdata6, aes(ymin=hid-hsd, ymax=hid+hsd, fill=exp), alpha=0.1, linetype=0) + - - geom_line(data=cdata7, aes(y=con, colour=exp)) + - geom_ribbon(data=cdata7, aes(ymin=con-csd, ymax=con+csd, fill=exp), alpha=0.1, linetype=0) + - - scale_fill_discrete(name="Experiment") + - scale_colour_discrete(name="Experiment") + - xlab("# of births") + - ylab(""); - -#last_gens = cdata[cdata$gen==max(cdata$gen),]; - -# Retrieve all the best robots per experiment -# See http://stackoverflow.com/questions/6289538/aggregate-a-dataframe-on-a-given-column-and-display-another-column -exp_maxes = do.call(rbind,lapply(split(data, list(data$exp, data$run)),function(chunk) chunk[which.max(chunk$fitness),])) -exp_maxes = exp_maxes[order(-exp_maxes$fitness),] - -exp_states = ddply(data, ~exp+run, summarise, cur_gen=max(gen)); -exp_states = exp_states[order(exp_states$exp, -exp_states$run),]; - -exp_states From 1351bf8e98cbaa53facfdf61e95e71217f41f281 Mon Sep 17 00:00:00 2001 From: raki123 Date: Sat, 19 Nov 2016 17:08:01 +0100 Subject: [PATCH 04/10] compiling but not working --- cpp/CMakeLists.txt | 2 +- cpp/tol/plugin/RobotController.cpp | 9 +- cpp/tol/plugin/simple_split_brain.cpp | 356 ++++++++++ cpp/tol/plugin/simple_split_brain.h | 115 +++ scripts/offline-evolve2/gait-learning.world | 43 ++ .../offline-evolve2/input-15/baseline.conf | 6 + .../input-15/baseline_no_fitness.conf | 7 + scripts/offline-evolve2/input-15/comma.conf | 7 + .../input-15/comma_aggressive.conf | 12 + scripts/offline-evolve2/input-15/plus.conf | 5 + .../input-15/plus_aggressive.conf | 11 + .../input-15/plus_gradual.conf | 6 + .../input-15/plus_less_aggressive.conf | 4 + .../input-15/plus_more_aggressive.conf | 11 + .../offline-evolve2/input-20/baseline.conf | 7 + scripts/offline-evolve2/input-20/plus.conf | 5 + .../input-20/plus_aggressive.conf | 10 + .../input-20/plus_more_aggressive.conf | 10 + scripts/offline-evolve2/input/baseline.conf | 5 + scripts/offline-evolve2/input/comma.conf | 4 + .../input/comma_aggressive.conf | 9 + scripts/offline-evolve2/input/plus.conf | 3 + .../input/plus_aggressive.conf | 8 + .../input/plus_more_aggressive.conf | 8 + scripts/offline-evolve2/make.sh | 3 + scripts/offline-evolve2/offline-evolve.world | 39 ++ scripts/offline-evolve2/offline_evolve.py | 437 ++++++++++++ scripts/offline-evolve2/rlpower.cfg | 12 + scripts/offline-evolve2/robots/babyA.yaml | 89 +++ scripts/offline-evolve2/robots/babyB.yaml | 101 +++ scripts/offline-evolve2/robots/babyC.yaml | 171 +++++ scripts/offline-evolve2/robots/gecko12.yaml | 124 ++++ scripts/offline-evolve2/robots/gecko17.yaml | 176 +++++ scripts/offline-evolve2/robots/gecko7.yaml | 73 ++ scripts/offline-evolve2/robots/snake5.yaml | 41 ++ scripts/offline-evolve2/robots/snake7.yaml | 63 ++ scripts/offline-evolve2/robots/snake9.yaml | 83 +++ scripts/offline-evolve2/robots/spider13.yaml | 121 ++++ scripts/offline-evolve2/robots/spider17.yaml | 161 +++++ scripts/offline-evolve2/robots/spider9.yaml | 659 ++++++++++++++++++ scripts/offline-evolve2/run-experiments.sh | 83 +++ .../offline-evolve2/single_robot_manager.py | 101 +++ scripts/offline-evolve2/start.py | 57 ++ scripts/offline-evolve2/summarize.R | 103 +++ 44 files changed, 3356 insertions(+), 4 deletions(-) create mode 100644 cpp/tol/plugin/simple_split_brain.cpp create mode 100644 cpp/tol/plugin/simple_split_brain.h create mode 100644 scripts/offline-evolve2/gait-learning.world create mode 100644 scripts/offline-evolve2/input-15/baseline.conf create mode 100644 scripts/offline-evolve2/input-15/baseline_no_fitness.conf create mode 100644 scripts/offline-evolve2/input-15/comma.conf create mode 100644 scripts/offline-evolve2/input-15/comma_aggressive.conf create mode 100644 scripts/offline-evolve2/input-15/plus.conf create mode 100644 scripts/offline-evolve2/input-15/plus_aggressive.conf create mode 100644 scripts/offline-evolve2/input-15/plus_gradual.conf create mode 100644 scripts/offline-evolve2/input-15/plus_less_aggressive.conf create mode 100644 scripts/offline-evolve2/input-15/plus_more_aggressive.conf create mode 100644 scripts/offline-evolve2/input-20/baseline.conf create mode 100644 scripts/offline-evolve2/input-20/plus.conf create mode 100644 scripts/offline-evolve2/input-20/plus_aggressive.conf create mode 100644 scripts/offline-evolve2/input-20/plus_more_aggressive.conf create mode 100644 scripts/offline-evolve2/input/baseline.conf create mode 100644 scripts/offline-evolve2/input/comma.conf create mode 100644 scripts/offline-evolve2/input/comma_aggressive.conf create mode 100644 scripts/offline-evolve2/input/plus.conf create mode 100644 scripts/offline-evolve2/input/plus_aggressive.conf create mode 100644 scripts/offline-evolve2/input/plus_more_aggressive.conf create mode 100755 scripts/offline-evolve2/make.sh create mode 100644 scripts/offline-evolve2/offline-evolve.world create mode 100644 scripts/offline-evolve2/offline_evolve.py create mode 100644 scripts/offline-evolve2/rlpower.cfg create mode 100644 scripts/offline-evolve2/robots/babyA.yaml create mode 100644 scripts/offline-evolve2/robots/babyB.yaml create mode 100644 scripts/offline-evolve2/robots/babyC.yaml create mode 100644 scripts/offline-evolve2/robots/gecko12.yaml create mode 100644 scripts/offline-evolve2/robots/gecko17.yaml create mode 100644 scripts/offline-evolve2/robots/gecko7.yaml create mode 100644 scripts/offline-evolve2/robots/snake5.yaml create mode 100644 scripts/offline-evolve2/robots/snake7.yaml create mode 100644 scripts/offline-evolve2/robots/snake9.yaml create mode 100644 scripts/offline-evolve2/robots/spider13.yaml create mode 100644 scripts/offline-evolve2/robots/spider17.yaml create mode 100644 scripts/offline-evolve2/robots/spider9.yaml create mode 100755 scripts/offline-evolve2/run-experiments.sh create mode 100644 scripts/offline-evolve2/single_robot_manager.py create mode 100644 scripts/offline-evolve2/start.py create mode 100644 scripts/offline-evolve2/summarize.R diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 0f8b35e..533623a 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -65,7 +65,7 @@ file(GLOB_RECURSE tol/plugin/fakebrain.cpp tol/plugin/helper.cpp tol/plugin/rlpower.cpp - tol/plugin/extended_neural_network.cpp + tol/plugin/simple_split_brain.cpp ) add_library(tolworldcontrol SHARED ${TOL_WORLD_SRC}) diff --git a/cpp/tol/plugin/RobotController.cpp b/cpp/tol/plugin/RobotController.cpp index 1389dd8..1bb255c 100644 --- a/cpp/tol/plugin/RobotController.cpp +++ b/cpp/tol/plugin/RobotController.cpp @@ -7,7 +7,7 @@ #include "RobotController.h" #include "rlpower.h" -#include "extended_neural_network.h" +#include "simple_split_brain.h" #include @@ -24,6 +24,8 @@ void RobotController::Load(::gazebo::physics::ModelPtr _parent, sdf::ElementPtr void RobotController::LoadBrain(sdf::ElementPtr sdf) { + std::cout << "i get here 0\n"; + double asd = 3/0; evaluator_ = boost::make_shared(); if (!sdf->HasElement("rv:brain")) { @@ -36,9 +38,10 @@ void RobotController::LoadBrain(sdf::ElementPtr sdf) std::cerr << "Brain does not define type, this is probably an error." << std::endl; return; } - + std::cout << "i get here 0\n"; if (brain->GetAttribute("algorithm")->GetAsString() == "rlpower") { - brain_.reset(new tol::ExtendedNeuralNetwork(this->model->GetName(), evaluator_, brain, motors_, sensors_)); + // brain_.reset(new tol::ExtendedNeuralNetwork(this->model->GetName(), evaluator_, brain, motors_, sensors_)); + brain_.reset(new tol::RLPower(this->model->GetName(), brain,evaluator_, motors_, sensors_)); } else { std::cout << "Calling default ANN brain." << std::endl; revolve::gazebo::RobotController::LoadBrain(sdf); diff --git a/cpp/tol/plugin/simple_split_brain.cpp b/cpp/tol/plugin/simple_split_brain.cpp new file mode 100644 index 0000000..ee3087e --- /dev/null +++ b/cpp/tol/plugin/simple_split_brain.cpp @@ -0,0 +1,356 @@ +#include "simple_split_brain.h" +#include "brain/split_cpg/extended_neural_network_controller.h" +#include "brain/split_cpg/weight_vector_learner.h" +#include "helper.h" +#include "sensor.h" +#include "actuator.h" +#include "revolve/gazebo/motors/Motor.h" +#include "revolve/gazebo/sensors/Sensor.h" + + +namespace tol { + + ExtendedNeuralNetwork::ExtendedNeuralNetwork(std::string modelName, + tol::EvaluatorPtr evaluator, + sdf::ElementPtr node, + const std::vector &actuators, + const std::vector &sensors) : revolve::brain::SimpleSplitBrain>() { + std::cout << "i get here \n"; + boost::shared_ptr swap1(new revolve::brain::ExtNNController(modelName, + parseSDF(node, actuators, sensors), + evaluator, + Helper::createWrapper(actuators), + Helper::createWrapper(sensors))); + controller = boost::static_pointer_cast>>(swap1); + boost::shared_ptr swap2(new revolve::brain::WeightVectorLearner()); + learner = boost::dynamic_pointer_cast>>(swap2); + std::cout << "done" << std::endl; + } + + ExtendedNeuralNetwork::~ExtendedNeuralNetwork() + { + + } + + + void ExtendedNeuralNetwork::update(const std::vector &actuators, + const std::vector &sensors, + double t, + double step) { + std::cout << "yay" << std::endl; + revolve::brain::SimpleSplitBrain>::update( + Helper::createWrapper(actuators), + Helper::createWrapper(sensors), + t, step + ); + } + + +revolve::brain::ExtNNController::ExtNNConfig ExtendedNeuralNetwork::parseSDF(sdf::ElementPtr node, + const std::vector< revolve::gazebo::MotorPtr > & motors, + const std::vector< revolve::gazebo::SensorPtr > & sensors) +{ + revolve::brain::ExtNNController::ExtNNConfig ret; + + // Map neuron sdf elements to their id's + std::map neuronDescriptions; + + // List of all hidden neuron id's + std::vector hiddenIds; + + // Number of input neurons for mapping them to the input buffer + ret.numInputNeurons_ = 0; + + // Number of output neurons for mapping them to the output buffer + ret.numOutputNeurons_ = 0; + + // Number of hidden neurons + ret.numHiddenNeurons_ = 0; + + // Get the first sdf neuron element + auto neuron = node->HasElement("rv:neuron") ? node->GetElement("rv:neuron") : sdf::ElementPtr(); + + while (neuron) { + if (!neuron->HasAttribute("layer") || !neuron->HasAttribute("id")) { + std::cerr << "Missing required neuron attributes (id or layer). '" << std::endl; + throw std::runtime_error("Robot brain error"); + } + auto layer = neuron->GetAttribute("layer")->GetAsString(); + auto neuronId = neuron->GetAttribute("id")->GetAsString(); + + + // check if a neuron with this id has been already added + if (neuronDescriptions.count(neuronId)) { + std::cerr << "Duplicate neuron ID '" + << neuronId << "'" << std::endl; + throw std::runtime_error("Robot brain error"); + } + + // add this neuron to the id->sdf map + neuronDescriptions[neuronId] = neuron; + + // add the neuron id to the appropriate list of id's + if ("input" == layer) { + // inputIds.push_back(neuronId); + } + + else if ("output" == layer) { + // outputIds.push_back(neuronId); + } + + else if ("hidden" == layer) { + hiddenIds.push_back(neuronId); + } + + else { + std::cerr << "Unknown neuron layer '" << layer << "'." << std::endl; + throw std::runtime_error("Robot brain error"); + } + + neuron = neuron->GetNextElement("rv:neuron"); + } + + + // Add output neurons for motors: + + // map of numbers of output neurons for each body part + std::map outputCountMap; + + for (auto it = motors.begin(); it != motors.end(); ++it) { + auto motor = *it; + auto partId = motor->partId(); + + if (!outputCountMap.count(partId)) { + outputCountMap[partId] = 0; + } + + for (unsigned int i = 0, l = motor->outputs(); i < l; ++i) { + std::stringstream neuronId; + neuronId << partId << "-out-" << outputCountMap[partId]; + outputCountMap[partId]++; + + auto neuronDescription = neuronDescriptions.find(neuronId.str()); + if (neuronDescription == neuronDescriptions.end()) { + std::cerr << "Required output neuron " << neuronId.str() << + " for motor could not be located" + << std::endl; + throw std::runtime_error("Robot brain error"); + } + + auto newNeuron = neuronHelper(neuronDescription->second, ret); + ret.idToNeuron_[neuronId.str()] = newNeuron; + + } + } + // Add input neurons for sensors: + + // map of number of input neurons for each part: + + std::map inputCountMap; + + for (auto it = sensors.begin(); it != sensors.end(); ++it) { + auto sensor = *it; + auto partId = sensor->partId(); + + if (!inputCountMap.count(partId)) { + inputCountMap[partId] = 0; + } + + for (unsigned int i = 0, l = sensor->inputs(); i < l; ++i) { + std::stringstream neuronId; + neuronId << partId << "-in-" << inputCountMap[partId]; + inputCountMap[partId]++; + + auto neuronDescription = neuronDescriptions.find(neuronId.str()); + if (neuronDescription == neuronDescriptions.end()) { + std::cerr << "Required input neuron " << neuronId.str() << + " for sensor could not be located" + << std::endl; + throw std::runtime_error("Robot brain error"); + } + + auto newNeuron = neuronHelper(neuronDescription->second,ret); + ret.idToNeuron_[neuronId.str()] = newNeuron; + } + } + + // initialize the array for sensor inputs: + ret.inputs_ = new double[ret.numInputNeurons_]; + ret.outputs_ = new double[ret.numOutputNeurons_]; + + + // Add hidden neurons: + for (auto it = hiddenIds.begin(); it != hiddenIds.end(); ++it) { + auto neuronDescription = neuronDescriptions.find(*it); + auto newNeuron = neuronHelper(neuronDescription->second,ret); + ret.idToNeuron_[*it] = newNeuron; + } + + + // Add connections: + auto connection = node->HasElement("rv:neural_connection") ? node->GetElement("rv:neural_connection") : sdf::ElementPtr(); + while (connection) { + if (!connection->HasAttribute("src") || !connection->HasAttribute("dst") + || !connection->HasAttribute("weight")) { + std::cerr << "Missing required connection attributes (`src`, `dst` or `weight`)." << std::endl; + throw std::runtime_error("Robot brain error"); + } + + auto src = connection->GetAttribute("src")->GetAsString(); + auto dst = connection->GetAttribute("dst")->GetAsString(); + + + std::string dstSocketName; + if (connection->HasAttribute("socket")) { + dstSocketName = connection->GetAttribute("socket")->GetAsString(); + } + else { + dstSocketName = "None"; // this is the default socket name + } + + double weight; + connection->GetAttribute("weight")->Get(weight); + + // Use connection helper to set the weight + connectionHelper(src, dst, dstSocketName, weight, ret.idToNeuron_, ret); + + // Load the next connection + connection = connection->GetNextElement("rv:neural_connection"); + } + return ret; +} + +std::map ExtendedNeuralNetwork::parseSDFElement(sdf::ElementPtr elem) +{ + std::map params; + + auto subElem = elem->GetFirstElement(); + while (subElem) { + auto elName = subElem->GetName(); + double elValue = subElem->Get(); + params[elName] = elValue; + subElem = subElem->GetNextElement(); + } + + return params; +} + +void ExtendedNeuralNetwork::connectionHelper(const std::string &src, + const std::string &dst, + const std::string &socket, + double weight, + const std::map &idToNeuron, + revolve::brain::ExtNNController::ExtNNConfig &ret) +{ + std::cout << "connection from " + src + " to " + dst + " was added with weight: " << weight << std::endl; + auto srcNeuron = idToNeuron.find(src); + if (srcNeuron == idToNeuron.end()) { + std::cerr << "Could not find source neuron '" << src << "'" << std::endl; + throw std::runtime_error("Robot brain error"); + } + auto dstNeuron = idToNeuron.find(dst); + if (dstNeuron == idToNeuron.end()) { + std::cerr << "Could not find destination neuron '" << dst << "'" << std::endl; + throw std::runtime_error("Robot brain error"); + } + + revolve::brain::NeuralConnectionPtr newConnection(new revolve::brain::NeuralConnection( + srcNeuron->second, + dstNeuron->second, + weight + )); + + // Add reference to this connection to the destination neuron + (dstNeuron->second)->AddIncomingConnection(socket, newConnection); + ret.connections_.push_back(newConnection); +} + + +revolve::brain::NeuronPtr ExtendedNeuralNetwork::neuronHelper(sdf::ElementPtr neuron, + revolve::brain::ExtNNController::ExtNNConfig &ret) +{ + if (!neuron->HasAttribute("type")) { + std::cerr << "Missing required `type` attribute for neuron." << std::endl; + throw std::runtime_error("Robot brain error"); + } + + if (!neuron->HasAttribute("layer")) { + std::cerr << "Missing required `layer` attribute for neuron." << std::endl; + throw std::runtime_error("Robot brain error"); + } + + auto type = neuron->GetAttribute("type")->GetAsString(); + auto layer = neuron->GetAttribute("layer")->GetAsString(); + auto id = neuron->GetAttribute("id")->GetAsString(); + + // map of parameter names and values + auto params = parseSDFElement(neuron); + + return addNeuron(id, type, layer, params, ret); +} + + + +revolve::brain::NeuronPtr ExtendedNeuralNetwork::addNeuron(const std::string &neuronId, + const std::string &neuronType, + const std::string &neuronLayer, // can be 'hidden', 'input' or 'output' + const std::map ¶ms, + revolve::brain::ExtNNController::ExtNNConfig &ret) +{ + revolve::brain::NeuronPtr newNeuron; + std::cout << neuronType + " " + neuronId + " was added in"+ " "+ neuronLayer << std::endl; + if ("input" == neuronLayer) { + newNeuron.reset(new revolve::brain::InputNeuron(neuronId, params)); + + ret.inputNeurons_.push_back(newNeuron); + ret.inputPositionMap_[newNeuron] = ret.numInputNeurons_; + ret.numInputNeurons_++; + } + + else { + + if ("Sigmoid" == neuronType) { + newNeuron.reset(new revolve::brain::SigmoidNeuron(neuronId, params)); + } + else if ("Simple" == neuronType) { + newNeuron.reset(new revolve::brain::LinearNeuron(neuronId, params)); + } + else if ("Oscillator" == neuronType) { + newNeuron.reset(new revolve::brain::OscillatorNeuron(neuronId, params)); + } + else if ("V-Neuron" == neuronType) { + newNeuron.reset(new revolve::brain::VOscillator(neuronId, params)); + } + else if ("X-Neuron" == neuronType) { + newNeuron.reset(new revolve::brain::XOscillator(neuronId, params)); + } + else if ("Bias" == neuronType) { + newNeuron.reset(new revolve::brain::BiasNeuron(neuronId, params)); + } + else if ("Leaky" == neuronType) { + newNeuron.reset(new revolve::brain::LeakyIntegrator(neuronId, params)); + } + else if ("DifferentialCPG" == neuronType) { + newNeuron.reset(new revolve::brain::DifferentialCPG(neuronId, params)); + } + else { + std::cerr << "Unsupported neuron type `" << neuronType << '`' << std::endl; + throw std::runtime_error("Robot brain error"); + } + + if ("output" == neuronLayer) { + ret.outputNeurons_.push_back(newNeuron); + ret.outputPositionMap_[newNeuron] = ret.numOutputNeurons_; + ret.numOutputNeurons_++; + } + else { + ret.hiddenNeurons_.push_back(newNeuron); + ret.numHiddenNeurons_++; + } + } + + ret.allNeurons_.push_back(newNeuron); + return newNeuron; +} +} /* namespace tol */ + diff --git a/cpp/tol/plugin/simple_split_brain.h b/cpp/tol/plugin/simple_split_brain.h new file mode 100644 index 0000000..13426ff --- /dev/null +++ b/cpp/tol/plugin/simple_split_brain.h @@ -0,0 +1,115 @@ +#ifndef REVOLVE_GAZEBO_BRAIN_DIFFERENTIAL_NEAT_H +#define REVOLVE_GAZEBO_BRAIN_DIFFERENTIAL_NEAT_H + +#include "brain/split_cpg/simple_split_brain.h" +#include "brain/split_cpg/extended_neural_network_controller.h" +#include "brain/split_cpg/weight_vector_learner.h" +#include "evaluator.h" +#include "revolve/gazebo/brain/Brain.h" + + +#include +#include + +#include +#include + +namespace tol { + + class ExtendedNeuralNetwork : public revolve::gazebo::Brain, private revolve::brain::SimpleSplitBrain> { + + public: + /** + * Constructor for a neural network including neurons that are of a different type than the usual ones. + * @param modelName: name of the model + * @param evaluator: pointer to the evaluator that is used + * @param node: the sdf file containing the necessary information to build the network + * @param actuators: vector list of robot's actuators + * @param sensors: vector list of robot's sensors + * @return pointer to the neural network + */ + ExtendedNeuralNetwork(std::string modelName, + tol::EvaluatorPtr evaluator, + sdf::ElementPtr node, + const std::vector &actuators, + const std::vector &sensors); + + virtual ~ExtendedNeuralNetwork(); + + /** + * Method for updating sensors readings, actuators positions, ranked list of policies and generating new policy + * @param actuators: vector list of robot's actuators + * @param sensors: vector list of robot's sensors + * @param t: + * @param step: + */ + virtual void update(const std::vector &actuators, + const std::vector &sensors, + double t, + double step); + + /** + * Method to transform the sdf file to a configuration + * @param node: sdf file to be transformed + * @param motors: vector list of robot's motors + * @param sensors: vector list of robot's sensors + * @return configuration needed for the neural network + */ + static revolve::brain::ExtNNController::ExtNNConfig parseSDF(sdf::ElementPtr node, + const std::vector & motors, + const std::vector & sensors); + + /** + * Method to get the parameters of neurons from an sdf ElementPtr + * @param elem: sdf that includes the parameters + * @return string to parameter mapping + */ + static std::map parseSDFElement(sdf::ElementPtr elem); + + /** + * Helpermethod for getting the configuration + * adds a new connection to the configuration + * @param src: the beginning of the connetion + * @param dst: the end of the connection + * @param weight: weighting factor of the connection + * @param idToNeuron: mapping between the neurons and their ids + * @param ret: configuration for the network where the connection should be included + */ + static void connectionHelper(const std::string &src, + const std::string &dst, + const std::string &socket, + double weight, + const std::map &idToNeuron, + revolve::brain::ExtNNController::ExtNNConfig &ret); + /** + * Helpermethod for getting the configuration + * @param neuron: sdf for the neuron to be added + * @param ret: configuration for the network where the neuron should be added + */ + static revolve::brain::NeuronPtr neuronHelper(sdf::ElementPtr neuron, + revolve::brain::ExtNNController::ExtNNConfig &ret); + + /** + * Helpermethod for getting the configuration + * This function creates neurons and adds them to the configuration + * @param neuronId: id of the neuron + * @param neuronType: type of the neuron + * @param neuronLayer: layer the neuron should be added to, can be 'hidden', 'input' or 'output' + * @param params: parameters of the new neuron + */ + static revolve::brain::NeuronPtr addNeuron(const std::string &neuronId, + const std::string &neuronType, + const std::string &neuronLayer, + const std::map ¶ms, + revolve::brain::ExtNNController::ExtNNConfig &ret); + +protected: +// boost::shared_ptr learner; + }; + + +} /* namespace tol */ + +#endif //REVOLVE_GAZEBO_BRAIN_REINFORCEDLEARNING_H + + diff --git a/scripts/offline-evolve2/gait-learning.world b/scripts/offline-evolve2/gait-learning.world new file mode 100644 index 0000000..fa159af --- /dev/null +++ b/scripts/offline-evolve2/gait-learning.world @@ -0,0 +1,43 @@ + + + + + 0 + 0 + + + + 0.005 + + + 0.0 + + + + + 0.1 + 10e-6 + + + 100 + 1e-8 + + + world + + + + + + + + + model://sun + + + model://tol_ground + + + + + \ No newline at end of file diff --git a/scripts/offline-evolve2/input-15/baseline.conf b/scripts/offline-evolve2/input-15/baseline.conf new file mode 100644 index 0000000..6483a30 --- /dev/null +++ b/scripts/offline-evolve2/input-15/baseline.conf @@ -0,0 +1,6 @@ +output_directory=/media/expdata/output +restore_directory=baseline-selection +disable_selection=1 +disable_fitness=1 +population_size=15 +num_children=15 diff --git a/scripts/offline-evolve2/input-15/baseline_no_fitness.conf b/scripts/offline-evolve2/input-15/baseline_no_fitness.conf new file mode 100644 index 0000000..95b27ec --- /dev/null +++ b/scripts/offline-evolve2/input-15/baseline_no_fitness.conf @@ -0,0 +1,7 @@ +output_directory=output +restore_directory=baseline-no-fitness-15 +disable_fitness=1 +disable_selection=1 +keep_parents=0 +population_size=15 +num_children=15 \ No newline at end of file diff --git a/scripts/offline-evolve2/input-15/comma.conf b/scripts/offline-evolve2/input-15/comma.conf new file mode 100644 index 0000000..251b434 --- /dev/null +++ b/scripts/offline-evolve2/input-15/comma.conf @@ -0,0 +1,7 @@ +output_directory=comma-output +restore_directory=comma-1000 +population_size=15 +num_children=15 +keep_parents=False +num_generations=1000 +num_evolutions=32 diff --git a/scripts/offline-evolve2/input-15/comma_aggressive.conf b/scripts/offline-evolve2/input-15/comma_aggressive.conf new file mode 100644 index 0000000..70818c4 --- /dev/null +++ b/scripts/offline-evolve2/input-15/comma_aggressive.conf @@ -0,0 +1,12 @@ +output_directory=comma-output +restore_directory=comma-aggressive-15-2000 +keep_parents=0 +enable_light_sensor=0 +body_mutation_epsilon=0.3 +brain_mutation_epsilon=0.3 +p_delete_subtree=0.25 +p_duplicate_subtree=0.25 +p_swap_subtree=0.25 +population_size=15 +num_children=15 +num_generations=2000 diff --git a/scripts/offline-evolve2/input-15/plus.conf b/scripts/offline-evolve2/input-15/plus.conf new file mode 100644 index 0000000..48d810c --- /dev/null +++ b/scripts/offline-evolve2/input-15/plus.conf @@ -0,0 +1,5 @@ +output_directory=/media/expdata/output +restore_directory=plus +population_size=15 +num_children=15 +world_step_size=0.003 \ No newline at end of file diff --git a/scripts/offline-evolve2/input-15/plus_aggressive.conf b/scripts/offline-evolve2/input-15/plus_aggressive.conf new file mode 100644 index 0000000..c8fedad --- /dev/null +++ b/scripts/offline-evolve2/input-15/plus_aggressive.conf @@ -0,0 +1,11 @@ +output_directory=population-output +restore_directory=plus-aggressive-15 +enable_light_sensor=0 +body_mutation_epsilon=0.3 +brain_mutation_epsilon=0.3 +p_delete_subtree=0.25 +p_duplicate_subtree=0.25 +p_swap_subtree=0.25 +population_size=15 +num_children=15 +num_evolutions=32 diff --git a/scripts/offline-evolve2/input-15/plus_gradual.conf b/scripts/offline-evolve2/input-15/plus_gradual.conf new file mode 100644 index 0000000..8339971 --- /dev/null +++ b/scripts/offline-evolve2/input-15/plus_gradual.conf @@ -0,0 +1,6 @@ +output_directory=/media/expdata/output +restore_directory=plus-gradual-new +population_size=15 +num_children=1 +num_generations=2991 +world_step_size=0.003 \ No newline at end of file diff --git a/scripts/offline-evolve2/input-15/plus_less_aggressive.conf b/scripts/offline-evolve2/input-15/plus_less_aggressive.conf new file mode 100644 index 0000000..d6833ba --- /dev/null +++ b/scripts/offline-evolve2/input-15/plus_less_aggressive.conf @@ -0,0 +1,4 @@ +output_directory=output +restore_directory=plus-less-aggressive-size-discount-3 +population_size=15 +num_children=15 diff --git a/scripts/offline-evolve2/input-15/plus_more_aggressive.conf b/scripts/offline-evolve2/input-15/plus_more_aggressive.conf new file mode 100644 index 0000000..02dce3e --- /dev/null +++ b/scripts/offline-evolve2/input-15/plus_more_aggressive.conf @@ -0,0 +1,11 @@ +output_directory=population-output +restore_directory=plus-more-aggressive-15 +enable_light_sensor=0 +body_mutation_epsilon=0.4 +brain_mutation_epsilon=0.4 +p_delete_subtree=0.4 +p_duplicate_subtree=0.4 +p_swap_subtree=0.4 +population_size=15 +num_children=15 +num_evolutions=32 diff --git a/scripts/offline-evolve2/input-20/baseline.conf b/scripts/offline-evolve2/input-20/baseline.conf new file mode 100644 index 0000000..7f80d63 --- /dev/null +++ b/scripts/offline-evolve2/input-20/baseline.conf @@ -0,0 +1,7 @@ +output_directory=output +restore_directory=baseline-20 +enable_light_sensor=0 +disable_evolution=1 +keep_parents=1 +population_size=20 +num_children=20 \ No newline at end of file diff --git a/scripts/offline-evolve2/input-20/plus.conf b/scripts/offline-evolve2/input-20/plus.conf new file mode 100644 index 0000000..79ed5cf --- /dev/null +++ b/scripts/offline-evolve2/input-20/plus.conf @@ -0,0 +1,5 @@ +output_directory=output +restore_directory=plus-20 +enable_light_sensor=0 +population_size=20 +num_children=20 diff --git a/scripts/offline-evolve2/input-20/plus_aggressive.conf b/scripts/offline-evolve2/input-20/plus_aggressive.conf new file mode 100644 index 0000000..7ee964d --- /dev/null +++ b/scripts/offline-evolve2/input-20/plus_aggressive.conf @@ -0,0 +1,10 @@ +output_directory=debug-output +restore_directory=plus-aggressive-20 +enable_light_sensor=0 +body_mutation_epsilon=0.3 +brain_mutation_epsilon=0.3 +p_delete_subtree=0.25 +p_duplicate_subtree=0.25 +p_swap_subtree=0.25 +population_size=20 +num_children=20 diff --git a/scripts/offline-evolve2/input-20/plus_more_aggressive.conf b/scripts/offline-evolve2/input-20/plus_more_aggressive.conf new file mode 100644 index 0000000..285e6d2 --- /dev/null +++ b/scripts/offline-evolve2/input-20/plus_more_aggressive.conf @@ -0,0 +1,10 @@ +output_directory=output +restore_directory=plus-more-aggressive-20 +enable_light_sensor=0 +body_mutation_epsilon=0.4 +brain_mutation_epsilon=0.4 +p_delete_subtree=0.4 +p_duplicate_subtree=0.4 +p_swap_subtree=0.4 +population_size=20 +num_children=20 \ No newline at end of file diff --git a/scripts/offline-evolve2/input/baseline.conf b/scripts/offline-evolve2/input/baseline.conf new file mode 100644 index 0000000..e3cf3e3 --- /dev/null +++ b/scripts/offline-evolve2/input/baseline.conf @@ -0,0 +1,5 @@ +output_directory=output +restore_directory=baseline +enable_light_sensor=0 +disable_evolution=1 +keep_parents=1 diff --git a/scripts/offline-evolve2/input/comma.conf b/scripts/offline-evolve2/input/comma.conf new file mode 100644 index 0000000..6e21d0d --- /dev/null +++ b/scripts/offline-evolve2/input/comma.conf @@ -0,0 +1,4 @@ +output_directory=output +restore_directory=comma +enable_light_sensor=0 +keep_parents=False diff --git a/scripts/offline-evolve2/input/comma_aggressive.conf b/scripts/offline-evolve2/input/comma_aggressive.conf new file mode 100644 index 0000000..7a913ef --- /dev/null +++ b/scripts/offline-evolve2/input/comma_aggressive.conf @@ -0,0 +1,9 @@ +output_directory=output +restore_directory=comma-aggressive +enable_light_sensor=0 +keep_parents=False +body_mutation_epsilon=0.3 +brain_mutation_epsilon=0.3 +p_delete_subtree=0.25 +p_duplicate_subtree=0.25 +p_swap_subtree=0.25 diff --git a/scripts/offline-evolve2/input/plus.conf b/scripts/offline-evolve2/input/plus.conf new file mode 100644 index 0000000..d615657 --- /dev/null +++ b/scripts/offline-evolve2/input/plus.conf @@ -0,0 +1,3 @@ +output_directory=output +restore_directory=plus +enable_light_sensor=0 diff --git a/scripts/offline-evolve2/input/plus_aggressive.conf b/scripts/offline-evolve2/input/plus_aggressive.conf new file mode 100644 index 0000000..62357f0 --- /dev/null +++ b/scripts/offline-evolve2/input/plus_aggressive.conf @@ -0,0 +1,8 @@ +output_directory=output +restore_directory=plus-aggressive +enable_light_sensor=0 +body_mutation_epsilon=0.3 +brain_mutation_epsilon=0.3 +p_delete_subtree=0.25 +p_duplicate_subtree=0.25 +p_swap_subtree=0.25 diff --git a/scripts/offline-evolve2/input/plus_more_aggressive.conf b/scripts/offline-evolve2/input/plus_more_aggressive.conf new file mode 100644 index 0000000..d96df1a --- /dev/null +++ b/scripts/offline-evolve2/input/plus_more_aggressive.conf @@ -0,0 +1,8 @@ +output_directory=output +restore_directory=plus-more-aggressive +enable_light_sensor=0 +body_mutation_epsilon=0.4 +brain_mutation_epsilon=0.4 +p_delete_subtree=0.4 +p_duplicate_subtree=0.4 +p_swap_subtree=0.4 diff --git a/scripts/offline-evolve2/make.sh b/scripts/offline-evolve2/make.sh new file mode 100755 index 0000000..57f317a --- /dev/null +++ b/scripts/offline-evolve2/make.sh @@ -0,0 +1,3 @@ +#!/bin/bash +cd ../../build/ +make -j4 diff --git a/scripts/offline-evolve2/offline-evolve.world b/scripts/offline-evolve2/offline-evolve.world new file mode 100644 index 0000000..8d48748 --- /dev/null +++ b/scripts/offline-evolve2/offline-evolve.world @@ -0,0 +1,39 @@ + + + + + 0 + 0 + + + 0.003 + + + 0.0 + + + + 0.1 + 10e-6 + + + 100 + 1e-8 + + + quick + + + + + + + model://sun + + + model://tol_ground + + + + + diff --git a/scripts/offline-evolve2/offline_evolve.py b/scripts/offline-evolve2/offline_evolve.py new file mode 100644 index 0000000..1715c35 --- /dev/null +++ b/scripts/offline-evolve2/offline_evolve.py @@ -0,0 +1,437 @@ +# Offline evolution scheme +# - We use a population of constant size 10 +# - Each robot is evaluated for 20 seconds, though we may vary this number +# - The average speed during this evaluation is the fitness +# - We do parent selection using a binary tournament: select two parents at +# random, the one with the best fitness is parent 1, repeat for parent 2. +# - Using this mechanism, we generate 10 children +# - After evaluation of the children, we either do: +# -- Plus scheme, sort *all* robots by fitness +# -- Comma scheme, get rid of the parents and continue with children only +from __future__ import absolute_import +import sys +import time +import os +import shutil +import random +import csv +import itertools +import logging +import trollius +from trollius import From, Return + +sys.path.append(os.path.dirname(os.path.abspath(__file__))+'/../../') + +from sdfbuilder import Pose +from sdfbuilder.math import Vector3 + +from revolve.util import wait_for + +from tol.manage.robot import Robot +from tol.config import parser +from tol.manage import World +from tol.logging import logger, output_console +from tol.util.analyze import list_extremities, count_joints, count_motors, count_extremities, count_connections + +# Log output to console +output_console() +logger.setLevel(logging.DEBUG) + +# Add offline evolve arguments +parser.add_argument( + '--population-size', + default=10, type=int, + help="Population size in each generation." +) + +parser.add_argument( + '--num-children', + default=10, type=int, + help="The number of children produced in each generation." +) + + +def str2bool(v): + return v.lower() == "true" or v == "1" + +parser.add_argument( + '--keep-parents', + default=True, type=str2bool, + help="Whether or not to discard the parents after each generation. This determines the strategy, + or ,." +) + +parser.add_argument( + '--num-generations', + default=200, type=int, + help="The number of generations to simulate." +) + +parser.add_argument( + '--disable-evolution', + default=False, type=str2bool, + help="Useful as a baseline test - if set to true, new robots are generated" + " every time rather than evolving them." +) + +parser.add_argument( + '--disable-selection', + default=False, type=str2bool, + help="Useful as a different baseline test - if set to true, robots reproduce," + " but parents are selected completely random." +) + +parser.add_argument( + '--disable-fitness', + default=False, type=str2bool, + help="Another baseline testing option, sorts robots randomly rather " + "than selecting the top pairs. This only matters if parents are kept." +) + +parser.add_argument( + '--num-evolutions', + default=30, type=int, + help="The number of times to repeat the experiment." +) + +parser.add_argument( + '--evaluation-threshold', + default=10.0, type=float, + help="Maximum number of seconds one evaluation can take before the " + "decision is made to restart from snapshot. The assumption is " + "that the world may have become slow and restarting will help." +) + + +class OfflineEvoManager(World): + """ + Extended world manager for the offline evolution script + """ + + def __init__(self, conf, _private): + """ + + :param conf: + :param _private: + :return: + """ + super(OfflineEvoManager, self).__init__(conf, _private) + + self._snapshot_data = {} + + # Output files + csvs = { + 'generations': ['run', 'gen', 'robot_id', 'vel', 'dvel', 'fitness', 't_eval'], + 'robot_details': ['robot_id', 'extremity_id', 'extremity_size', + 'joint_count', 'motor_count'] + } + self.csv_files = {k: {'filename': None, 'file': None, 'csv': None, + 'header': csvs[k]} + for k in csvs} + + self.current_run = 0 + + if self.output_directory: + for k in self.csv_files: + fname = os.path.join(self.output_directory, k + '.csv') + self.csv_files[k]['filename'] = fname + if self.do_restore: + shutil.copy(fname + '.snapshot', fname) + f = open(fname, 'ab', buffering=1) + else: + f = open(fname, 'wb', buffering=1) + + self.csv_files[k]['file'] = f + self.csv_files[k]['csv'] = csv.writer(f, delimiter=',') + + if not self.do_restore: + self.csv_files[k]['csv'].writerow(self.csv_files[k]['header']) + + def robots_header(self): + return Robot.header() + + @classmethod + @trollius.coroutine + def create(cls, conf): + """ + Coroutine to instantiate a Revolve.Angle WorldManager + :param conf: + :return: + """ + self = cls(_private=cls._PRIVATE, conf=conf) + yield From(self._init()) + raise Return(self) + + @trollius.coroutine + def create_snapshot(self): + """ + Copy the generations file in the snapshot + :return: + """ + ret = yield From(super(OfflineEvoManager, self).create_snapshot()) + if not ret: + raise Return(ret) + + for k in self.csv_files: + entry = self.csv_files[k] + if entry['file']: + entry['file'].flush() + shutil.copy(entry['filename'], entry['filename'] + '.snapshot') + + @trollius.coroutine + def get_snapshot_data(self): + """ + :return: + """ + data = yield From(super(OfflineEvoManager, self).get_snapshot_data()) + data.update(self._snapshot_data) + raise Return(data) + + @trollius.coroutine + def evaluate_pair(self, tree, bbox, parents=None): + """ + Evaluates a single robot tree. + :param tree: + :param bbox: + :param parents: + :return: Evaluated Robot object + """ + # Pause the world just in case it wasn't already + yield From(wait_for(self.pause(True))) + + pose = Pose(position=Vector3(0, 0, -bbox.min.z)) + fut = yield From(self.insert_robot(tree, pose, parents=parents)) + robot = yield From(fut) + + max_age = self.conf.evaluation_time + self.conf.warmup_time + + # Unpause the world to start evaluation + yield From(wait_for(self.pause(False))) + + before = time.time() + + while True: + if robot.age() >= max_age: + break + + # Sleep for the pose update frequency, which is about when + # we expect a new age update. + yield From(trollius.sleep(1.0 / self.state_update_frequency)) + + yield From(wait_for(self.delete_robot(robot))) + yield From(wait_for(self.pause(True))) + + diff = time.time() - before + if diff > self.conf.evaluation_threshold: + sys.stderr.write("Evaluation threshold exceeded, shutting down with nonzero status code.\n") + sys.stderr.flush() + sys.exit(15) + + raise Return(robot) + + @trollius.coroutine + def evaluate_population(self, trees, bboxes, parents=None): + """ + :param trees: + :param bboxes: + :param parents: + :return: + """ + if parents is None: + parents = [None for _ in trees] + + pairs = [] + print("Evaluating population...") + for tree, bbox, par in itertools.izip(trees, bboxes, parents): + print("Evaluating individual...") + before = time.time() + robot = yield From(self.evaluate_pair(tree, bbox, par)) + pairs.append((robot, time.time() - before)) + print("Done.") + + print("Done evaluating population.") + raise Return(pairs) + + @trollius.coroutine + def produce_generation(self, parents): + """ + Produce the next generation of robots from + the current. + :param parents: + :return: + """ + print("Producing generation...") + trees = [] + bboxes = [] + parent_pairs = [] + + while len(trees) < self.conf.num_children: + print("Producing individual...") + if self.conf.disable_selection: + p1, p2 = random.sample(parents, 2) + else: + p1, p2 = select_parents(parents, self.conf) + + for j in xrange(self.conf.max_mating_attempts): + pair = yield From(self.attempt_mate(p1, p2)) + if pair: + trees.append(pair[0]) + bboxes.append(pair[1]) + parent_pairs.append((p1, p2)) + break + + print("Done.") + + print("Done producing generation.") + raise Return(trees, bboxes, parent_pairs) + + def log_generation(self, evo, generation, pairs): + """ + :param evo: The evolution run + :param generation: + :param pairs: List of tuples (robot, evaluation wallclock time) + :return: + """ + print("================== GENERATION %d ==================" % generation) + if not self.output_directory: + return + + go = self.csv_files['generations']['csv'] + do = self.csv_files['robot_details']['csv'] + for robot, t_eval in pairs: + robot_id = robot.robot.id + root = robot.tree.root + go.writerow([evo, generation, robot.robot.id, robot.velocity(), + robot.displacement_velocity(), robot.fitness(), t_eval]) + + # TODO Write this once when robot is written instead + counter = 0 + for extr in list_extremities(root): + num_joints = count_joints(extr) + num_motors = count_motors(extr) + do.writerow((robot_id, counter, len(extr), num_joints, num_motors)) + counter += 1 + + @trollius.coroutine + def run(self): + """ + :return: + """ + conf = self.conf + + if self.do_restore: + # Recover from a previously cancelled / crashed experiment + data = self.do_restore + evo_start = data['evo_start'] + gen_start = data['gen_start'] + pairs = data['local_pairs'] + else: + # Start at the first experiment + evo_start = 1 + gen_start = 1 + pairs = None + + for evo in range(evo_start, conf.num_evolutions + 1): + self.current_run = evo + + if not pairs: + # Only create initial population if we are not restoring from + # a previous experiment. + trees, bboxes = yield From(self.generate_population(conf.population_size)) + pairs = yield From(self.evaluate_population(trees, bboxes)) + self.log_generation(evo, 0, pairs) + + for generation in xrange(gen_start, conf.num_generations): + if (generation % 10) == 0: + # Snapshot every 10 generations + self._snapshot_data = { + "local_pairs": pairs, + "gen_start": generation, + "evo_start": evo + } + yield From(self.create_snapshot()) + print("Created snapshot of experiment state.") + + # Produce the next generation and evaluate them + robots = [p[0] for p in pairs] + if conf.disable_evolution: + child_trees, child_bboxes = yield From( + self.generate_population(conf.population_size)) + parent_pairs = None + else: + child_trees, child_bboxes, parent_pairs = yield From(self.produce_generation(robots)) + + child_pairs = yield From(self.evaluate_population(child_trees, child_bboxes, parent_pairs)) + + if conf.keep_parents: + pairs += child_pairs + else: + pairs = child_pairs + + # Sort the bots and reduce to population size + if conf.disable_fitness: + random.shuffle(pairs) + else: + pairs = sorted(pairs, key=lambda r: r[0].fitness(), reverse=True) + + pairs = pairs[:conf.population_size] + self.log_generation(evo, generation, pairs) + + # Clear "restore" parameters + gen_start = 1 + pairs = None + + yield From(self.teardown()) + + @trollius.coroutine + def teardown(self): + """ + :return: + """ + yield From(super(OfflineEvoManager, self).teardown()) + for k in self.csv_files: + if self.csv_files[k]['file']: + self.csv_files[k]['file'].close() + + +def select_parent(parents, conf): + """ + Select a parent using a binary tournament. + :param parents: + :param conf: Configuration object + :return: + """ + return sorted(random.sample(parents, conf.tournament_size), key=lambda r: r.fitness())[-1] + + +def select_parents(parents, conf): + """ + :param parents: + :param conf: Configuration object + :return: + """ + p1 = select_parent(parents, conf) + p2 = select_parent(list(parent for parent in parents if parent != p1), conf) + return p1, p2 + + +@trollius.coroutine +def run(): + """ + :return: + """ + conf = parser.parse_args() + world = yield From(OfflineEvoManager.create(conf)) + yield From(world.run()) + + +def main(): + try: + loop = trollius.get_event_loop() + loop.run_until_complete(run()) + except KeyboardInterrupt: + print("Got Ctrl+C, shutting down.") + + +if __name__ == '__main__': + main() + diff --git a/scripts/offline-evolve2/rlpower.cfg b/scripts/offline-evolve2/rlpower.cfg new file mode 100644 index 0000000..6b9f00b --- /dev/null +++ b/scripts/offline-evolve2/rlpower.cfg @@ -0,0 +1,12 @@ +{ + 'algorithm': 'rlpower', + 'type': 'A', # original rlpower + 'evaluation_rate': '30.0', + 'max_evaluations': '1000', + 'max_ranked_policies': '10', + 'init_spline_size': '3', + 'interpolation_spline_size': '100', + 'init_sigma': '0.8', +# 'policy_load_path': 'spider.policy', # Used to load policy + 'sigma_tau_correction': '0.2' +} \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/babyA.yaml b/scripts/offline-evolve2/robots/babyA.yaml new file mode 100644 index 0000000..c0e0b45 --- /dev/null +++ b/scripts/offline-evolve2/robots/babyA.yaml @@ -0,0 +1,89 @@ +--- +body: + id : Core + type : Core + children : + 2: + slot : 0 + id : Leg00Joint + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Leg00 + type : FixedBrick + orientation : 0 + 3: + slot : 0 + id : Leg01Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg011Joint + type : ActiveHinge + orientation : 90 + children : + 1: + slot : 0 + id : Leg01 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg021Joint + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Leg02 + type : FixedBrick + orientation : 0 + 1: + slot : 0 + id : BodyJoint0 + type : ActiveHinge + orientation : 90 + children : + 1: + slot : 0 + id : Body0 + type : FixedBrick + orientation : -90 + children : + 1: + slot : 0 + id : BodyJoint1 + type : ActiveHinge + orientation : 90 + children : + 1: + slot : 0 + id : Body1 + type : FixedBrick + orientation : -90 + children: + 2: + slot : 0 + id : Leg10Joint + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Leg10 + type : FixedBrick + orientation : 0 + 3: + slot : 0 + id : Leg11Joint + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Leg11 + type : FixedBrick + orientation : 0 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/babyB.yaml b/scripts/offline-evolve2/robots/babyB.yaml new file mode 100644 index 0000000..4508b99 --- /dev/null +++ b/scripts/offline-evolve2/robots/babyB.yaml @@ -0,0 +1,101 @@ +--- +body: + id : Core + type : Core + children : + 0: + id : Leg00Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg00 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg01Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg01 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg02Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg02 + type : FixedBrick + orientation : -90 + 1: + id : Leg10Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg10 + type : FixedBrick + orientation : -90 + 2: + id : Leg20Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg20 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg21Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg21 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg22Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg22 + type : FixedBrick + orientation : -90 + 3: + id : Leg30Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg30 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg31Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg31 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg32Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg32 + type : FixedBrick + orientation : -90 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/babyC.yaml b/scripts/offline-evolve2/robots/babyC.yaml new file mode 100644 index 0000000..4667693 --- /dev/null +++ b/scripts/offline-evolve2/robots/babyC.yaml @@ -0,0 +1,171 @@ +--- +body: + id : Core + type : Core + children : + 2: + slot : 0 + id : Leg00Joint + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Leg00 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg001Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg001 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg002Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg002 + type : FixedBrick + orientation : 0 + 3: + slot : 0 + id : Leg01Joint + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Leg01 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg011Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg011 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg012Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg012 + type : FixedBrick + orientation : 0 + 1: + slot : 0 + id : BodyJoint0 + type : ActiveHinge + orientation : 90 + children : + 1: + slot : 0 + id : Body0 + type : FixedBrick + orientation : -90 + children : + 1: + slot : 0 + id : BodyJoint1 + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Body1 + type : FixedBrick + orientation : 0 + children : + 1: + slot : 0 + id : BodyJoint2 + type : ActiveHinge + orientation : 90 + children : + 1: + slot : 0 + id : Body2 + type : FixedBrick + orientation : -90 + children : + 1: + id : BodyJoint3 + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Body3 + type : FixedBrick + orientation : 0 + children: + 2: + slot : 0 + id : Leg10Joint + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Leg10 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg101Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg101 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg102Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg102 + type : FixedBrick + orientation : 0 + 3: + slot : 0 + id : Leg11Joint + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Leg11 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg111Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg112Joint + type : ActiveHinge + orientation : -90 + children : + 1: + id : Leg112 + type : FixedBrick + orientation : 0 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/gecko12.yaml b/scripts/offline-evolve2/robots/gecko12.yaml new file mode 100644 index 0000000..9c138ad --- /dev/null +++ b/scripts/offline-evolve2/robots/gecko12.yaml @@ -0,0 +1,124 @@ +--- +body: + id : Core + type : Core + children : + 2: + slot : 0 + id : Leg00Joint + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Leg00 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg001Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg001 + type : FixedBrick + orientation : -90 + 3: + slot : 0 + id : Leg01Joint + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Leg01 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg011Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg011 + type : FixedBrick + orientation : -90 + 1: + slot : 0 + id : BodyJoint0 + type : ActiveHinge + orientation : 90 + children : + 1: + slot : 0 + id : Body0 + type : FixedBrick + orientation : -90 + children : + 1: + slot : 0 + id : BodyJoint1 + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Body1 + type : FixedBrick + orientation : 0 + children : + 1: + id : BodyJoint2 + type : ActiveHinge + orientation : 90 + children : + 1: + slot : 0 + id : Body2 + type : FixedBrick + orientation : -90 + children: + 2: + slot : 0 + id : Leg10Joint + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Leg10 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg101Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg101 + type : FixedBrick + orientation : -90 + 3: + slot : 0 + id : Leg11Joint + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Leg11 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg111Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg111 + type : FixedBrick + orientation : -90 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/gecko17.yaml b/scripts/offline-evolve2/robots/gecko17.yaml new file mode 100644 index 0000000..5e11c4f --- /dev/null +++ b/scripts/offline-evolve2/robots/gecko17.yaml @@ -0,0 +1,176 @@ +--- +body: + id : Core + type : Core + children : + 2: + slot : 0 + id : Leg00Joint + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Leg00 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg001Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg001 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg002Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg002 + type : FixedBrick + orientation : 0 + 3: + slot : 0 + id : Leg01Joint + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Leg01 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg011Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg011 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg012Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg012 + type : FixedBrick + orientation : 0 + 1: + slot : 0 + id : BodyJoint0 + type : ActiveHinge + orientation : 90 + children : + 1: + slot : 0 + id : Body0 + type : FixedBrick + orientation : -90 + children : + 1: + slot : 0 + id : BodyJoint1 + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Body1 + type : FixedBrick + orientation : 0 + children : + 1: + slot : 0 + id : BodyJoint2 + type : ActiveHinge + orientation : 90 + children : + 1: + slot : 0 + id : Body2 + type : FixedBrick + orientation : -90 + children : + 1: + id : BodyJoint3 + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Body3 + type : FixedBrick + orientation : 0 + children: + 2: + slot : 0 + id : Leg10Joint + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Leg10 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg101Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg101 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg102Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg102 + type : FixedBrick + orientation : 0 + 3: + slot : 0 + id : Leg11Joint + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Leg11 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg111Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg111 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg112Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg112 + type : FixedBrick + orientation : 0 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/gecko7.yaml b/scripts/offline-evolve2/robots/gecko7.yaml new file mode 100644 index 0000000..806b736 --- /dev/null +++ b/scripts/offline-evolve2/robots/gecko7.yaml @@ -0,0 +1,73 @@ +--- +body: + id : Core + type : Core + children : + 2: + slot : 0 + id : Leg00Joint + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Leg00 + type : FixedBrick + orientation : 0 + 3: + slot : 0 + id : Leg01Joint + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Leg01 + type : FixedBrick + orientation : 0 + 1: + slot : 0 + id : BodyJoint0 + type : ActiveHinge + orientation : 90 + children : + 1: + slot : 0 + id : Body0 + type : FixedBrick + orientation : -90 + children : + 1: + slot : 0 + id : BodyJoint1 + type : ActiveHinge + orientation : 90 + children : + 1: + slot : 0 + id : Body1 + type : FixedBrick + orientation : -90 + children: + 2: + slot : 0 + id : Leg10Joint + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Leg10 + type : FixedBrick + orientation : 0 + 3: + slot : 0 + id : Leg11Joint + type : ActiveHinge + orientation : 0 + children : + 1: + slot : 0 + id : Leg11 + type : FixedBrick + orientation : 0 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/snake5.yaml b/scripts/offline-evolve2/robots/snake5.yaml new file mode 100644 index 0000000..d09976a --- /dev/null +++ b/scripts/offline-evolve2/robots/snake5.yaml @@ -0,0 +1,41 @@ +--- +body: + id : Core + type : Core + children : + 0: + id : Leg00Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg00 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg01Joint + type : ActiveHinge + children : + 1: + id : Leg01 + type : FixedBrick + orientation : 0 + 1: + id : Leg10Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg10 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg11Joint + type : ActiveHinge + children : + 1: + id : Leg11 + type : FixedBrick + orientation : 0 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/snake7.yaml b/scripts/offline-evolve2/robots/snake7.yaml new file mode 100644 index 0000000..123bbed --- /dev/null +++ b/scripts/offline-evolve2/robots/snake7.yaml @@ -0,0 +1,63 @@ +--- +body: + id : Core + type : Core + children : + 0: + id : Leg00Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg00 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg01Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg01 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg02Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg02 + type : FixedBrick + orientation : -90 + 1: + id : Leg10Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg10 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg11Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg11 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg12Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg12 + type : FixedBrick + orientation : -90 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/snake9.yaml b/scripts/offline-evolve2/robots/snake9.yaml new file mode 100644 index 0000000..6ecf5a0 --- /dev/null +++ b/scripts/offline-evolve2/robots/snake9.yaml @@ -0,0 +1,83 @@ +--- +body: + id : Core + type : Core + children : + 0: + id : Leg00Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg00 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg01Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg01 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg02Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg02 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg03Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg03 + type : FixedBrick + orientation : 0 + 1: + id : Leg10Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg10 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg11Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg11 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg12Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg12 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg13Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg13 + type : FixedBrick + orientation : 0 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/spider13.yaml b/scripts/offline-evolve2/robots/spider13.yaml new file mode 100644 index 0000000..bce3693 --- /dev/null +++ b/scripts/offline-evolve2/robots/spider13.yaml @@ -0,0 +1,121 @@ +--- +body: + id : Core + type : Core + children : + 0: + id : Leg00Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg00 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg01Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg01 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg02Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg02 + type : FixedBrick + orientation : -90 + 1: + id : Leg10Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg10 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg11Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg11 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg12Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg12 + type : FixedBrick + orientation : -90 + 2: + id : Leg20Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg20 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg21Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg21 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg22Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg22 + type : FixedBrick + orientation : -90 + 3: + id : Leg30Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg30 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg31Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg31 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg32Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg32 + type : FixedBrick + orientation : -90 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/spider17.yaml b/scripts/offline-evolve2/robots/spider17.yaml new file mode 100644 index 0000000..8def37b --- /dev/null +++ b/scripts/offline-evolve2/robots/spider17.yaml @@ -0,0 +1,161 @@ +--- +body: + id : Core + type : Core + children : + 0: + id : Leg00Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg00 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg01Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg01 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg02Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg02 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg03Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg03 + type : FixedBrick + orientation : 0 + 1: + id : Leg10Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg10 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg11Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg11 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg12Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg12 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg13Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg13 + type : FixedBrick + orientation : 0 + 2: + id : Leg20Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg20 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg21Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg21 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg22Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg22 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg23Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg23 + type : FixedBrick + orientation : 0 + 3: + id : Leg30Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg30 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg31Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg31 + type : FixedBrick + orientation : 0 + children : + 1: + id : Leg32Joint + type : ActiveHinge + orientation : 90 + children : + 1: + id : Leg32 + type : FixedBrick + orientation : -90 + children : + 1: + id : Leg33Joint + type : ActiveHinge + orientation : 0 + children : + 1: + id : Leg33 + type : FixedBrick + orientation : 0 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/spider9.yaml b/scripts/offline-evolve2/robots/spider9.yaml new file mode 100644 index 0000000..53bab38 --- /dev/null +++ b/scripts/offline-evolve2/robots/spider9.yaml @@ -0,0 +1,659 @@ +body: + children: + 0: + children: + 1: + children: + 1: + children: + 1: + id: Leg01 + label: '' + orientation: 0 + params: + blue: 0.5 + green: 0.5 + red: 0.5 + slot: 0 + type: FixedBrick + id: Leg01Joint + label: '' + orientation: 0 + params: + blue: 0.5 + green: 0.5 + red: 0.5 + slot: 0 + type: ActiveHinge + id: Leg00 + label: '' + orientation: -90 + params: + blue: 0.5 + green: 0.5 + red: 0.5 + slot: 0 + type: FixedBrick + id: Leg00Joint + label: '' + orientation: 90 + params: + blue: 0.5 + green: 0.5 + red: 0.5 + slot: 0 + type: ActiveHinge + 1: + children: + 1: + children: + 1: + children: + 1: + id: Leg11 + label: '' + orientation: 0 + params: + blue: 0.5 + green: 0.5 + red: 0.5 + slot: 0 + type: FixedBrick + id: Leg11Joint + label: '' + orientation: 0 + params: + blue: 0.5 + green: 0.5 + red: 0.5 + slot: 0 + type: ActiveHinge + id: Leg10 + label: '' + orientation: -90 + params: + blue: 0.5 + green: 0.5 + red: 0.5 + slot: 0 + type: FixedBrick + id: Leg10Joint + label: '' + orientation: 90 + params: + blue: 0.5 + green: 0.5 + red: 0.5 + slot: 0 + type: ActiveHinge + 2: + children: + 1: + children: + 1: + children: + 1: + id: Leg21 + label: '' + orientation: 0 + params: + blue: 0.5 + green: 0.5 + red: 0.5 + slot: 0 + type: FixedBrick + id: Leg21Joint + label: '' + orientation: 0 + params: + blue: 0.5 + green: 0.5 + red: 0.5 + slot: 0 + type: ActiveHinge + id: Leg20 + label: '' + orientation: -90 + params: + blue: 0.5 + green: 0.5 + red: 0.5 + slot: 0 + type: FixedBrick + id: Leg20Joint + label: '' + orientation: 90 + params: + blue: 0.5 + green: 0.5 + red: 0.5 + slot: 0 + type: ActiveHinge + 3: + children: + 1: + children: + 1: + children: + 1: + id: Leg31 + label: '' + orientation: 0 + params: + blue: 0.5 + green: 0.5 + red: 0.5 + slot: 0 + type: FixedBrick + id: Leg31Joint + label: '' + orientation: 0 + params: + blue: 0.5 + green: 0.5 + red: 0.5 + slot: 0 + type: ActiveHinge + id: Leg30 + label: '' + orientation: -90 + params: + blue: 0.5 + green: 0.5 + red: 0.5 + slot: 0 + type: FixedBrick + id: Leg30Joint + label: '' + orientation: 90 + params: + blue: 0.5 + green: 0.5 + red: 0.5 + slot: 0 + type: ActiveHinge + id: Core + label: '' + orientation: 0 + params: + blue: 0.5 + green: 0.5 + red: 0.5 + type: Core +brain: + connections: + - dst: Leg00Joint-cpg-0 + socket: from_x + src: Leg00Joint-cpg-1 + weight: 1.0 + - dst: Leg00Joint-cpg-1 + socket: from_v + src: Leg00Joint-cpg-0 + weight: 1.0 + - dst: Leg00Joint-out-0 + src: Leg00Joint-cpg-0 + weight: 1.0 + - dst: Leg01Joint-cpg-2 + socket: from_x + src: Leg01Joint-cpg-3 + weight: 1.0 + - dst: Leg01Joint-cpg-3 + socket: from_v + src: Leg01Joint-cpg-2 + weight: 1.0 + - dst: Leg01Joint-out-0 + src: Leg01Joint-cpg-2 + weight: 1.0 + - dst: Leg00Joint-cpg-0 + socket: from_x_ext + src: Leg01Joint-cpg-3 + weight: 1.0 + - dst: Leg01Joint-cpg-2 + socket: from_x_ext + src: Leg00Joint-cpg-1 + weight: 1.0 + - dst: Leg00Joint-cpg-0 + socket: from_v_ext + src: Leg01Joint-cpg-2 + weight: 1.0 + - dst: Leg01Joint-cpg-2 + socket: from_v_ext + src: Leg00Joint-cpg-0 + weight: 1.0 + - dst: Leg10Joint-cpg-4 + socket: from_x + src: Leg10Joint-cpg-5 + weight: 1.0 + - dst: Leg10Joint-cpg-5 + socket: from_v + src: Leg10Joint-cpg-4 + weight: 1.0 + - dst: Leg10Joint-out-0 + src: Leg10Joint-cpg-4 + weight: 1.0 + - dst: Leg11Joint-cpg-6 + socket: from_x + src: Leg11Joint-cpg-7 + weight: 1.0 + - dst: Leg11Joint-cpg-7 + socket: from_v + src: Leg11Joint-cpg-6 + weight: 1.0 + - dst: Leg11Joint-out-0 + src: Leg11Joint-cpg-6 + weight: 1.0 + - dst: Leg10Joint-cpg-4 + socket: from_x_ext + src: Leg11Joint-cpg-7 + weight: 1.0 + - dst: Leg11Joint-cpg-6 + socket: from_x_ext + src: Leg10Joint-cpg-5 + weight: 1.0 + - dst: Leg10Joint-cpg-4 + socket: from_v_ext + src: Leg11Joint-cpg-6 + weight: 1.0 + - dst: Leg11Joint-cpg-6 + socket: from_v_ext + src: Leg10Joint-cpg-4 + weight: 1.0 + - dst: Leg20Joint-cpg-8 + socket: from_x + src: Leg20Joint-cpg-9 + weight: 1.0 + - dst: Leg20Joint-cpg-9 + socket: from_v + src: Leg20Joint-cpg-8 + weight: 1.0 + - dst: Leg20Joint-out-0 + src: Leg20Joint-cpg-8 + weight: 1.0 + - dst: Leg21Joint-cpg-10 + socket: from_x + src: Leg21Joint-cpg-11 + weight: 1.0 + - dst: Leg21Joint-cpg-11 + socket: from_v + src: Leg21Joint-cpg-10 + weight: 1.0 + - dst: Leg21Joint-out-0 + src: Leg21Joint-cpg-10 + weight: 1.0 + - dst: Leg20Joint-cpg-8 + socket: from_x_ext + src: Leg21Joint-cpg-11 + weight: 1.0 + - dst: Leg21Joint-cpg-10 + socket: from_x_ext + src: Leg20Joint-cpg-9 + weight: 1.0 + - dst: Leg20Joint-cpg-8 + socket: from_v_ext + src: Leg21Joint-cpg-10 + weight: 1.0 + - dst: Leg21Joint-cpg-10 + socket: from_v_ext + src: Leg20Joint-cpg-8 + weight: 1.0 + - dst: Leg30Joint-cpg-12 + socket: from_x + src: Leg30Joint-cpg-13 + weight: 1.0 + - dst: Leg30Joint-cpg-13 + socket: from_v + src: Leg30Joint-cpg-12 + weight: 1.0 + - dst: Leg30Joint-out-0 + src: Leg30Joint-cpg-12 + weight: 1.0 + - dst: Leg31Joint-cpg-14 + socket: from_x + src: Leg31Joint-cpg-15 + weight: 1.0 + - dst: Leg31Joint-cpg-15 + socket: from_v + src: Leg31Joint-cpg-14 + weight: 1.0 + - dst: Leg31Joint-out-0 + src: Leg31Joint-cpg-14 + weight: 1.0 + - dst: Leg30Joint-cpg-12 + socket: from_x_ext + src: Leg31Joint-cpg-15 + weight: 1.0 + - dst: Leg31Joint-cpg-14 + socket: from_x_ext + src: Leg30Joint-cpg-13 + weight: 1.0 + - dst: Leg30Joint-cpg-12 + socket: from_v_ext + src: Leg31Joint-cpg-14 + weight: 1.0 + - dst: Leg31Joint-cpg-14 + socket: from_v_ext + src: Leg30Joint-cpg-12 + weight: 1.0 + - dst: Leg00Joint-cpg-0 + src: Core-in-5 + weight: 1.0 + - dst: Leg00Joint-cpg-0 + src: Core-in-4 + weight: 1.0 + - dst: Leg00Joint-cpg-0 + src: Core-in-0 + weight: 1.0 + - dst: Leg00Joint-cpg-0 + src: Core-in-3 + weight: 1.0 + - dst: Leg00Joint-cpg-0 + src: Core-in-2 + weight: 1.0 + - dst: Leg00Joint-cpg-0 + src: Core-in-1 + weight: 1.0 + - dst: Leg10Joint-cpg-4 + src: Core-in-5 + weight: 1.0 + - dst: Leg10Joint-cpg-4 + src: Core-in-4 + weight: 1.0 + - dst: Leg10Joint-cpg-4 + src: Core-in-0 + weight: 1.0 + - dst: Leg10Joint-cpg-4 + src: Core-in-3 + weight: 1.0 + - dst: Leg10Joint-cpg-4 + src: Core-in-2 + weight: 1.0 + - dst: Leg10Joint-cpg-4 + src: Core-in-1 + weight: 1.0 + - dst: Leg20Joint-cpg-8 + src: Core-in-5 + weight: 1.0 + - dst: Leg20Joint-cpg-8 + src: Core-in-4 + weight: 1.0 + - dst: Leg20Joint-cpg-8 + src: Core-in-0 + weight: 1.0 + - dst: Leg20Joint-cpg-8 + src: Core-in-3 + weight: 1.0 + - dst: Leg20Joint-cpg-8 + src: Core-in-2 + weight: 1.0 + - dst: Leg20Joint-cpg-8 + src: Core-in-1 + weight: 1.0 + - dst: Leg30Joint-cpg-12 + src: Core-in-5 + weight: 1.0 + - dst: Leg30Joint-cpg-12 + src: Core-in-4 + weight: 1.0 + - dst: Leg30Joint-cpg-12 + src: Core-in-0 + weight: 1.0 + - dst: Leg30Joint-cpg-12 + src: Core-in-3 + weight: 1.0 + - dst: Leg30Joint-cpg-12 + src: Core-in-2 + weight: 1.0 + - dst: Leg30Joint-cpg-12 + src: Core-in-1 + weight: 1.0 + - dst: Leg10Joint-cpg-4 + socket: from_x_ext + src: Leg00Joint-cpg-1 + weight: 1.0 + - dst: Leg00Joint-cpg-0 + socket: from_x_ext + src: Leg10Joint-cpg-5 + weight: 1.0 + - dst: Leg10Joint-cpg-4 + socket: from_v_ext + src: Leg00Joint-cpg-0 + weight: 1.0 + - dst: Leg00Joint-cpg-0 + socket: from_v_ext + src: Leg10Joint-cpg-4 + weight: 1.0 + - dst: Leg20Joint-cpg-8 + socket: from_x_ext + src: Leg00Joint-cpg-1 + weight: 1.0 + - dst: Leg00Joint-cpg-0 + socket: from_x_ext + src: Leg20Joint-cpg-9 + weight: 1.0 + - dst: Leg20Joint-cpg-8 + socket: from_v_ext + src: Leg00Joint-cpg-0 + weight: 1.0 + - dst: Leg00Joint-cpg-0 + socket: from_v_ext + src: Leg20Joint-cpg-8 + weight: 1.0 + - dst: Leg30Joint-cpg-12 + socket: from_x_ext + src: Leg00Joint-cpg-1 + weight: 1.0 + - dst: Leg00Joint-cpg-0 + socket: from_x_ext + src: Leg30Joint-cpg-13 + weight: 1.0 + - dst: Leg30Joint-cpg-12 + socket: from_v_ext + src: Leg00Joint-cpg-0 + weight: 1.0 + - dst: Leg00Joint-cpg-0 + socket: from_v_ext + src: Leg30Joint-cpg-12 + weight: 1.0 + - dst: Leg20Joint-cpg-8 + socket: from_x_ext + src: Leg10Joint-cpg-5 + weight: 1.0 + - dst: Leg10Joint-cpg-4 + socket: from_x_ext + src: Leg20Joint-cpg-9 + weight: 1.0 + - dst: Leg20Joint-cpg-8 + socket: from_v_ext + src: Leg10Joint-cpg-4 + weight: 1.0 + - dst: Leg10Joint-cpg-4 + socket: from_v_ext + src: Leg20Joint-cpg-8 + weight: 1.0 + - dst: Leg30Joint-cpg-12 + socket: from_x_ext + src: Leg10Joint-cpg-5 + weight: 1.0 + - dst: Leg10Joint-cpg-4 + socket: from_x_ext + src: Leg30Joint-cpg-13 + weight: 1.0 + - dst: Leg30Joint-cpg-12 + socket: from_v_ext + src: Leg10Joint-cpg-4 + weight: 1.0 + - dst: Leg10Joint-cpg-4 + socket: from_v_ext + src: Leg30Joint-cpg-12 + weight: 1.0 + - dst: Leg30Joint-cpg-12 + socket: from_x_ext + src: Leg20Joint-cpg-9 + weight: 1.0 + - dst: Leg20Joint-cpg-8 + socket: from_x_ext + src: Leg30Joint-cpg-13 + weight: 1.0 + - dst: Leg30Joint-cpg-12 + socket: from_v_ext + src: Leg20Joint-cpg-8 + weight: 1.0 + - dst: Leg20Joint-cpg-8 + socket: from_v_ext + src: Leg30Joint-cpg-12 + weight: 1.0 + neurons: + Leg00Joint-cpg-0: + id: Leg00Joint-cpg-0 + layer: hidden + part_id: Leg00Joint + type: V-Neuron + Leg00Joint-cpg-1: + id: Leg00Joint-cpg-1 + layer: hidden + part_id: Leg00Joint + type: X-Neuron + Leg01Joint-cpg-2: + id: Leg01Joint-cpg-2 + layer: hidden + part_id: Leg01Joint + type: V-Neuron + Leg01Joint-cpg-3: + id: Leg01Joint-cpg-3 + layer: hidden + part_id: Leg01Joint + type: X-Neuron + Leg10Joint-cpg-4: + id: Leg10Joint-cpg-4 + layer: hidden + part_id: Leg10Joint + type: V-Neuron + Leg10Joint-cpg-5: + id: Leg10Joint-cpg-5 + layer: hidden + part_id: Leg10Joint + type: X-Neuron + Leg11Joint-cpg-6: + id: Leg11Joint-cpg-6 + layer: hidden + part_id: Leg11Joint + type: V-Neuron + Leg11Joint-cpg-7: + id: Leg11Joint-cpg-7 + layer: hidden + part_id: Leg11Joint + type: X-Neuron + Leg20Joint-cpg-8: + id: Leg20Joint-cpg-8 + layer: hidden + part_id: Leg20Joint + type: V-Neuron + Leg20Joint-cpg-9: + id: Leg20Joint-cpg-9 + layer: hidden + part_id: Leg20Joint + type: X-Neuron + Leg21Joint-cpg-10: + id: Leg21Joint-cpg-10 + layer: hidden + part_id: Leg21Joint + type: V-Neuron + Leg21Joint-cpg-11: + id: Leg21Joint-cpg-11 + layer: hidden + part_id: Leg21Joint + type: X-Neuron + Leg30Joint-cpg-12: + id: Leg30Joint-cpg-12 + layer: hidden + part_id: Leg30Joint + type: V-Neuron + Leg30Joint-cpg-13: + id: Leg30Joint-cpg-13 + layer: hidden + part_id: Leg30Joint + type: X-Neuron + Leg31Joint-cpg-14: + id: Leg31Joint-cpg-14 + layer: hidden + part_id: Leg31Joint + type: V-Neuron + Leg31Joint-cpg-15: + id: Leg31Joint-cpg-15 + layer: hidden + part_id: Leg31Joint + type: X-Neuron + params: + Leg00Joint-cpg-0: + alpha: 1.0 + energy: 1.0 + tau: 1.0 + Leg00Joint-cpg-1: + tau: 1.0 + Leg00Joint-out-0: + bias: 0.0 + gain: 0.5 + Leg01Joint-cpg-2: + alpha: 1.0 + energy: 1.0 + tau: 1.0 + Leg01Joint-cpg-3: + tau: 1.0 + Leg01Joint-out-0: + bias: 0.0 + gain: 0.5 + Leg10Joint-cpg-4: + alpha: 1.0 + energy: 1.0 + tau: 1.0 + Leg10Joint-cpg-5: + tau: 1.0 + Leg10Joint-out-0: + bias: 0.0 + gain: 0.5 + Leg11Joint-cpg-6: + alpha: 1.0 + energy: 1.0 + tau: 1.0 + Leg11Joint-cpg-7: + tau: 1.0 + Leg11Joint-out-0: + bias: 0.0 + gain: 0.5 + Leg20Joint-cpg-8: + alpha: 1.0 + energy: 1.0 + tau: 1.0 + Leg20Joint-cpg-9: + tau: 1.0 + Leg20Joint-out-0: + bias: 0.0 + gain: 0.5 + Leg21Joint-cpg-10: + alpha: 1.0 + energy: 1.0 + tau: 1.0 + Leg21Joint-cpg-11: + tau: 1.0 + Leg21Joint-out-0: + bias: 0.0 + gain: 0.5 + Leg30Joint-cpg-12: + alpha: 1.0 + energy: 1.0 + tau: 1.0 + Leg30Joint-cpg-13: + tau: 1.0 + Leg30Joint-out-0: + bias: 0.0 + gain: 0.5 + Leg31Joint-cpg-14: + alpha: 1.0 + energy: 1.0 + tau: 1.0 + Leg31Joint-cpg-15: + tau: 1.0 + Leg31Joint-out-0: + bias: 0.0 + gain: 0.5 +id: 0 diff --git a/scripts/offline-evolve2/run-experiments.sh b/scripts/offline-evolve2/run-experiments.sh new file mode 100755 index 0000000..ddf01fd --- /dev/null +++ b/scripts/offline-evolve2/run-experiments.sh @@ -0,0 +1,83 @@ +#!/usr/bin/env bash + +# Handle keyboard interrupt +trap " exit " INT + +PROGNAME=$(basename $0) + +# Default argument list +robot_list=( spider9 spider13 spider17 gecko7 gecko12 gecko17 snake5 snake7 snake9 babyA babyB babyC ) + +config=rlpower.cfg +manager=single_robot_manager.py +world=gait-learning.world +output=output +restore=restore +gz_command=gzserver +no_experiments=10 + +function error_exit() { + echo "${PROGNAME}: ${1:-"Unknown Error"}" 1 >&2 + exit 1 +} + +function help() { + echo "Usage: ${PROGNAME} [args...]" + echo "Arguments:" + echo " -c | --config Path to robot brain config file" + echo " -g | --gzcommand Gazebo command [gzserver|gazebo] Default: gzserver" + echo " -h | --help Help page" + echo " -m | --manager Name of script that controls robots and the environment" + echo " -n | --no-experiments Number of experiment repetitions" + echo " -o | --output Name of the output directory" + echo " -r | --restore Name of the restore directory" + echo " -w | --world Name of world file" + + exit 0 +} + +function main() { + + # Read out the argument list + if [ $# -gt 0 ]; then + while [ "$1" != "" ] + do + local argument="$1"; + shift + local parameter="$1"; + shift + case ${argument} in + -c | --config) local config=${parameter} ;; + -g | --gzcommand) local gz_command=${parameter} ;; + -h | --help) help ;; + -m | --manager) local manager=${parameter} ;; + -n | --no-experiments) local no_experiments=${parameter} ;; + -o | --output) local output=${parameter} ;; + -r | --restore) local restore=${parameter} ;; + -w | --world) local world=${parameter} ;; + *) error_exit "${LINENO}: In ${FUNCNAME}() unknown argument ${argument}." ;; + esac + done + fi + + # For each name in 'robot_list' run 'no_experiments' experiments + for index in ${!robot_list[*]} + do + for (( i = 1; i <= ${no_experiments}; ++ i )) + do + python start.py \ + --manager ${manager} \ + --world ${world} \ + --output ${output} \ + --restore ${restore} \ + --robot-name robots/${robot_list[$index]} \ + --experiment-round ${i} \ + --brain-conf-path ${config} \ + --gazebo-cmd ${gz_command} + done + done + + exit 0 +} + +main $@ diff --git a/scripts/offline-evolve2/single_robot_manager.py b/scripts/offline-evolve2/single_robot_manager.py new file mode 100644 index 0000000..633c4f7 --- /dev/null +++ b/scripts/offline-evolve2/single_robot_manager.py @@ -0,0 +1,101 @@ +import ast +import os +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..')) + +from pygazebo.pygazebo import DisconnectError +from trollius.py33_exceptions import ConnectionResetError + +import trollius +from trollius import From + +from tol.config import parser +from tol.manage import World + +from sdfbuilder import Pose +from sdfbuilder.math import Vector3 + +from revolve.convert.yaml import yaml_to_robot +from revolve.angle import Tree +from revolve.util import wait_for + +from tol.spec import get_extended_brain_spec + + +@trollius.coroutine +def run(): + """ + The main coroutine, which is started below. + """ + # Parse command line / file input arguments + conf = parser.parse_args() + + # Adding brain configuration + with open(conf.brain_conf_path, 'r') as f: + s = f.read() + brain_conf = ast.literal_eval(s) + brain_conf["policy_load_path"] = conf.load_controller + conf.brain_conf = brain_conf + + # This disables the analyzer; enable it if you want to generate valid robots + # Can also do this using arguments of course, just pass an empty string + # conf.analyzer_address = None + + with open("{}.yaml".format(conf.robot_name), 'r') as yamlfile: + bot_yaml = yamlfile.read() + + # Create the world, this connects to the Gazebo world + world = yield From(World.create(conf)) + + # These are useful when working with YAML + body_spec = world.builder.body_builder.spec + brain_spec = get_extended_brain_spec(conf) + + # Create a robot from YAML + robot = yaml_to_robot(body_spec, brain_spec, bot_yaml) + + # Create a revolve.angle `Tree` representation from the robot, which + # is what is used in the world manager. + robot_tree = Tree.from_body_brain(robot.body, robot.brain, body_spec) + + # Insert the robot into the world. `insert_robot` resolves when the insert + # request is sent, the future it returns resolves when the robot insert + # is actually confirmed and a robot manager object has been created + pose = Pose(position=Vector3(0, 0, 0.05)) + future = yield From(world.insert_robot(robot_tree, pose, "{}-{}".format(conf.robot_name, conf.experiment_round))) + robot_manager = yield From(future) + + # I usually start the world paused, un-pause it here. Note that + # pause again returns a future for when the request is sent, + # that future in turn resolves when a response has been received. + # This is the general convention for all message actions in the + # world manager. `wait_for` saves the hassle of grabbing the + # intermediary future in this case. + yield From(wait_for(world.pause(False))) + + # Start a run loop to do some stuff + while True: + # Print robot fitness every second + print("Robot fitness: %f" % robot_manager.fitness()) + yield From(trollius.sleep(1.0)) + + +def main(): + def handler(loop, context): + exc = context['exception'] + if isinstance(exc, DisconnectError) or isinstance(exc, ConnectionResetError): + print("Got disconnect / connection reset - shutting down.") + sys.exit(0) + raise context['exception'] + + try: + loop = trollius.get_event_loop() + loop.set_exception_handler(handler) + loop.run_until_complete(run()) + except KeyboardInterrupt: + print("Got CtrlC, shutting down.") + + +if __name__ == '__main__': + main() diff --git a/scripts/offline-evolve2/start.py b/scripts/offline-evolve2/start.py new file mode 100644 index 0000000..285a737 --- /dev/null +++ b/scripts/offline-evolve2/start.py @@ -0,0 +1,57 @@ +import os +import sys + +here = os.path.dirname(os.path.abspath(__file__)) +tol_path = os.path.abspath(os.path.join(here, '..', '..')) +rv_path = os.path.abspath(os.path.join(tol_path, '..', 'revolve')) +sys.path.append(os.path.dirname(os.path.abspath(__file__))) + +from revolve.util import Supervisor +from offline_evolve import parser + + +class OfflineEvolutionSupervisor(Supervisor): + """ + Supervisor class that adds some output filtering for ODE errors + """ + + def __init__(self, *args, **kwargs): + super(OfflineEvolutionSupervisor, self).__init__(*args, **kwargs) + self.ode_errors = 0 + + def write_stderr(self, data): + """ + :param data: + :return: + """ + if 'ODE Message 3' in data: + self.ode_errors += 1 + elif data.strip(): + sys.stderr.write(data) + + if self.ode_errors >= 100: + self.ode_errors = 0 + sys.stderr.write('ODE Message 3 (100)\n') + + +args = parser.parse_args() + +os.environ['GAZEBO_PLUGIN_PATH'] = os.path.join(tol_path, 'build') +os.environ['GAZEBO_MODEL_PATH'] = os.path.join(tol_path, 'tools', 'models') + \ + ':' + os.path.join(rv_path, 'tools', 'models') + +supervisor = OfflineEvolutionSupervisor( + manager_cmd=[sys.executable, args.manager, + "--load-controller", args.load_controller, + "--robot-name", args.robot_name, + "--experiment-round", args.experiment_round, + "--brain-conf-path", args.brain_conf_path], + analyzer_cmd=os.path.join(rv_path, 'tools', 'analyzer', 'run-analyzer'), + world_file=os.path.join(here, args.world), + output_directory=args.output_directory, + restore_directory=args.restore_directory, + gazebo_cmd=args.gazebo_cmd, + manager_args=sys.argv[1:] +) + +supervisor.launch() diff --git a/scripts/offline-evolve2/summarize.R b/scripts/offline-evolve2/summarize.R new file mode 100644 index 0000000..a83d9a0 --- /dev/null +++ b/scripts/offline-evolve2/summarize.R @@ -0,0 +1,103 @@ +# Use this script to summarize one or multiple concatenated +# runs of evolution data. +# This post helps here: +# http://stackoverflow.com/a/10349375/358873 + +library(ggplot2) +library(plyr) +library(reshape) + +read_dir_data <- function(odir) { + tdata = read.csv(paste(odir, "/generations.csv", sep=""), head=TRUE); + tdata$exp = as.factor(odir); + if (tdata[1,]$exp == "plus-gradual") { + tdata$births = tdata$gen + 15; + } else { + tdata$births = tdata$gen * 15 + 15; + } + + rdata = read.csv(paste(odir, "/robots.csv", sep=""), head=TRUE); + + return(merge(tdata[tdata$births<=3000,], rdata, by.x=c("robot_id", "run"), by.y=c("id", "run"))); +} + +dirs = list.files("."); +data = do.call(rbind, lapply(dirs, read_dir_data)); + +# Unify fitness calculation +data$fitness = 5*data$dvel + data$vel; + +# Remove outliers +data = data[data$fitness<1,]; + +cdata = ddply(data, c("births", "exp"), summarise, + fit=mean(fitness), fsd=sd(fitness), + ext=mean(extremity_count), esd=sd(extremity_count), + joints=mean(joint_count), jsd=sd(joint_count), + motors=mean(motor_count), msd=sd(motor_count), + sz=mean(nparts), ssd=sd(nparts), + inp=mean(inputs), isd=sd(inputs), + hid=mean(hidden), hsd=sd(hidden), + con=mean(conn), csd=sd(conn) + ); + +cdata$plot = as.factor("Fitness"); +cdata1 = cdata; +cdata2 = cdata; +cdata3 = cdata; +cdata4 = cdata; +cdata5 = cdata; +cdata6 = cdata; +cdata7 = cdata; + +cdata1$plot = as.factor("# of joints"); +cdata2$plot = as.factor("# of active joints"); +cdata3$plot = as.factor("Total size"); +cdata4$plot = as.factor("# of extremities"); +cdata5$plot = as.factor("# of inputs"); +cdata6$plot = as.factor("# of hidden neurons"); +cdata7$plot = as.factor("# of connections"); + +# Fitness over generations +ggplot(cdata, aes(births)) + + facet_grid(plot~., scale="free") + + geom_line(aes(y=fit, colour=exp)) + + geom_ribbon(aes(ymin=fit-fsd, ymax=fit+fsd, fill=exp), alpha=0.1, linetype=0) + + + geom_line(data=cdata1, aes(y=joints, colour=exp)) + + geom_ribbon(data=cdata1, aes(ymin=joints-jsd, ymax=joints+jsd, fill=exp), alpha=0.1, linetype=0) + + + geom_line(data=cdata2, aes(y=motors, colour=exp)) + + geom_ribbon(data=cdata2, aes(ymin=motors-jsd, ymax=motors+jsd, fill=exp), alpha=0.1, linetype=0) + + + geom_line(data=cdata3, aes(y=sz, colour=exp)) + + geom_ribbon(data=cdata3, aes(ymin=sz-ssd, ymax=sz+ssd, fill=exp), alpha=0.1, linetype=0) + + + geom_line(data=cdata4, aes(y=ext, colour=exp)) + + geom_ribbon(data=cdata4, aes(ymin=ext-esd, ymax=ext+esd, fill=exp), alpha=0.1, linetype=0) + + + geom_line(data=cdata5, aes(y=inp, colour=exp)) + + geom_ribbon(data=cdata5, aes(ymin=inp-isd, ymax=inp+isd, fill=exp), alpha=0.1, linetype=0) + + + geom_line(data=cdata6, aes(y=hid, colour=exp)) + + geom_ribbon(data=cdata6, aes(ymin=hid-hsd, ymax=hid+hsd, fill=exp), alpha=0.1, linetype=0) + + + geom_line(data=cdata7, aes(y=con, colour=exp)) + + geom_ribbon(data=cdata7, aes(ymin=con-csd, ymax=con+csd, fill=exp), alpha=0.1, linetype=0) + + + scale_fill_discrete(name="Experiment") + + scale_colour_discrete(name="Experiment") + + xlab("# of births") + + ylab(""); + +#last_gens = cdata[cdata$gen==max(cdata$gen),]; + +# Retrieve all the best robots per experiment +# See http://stackoverflow.com/questions/6289538/aggregate-a-dataframe-on-a-given-column-and-display-another-column +exp_maxes = do.call(rbind,lapply(split(data, list(data$exp, data$run)),function(chunk) chunk[which.max(chunk$fitness),])) +exp_maxes = exp_maxes[order(-exp_maxes$fitness),] + +exp_states = ddply(data, ~exp+run, summarise, cur_gen=max(gen)); +exp_states = exp_states[order(exp_states$exp, -exp_states$run),]; + +exp_states From 4d2e9f9db5911e218d10195d7c66a45a520bc609 Mon Sep 17 00:00:00 2001 From: raki123 Date: Sun, 20 Nov 2016 13:28:44 +0100 Subject: [PATCH 05/10] save --- cpp/CMakeLists.txt | 1 + cpp/tol/plugin/RobotController.cpp | 13 +++++++------ cpp/tol/plugin/extended_neural_network.cpp | 5 ++--- cpp/tol/plugin/simple_split_brain.cpp | 16 ++++++++-------- cpp/tol/plugin/simple_split_brain.h | 14 ++++++-------- 5 files changed, 24 insertions(+), 25 deletions(-) diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 533623a..c94326a 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -66,6 +66,7 @@ file(GLOB_RECURSE tol/plugin/helper.cpp tol/plugin/rlpower.cpp tol/plugin/simple_split_brain.cpp + tol/plugin/extended_neural_network.cpp ) add_library(tolworldcontrol SHARED ${TOL_WORLD_SRC}) diff --git a/cpp/tol/plugin/RobotController.cpp b/cpp/tol/plugin/RobotController.cpp index 1bb255c..343ecbb 100644 --- a/cpp/tol/plugin/RobotController.cpp +++ b/cpp/tol/plugin/RobotController.cpp @@ -7,7 +7,8 @@ #include "RobotController.h" #include "rlpower.h" -#include "simple_split_brain.h" +//#include "simple_split_brain.h" +#include "extended_neural_network.h" #include @@ -18,15 +19,15 @@ RobotController::RobotController() {} RobotController::~RobotController() {} void RobotController::Load(::gazebo::physics::ModelPtr _parent, sdf::ElementPtr _sdf) { + throw "hello"; + ::revolve::gazebo::RobotController::Load(_parent, _sdf); std::cout << "ToL Robot loaded." << std::endl; } void RobotController::LoadBrain(sdf::ElementPtr sdf) { - std::cout << "i get here 0\n"; - double asd = 3/0; - evaluator_ = boost::make_shared(); + //evaluator_ = boost::make_shared(); if (!sdf->HasElement("rv:brain")) { std::cerr << "No robot brain detected, this is probably an error." << std::endl; @@ -40,8 +41,8 @@ void RobotController::LoadBrain(sdf::ElementPtr sdf) } std::cout << "i get here 0\n"; if (brain->GetAttribute("algorithm")->GetAsString() == "rlpower") { - // brain_.reset(new tol::ExtendedNeuralNetwork(this->model->GetName(), evaluator_, brain, motors_, sensors_)); - brain_.reset(new tol::RLPower(this->model->GetName(), brain,evaluator_, motors_, sensors_)); + brain_.reset(new tol::ExtendedNeuralNetwork(this->model->GetName(), evaluator_, brain, motors_, sensors_)); + //brain_.reset(new tol::RLPower(this->model->GetName(), brain,evaluator_, motors_, sensors_)); } else { std::cout << "Calling default ANN brain." << std::endl; revolve::gazebo::RobotController::LoadBrain(sdf); diff --git a/cpp/tol/plugin/extended_neural_network.cpp b/cpp/tol/plugin/extended_neural_network.cpp index 8cd13cd..9e1edfd 100644 --- a/cpp/tol/plugin/extended_neural_network.cpp +++ b/cpp/tol/plugin/extended_neural_network.cpp @@ -30,12 +30,11 @@ namespace tol { const std::vector &sensors, double t, double step) { - //std::cout << "yay" << std::endl; + std::cout << "yay" << std::endl; revolve::brain::ExtendedNeuralNetwork::update( Helper::createWrapper(actuators), Helper::createWrapper(sensors), - t, step - ); + t, step); } diff --git a/cpp/tol/plugin/simple_split_brain.cpp b/cpp/tol/plugin/simple_split_brain.cpp index ee3087e..19bbd13 100644 --- a/cpp/tol/plugin/simple_split_brain.cpp +++ b/cpp/tol/plugin/simple_split_brain.cpp @@ -10,7 +10,7 @@ namespace tol { - ExtendedNeuralNetwork::ExtendedNeuralNetwork(std::string modelName, + ExtNN::ExtNN(std::string modelName, tol::EvaluatorPtr evaluator, sdf::ElementPtr node, const std::vector &actuators, @@ -27,13 +27,13 @@ namespace tol { std::cout << "done" << std::endl; } - ExtendedNeuralNetwork::~ExtendedNeuralNetwork() + ExtNN::~ExtNN() { } - void ExtendedNeuralNetwork::update(const std::vector &actuators, + void ExtNN::update(const std::vector &actuators, const std::vector &sensors, double t, double step) { @@ -46,7 +46,7 @@ namespace tol { } -revolve::brain::ExtNNController::ExtNNConfig ExtendedNeuralNetwork::parseSDF(sdf::ElementPtr node, +revolve::brain::ExtNNController::ExtNNConfig ExtNN::parseSDF(sdf::ElementPtr node, const std::vector< revolve::gazebo::MotorPtr > & motors, const std::vector< revolve::gazebo::SensorPtr > & sensors) { @@ -220,7 +220,7 @@ revolve::brain::ExtNNController::ExtNNConfig ExtendedNeuralNetwork::parseSDF(sdf return ret; } -std::map ExtendedNeuralNetwork::parseSDFElement(sdf::ElementPtr elem) +std::map ExtNN::parseSDFElement(sdf::ElementPtr elem) { std::map params; @@ -235,7 +235,7 @@ std::map ExtendedNeuralNetwork::parseSDFElement(sdf::Elemen return params; } -void ExtendedNeuralNetwork::connectionHelper(const std::string &src, +void ExtNN::connectionHelper(const std::string &src, const std::string &dst, const std::string &socket, double weight, @@ -266,7 +266,7 @@ void ExtendedNeuralNetwork::connectionHelper(const std::string &src, } -revolve::brain::NeuronPtr ExtendedNeuralNetwork::neuronHelper(sdf::ElementPtr neuron, +revolve::brain::NeuronPtr ExtNN::neuronHelper(sdf::ElementPtr neuron, revolve::brain::ExtNNController::ExtNNConfig &ret) { if (!neuron->HasAttribute("type")) { @@ -291,7 +291,7 @@ revolve::brain::NeuronPtr ExtendedNeuralNetwork::neuronHelper(sdf::ElementPtr ne -revolve::brain::NeuronPtr ExtendedNeuralNetwork::addNeuron(const std::string &neuronId, +revolve::brain::NeuronPtr ExtNN::addNeuron(const std::string &neuronId, const std::string &neuronType, const std::string &neuronLayer, // can be 'hidden', 'input' or 'output' const std::map ¶ms, diff --git a/cpp/tol/plugin/simple_split_brain.h b/cpp/tol/plugin/simple_split_brain.h index 13426ff..7450157 100644 --- a/cpp/tol/plugin/simple_split_brain.h +++ b/cpp/tol/plugin/simple_split_brain.h @@ -1,5 +1,5 @@ -#ifndef REVOLVE_GAZEBO_BRAIN_DIFFERENTIAL_NEAT_H -#define REVOLVE_GAZEBO_BRAIN_DIFFERENTIAL_NEAT_H +#ifndef REVOLVE_GAZEBO_BRAIN_DIFFERENTIAL_SPLIT_BRAIN_H_ +#define REVOLVE_GAZEBO_BRAIN_DIFFERENTIAL_SPLIT_BRAIN_H_ #include "brain/split_cpg/simple_split_brain.h" #include "brain/split_cpg/extended_neural_network_controller.h" @@ -16,7 +16,7 @@ namespace tol { - class ExtendedNeuralNetwork : public revolve::gazebo::Brain, private revolve::brain::SimpleSplitBrain> { + class ExtNN : public revolve::gazebo::Brain, private revolve::brain::SimpleSplitBrain> { public: /** @@ -28,13 +28,13 @@ namespace tol { * @param sensors: vector list of robot's sensors * @return pointer to the neural network */ - ExtendedNeuralNetwork(std::string modelName, + ExtNN(std::string modelName, tol::EvaluatorPtr evaluator, sdf::ElementPtr node, const std::vector &actuators, const std::vector &sensors); - virtual ~ExtendedNeuralNetwork(); + virtual ~ExtNN(); /** * Method for updating sensors readings, actuators positions, ranked list of policies and generating new policy @@ -103,13 +103,11 @@ namespace tol { const std::map ¶ms, revolve::brain::ExtNNController::ExtNNConfig &ret); -protected: -// boost::shared_ptr learner; }; } /* namespace tol */ -#endif //REVOLVE_GAZEBO_BRAIN_REINFORCEDLEARNING_H +#endif //REVOLVE_GAZEBO_BRARN_DIFFERENTIAL_SPLIT_BRAIN_H_ From 37cebf0c1073fb432e85d6b82c1499413bdc061d Mon Sep 17 00:00:00 2001 From: raki123 Date: Sun, 20 Nov 2016 13:34:22 +0100 Subject: [PATCH 06/10] revert --- cpp/tol/plugin/RobotController.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/tol/plugin/RobotController.cpp b/cpp/tol/plugin/RobotController.cpp index 1389dd8..aceb706 100644 --- a/cpp/tol/plugin/RobotController.cpp +++ b/cpp/tol/plugin/RobotController.cpp @@ -38,7 +38,7 @@ void RobotController::LoadBrain(sdf::ElementPtr sdf) } if (brain->GetAttribute("algorithm")->GetAsString() == "rlpower") { - brain_.reset(new tol::ExtendedNeuralNetwork(this->model->GetName(), evaluator_, brain, motors_, sensors_)); + brain_.reset(new tol::RLPower(this->model->GetName(), brain,evaluator_, motors_, sensors_)); } else { std::cout << "Calling default ANN brain." << std::endl; revolve::gazebo::RobotController::LoadBrain(sdf); From f9d6ee70adf2ac39d09a30127aa588a237a399a3 Mon Sep 17 00:00:00 2001 From: raki123 Date: Mon, 21 Nov 2016 12:41:43 +0100 Subject: [PATCH 07/10] save --- cpp/CMakeLists.txt | 2 +- cpp/tol/plugin/RobotController.cpp | 13 +++++-------- cpp/tol/plugin/simple_split_brain.cpp | 16 ++++++++-------- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index c94326a..5b31a6e 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -65,7 +65,7 @@ file(GLOB_RECURSE tol/plugin/fakebrain.cpp tol/plugin/helper.cpp tol/plugin/rlpower.cpp - tol/plugin/simple_split_brain.cpp + #tol/plugin/simple_split_brain.cpp tol/plugin/extended_neural_network.cpp ) diff --git a/cpp/tol/plugin/RobotController.cpp b/cpp/tol/plugin/RobotController.cpp index 343ecbb..8bb009f 100644 --- a/cpp/tol/plugin/RobotController.cpp +++ b/cpp/tol/plugin/RobotController.cpp @@ -8,7 +8,7 @@ #include "RobotController.h" #include "rlpower.h" //#include "simple_split_brain.h" -#include "extended_neural_network.h" +//#include "extended_neural_network.h" #include @@ -19,15 +19,13 @@ RobotController::RobotController() {} RobotController::~RobotController() {} void RobotController::Load(::gazebo::physics::ModelPtr _parent, sdf::ElementPtr _sdf) { - throw "hello"; - - ::revolve::gazebo::RobotController::Load(_parent, _sdf); + ::revolve::gazebo::RobotController::Load(_parent, _sdf); std::cout << "ToL Robot loaded." << std::endl; } void RobotController::LoadBrain(sdf::ElementPtr sdf) { - //evaluator_ = boost::make_shared(); + evaluator_ = boost::make_shared(); if (!sdf->HasElement("rv:brain")) { std::cerr << "No robot brain detected, this is probably an error." << std::endl; @@ -39,10 +37,9 @@ void RobotController::LoadBrain(sdf::ElementPtr sdf) std::cerr << "Brain does not define type, this is probably an error." << std::endl; return; } - std::cout << "i get here 0\n"; + if (brain->GetAttribute("algorithm")->GetAsString() == "rlpower") { - brain_.reset(new tol::ExtendedNeuralNetwork(this->model->GetName(), evaluator_, brain, motors_, sensors_)); - //brain_.reset(new tol::RLPower(this->model->GetName(), brain,evaluator_, motors_, sensors_)); + brain_.reset(new tol::RLPower(this->model->GetName(), brain,evaluator_, motors_, sensors_)); } else { std::cout << "Calling default ANN brain." << std::endl; revolve::gazebo::RobotController::LoadBrain(sdf); diff --git a/cpp/tol/plugin/simple_split_brain.cpp b/cpp/tol/plugin/simple_split_brain.cpp index 19bbd13..ce71c93 100644 --- a/cpp/tol/plugin/simple_split_brain.cpp +++ b/cpp/tol/plugin/simple_split_brain.cpp @@ -16,14 +16,14 @@ namespace tol { const std::vector &actuators, const std::vector &sensors) : revolve::brain::SimpleSplitBrain>() { std::cout << "i get here \n"; - boost::shared_ptr swap1(new revolve::brain::ExtNNController(modelName, - parseSDF(node, actuators, sensors), - evaluator, - Helper::createWrapper(actuators), - Helper::createWrapper(sensors))); - controller = boost::static_pointer_cast>>(swap1); - boost::shared_ptr swap2(new revolve::brain::WeightVectorLearner()); - learner = boost::dynamic_pointer_cast>>(swap2); +// boost::shared_ptr swap1(new revolve::brain::ExtNNController(modelName, +// parseSDF(node, actuators, sensors), +// evaluator, +// Helper::createWrapper(actuators), +// Helper::createWrapper(sensors))); +// controller = boost::static_pointer_cast>>(swap1); +// boost::shared_ptr swap2(new revolve::brain::WeightVectorLearner()); +// learner = boost::dynamic_pointer_cast>>(swap2); std::cout << "done" << std::endl; } From 4ca670248a4eab259fb5f9b3e6ec935990bdeb24 Mon Sep 17 00:00:00 2001 From: raki123 Date: Mon, 21 Nov 2016 17:06:19 +0100 Subject: [PATCH 08/10] first fix --- cpp/CMakeLists.txt | 5 +++-- cpp/tol/plugin/RobotController.cpp | 5 +++-- cpp/tol/plugin/simple_split_brain.cpp | 10 +++++----- cpp/tol/plugin/simple_split_brain.h | 2 +- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 5b31a6e..d415e4e 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -66,9 +66,10 @@ file(GLOB_RECURSE tol/plugin/helper.cpp tol/plugin/rlpower.cpp #tol/plugin/simple_split_brain.cpp - tol/plugin/extended_neural_network.cpp + #tol/plugin/extended_neural_network.cpp ) +add_library(split_gaz SHARED tol/plugin/simple_split_brain.cpp) add_library(tolworldcontrol SHARED ${TOL_WORLD_SRC}) add_library(tolrobotcontrol SHARED ${TOL_ROBOT_SRC}) @@ -137,7 +138,7 @@ include_directories(../../revolve-brain/cpp) include_directories(${Boost_INCLUDE_DIRS} ${REVOLVE_INCLUDE_PATH} ${GAZEBO_INCLUDE_DIRS} ${GSL_INCLUDE_DIRS}) set(TOL_DEPS ${GAZEBO_LIBRARIES} ${Boost_LIBRARIES} ${REVOLVE_LIBRARIES} ${GAZEBO_LIBRARIES} ${GSL_LIBRARIES}) -target_link_libraries(tolrobotcontrol ${TOL_DEPS} revolve-brain-static) +target_link_libraries(tolrobotcontrol ${TOL_DEPS} revolve-brain-static split_gaz) target_link_libraries(tolworldcontrol ${TOL_DEPS} tolrobotcontrol) # Evolution keys library diff --git a/cpp/tol/plugin/RobotController.cpp b/cpp/tol/plugin/RobotController.cpp index 8bb009f..4cdf03f 100644 --- a/cpp/tol/plugin/RobotController.cpp +++ b/cpp/tol/plugin/RobotController.cpp @@ -7,7 +7,7 @@ #include "RobotController.h" #include "rlpower.h" -//#include "simple_split_brain.h" +#include "simple_split_brain.h" //#include "extended_neural_network.h" #include @@ -39,7 +39,8 @@ void RobotController::LoadBrain(sdf::ElementPtr sdf) } if (brain->GetAttribute("algorithm")->GetAsString() == "rlpower") { - brain_.reset(new tol::RLPower(this->model->GetName(), brain,evaluator_, motors_, sensors_)); +// brain_.reset(new tol::RLPower(this->model->GetName(), brain,evaluator_, motors_, sensors_)); + brain_.reset(new tol::ExtNN(this->model->GetName(), evaluator_, brain, motors_, sensors_)); } else { std::cout << "Calling default ANN brain." << std::endl; revolve::gazebo::RobotController::LoadBrain(sdf); diff --git a/cpp/tol/plugin/simple_split_brain.cpp b/cpp/tol/plugin/simple_split_brain.cpp index ce71c93..72297e9 100644 --- a/cpp/tol/plugin/simple_split_brain.cpp +++ b/cpp/tol/plugin/simple_split_brain.cpp @@ -38,11 +38,11 @@ namespace tol { double t, double step) { std::cout << "yay" << std::endl; - revolve::brain::SimpleSplitBrain>::update( - Helper::createWrapper(actuators), - Helper::createWrapper(sensors), - t, step - ); +// revolve::brain::SimpleSplitBrain>::update( +// Helper::createWrapper(actuators), +// Helper::createWrapper(sensors), +// t, step +// ); } diff --git a/cpp/tol/plugin/simple_split_brain.h b/cpp/tol/plugin/simple_split_brain.h index 7450157..4fc942e 100644 --- a/cpp/tol/plugin/simple_split_brain.h +++ b/cpp/tol/plugin/simple_split_brain.h @@ -16,7 +16,7 @@ namespace tol { - class ExtNN : public revolve::gazebo::Brain, private revolve::brain::SimpleSplitBrain> { + class ExtNN : public revolve::gazebo::Brain, public revolve::brain::SimpleSplitBrain> { public: /** From 4d21c622623517012c26d69baec246e411ec807a Mon Sep 17 00:00:00 2001 From: raki123 Date: Tue, 22 Nov 2016 12:49:36 +0100 Subject: [PATCH 09/10] finished, cleaned up version of brain split in controller and learner --- cpp/CMakeLists.txt | 7 +- cpp/tol/plugin/RobotController.cpp | 7 +- cpp/tol/plugin/extended_neural_network.cpp | 6 +- cpp/tol/plugin/extended_neural_network.h | 2 +- cpp/tol/plugin/simple_split_brain.cpp | 39 +- cpp/tol/plugin/simple_split_brain.h | 2 +- scripts/offline-evolve2/gait-learning.world | 43 -- .../offline-evolve2/input-15/baseline.conf | 6 - .../input-15/baseline_no_fitness.conf | 7 - scripts/offline-evolve2/input-15/comma.conf | 7 - .../input-15/comma_aggressive.conf | 12 - scripts/offline-evolve2/input-15/plus.conf | 5 - .../input-15/plus_aggressive.conf | 11 - .../input-15/plus_gradual.conf | 6 - .../input-15/plus_less_aggressive.conf | 4 - .../input-15/plus_more_aggressive.conf | 11 - .../offline-evolve2/input-20/baseline.conf | 7 - scripts/offline-evolve2/input-20/plus.conf | 5 - .../input-20/plus_aggressive.conf | 10 - .../input-20/plus_more_aggressive.conf | 10 - scripts/offline-evolve2/input/baseline.conf | 5 - scripts/offline-evolve2/input/comma.conf | 4 - .../input/comma_aggressive.conf | 9 - scripts/offline-evolve2/input/plus.conf | 3 - .../input/plus_aggressive.conf | 8 - .../input/plus_more_aggressive.conf | 8 - scripts/offline-evolve2/make.sh | 3 - scripts/offline-evolve2/offline-evolve.world | 39 -- scripts/offline-evolve2/offline_evolve.py | 437 ------------ scripts/offline-evolve2/rlpower.cfg | 12 - scripts/offline-evolve2/robots/babyA.yaml | 89 --- scripts/offline-evolve2/robots/babyB.yaml | 101 --- scripts/offline-evolve2/robots/babyC.yaml | 171 ----- scripts/offline-evolve2/robots/gecko12.yaml | 124 ---- scripts/offline-evolve2/robots/gecko17.yaml | 176 ----- scripts/offline-evolve2/robots/gecko7.yaml | 73 -- scripts/offline-evolve2/robots/snake5.yaml | 41 -- scripts/offline-evolve2/robots/snake7.yaml | 63 -- scripts/offline-evolve2/robots/snake9.yaml | 83 --- scripts/offline-evolve2/robots/spider13.yaml | 121 ---- scripts/offline-evolve2/robots/spider17.yaml | 161 ----- scripts/offline-evolve2/robots/spider9.yaml | 659 ------------------ scripts/offline-evolve2/run-experiments.sh | 83 --- .../offline-evolve2/single_robot_manager.py | 101 --- scripts/offline-evolve2/start.py | 57 -- scripts/offline-evolve2/summarize.R | 103 --- 46 files changed, 31 insertions(+), 2910 deletions(-) delete mode 100644 scripts/offline-evolve2/gait-learning.world delete mode 100644 scripts/offline-evolve2/input-15/baseline.conf delete mode 100644 scripts/offline-evolve2/input-15/baseline_no_fitness.conf delete mode 100644 scripts/offline-evolve2/input-15/comma.conf delete mode 100644 scripts/offline-evolve2/input-15/comma_aggressive.conf delete mode 100644 scripts/offline-evolve2/input-15/plus.conf delete mode 100644 scripts/offline-evolve2/input-15/plus_aggressive.conf delete mode 100644 scripts/offline-evolve2/input-15/plus_gradual.conf delete mode 100644 scripts/offline-evolve2/input-15/plus_less_aggressive.conf delete mode 100644 scripts/offline-evolve2/input-15/plus_more_aggressive.conf delete mode 100644 scripts/offline-evolve2/input-20/baseline.conf delete mode 100644 scripts/offline-evolve2/input-20/plus.conf delete mode 100644 scripts/offline-evolve2/input-20/plus_aggressive.conf delete mode 100644 scripts/offline-evolve2/input-20/plus_more_aggressive.conf delete mode 100644 scripts/offline-evolve2/input/baseline.conf delete mode 100644 scripts/offline-evolve2/input/comma.conf delete mode 100644 scripts/offline-evolve2/input/comma_aggressive.conf delete mode 100644 scripts/offline-evolve2/input/plus.conf delete mode 100644 scripts/offline-evolve2/input/plus_aggressive.conf delete mode 100644 scripts/offline-evolve2/input/plus_more_aggressive.conf delete mode 100755 scripts/offline-evolve2/make.sh delete mode 100644 scripts/offline-evolve2/offline-evolve.world delete mode 100644 scripts/offline-evolve2/offline_evolve.py delete mode 100644 scripts/offline-evolve2/rlpower.cfg delete mode 100644 scripts/offline-evolve2/robots/babyA.yaml delete mode 100644 scripts/offline-evolve2/robots/babyB.yaml delete mode 100644 scripts/offline-evolve2/robots/babyC.yaml delete mode 100644 scripts/offline-evolve2/robots/gecko12.yaml delete mode 100644 scripts/offline-evolve2/robots/gecko17.yaml delete mode 100644 scripts/offline-evolve2/robots/gecko7.yaml delete mode 100644 scripts/offline-evolve2/robots/snake5.yaml delete mode 100644 scripts/offline-evolve2/robots/snake7.yaml delete mode 100644 scripts/offline-evolve2/robots/snake9.yaml delete mode 100644 scripts/offline-evolve2/robots/spider13.yaml delete mode 100644 scripts/offline-evolve2/robots/spider17.yaml delete mode 100644 scripts/offline-evolve2/robots/spider9.yaml delete mode 100755 scripts/offline-evolve2/run-experiments.sh delete mode 100644 scripts/offline-evolve2/single_robot_manager.py delete mode 100644 scripts/offline-evolve2/start.py delete mode 100644 scripts/offline-evolve2/summarize.R diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index d415e4e..d45392a 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -65,11 +65,10 @@ file(GLOB_RECURSE tol/plugin/fakebrain.cpp tol/plugin/helper.cpp tol/plugin/rlpower.cpp - #tol/plugin/simple_split_brain.cpp - #tol/plugin/extended_neural_network.cpp + tol/plugin/simple_split_brain.cpp + tol/plugin/extended_neural_network.cpp ) -add_library(split_gaz SHARED tol/plugin/simple_split_brain.cpp) add_library(tolworldcontrol SHARED ${TOL_WORLD_SRC}) add_library(tolrobotcontrol SHARED ${TOL_ROBOT_SRC}) @@ -138,7 +137,7 @@ include_directories(../../revolve-brain/cpp) include_directories(${Boost_INCLUDE_DIRS} ${REVOLVE_INCLUDE_PATH} ${GAZEBO_INCLUDE_DIRS} ${GSL_INCLUDE_DIRS}) set(TOL_DEPS ${GAZEBO_LIBRARIES} ${Boost_LIBRARIES} ${REVOLVE_LIBRARIES} ${GAZEBO_LIBRARIES} ${GSL_LIBRARIES}) -target_link_libraries(tolrobotcontrol ${TOL_DEPS} revolve-brain-static split_gaz) +target_link_libraries(tolrobotcontrol ${TOL_DEPS} revolve-brain-static) target_link_libraries(tolworldcontrol ${TOL_DEPS} tolrobotcontrol) # Evolution keys library diff --git a/cpp/tol/plugin/RobotController.cpp b/cpp/tol/plugin/RobotController.cpp index 4cdf03f..361afcf 100644 --- a/cpp/tol/plugin/RobotController.cpp +++ b/cpp/tol/plugin/RobotController.cpp @@ -8,7 +8,7 @@ #include "RobotController.h" #include "rlpower.h" #include "simple_split_brain.h" -//#include "extended_neural_network.h" +#include "extended_neural_network.h" #include @@ -39,8 +39,9 @@ void RobotController::LoadBrain(sdf::ElementPtr sdf) } if (brain->GetAttribute("algorithm")->GetAsString() == "rlpower") { -// brain_.reset(new tol::RLPower(this->model->GetName(), brain,evaluator_, motors_, sensors_)); - brain_.reset(new tol::ExtNN(this->model->GetName(), evaluator_, brain, motors_, sensors_)); + brain_.reset(new tol::RLPower(this->model->GetName(), brain,evaluator_, motors_, sensors_)); +// brain_. reset(new tol::ExtNN(this->model->GetName(), evaluator_, brain, motors_, sensors_)); +// brain_.reset(new tol::ExtendedNeuralNetwork(this->model->GetName(), evaluator_, brain, motors_, sensors_)); } else { std::cout << "Calling default ANN brain." << std::endl; revolve::gazebo::RobotController::LoadBrain(sdf); diff --git a/cpp/tol/plugin/extended_neural_network.cpp b/cpp/tol/plugin/extended_neural_network.cpp index 9e1edfd..1733d06 100644 --- a/cpp/tol/plugin/extended_neural_network.cpp +++ b/cpp/tol/plugin/extended_neural_network.cpp @@ -30,7 +30,7 @@ namespace tol { const std::vector &sensors, double t, double step) { - std::cout << "yay" << std::endl; +// std::cout << "yay" << std::endl; revolve::brain::ExtendedNeuralNetwork::update( Helper::createWrapper(actuators), Helper::createWrapper(sensors), @@ -233,7 +233,7 @@ void ExtendedNeuralNetwork::connectionHelper(const std::string &src, const std::map &idToNeuron, ExtNNConfig &ret) { - std::cout << "connection from " + src + " to " + dst + " was added with weight: " << weight << std::endl; +// std::cout << "connection from " + src + " to " + dst + " was added with weight: " << weight << std::endl; auto srcNeuron = idToNeuron.find(src); if (srcNeuron == idToNeuron.end()) { std::cerr << "Could not find source neuron '" << src << "'" << std::endl; @@ -289,7 +289,7 @@ revolve::brain::NeuronPtr ExtendedNeuralNetwork::addNeuron(const std::string &ne ExtNNConfig &ret) { revolve::brain::NeuronPtr newNeuron; - std::cout << neuronType + " " + neuronId + " was added in"+ " "+ neuronLayer << std::endl; +// std::cout << neuronType + " " + neuronId + " was added in"+ " "+ neuronLayer << std::endl; if ("input" == neuronLayer) { newNeuron.reset(new revolve::brain::InputNeuron(neuronId, params)); diff --git a/cpp/tol/plugin/extended_neural_network.h b/cpp/tol/plugin/extended_neural_network.h index 740daf6..2256ec3 100644 --- a/cpp/tol/plugin/extended_neural_network.h +++ b/cpp/tol/plugin/extended_neural_network.h @@ -1,7 +1,7 @@ #ifndef REVOLVE_GAZEBO_BRAIN_DIFFERENTIAL_NEAT_H #define REVOLVE_GAZEBO_BRAIN_DIFFERENTIAL_NEAT_H -#include "brain/ccpg/extended_neural_network.h" +#include "brain/extnn/extended_neural_network.h" #include "evaluator.h" #include "revolve/gazebo/brain/Brain.h" diff --git a/cpp/tol/plugin/simple_split_brain.cpp b/cpp/tol/plugin/simple_split_brain.cpp index 72297e9..30e17a2 100644 --- a/cpp/tol/plugin/simple_split_brain.cpp +++ b/cpp/tol/plugin/simple_split_brain.cpp @@ -1,6 +1,4 @@ #include "simple_split_brain.h" -#include "brain/split_cpg/extended_neural_network_controller.h" -#include "brain/split_cpg/weight_vector_learner.h" #include "helper.h" #include "sensor.h" #include "actuator.h" @@ -15,16 +13,17 @@ namespace tol { sdf::ElementPtr node, const std::vector &actuators, const std::vector &sensors) : revolve::brain::SimpleSplitBrain>() { - std::cout << "i get here \n"; -// boost::shared_ptr swap1(new revolve::brain::ExtNNController(modelName, -// parseSDF(node, actuators, sensors), -// evaluator, -// Helper::createWrapper(actuators), -// Helper::createWrapper(sensors))); -// controller = boost::static_pointer_cast>>(swap1); -// boost::shared_ptr swap2(new revolve::brain::WeightVectorLearner()); -// learner = boost::dynamic_pointer_cast>>(swap2); - std::cout << "done" << std::endl; +// std::cout << "i get here \n"; + boost::shared_ptr swap1(new revolve::brain::ExtNNController(modelName, + parseSDF(node, actuators, sensors), + evaluator, + Helper::createWrapper(actuators), + Helper::createWrapper(sensors))); + controller = boost::static_pointer_cast>>(swap1); + boost::shared_ptr swap2(new revolve::brain::WeightVectorLearner()); + learner = boost::static_pointer_cast>>(swap2); + evaluator_ = evaluator; +// std::cout << "done" << std::endl; } ExtNN::~ExtNN() @@ -37,12 +36,12 @@ namespace tol { const std::vector &sensors, double t, double step) { - std::cout << "yay" << std::endl; -// revolve::brain::SimpleSplitBrain>::update( -// Helper::createWrapper(actuators), -// Helper::createWrapper(sensors), -// t, step -// ); +// std::cout << "yay" << std::endl; + revolve::brain::SimpleSplitBrain>::update( + Helper::createWrapper(actuators), + Helper::createWrapper(sensors), + t, step + ); } @@ -242,7 +241,7 @@ void ExtNN::connectionHelper(const std::string &src, const std::map &idToNeuron, revolve::brain::ExtNNController::ExtNNConfig &ret) { - std::cout << "connection from " + src + " to " + dst + " was added with weight: " << weight << std::endl; +// std::cout << "connection from " + src + " to " + dst + " was added with weight: " << weight << std::endl; auto srcNeuron = idToNeuron.find(src); if (srcNeuron == idToNeuron.end()) { std::cerr << "Could not find source neuron '" << src << "'" << std::endl; @@ -298,7 +297,7 @@ revolve::brain::NeuronPtr ExtNN::addNeuron(const std::string &neuronId, revolve::brain::ExtNNController::ExtNNConfig &ret) { revolve::brain::NeuronPtr newNeuron; - std::cout << neuronType + " " + neuronId + " was added in"+ " "+ neuronLayer << std::endl; +// std::cout << neuronType + " " + neuronId + " was added in"+ " "+ neuronLayer << std::endl; if ("input" == neuronLayer) { newNeuron.reset(new revolve::brain::InputNeuron(neuronId, params)); diff --git a/cpp/tol/plugin/simple_split_brain.h b/cpp/tol/plugin/simple_split_brain.h index 4fc942e..7450157 100644 --- a/cpp/tol/plugin/simple_split_brain.h +++ b/cpp/tol/plugin/simple_split_brain.h @@ -16,7 +16,7 @@ namespace tol { - class ExtNN : public revolve::gazebo::Brain, public revolve::brain::SimpleSplitBrain> { + class ExtNN : public revolve::gazebo::Brain, private revolve::brain::SimpleSplitBrain> { public: /** diff --git a/scripts/offline-evolve2/gait-learning.world b/scripts/offline-evolve2/gait-learning.world deleted file mode 100644 index fa159af..0000000 --- a/scripts/offline-evolve2/gait-learning.world +++ /dev/null @@ -1,43 +0,0 @@ - - - - - 0 - 0 - - - - 0.005 - - - 0.0 - - - - - 0.1 - 10e-6 - - - 100 - 1e-8 - - - world - - - - - - - - - model://sun - - - model://tol_ground - - - - - \ No newline at end of file diff --git a/scripts/offline-evolve2/input-15/baseline.conf b/scripts/offline-evolve2/input-15/baseline.conf deleted file mode 100644 index 6483a30..0000000 --- a/scripts/offline-evolve2/input-15/baseline.conf +++ /dev/null @@ -1,6 +0,0 @@ -output_directory=/media/expdata/output -restore_directory=baseline-selection -disable_selection=1 -disable_fitness=1 -population_size=15 -num_children=15 diff --git a/scripts/offline-evolve2/input-15/baseline_no_fitness.conf b/scripts/offline-evolve2/input-15/baseline_no_fitness.conf deleted file mode 100644 index 95b27ec..0000000 --- a/scripts/offline-evolve2/input-15/baseline_no_fitness.conf +++ /dev/null @@ -1,7 +0,0 @@ -output_directory=output -restore_directory=baseline-no-fitness-15 -disable_fitness=1 -disable_selection=1 -keep_parents=0 -population_size=15 -num_children=15 \ No newline at end of file diff --git a/scripts/offline-evolve2/input-15/comma.conf b/scripts/offline-evolve2/input-15/comma.conf deleted file mode 100644 index 251b434..0000000 --- a/scripts/offline-evolve2/input-15/comma.conf +++ /dev/null @@ -1,7 +0,0 @@ -output_directory=comma-output -restore_directory=comma-1000 -population_size=15 -num_children=15 -keep_parents=False -num_generations=1000 -num_evolutions=32 diff --git a/scripts/offline-evolve2/input-15/comma_aggressive.conf b/scripts/offline-evolve2/input-15/comma_aggressive.conf deleted file mode 100644 index 70818c4..0000000 --- a/scripts/offline-evolve2/input-15/comma_aggressive.conf +++ /dev/null @@ -1,12 +0,0 @@ -output_directory=comma-output -restore_directory=comma-aggressive-15-2000 -keep_parents=0 -enable_light_sensor=0 -body_mutation_epsilon=0.3 -brain_mutation_epsilon=0.3 -p_delete_subtree=0.25 -p_duplicate_subtree=0.25 -p_swap_subtree=0.25 -population_size=15 -num_children=15 -num_generations=2000 diff --git a/scripts/offline-evolve2/input-15/plus.conf b/scripts/offline-evolve2/input-15/plus.conf deleted file mode 100644 index 48d810c..0000000 --- a/scripts/offline-evolve2/input-15/plus.conf +++ /dev/null @@ -1,5 +0,0 @@ -output_directory=/media/expdata/output -restore_directory=plus -population_size=15 -num_children=15 -world_step_size=0.003 \ No newline at end of file diff --git a/scripts/offline-evolve2/input-15/plus_aggressive.conf b/scripts/offline-evolve2/input-15/plus_aggressive.conf deleted file mode 100644 index c8fedad..0000000 --- a/scripts/offline-evolve2/input-15/plus_aggressive.conf +++ /dev/null @@ -1,11 +0,0 @@ -output_directory=population-output -restore_directory=plus-aggressive-15 -enable_light_sensor=0 -body_mutation_epsilon=0.3 -brain_mutation_epsilon=0.3 -p_delete_subtree=0.25 -p_duplicate_subtree=0.25 -p_swap_subtree=0.25 -population_size=15 -num_children=15 -num_evolutions=32 diff --git a/scripts/offline-evolve2/input-15/plus_gradual.conf b/scripts/offline-evolve2/input-15/plus_gradual.conf deleted file mode 100644 index 8339971..0000000 --- a/scripts/offline-evolve2/input-15/plus_gradual.conf +++ /dev/null @@ -1,6 +0,0 @@ -output_directory=/media/expdata/output -restore_directory=plus-gradual-new -population_size=15 -num_children=1 -num_generations=2991 -world_step_size=0.003 \ No newline at end of file diff --git a/scripts/offline-evolve2/input-15/plus_less_aggressive.conf b/scripts/offline-evolve2/input-15/plus_less_aggressive.conf deleted file mode 100644 index d6833ba..0000000 --- a/scripts/offline-evolve2/input-15/plus_less_aggressive.conf +++ /dev/null @@ -1,4 +0,0 @@ -output_directory=output -restore_directory=plus-less-aggressive-size-discount-3 -population_size=15 -num_children=15 diff --git a/scripts/offline-evolve2/input-15/plus_more_aggressive.conf b/scripts/offline-evolve2/input-15/plus_more_aggressive.conf deleted file mode 100644 index 02dce3e..0000000 --- a/scripts/offline-evolve2/input-15/plus_more_aggressive.conf +++ /dev/null @@ -1,11 +0,0 @@ -output_directory=population-output -restore_directory=plus-more-aggressive-15 -enable_light_sensor=0 -body_mutation_epsilon=0.4 -brain_mutation_epsilon=0.4 -p_delete_subtree=0.4 -p_duplicate_subtree=0.4 -p_swap_subtree=0.4 -population_size=15 -num_children=15 -num_evolutions=32 diff --git a/scripts/offline-evolve2/input-20/baseline.conf b/scripts/offline-evolve2/input-20/baseline.conf deleted file mode 100644 index 7f80d63..0000000 --- a/scripts/offline-evolve2/input-20/baseline.conf +++ /dev/null @@ -1,7 +0,0 @@ -output_directory=output -restore_directory=baseline-20 -enable_light_sensor=0 -disable_evolution=1 -keep_parents=1 -population_size=20 -num_children=20 \ No newline at end of file diff --git a/scripts/offline-evolve2/input-20/plus.conf b/scripts/offline-evolve2/input-20/plus.conf deleted file mode 100644 index 79ed5cf..0000000 --- a/scripts/offline-evolve2/input-20/plus.conf +++ /dev/null @@ -1,5 +0,0 @@ -output_directory=output -restore_directory=plus-20 -enable_light_sensor=0 -population_size=20 -num_children=20 diff --git a/scripts/offline-evolve2/input-20/plus_aggressive.conf b/scripts/offline-evolve2/input-20/plus_aggressive.conf deleted file mode 100644 index 7ee964d..0000000 --- a/scripts/offline-evolve2/input-20/plus_aggressive.conf +++ /dev/null @@ -1,10 +0,0 @@ -output_directory=debug-output -restore_directory=plus-aggressive-20 -enable_light_sensor=0 -body_mutation_epsilon=0.3 -brain_mutation_epsilon=0.3 -p_delete_subtree=0.25 -p_duplicate_subtree=0.25 -p_swap_subtree=0.25 -population_size=20 -num_children=20 diff --git a/scripts/offline-evolve2/input-20/plus_more_aggressive.conf b/scripts/offline-evolve2/input-20/plus_more_aggressive.conf deleted file mode 100644 index 285e6d2..0000000 --- a/scripts/offline-evolve2/input-20/plus_more_aggressive.conf +++ /dev/null @@ -1,10 +0,0 @@ -output_directory=output -restore_directory=plus-more-aggressive-20 -enable_light_sensor=0 -body_mutation_epsilon=0.4 -brain_mutation_epsilon=0.4 -p_delete_subtree=0.4 -p_duplicate_subtree=0.4 -p_swap_subtree=0.4 -population_size=20 -num_children=20 \ No newline at end of file diff --git a/scripts/offline-evolve2/input/baseline.conf b/scripts/offline-evolve2/input/baseline.conf deleted file mode 100644 index e3cf3e3..0000000 --- a/scripts/offline-evolve2/input/baseline.conf +++ /dev/null @@ -1,5 +0,0 @@ -output_directory=output -restore_directory=baseline -enable_light_sensor=0 -disable_evolution=1 -keep_parents=1 diff --git a/scripts/offline-evolve2/input/comma.conf b/scripts/offline-evolve2/input/comma.conf deleted file mode 100644 index 6e21d0d..0000000 --- a/scripts/offline-evolve2/input/comma.conf +++ /dev/null @@ -1,4 +0,0 @@ -output_directory=output -restore_directory=comma -enable_light_sensor=0 -keep_parents=False diff --git a/scripts/offline-evolve2/input/comma_aggressive.conf b/scripts/offline-evolve2/input/comma_aggressive.conf deleted file mode 100644 index 7a913ef..0000000 --- a/scripts/offline-evolve2/input/comma_aggressive.conf +++ /dev/null @@ -1,9 +0,0 @@ -output_directory=output -restore_directory=comma-aggressive -enable_light_sensor=0 -keep_parents=False -body_mutation_epsilon=0.3 -brain_mutation_epsilon=0.3 -p_delete_subtree=0.25 -p_duplicate_subtree=0.25 -p_swap_subtree=0.25 diff --git a/scripts/offline-evolve2/input/plus.conf b/scripts/offline-evolve2/input/plus.conf deleted file mode 100644 index d615657..0000000 --- a/scripts/offline-evolve2/input/plus.conf +++ /dev/null @@ -1,3 +0,0 @@ -output_directory=output -restore_directory=plus -enable_light_sensor=0 diff --git a/scripts/offline-evolve2/input/plus_aggressive.conf b/scripts/offline-evolve2/input/plus_aggressive.conf deleted file mode 100644 index 62357f0..0000000 --- a/scripts/offline-evolve2/input/plus_aggressive.conf +++ /dev/null @@ -1,8 +0,0 @@ -output_directory=output -restore_directory=plus-aggressive -enable_light_sensor=0 -body_mutation_epsilon=0.3 -brain_mutation_epsilon=0.3 -p_delete_subtree=0.25 -p_duplicate_subtree=0.25 -p_swap_subtree=0.25 diff --git a/scripts/offline-evolve2/input/plus_more_aggressive.conf b/scripts/offline-evolve2/input/plus_more_aggressive.conf deleted file mode 100644 index d96df1a..0000000 --- a/scripts/offline-evolve2/input/plus_more_aggressive.conf +++ /dev/null @@ -1,8 +0,0 @@ -output_directory=output -restore_directory=plus-more-aggressive -enable_light_sensor=0 -body_mutation_epsilon=0.4 -brain_mutation_epsilon=0.4 -p_delete_subtree=0.4 -p_duplicate_subtree=0.4 -p_swap_subtree=0.4 diff --git a/scripts/offline-evolve2/make.sh b/scripts/offline-evolve2/make.sh deleted file mode 100755 index 57f317a..0000000 --- a/scripts/offline-evolve2/make.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -cd ../../build/ -make -j4 diff --git a/scripts/offline-evolve2/offline-evolve.world b/scripts/offline-evolve2/offline-evolve.world deleted file mode 100644 index 8d48748..0000000 --- a/scripts/offline-evolve2/offline-evolve.world +++ /dev/null @@ -1,39 +0,0 @@ - - - - - 0 - 0 - - - 0.003 - - - 0.0 - - - - 0.1 - 10e-6 - - - 100 - 1e-8 - - - quick - - - - - - - model://sun - - - model://tol_ground - - - - - diff --git a/scripts/offline-evolve2/offline_evolve.py b/scripts/offline-evolve2/offline_evolve.py deleted file mode 100644 index 1715c35..0000000 --- a/scripts/offline-evolve2/offline_evolve.py +++ /dev/null @@ -1,437 +0,0 @@ -# Offline evolution scheme -# - We use a population of constant size 10 -# - Each robot is evaluated for 20 seconds, though we may vary this number -# - The average speed during this evaluation is the fitness -# - We do parent selection using a binary tournament: select two parents at -# random, the one with the best fitness is parent 1, repeat for parent 2. -# - Using this mechanism, we generate 10 children -# - After evaluation of the children, we either do: -# -- Plus scheme, sort *all* robots by fitness -# -- Comma scheme, get rid of the parents and continue with children only -from __future__ import absolute_import -import sys -import time -import os -import shutil -import random -import csv -import itertools -import logging -import trollius -from trollius import From, Return - -sys.path.append(os.path.dirname(os.path.abspath(__file__))+'/../../') - -from sdfbuilder import Pose -from sdfbuilder.math import Vector3 - -from revolve.util import wait_for - -from tol.manage.robot import Robot -from tol.config import parser -from tol.manage import World -from tol.logging import logger, output_console -from tol.util.analyze import list_extremities, count_joints, count_motors, count_extremities, count_connections - -# Log output to console -output_console() -logger.setLevel(logging.DEBUG) - -# Add offline evolve arguments -parser.add_argument( - '--population-size', - default=10, type=int, - help="Population size in each generation." -) - -parser.add_argument( - '--num-children', - default=10, type=int, - help="The number of children produced in each generation." -) - - -def str2bool(v): - return v.lower() == "true" or v == "1" - -parser.add_argument( - '--keep-parents', - default=True, type=str2bool, - help="Whether or not to discard the parents after each generation. This determines the strategy, + or ,." -) - -parser.add_argument( - '--num-generations', - default=200, type=int, - help="The number of generations to simulate." -) - -parser.add_argument( - '--disable-evolution', - default=False, type=str2bool, - help="Useful as a baseline test - if set to true, new robots are generated" - " every time rather than evolving them." -) - -parser.add_argument( - '--disable-selection', - default=False, type=str2bool, - help="Useful as a different baseline test - if set to true, robots reproduce," - " but parents are selected completely random." -) - -parser.add_argument( - '--disable-fitness', - default=False, type=str2bool, - help="Another baseline testing option, sorts robots randomly rather " - "than selecting the top pairs. This only matters if parents are kept." -) - -parser.add_argument( - '--num-evolutions', - default=30, type=int, - help="The number of times to repeat the experiment." -) - -parser.add_argument( - '--evaluation-threshold', - default=10.0, type=float, - help="Maximum number of seconds one evaluation can take before the " - "decision is made to restart from snapshot. The assumption is " - "that the world may have become slow and restarting will help." -) - - -class OfflineEvoManager(World): - """ - Extended world manager for the offline evolution script - """ - - def __init__(self, conf, _private): - """ - - :param conf: - :param _private: - :return: - """ - super(OfflineEvoManager, self).__init__(conf, _private) - - self._snapshot_data = {} - - # Output files - csvs = { - 'generations': ['run', 'gen', 'robot_id', 'vel', 'dvel', 'fitness', 't_eval'], - 'robot_details': ['robot_id', 'extremity_id', 'extremity_size', - 'joint_count', 'motor_count'] - } - self.csv_files = {k: {'filename': None, 'file': None, 'csv': None, - 'header': csvs[k]} - for k in csvs} - - self.current_run = 0 - - if self.output_directory: - for k in self.csv_files: - fname = os.path.join(self.output_directory, k + '.csv') - self.csv_files[k]['filename'] = fname - if self.do_restore: - shutil.copy(fname + '.snapshot', fname) - f = open(fname, 'ab', buffering=1) - else: - f = open(fname, 'wb', buffering=1) - - self.csv_files[k]['file'] = f - self.csv_files[k]['csv'] = csv.writer(f, delimiter=',') - - if not self.do_restore: - self.csv_files[k]['csv'].writerow(self.csv_files[k]['header']) - - def robots_header(self): - return Robot.header() - - @classmethod - @trollius.coroutine - def create(cls, conf): - """ - Coroutine to instantiate a Revolve.Angle WorldManager - :param conf: - :return: - """ - self = cls(_private=cls._PRIVATE, conf=conf) - yield From(self._init()) - raise Return(self) - - @trollius.coroutine - def create_snapshot(self): - """ - Copy the generations file in the snapshot - :return: - """ - ret = yield From(super(OfflineEvoManager, self).create_snapshot()) - if not ret: - raise Return(ret) - - for k in self.csv_files: - entry = self.csv_files[k] - if entry['file']: - entry['file'].flush() - shutil.copy(entry['filename'], entry['filename'] + '.snapshot') - - @trollius.coroutine - def get_snapshot_data(self): - """ - :return: - """ - data = yield From(super(OfflineEvoManager, self).get_snapshot_data()) - data.update(self._snapshot_data) - raise Return(data) - - @trollius.coroutine - def evaluate_pair(self, tree, bbox, parents=None): - """ - Evaluates a single robot tree. - :param tree: - :param bbox: - :param parents: - :return: Evaluated Robot object - """ - # Pause the world just in case it wasn't already - yield From(wait_for(self.pause(True))) - - pose = Pose(position=Vector3(0, 0, -bbox.min.z)) - fut = yield From(self.insert_robot(tree, pose, parents=parents)) - robot = yield From(fut) - - max_age = self.conf.evaluation_time + self.conf.warmup_time - - # Unpause the world to start evaluation - yield From(wait_for(self.pause(False))) - - before = time.time() - - while True: - if robot.age() >= max_age: - break - - # Sleep for the pose update frequency, which is about when - # we expect a new age update. - yield From(trollius.sleep(1.0 / self.state_update_frequency)) - - yield From(wait_for(self.delete_robot(robot))) - yield From(wait_for(self.pause(True))) - - diff = time.time() - before - if diff > self.conf.evaluation_threshold: - sys.stderr.write("Evaluation threshold exceeded, shutting down with nonzero status code.\n") - sys.stderr.flush() - sys.exit(15) - - raise Return(robot) - - @trollius.coroutine - def evaluate_population(self, trees, bboxes, parents=None): - """ - :param trees: - :param bboxes: - :param parents: - :return: - """ - if parents is None: - parents = [None for _ in trees] - - pairs = [] - print("Evaluating population...") - for tree, bbox, par in itertools.izip(trees, bboxes, parents): - print("Evaluating individual...") - before = time.time() - robot = yield From(self.evaluate_pair(tree, bbox, par)) - pairs.append((robot, time.time() - before)) - print("Done.") - - print("Done evaluating population.") - raise Return(pairs) - - @trollius.coroutine - def produce_generation(self, parents): - """ - Produce the next generation of robots from - the current. - :param parents: - :return: - """ - print("Producing generation...") - trees = [] - bboxes = [] - parent_pairs = [] - - while len(trees) < self.conf.num_children: - print("Producing individual...") - if self.conf.disable_selection: - p1, p2 = random.sample(parents, 2) - else: - p1, p2 = select_parents(parents, self.conf) - - for j in xrange(self.conf.max_mating_attempts): - pair = yield From(self.attempt_mate(p1, p2)) - if pair: - trees.append(pair[0]) - bboxes.append(pair[1]) - parent_pairs.append((p1, p2)) - break - - print("Done.") - - print("Done producing generation.") - raise Return(trees, bboxes, parent_pairs) - - def log_generation(self, evo, generation, pairs): - """ - :param evo: The evolution run - :param generation: - :param pairs: List of tuples (robot, evaluation wallclock time) - :return: - """ - print("================== GENERATION %d ==================" % generation) - if not self.output_directory: - return - - go = self.csv_files['generations']['csv'] - do = self.csv_files['robot_details']['csv'] - for robot, t_eval in pairs: - robot_id = robot.robot.id - root = robot.tree.root - go.writerow([evo, generation, robot.robot.id, robot.velocity(), - robot.displacement_velocity(), robot.fitness(), t_eval]) - - # TODO Write this once when robot is written instead - counter = 0 - for extr in list_extremities(root): - num_joints = count_joints(extr) - num_motors = count_motors(extr) - do.writerow((robot_id, counter, len(extr), num_joints, num_motors)) - counter += 1 - - @trollius.coroutine - def run(self): - """ - :return: - """ - conf = self.conf - - if self.do_restore: - # Recover from a previously cancelled / crashed experiment - data = self.do_restore - evo_start = data['evo_start'] - gen_start = data['gen_start'] - pairs = data['local_pairs'] - else: - # Start at the first experiment - evo_start = 1 - gen_start = 1 - pairs = None - - for evo in range(evo_start, conf.num_evolutions + 1): - self.current_run = evo - - if not pairs: - # Only create initial population if we are not restoring from - # a previous experiment. - trees, bboxes = yield From(self.generate_population(conf.population_size)) - pairs = yield From(self.evaluate_population(trees, bboxes)) - self.log_generation(evo, 0, pairs) - - for generation in xrange(gen_start, conf.num_generations): - if (generation % 10) == 0: - # Snapshot every 10 generations - self._snapshot_data = { - "local_pairs": pairs, - "gen_start": generation, - "evo_start": evo - } - yield From(self.create_snapshot()) - print("Created snapshot of experiment state.") - - # Produce the next generation and evaluate them - robots = [p[0] for p in pairs] - if conf.disable_evolution: - child_trees, child_bboxes = yield From( - self.generate_population(conf.population_size)) - parent_pairs = None - else: - child_trees, child_bboxes, parent_pairs = yield From(self.produce_generation(robots)) - - child_pairs = yield From(self.evaluate_population(child_trees, child_bboxes, parent_pairs)) - - if conf.keep_parents: - pairs += child_pairs - else: - pairs = child_pairs - - # Sort the bots and reduce to population size - if conf.disable_fitness: - random.shuffle(pairs) - else: - pairs = sorted(pairs, key=lambda r: r[0].fitness(), reverse=True) - - pairs = pairs[:conf.population_size] - self.log_generation(evo, generation, pairs) - - # Clear "restore" parameters - gen_start = 1 - pairs = None - - yield From(self.teardown()) - - @trollius.coroutine - def teardown(self): - """ - :return: - """ - yield From(super(OfflineEvoManager, self).teardown()) - for k in self.csv_files: - if self.csv_files[k]['file']: - self.csv_files[k]['file'].close() - - -def select_parent(parents, conf): - """ - Select a parent using a binary tournament. - :param parents: - :param conf: Configuration object - :return: - """ - return sorted(random.sample(parents, conf.tournament_size), key=lambda r: r.fitness())[-1] - - -def select_parents(parents, conf): - """ - :param parents: - :param conf: Configuration object - :return: - """ - p1 = select_parent(parents, conf) - p2 = select_parent(list(parent for parent in parents if parent != p1), conf) - return p1, p2 - - -@trollius.coroutine -def run(): - """ - :return: - """ - conf = parser.parse_args() - world = yield From(OfflineEvoManager.create(conf)) - yield From(world.run()) - - -def main(): - try: - loop = trollius.get_event_loop() - loop.run_until_complete(run()) - except KeyboardInterrupt: - print("Got Ctrl+C, shutting down.") - - -if __name__ == '__main__': - main() - diff --git a/scripts/offline-evolve2/rlpower.cfg b/scripts/offline-evolve2/rlpower.cfg deleted file mode 100644 index 6b9f00b..0000000 --- a/scripts/offline-evolve2/rlpower.cfg +++ /dev/null @@ -1,12 +0,0 @@ -{ - 'algorithm': 'rlpower', - 'type': 'A', # original rlpower - 'evaluation_rate': '30.0', - 'max_evaluations': '1000', - 'max_ranked_policies': '10', - 'init_spline_size': '3', - 'interpolation_spline_size': '100', - 'init_sigma': '0.8', -# 'policy_load_path': 'spider.policy', # Used to load policy - 'sigma_tau_correction': '0.2' -} \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/babyA.yaml b/scripts/offline-evolve2/robots/babyA.yaml deleted file mode 100644 index c0e0b45..0000000 --- a/scripts/offline-evolve2/robots/babyA.yaml +++ /dev/null @@ -1,89 +0,0 @@ ---- -body: - id : Core - type : Core - children : - 2: - slot : 0 - id : Leg00Joint - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Leg00 - type : FixedBrick - orientation : 0 - 3: - slot : 0 - id : Leg01Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg011Joint - type : ActiveHinge - orientation : 90 - children : - 1: - slot : 0 - id : Leg01 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg021Joint - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Leg02 - type : FixedBrick - orientation : 0 - 1: - slot : 0 - id : BodyJoint0 - type : ActiveHinge - orientation : 90 - children : - 1: - slot : 0 - id : Body0 - type : FixedBrick - orientation : -90 - children : - 1: - slot : 0 - id : BodyJoint1 - type : ActiveHinge - orientation : 90 - children : - 1: - slot : 0 - id : Body1 - type : FixedBrick - orientation : -90 - children: - 2: - slot : 0 - id : Leg10Joint - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Leg10 - type : FixedBrick - orientation : 0 - 3: - slot : 0 - id : Leg11Joint - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Leg11 - type : FixedBrick - orientation : 0 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/babyB.yaml b/scripts/offline-evolve2/robots/babyB.yaml deleted file mode 100644 index 4508b99..0000000 --- a/scripts/offline-evolve2/robots/babyB.yaml +++ /dev/null @@ -1,101 +0,0 @@ ---- -body: - id : Core - type : Core - children : - 0: - id : Leg00Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg00 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg01Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg01 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg02Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg02 - type : FixedBrick - orientation : -90 - 1: - id : Leg10Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg10 - type : FixedBrick - orientation : -90 - 2: - id : Leg20Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg20 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg21Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg21 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg22Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg22 - type : FixedBrick - orientation : -90 - 3: - id : Leg30Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg30 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg31Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg31 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg32Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg32 - type : FixedBrick - orientation : -90 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/babyC.yaml b/scripts/offline-evolve2/robots/babyC.yaml deleted file mode 100644 index 4667693..0000000 --- a/scripts/offline-evolve2/robots/babyC.yaml +++ /dev/null @@ -1,171 +0,0 @@ ---- -body: - id : Core - type : Core - children : - 2: - slot : 0 - id : Leg00Joint - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Leg00 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg001Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg001 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg002Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg002 - type : FixedBrick - orientation : 0 - 3: - slot : 0 - id : Leg01Joint - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Leg01 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg011Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg011 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg012Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg012 - type : FixedBrick - orientation : 0 - 1: - slot : 0 - id : BodyJoint0 - type : ActiveHinge - orientation : 90 - children : - 1: - slot : 0 - id : Body0 - type : FixedBrick - orientation : -90 - children : - 1: - slot : 0 - id : BodyJoint1 - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Body1 - type : FixedBrick - orientation : 0 - children : - 1: - slot : 0 - id : BodyJoint2 - type : ActiveHinge - orientation : 90 - children : - 1: - slot : 0 - id : Body2 - type : FixedBrick - orientation : -90 - children : - 1: - id : BodyJoint3 - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Body3 - type : FixedBrick - orientation : 0 - children: - 2: - slot : 0 - id : Leg10Joint - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Leg10 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg101Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg101 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg102Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg102 - type : FixedBrick - orientation : 0 - 3: - slot : 0 - id : Leg11Joint - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Leg11 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg111Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg112Joint - type : ActiveHinge - orientation : -90 - children : - 1: - id : Leg112 - type : FixedBrick - orientation : 0 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/gecko12.yaml b/scripts/offline-evolve2/robots/gecko12.yaml deleted file mode 100644 index 9c138ad..0000000 --- a/scripts/offline-evolve2/robots/gecko12.yaml +++ /dev/null @@ -1,124 +0,0 @@ ---- -body: - id : Core - type : Core - children : - 2: - slot : 0 - id : Leg00Joint - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Leg00 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg001Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg001 - type : FixedBrick - orientation : -90 - 3: - slot : 0 - id : Leg01Joint - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Leg01 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg011Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg011 - type : FixedBrick - orientation : -90 - 1: - slot : 0 - id : BodyJoint0 - type : ActiveHinge - orientation : 90 - children : - 1: - slot : 0 - id : Body0 - type : FixedBrick - orientation : -90 - children : - 1: - slot : 0 - id : BodyJoint1 - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Body1 - type : FixedBrick - orientation : 0 - children : - 1: - id : BodyJoint2 - type : ActiveHinge - orientation : 90 - children : - 1: - slot : 0 - id : Body2 - type : FixedBrick - orientation : -90 - children: - 2: - slot : 0 - id : Leg10Joint - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Leg10 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg101Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg101 - type : FixedBrick - orientation : -90 - 3: - slot : 0 - id : Leg11Joint - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Leg11 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg111Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg111 - type : FixedBrick - orientation : -90 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/gecko17.yaml b/scripts/offline-evolve2/robots/gecko17.yaml deleted file mode 100644 index 5e11c4f..0000000 --- a/scripts/offline-evolve2/robots/gecko17.yaml +++ /dev/null @@ -1,176 +0,0 @@ ---- -body: - id : Core - type : Core - children : - 2: - slot : 0 - id : Leg00Joint - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Leg00 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg001Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg001 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg002Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg002 - type : FixedBrick - orientation : 0 - 3: - slot : 0 - id : Leg01Joint - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Leg01 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg011Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg011 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg012Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg012 - type : FixedBrick - orientation : 0 - 1: - slot : 0 - id : BodyJoint0 - type : ActiveHinge - orientation : 90 - children : - 1: - slot : 0 - id : Body0 - type : FixedBrick - orientation : -90 - children : - 1: - slot : 0 - id : BodyJoint1 - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Body1 - type : FixedBrick - orientation : 0 - children : - 1: - slot : 0 - id : BodyJoint2 - type : ActiveHinge - orientation : 90 - children : - 1: - slot : 0 - id : Body2 - type : FixedBrick - orientation : -90 - children : - 1: - id : BodyJoint3 - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Body3 - type : FixedBrick - orientation : 0 - children: - 2: - slot : 0 - id : Leg10Joint - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Leg10 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg101Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg101 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg102Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg102 - type : FixedBrick - orientation : 0 - 3: - slot : 0 - id : Leg11Joint - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Leg11 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg111Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg111 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg112Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg112 - type : FixedBrick - orientation : 0 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/gecko7.yaml b/scripts/offline-evolve2/robots/gecko7.yaml deleted file mode 100644 index 806b736..0000000 --- a/scripts/offline-evolve2/robots/gecko7.yaml +++ /dev/null @@ -1,73 +0,0 @@ ---- -body: - id : Core - type : Core - children : - 2: - slot : 0 - id : Leg00Joint - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Leg00 - type : FixedBrick - orientation : 0 - 3: - slot : 0 - id : Leg01Joint - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Leg01 - type : FixedBrick - orientation : 0 - 1: - slot : 0 - id : BodyJoint0 - type : ActiveHinge - orientation : 90 - children : - 1: - slot : 0 - id : Body0 - type : FixedBrick - orientation : -90 - children : - 1: - slot : 0 - id : BodyJoint1 - type : ActiveHinge - orientation : 90 - children : - 1: - slot : 0 - id : Body1 - type : FixedBrick - orientation : -90 - children: - 2: - slot : 0 - id : Leg10Joint - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Leg10 - type : FixedBrick - orientation : 0 - 3: - slot : 0 - id : Leg11Joint - type : ActiveHinge - orientation : 0 - children : - 1: - slot : 0 - id : Leg11 - type : FixedBrick - orientation : 0 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/snake5.yaml b/scripts/offline-evolve2/robots/snake5.yaml deleted file mode 100644 index d09976a..0000000 --- a/scripts/offline-evolve2/robots/snake5.yaml +++ /dev/null @@ -1,41 +0,0 @@ ---- -body: - id : Core - type : Core - children : - 0: - id : Leg00Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg00 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg01Joint - type : ActiveHinge - children : - 1: - id : Leg01 - type : FixedBrick - orientation : 0 - 1: - id : Leg10Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg10 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg11Joint - type : ActiveHinge - children : - 1: - id : Leg11 - type : FixedBrick - orientation : 0 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/snake7.yaml b/scripts/offline-evolve2/robots/snake7.yaml deleted file mode 100644 index 123bbed..0000000 --- a/scripts/offline-evolve2/robots/snake7.yaml +++ /dev/null @@ -1,63 +0,0 @@ ---- -body: - id : Core - type : Core - children : - 0: - id : Leg00Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg00 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg01Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg01 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg02Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg02 - type : FixedBrick - orientation : -90 - 1: - id : Leg10Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg10 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg11Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg11 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg12Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg12 - type : FixedBrick - orientation : -90 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/snake9.yaml b/scripts/offline-evolve2/robots/snake9.yaml deleted file mode 100644 index 6ecf5a0..0000000 --- a/scripts/offline-evolve2/robots/snake9.yaml +++ /dev/null @@ -1,83 +0,0 @@ ---- -body: - id : Core - type : Core - children : - 0: - id : Leg00Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg00 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg01Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg01 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg02Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg02 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg03Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg03 - type : FixedBrick - orientation : 0 - 1: - id : Leg10Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg10 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg11Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg11 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg12Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg12 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg13Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg13 - type : FixedBrick - orientation : 0 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/spider13.yaml b/scripts/offline-evolve2/robots/spider13.yaml deleted file mode 100644 index bce3693..0000000 --- a/scripts/offline-evolve2/robots/spider13.yaml +++ /dev/null @@ -1,121 +0,0 @@ ---- -body: - id : Core - type : Core - children : - 0: - id : Leg00Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg00 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg01Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg01 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg02Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg02 - type : FixedBrick - orientation : -90 - 1: - id : Leg10Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg10 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg11Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg11 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg12Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg12 - type : FixedBrick - orientation : -90 - 2: - id : Leg20Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg20 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg21Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg21 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg22Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg22 - type : FixedBrick - orientation : -90 - 3: - id : Leg30Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg30 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg31Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg31 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg32Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg32 - type : FixedBrick - orientation : -90 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/spider17.yaml b/scripts/offline-evolve2/robots/spider17.yaml deleted file mode 100644 index 8def37b..0000000 --- a/scripts/offline-evolve2/robots/spider17.yaml +++ /dev/null @@ -1,161 +0,0 @@ ---- -body: - id : Core - type : Core - children : - 0: - id : Leg00Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg00 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg01Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg01 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg02Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg02 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg03Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg03 - type : FixedBrick - orientation : 0 - 1: - id : Leg10Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg10 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg11Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg11 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg12Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg12 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg13Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg13 - type : FixedBrick - orientation : 0 - 2: - id : Leg20Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg20 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg21Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg21 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg22Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg22 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg23Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg23 - type : FixedBrick - orientation : 0 - 3: - id : Leg30Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg30 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg31Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg31 - type : FixedBrick - orientation : 0 - children : - 1: - id : Leg32Joint - type : ActiveHinge - orientation : 90 - children : - 1: - id : Leg32 - type : FixedBrick - orientation : -90 - children : - 1: - id : Leg33Joint - type : ActiveHinge - orientation : 0 - children : - 1: - id : Leg33 - type : FixedBrick - orientation : 0 \ No newline at end of file diff --git a/scripts/offline-evolve2/robots/spider9.yaml b/scripts/offline-evolve2/robots/spider9.yaml deleted file mode 100644 index 53bab38..0000000 --- a/scripts/offline-evolve2/robots/spider9.yaml +++ /dev/null @@ -1,659 +0,0 @@ -body: - children: - 0: - children: - 1: - children: - 1: - children: - 1: - id: Leg01 - label: '' - orientation: 0 - params: - blue: 0.5 - green: 0.5 - red: 0.5 - slot: 0 - type: FixedBrick - id: Leg01Joint - label: '' - orientation: 0 - params: - blue: 0.5 - green: 0.5 - red: 0.5 - slot: 0 - type: ActiveHinge - id: Leg00 - label: '' - orientation: -90 - params: - blue: 0.5 - green: 0.5 - red: 0.5 - slot: 0 - type: FixedBrick - id: Leg00Joint - label: '' - orientation: 90 - params: - blue: 0.5 - green: 0.5 - red: 0.5 - slot: 0 - type: ActiveHinge - 1: - children: - 1: - children: - 1: - children: - 1: - id: Leg11 - label: '' - orientation: 0 - params: - blue: 0.5 - green: 0.5 - red: 0.5 - slot: 0 - type: FixedBrick - id: Leg11Joint - label: '' - orientation: 0 - params: - blue: 0.5 - green: 0.5 - red: 0.5 - slot: 0 - type: ActiveHinge - id: Leg10 - label: '' - orientation: -90 - params: - blue: 0.5 - green: 0.5 - red: 0.5 - slot: 0 - type: FixedBrick - id: Leg10Joint - label: '' - orientation: 90 - params: - blue: 0.5 - green: 0.5 - red: 0.5 - slot: 0 - type: ActiveHinge - 2: - children: - 1: - children: - 1: - children: - 1: - id: Leg21 - label: '' - orientation: 0 - params: - blue: 0.5 - green: 0.5 - red: 0.5 - slot: 0 - type: FixedBrick - id: Leg21Joint - label: '' - orientation: 0 - params: - blue: 0.5 - green: 0.5 - red: 0.5 - slot: 0 - type: ActiveHinge - id: Leg20 - label: '' - orientation: -90 - params: - blue: 0.5 - green: 0.5 - red: 0.5 - slot: 0 - type: FixedBrick - id: Leg20Joint - label: '' - orientation: 90 - params: - blue: 0.5 - green: 0.5 - red: 0.5 - slot: 0 - type: ActiveHinge - 3: - children: - 1: - children: - 1: - children: - 1: - id: Leg31 - label: '' - orientation: 0 - params: - blue: 0.5 - green: 0.5 - red: 0.5 - slot: 0 - type: FixedBrick - id: Leg31Joint - label: '' - orientation: 0 - params: - blue: 0.5 - green: 0.5 - red: 0.5 - slot: 0 - type: ActiveHinge - id: Leg30 - label: '' - orientation: -90 - params: - blue: 0.5 - green: 0.5 - red: 0.5 - slot: 0 - type: FixedBrick - id: Leg30Joint - label: '' - orientation: 90 - params: - blue: 0.5 - green: 0.5 - red: 0.5 - slot: 0 - type: ActiveHinge - id: Core - label: '' - orientation: 0 - params: - blue: 0.5 - green: 0.5 - red: 0.5 - type: Core -brain: - connections: - - dst: Leg00Joint-cpg-0 - socket: from_x - src: Leg00Joint-cpg-1 - weight: 1.0 - - dst: Leg00Joint-cpg-1 - socket: from_v - src: Leg00Joint-cpg-0 - weight: 1.0 - - dst: Leg00Joint-out-0 - src: Leg00Joint-cpg-0 - weight: 1.0 - - dst: Leg01Joint-cpg-2 - socket: from_x - src: Leg01Joint-cpg-3 - weight: 1.0 - - dst: Leg01Joint-cpg-3 - socket: from_v - src: Leg01Joint-cpg-2 - weight: 1.0 - - dst: Leg01Joint-out-0 - src: Leg01Joint-cpg-2 - weight: 1.0 - - dst: Leg00Joint-cpg-0 - socket: from_x_ext - src: Leg01Joint-cpg-3 - weight: 1.0 - - dst: Leg01Joint-cpg-2 - socket: from_x_ext - src: Leg00Joint-cpg-1 - weight: 1.0 - - dst: Leg00Joint-cpg-0 - socket: from_v_ext - src: Leg01Joint-cpg-2 - weight: 1.0 - - dst: Leg01Joint-cpg-2 - socket: from_v_ext - src: Leg00Joint-cpg-0 - weight: 1.0 - - dst: Leg10Joint-cpg-4 - socket: from_x - src: Leg10Joint-cpg-5 - weight: 1.0 - - dst: Leg10Joint-cpg-5 - socket: from_v - src: Leg10Joint-cpg-4 - weight: 1.0 - - dst: Leg10Joint-out-0 - src: Leg10Joint-cpg-4 - weight: 1.0 - - dst: Leg11Joint-cpg-6 - socket: from_x - src: Leg11Joint-cpg-7 - weight: 1.0 - - dst: Leg11Joint-cpg-7 - socket: from_v - src: Leg11Joint-cpg-6 - weight: 1.0 - - dst: Leg11Joint-out-0 - src: Leg11Joint-cpg-6 - weight: 1.0 - - dst: Leg10Joint-cpg-4 - socket: from_x_ext - src: Leg11Joint-cpg-7 - weight: 1.0 - - dst: Leg11Joint-cpg-6 - socket: from_x_ext - src: Leg10Joint-cpg-5 - weight: 1.0 - - dst: Leg10Joint-cpg-4 - socket: from_v_ext - src: Leg11Joint-cpg-6 - weight: 1.0 - - dst: Leg11Joint-cpg-6 - socket: from_v_ext - src: Leg10Joint-cpg-4 - weight: 1.0 - - dst: Leg20Joint-cpg-8 - socket: from_x - src: Leg20Joint-cpg-9 - weight: 1.0 - - dst: Leg20Joint-cpg-9 - socket: from_v - src: Leg20Joint-cpg-8 - weight: 1.0 - - dst: Leg20Joint-out-0 - src: Leg20Joint-cpg-8 - weight: 1.0 - - dst: Leg21Joint-cpg-10 - socket: from_x - src: Leg21Joint-cpg-11 - weight: 1.0 - - dst: Leg21Joint-cpg-11 - socket: from_v - src: Leg21Joint-cpg-10 - weight: 1.0 - - dst: Leg21Joint-out-0 - src: Leg21Joint-cpg-10 - weight: 1.0 - - dst: Leg20Joint-cpg-8 - socket: from_x_ext - src: Leg21Joint-cpg-11 - weight: 1.0 - - dst: Leg21Joint-cpg-10 - socket: from_x_ext - src: Leg20Joint-cpg-9 - weight: 1.0 - - dst: Leg20Joint-cpg-8 - socket: from_v_ext - src: Leg21Joint-cpg-10 - weight: 1.0 - - dst: Leg21Joint-cpg-10 - socket: from_v_ext - src: Leg20Joint-cpg-8 - weight: 1.0 - - dst: Leg30Joint-cpg-12 - socket: from_x - src: Leg30Joint-cpg-13 - weight: 1.0 - - dst: Leg30Joint-cpg-13 - socket: from_v - src: Leg30Joint-cpg-12 - weight: 1.0 - - dst: Leg30Joint-out-0 - src: Leg30Joint-cpg-12 - weight: 1.0 - - dst: Leg31Joint-cpg-14 - socket: from_x - src: Leg31Joint-cpg-15 - weight: 1.0 - - dst: Leg31Joint-cpg-15 - socket: from_v - src: Leg31Joint-cpg-14 - weight: 1.0 - - dst: Leg31Joint-out-0 - src: Leg31Joint-cpg-14 - weight: 1.0 - - dst: Leg30Joint-cpg-12 - socket: from_x_ext - src: Leg31Joint-cpg-15 - weight: 1.0 - - dst: Leg31Joint-cpg-14 - socket: from_x_ext - src: Leg30Joint-cpg-13 - weight: 1.0 - - dst: Leg30Joint-cpg-12 - socket: from_v_ext - src: Leg31Joint-cpg-14 - weight: 1.0 - - dst: Leg31Joint-cpg-14 - socket: from_v_ext - src: Leg30Joint-cpg-12 - weight: 1.0 - - dst: Leg00Joint-cpg-0 - src: Core-in-5 - weight: 1.0 - - dst: Leg00Joint-cpg-0 - src: Core-in-4 - weight: 1.0 - - dst: Leg00Joint-cpg-0 - src: Core-in-0 - weight: 1.0 - - dst: Leg00Joint-cpg-0 - src: Core-in-3 - weight: 1.0 - - dst: Leg00Joint-cpg-0 - src: Core-in-2 - weight: 1.0 - - dst: Leg00Joint-cpg-0 - src: Core-in-1 - weight: 1.0 - - dst: Leg10Joint-cpg-4 - src: Core-in-5 - weight: 1.0 - - dst: Leg10Joint-cpg-4 - src: Core-in-4 - weight: 1.0 - - dst: Leg10Joint-cpg-4 - src: Core-in-0 - weight: 1.0 - - dst: Leg10Joint-cpg-4 - src: Core-in-3 - weight: 1.0 - - dst: Leg10Joint-cpg-4 - src: Core-in-2 - weight: 1.0 - - dst: Leg10Joint-cpg-4 - src: Core-in-1 - weight: 1.0 - - dst: Leg20Joint-cpg-8 - src: Core-in-5 - weight: 1.0 - - dst: Leg20Joint-cpg-8 - src: Core-in-4 - weight: 1.0 - - dst: Leg20Joint-cpg-8 - src: Core-in-0 - weight: 1.0 - - dst: Leg20Joint-cpg-8 - src: Core-in-3 - weight: 1.0 - - dst: Leg20Joint-cpg-8 - src: Core-in-2 - weight: 1.0 - - dst: Leg20Joint-cpg-8 - src: Core-in-1 - weight: 1.0 - - dst: Leg30Joint-cpg-12 - src: Core-in-5 - weight: 1.0 - - dst: Leg30Joint-cpg-12 - src: Core-in-4 - weight: 1.0 - - dst: Leg30Joint-cpg-12 - src: Core-in-0 - weight: 1.0 - - dst: Leg30Joint-cpg-12 - src: Core-in-3 - weight: 1.0 - - dst: Leg30Joint-cpg-12 - src: Core-in-2 - weight: 1.0 - - dst: Leg30Joint-cpg-12 - src: Core-in-1 - weight: 1.0 - - dst: Leg10Joint-cpg-4 - socket: from_x_ext - src: Leg00Joint-cpg-1 - weight: 1.0 - - dst: Leg00Joint-cpg-0 - socket: from_x_ext - src: Leg10Joint-cpg-5 - weight: 1.0 - - dst: Leg10Joint-cpg-4 - socket: from_v_ext - src: Leg00Joint-cpg-0 - weight: 1.0 - - dst: Leg00Joint-cpg-0 - socket: from_v_ext - src: Leg10Joint-cpg-4 - weight: 1.0 - - dst: Leg20Joint-cpg-8 - socket: from_x_ext - src: Leg00Joint-cpg-1 - weight: 1.0 - - dst: Leg00Joint-cpg-0 - socket: from_x_ext - src: Leg20Joint-cpg-9 - weight: 1.0 - - dst: Leg20Joint-cpg-8 - socket: from_v_ext - src: Leg00Joint-cpg-0 - weight: 1.0 - - dst: Leg00Joint-cpg-0 - socket: from_v_ext - src: Leg20Joint-cpg-8 - weight: 1.0 - - dst: Leg30Joint-cpg-12 - socket: from_x_ext - src: Leg00Joint-cpg-1 - weight: 1.0 - - dst: Leg00Joint-cpg-0 - socket: from_x_ext - src: Leg30Joint-cpg-13 - weight: 1.0 - - dst: Leg30Joint-cpg-12 - socket: from_v_ext - src: Leg00Joint-cpg-0 - weight: 1.0 - - dst: Leg00Joint-cpg-0 - socket: from_v_ext - src: Leg30Joint-cpg-12 - weight: 1.0 - - dst: Leg20Joint-cpg-8 - socket: from_x_ext - src: Leg10Joint-cpg-5 - weight: 1.0 - - dst: Leg10Joint-cpg-4 - socket: from_x_ext - src: Leg20Joint-cpg-9 - weight: 1.0 - - dst: Leg20Joint-cpg-8 - socket: from_v_ext - src: Leg10Joint-cpg-4 - weight: 1.0 - - dst: Leg10Joint-cpg-4 - socket: from_v_ext - src: Leg20Joint-cpg-8 - weight: 1.0 - - dst: Leg30Joint-cpg-12 - socket: from_x_ext - src: Leg10Joint-cpg-5 - weight: 1.0 - - dst: Leg10Joint-cpg-4 - socket: from_x_ext - src: Leg30Joint-cpg-13 - weight: 1.0 - - dst: Leg30Joint-cpg-12 - socket: from_v_ext - src: Leg10Joint-cpg-4 - weight: 1.0 - - dst: Leg10Joint-cpg-4 - socket: from_v_ext - src: Leg30Joint-cpg-12 - weight: 1.0 - - dst: Leg30Joint-cpg-12 - socket: from_x_ext - src: Leg20Joint-cpg-9 - weight: 1.0 - - dst: Leg20Joint-cpg-8 - socket: from_x_ext - src: Leg30Joint-cpg-13 - weight: 1.0 - - dst: Leg30Joint-cpg-12 - socket: from_v_ext - src: Leg20Joint-cpg-8 - weight: 1.0 - - dst: Leg20Joint-cpg-8 - socket: from_v_ext - src: Leg30Joint-cpg-12 - weight: 1.0 - neurons: - Leg00Joint-cpg-0: - id: Leg00Joint-cpg-0 - layer: hidden - part_id: Leg00Joint - type: V-Neuron - Leg00Joint-cpg-1: - id: Leg00Joint-cpg-1 - layer: hidden - part_id: Leg00Joint - type: X-Neuron - Leg01Joint-cpg-2: - id: Leg01Joint-cpg-2 - layer: hidden - part_id: Leg01Joint - type: V-Neuron - Leg01Joint-cpg-3: - id: Leg01Joint-cpg-3 - layer: hidden - part_id: Leg01Joint - type: X-Neuron - Leg10Joint-cpg-4: - id: Leg10Joint-cpg-4 - layer: hidden - part_id: Leg10Joint - type: V-Neuron - Leg10Joint-cpg-5: - id: Leg10Joint-cpg-5 - layer: hidden - part_id: Leg10Joint - type: X-Neuron - Leg11Joint-cpg-6: - id: Leg11Joint-cpg-6 - layer: hidden - part_id: Leg11Joint - type: V-Neuron - Leg11Joint-cpg-7: - id: Leg11Joint-cpg-7 - layer: hidden - part_id: Leg11Joint - type: X-Neuron - Leg20Joint-cpg-8: - id: Leg20Joint-cpg-8 - layer: hidden - part_id: Leg20Joint - type: V-Neuron - Leg20Joint-cpg-9: - id: Leg20Joint-cpg-9 - layer: hidden - part_id: Leg20Joint - type: X-Neuron - Leg21Joint-cpg-10: - id: Leg21Joint-cpg-10 - layer: hidden - part_id: Leg21Joint - type: V-Neuron - Leg21Joint-cpg-11: - id: Leg21Joint-cpg-11 - layer: hidden - part_id: Leg21Joint - type: X-Neuron - Leg30Joint-cpg-12: - id: Leg30Joint-cpg-12 - layer: hidden - part_id: Leg30Joint - type: V-Neuron - Leg30Joint-cpg-13: - id: Leg30Joint-cpg-13 - layer: hidden - part_id: Leg30Joint - type: X-Neuron - Leg31Joint-cpg-14: - id: Leg31Joint-cpg-14 - layer: hidden - part_id: Leg31Joint - type: V-Neuron - Leg31Joint-cpg-15: - id: Leg31Joint-cpg-15 - layer: hidden - part_id: Leg31Joint - type: X-Neuron - params: - Leg00Joint-cpg-0: - alpha: 1.0 - energy: 1.0 - tau: 1.0 - Leg00Joint-cpg-1: - tau: 1.0 - Leg00Joint-out-0: - bias: 0.0 - gain: 0.5 - Leg01Joint-cpg-2: - alpha: 1.0 - energy: 1.0 - tau: 1.0 - Leg01Joint-cpg-3: - tau: 1.0 - Leg01Joint-out-0: - bias: 0.0 - gain: 0.5 - Leg10Joint-cpg-4: - alpha: 1.0 - energy: 1.0 - tau: 1.0 - Leg10Joint-cpg-5: - tau: 1.0 - Leg10Joint-out-0: - bias: 0.0 - gain: 0.5 - Leg11Joint-cpg-6: - alpha: 1.0 - energy: 1.0 - tau: 1.0 - Leg11Joint-cpg-7: - tau: 1.0 - Leg11Joint-out-0: - bias: 0.0 - gain: 0.5 - Leg20Joint-cpg-8: - alpha: 1.0 - energy: 1.0 - tau: 1.0 - Leg20Joint-cpg-9: - tau: 1.0 - Leg20Joint-out-0: - bias: 0.0 - gain: 0.5 - Leg21Joint-cpg-10: - alpha: 1.0 - energy: 1.0 - tau: 1.0 - Leg21Joint-cpg-11: - tau: 1.0 - Leg21Joint-out-0: - bias: 0.0 - gain: 0.5 - Leg30Joint-cpg-12: - alpha: 1.0 - energy: 1.0 - tau: 1.0 - Leg30Joint-cpg-13: - tau: 1.0 - Leg30Joint-out-0: - bias: 0.0 - gain: 0.5 - Leg31Joint-cpg-14: - alpha: 1.0 - energy: 1.0 - tau: 1.0 - Leg31Joint-cpg-15: - tau: 1.0 - Leg31Joint-out-0: - bias: 0.0 - gain: 0.5 -id: 0 diff --git a/scripts/offline-evolve2/run-experiments.sh b/scripts/offline-evolve2/run-experiments.sh deleted file mode 100755 index ddf01fd..0000000 --- a/scripts/offline-evolve2/run-experiments.sh +++ /dev/null @@ -1,83 +0,0 @@ -#!/usr/bin/env bash - -# Handle keyboard interrupt -trap " exit " INT - -PROGNAME=$(basename $0) - -# Default argument list -robot_list=( spider9 spider13 spider17 gecko7 gecko12 gecko17 snake5 snake7 snake9 babyA babyB babyC ) - -config=rlpower.cfg -manager=single_robot_manager.py -world=gait-learning.world -output=output -restore=restore -gz_command=gzserver -no_experiments=10 - -function error_exit() { - echo "${PROGNAME}: ${1:-"Unknown Error"}" 1 >&2 - exit 1 -} - -function help() { - echo "Usage: ${PROGNAME} [args...]" - echo "Arguments:" - echo " -c | --config Path to robot brain config file" - echo " -g | --gzcommand Gazebo command [gzserver|gazebo] Default: gzserver" - echo " -h | --help Help page" - echo " -m | --manager Name of script that controls robots and the environment" - echo " -n | --no-experiments Number of experiment repetitions" - echo " -o | --output Name of the output directory" - echo " -r | --restore Name of the restore directory" - echo " -w | --world Name of world file" - - exit 0 -} - -function main() { - - # Read out the argument list - if [ $# -gt 0 ]; then - while [ "$1" != "" ] - do - local argument="$1"; - shift - local parameter="$1"; - shift - case ${argument} in - -c | --config) local config=${parameter} ;; - -g | --gzcommand) local gz_command=${parameter} ;; - -h | --help) help ;; - -m | --manager) local manager=${parameter} ;; - -n | --no-experiments) local no_experiments=${parameter} ;; - -o | --output) local output=${parameter} ;; - -r | --restore) local restore=${parameter} ;; - -w | --world) local world=${parameter} ;; - *) error_exit "${LINENO}: In ${FUNCNAME}() unknown argument ${argument}." ;; - esac - done - fi - - # For each name in 'robot_list' run 'no_experiments' experiments - for index in ${!robot_list[*]} - do - for (( i = 1; i <= ${no_experiments}; ++ i )) - do - python start.py \ - --manager ${manager} \ - --world ${world} \ - --output ${output} \ - --restore ${restore} \ - --robot-name robots/${robot_list[$index]} \ - --experiment-round ${i} \ - --brain-conf-path ${config} \ - --gazebo-cmd ${gz_command} - done - done - - exit 0 -} - -main $@ diff --git a/scripts/offline-evolve2/single_robot_manager.py b/scripts/offline-evolve2/single_robot_manager.py deleted file mode 100644 index 633c4f7..0000000 --- a/scripts/offline-evolve2/single_robot_manager.py +++ /dev/null @@ -1,101 +0,0 @@ -import ast -import os -import sys - -sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..')) - -from pygazebo.pygazebo import DisconnectError -from trollius.py33_exceptions import ConnectionResetError - -import trollius -from trollius import From - -from tol.config import parser -from tol.manage import World - -from sdfbuilder import Pose -from sdfbuilder.math import Vector3 - -from revolve.convert.yaml import yaml_to_robot -from revolve.angle import Tree -from revolve.util import wait_for - -from tol.spec import get_extended_brain_spec - - -@trollius.coroutine -def run(): - """ - The main coroutine, which is started below. - """ - # Parse command line / file input arguments - conf = parser.parse_args() - - # Adding brain configuration - with open(conf.brain_conf_path, 'r') as f: - s = f.read() - brain_conf = ast.literal_eval(s) - brain_conf["policy_load_path"] = conf.load_controller - conf.brain_conf = brain_conf - - # This disables the analyzer; enable it if you want to generate valid robots - # Can also do this using arguments of course, just pass an empty string - # conf.analyzer_address = None - - with open("{}.yaml".format(conf.robot_name), 'r') as yamlfile: - bot_yaml = yamlfile.read() - - # Create the world, this connects to the Gazebo world - world = yield From(World.create(conf)) - - # These are useful when working with YAML - body_spec = world.builder.body_builder.spec - brain_spec = get_extended_brain_spec(conf) - - # Create a robot from YAML - robot = yaml_to_robot(body_spec, brain_spec, bot_yaml) - - # Create a revolve.angle `Tree` representation from the robot, which - # is what is used in the world manager. - robot_tree = Tree.from_body_brain(robot.body, robot.brain, body_spec) - - # Insert the robot into the world. `insert_robot` resolves when the insert - # request is sent, the future it returns resolves when the robot insert - # is actually confirmed and a robot manager object has been created - pose = Pose(position=Vector3(0, 0, 0.05)) - future = yield From(world.insert_robot(robot_tree, pose, "{}-{}".format(conf.robot_name, conf.experiment_round))) - robot_manager = yield From(future) - - # I usually start the world paused, un-pause it here. Note that - # pause again returns a future for when the request is sent, - # that future in turn resolves when a response has been received. - # This is the general convention for all message actions in the - # world manager. `wait_for` saves the hassle of grabbing the - # intermediary future in this case. - yield From(wait_for(world.pause(False))) - - # Start a run loop to do some stuff - while True: - # Print robot fitness every second - print("Robot fitness: %f" % robot_manager.fitness()) - yield From(trollius.sleep(1.0)) - - -def main(): - def handler(loop, context): - exc = context['exception'] - if isinstance(exc, DisconnectError) or isinstance(exc, ConnectionResetError): - print("Got disconnect / connection reset - shutting down.") - sys.exit(0) - raise context['exception'] - - try: - loop = trollius.get_event_loop() - loop.set_exception_handler(handler) - loop.run_until_complete(run()) - except KeyboardInterrupt: - print("Got CtrlC, shutting down.") - - -if __name__ == '__main__': - main() diff --git a/scripts/offline-evolve2/start.py b/scripts/offline-evolve2/start.py deleted file mode 100644 index 285a737..0000000 --- a/scripts/offline-evolve2/start.py +++ /dev/null @@ -1,57 +0,0 @@ -import os -import sys - -here = os.path.dirname(os.path.abspath(__file__)) -tol_path = os.path.abspath(os.path.join(here, '..', '..')) -rv_path = os.path.abspath(os.path.join(tol_path, '..', 'revolve')) -sys.path.append(os.path.dirname(os.path.abspath(__file__))) - -from revolve.util import Supervisor -from offline_evolve import parser - - -class OfflineEvolutionSupervisor(Supervisor): - """ - Supervisor class that adds some output filtering for ODE errors - """ - - def __init__(self, *args, **kwargs): - super(OfflineEvolutionSupervisor, self).__init__(*args, **kwargs) - self.ode_errors = 0 - - def write_stderr(self, data): - """ - :param data: - :return: - """ - if 'ODE Message 3' in data: - self.ode_errors += 1 - elif data.strip(): - sys.stderr.write(data) - - if self.ode_errors >= 100: - self.ode_errors = 0 - sys.stderr.write('ODE Message 3 (100)\n') - - -args = parser.parse_args() - -os.environ['GAZEBO_PLUGIN_PATH'] = os.path.join(tol_path, 'build') -os.environ['GAZEBO_MODEL_PATH'] = os.path.join(tol_path, 'tools', 'models') + \ - ':' + os.path.join(rv_path, 'tools', 'models') - -supervisor = OfflineEvolutionSupervisor( - manager_cmd=[sys.executable, args.manager, - "--load-controller", args.load_controller, - "--robot-name", args.robot_name, - "--experiment-round", args.experiment_round, - "--brain-conf-path", args.brain_conf_path], - analyzer_cmd=os.path.join(rv_path, 'tools', 'analyzer', 'run-analyzer'), - world_file=os.path.join(here, args.world), - output_directory=args.output_directory, - restore_directory=args.restore_directory, - gazebo_cmd=args.gazebo_cmd, - manager_args=sys.argv[1:] -) - -supervisor.launch() diff --git a/scripts/offline-evolve2/summarize.R b/scripts/offline-evolve2/summarize.R deleted file mode 100644 index a83d9a0..0000000 --- a/scripts/offline-evolve2/summarize.R +++ /dev/null @@ -1,103 +0,0 @@ -# Use this script to summarize one or multiple concatenated -# runs of evolution data. -# This post helps here: -# http://stackoverflow.com/a/10349375/358873 - -library(ggplot2) -library(plyr) -library(reshape) - -read_dir_data <- function(odir) { - tdata = read.csv(paste(odir, "/generations.csv", sep=""), head=TRUE); - tdata$exp = as.factor(odir); - if (tdata[1,]$exp == "plus-gradual") { - tdata$births = tdata$gen + 15; - } else { - tdata$births = tdata$gen * 15 + 15; - } - - rdata = read.csv(paste(odir, "/robots.csv", sep=""), head=TRUE); - - return(merge(tdata[tdata$births<=3000,], rdata, by.x=c("robot_id", "run"), by.y=c("id", "run"))); -} - -dirs = list.files("."); -data = do.call(rbind, lapply(dirs, read_dir_data)); - -# Unify fitness calculation -data$fitness = 5*data$dvel + data$vel; - -# Remove outliers -data = data[data$fitness<1,]; - -cdata = ddply(data, c("births", "exp"), summarise, - fit=mean(fitness), fsd=sd(fitness), - ext=mean(extremity_count), esd=sd(extremity_count), - joints=mean(joint_count), jsd=sd(joint_count), - motors=mean(motor_count), msd=sd(motor_count), - sz=mean(nparts), ssd=sd(nparts), - inp=mean(inputs), isd=sd(inputs), - hid=mean(hidden), hsd=sd(hidden), - con=mean(conn), csd=sd(conn) - ); - -cdata$plot = as.factor("Fitness"); -cdata1 = cdata; -cdata2 = cdata; -cdata3 = cdata; -cdata4 = cdata; -cdata5 = cdata; -cdata6 = cdata; -cdata7 = cdata; - -cdata1$plot = as.factor("# of joints"); -cdata2$plot = as.factor("# of active joints"); -cdata3$plot = as.factor("Total size"); -cdata4$plot = as.factor("# of extremities"); -cdata5$plot = as.factor("# of inputs"); -cdata6$plot = as.factor("# of hidden neurons"); -cdata7$plot = as.factor("# of connections"); - -# Fitness over generations -ggplot(cdata, aes(births)) + - facet_grid(plot~., scale="free") + - geom_line(aes(y=fit, colour=exp)) + - geom_ribbon(aes(ymin=fit-fsd, ymax=fit+fsd, fill=exp), alpha=0.1, linetype=0) + - - geom_line(data=cdata1, aes(y=joints, colour=exp)) + - geom_ribbon(data=cdata1, aes(ymin=joints-jsd, ymax=joints+jsd, fill=exp), alpha=0.1, linetype=0) + - - geom_line(data=cdata2, aes(y=motors, colour=exp)) + - geom_ribbon(data=cdata2, aes(ymin=motors-jsd, ymax=motors+jsd, fill=exp), alpha=0.1, linetype=0) + - - geom_line(data=cdata3, aes(y=sz, colour=exp)) + - geom_ribbon(data=cdata3, aes(ymin=sz-ssd, ymax=sz+ssd, fill=exp), alpha=0.1, linetype=0) + - - geom_line(data=cdata4, aes(y=ext, colour=exp)) + - geom_ribbon(data=cdata4, aes(ymin=ext-esd, ymax=ext+esd, fill=exp), alpha=0.1, linetype=0) + - - geom_line(data=cdata5, aes(y=inp, colour=exp)) + - geom_ribbon(data=cdata5, aes(ymin=inp-isd, ymax=inp+isd, fill=exp), alpha=0.1, linetype=0) + - - geom_line(data=cdata6, aes(y=hid, colour=exp)) + - geom_ribbon(data=cdata6, aes(ymin=hid-hsd, ymax=hid+hsd, fill=exp), alpha=0.1, linetype=0) + - - geom_line(data=cdata7, aes(y=con, colour=exp)) + - geom_ribbon(data=cdata7, aes(ymin=con-csd, ymax=con+csd, fill=exp), alpha=0.1, linetype=0) + - - scale_fill_discrete(name="Experiment") + - scale_colour_discrete(name="Experiment") + - xlab("# of births") + - ylab(""); - -#last_gens = cdata[cdata$gen==max(cdata$gen),]; - -# Retrieve all the best robots per experiment -# See http://stackoverflow.com/questions/6289538/aggregate-a-dataframe-on-a-given-column-and-display-another-column -exp_maxes = do.call(rbind,lapply(split(data, list(data$exp, data$run)),function(chunk) chunk[which.max(chunk$fitness),])) -exp_maxes = exp_maxes[order(-exp_maxes$fitness),] - -exp_states = ddply(data, ~exp+run, summarise, cur_gen=max(gen)); -exp_states = exp_states[order(exp_states$exp, -exp_states$run),]; - -exp_states From f834b2ba8f8af40190061027019db43de4498d5a Mon Sep 17 00:00:00 2001 From: raki123 Date: Wed, 23 Nov 2016 15:00:07 +0100 Subject: [PATCH 10/10] added RLPower learner combined with ExtNN --- cpp/CMakeLists.txt | 1 + cpp/tol/plugin/RobotController.cpp | 5 +- cpp/tol/plugin/rlpowered_network.cpp | 81 ++++++++++++++++++++++++++++ cpp/tol/plugin/rlpowered_network.h | 61 +++++++++++++++++++++ 4 files changed, 146 insertions(+), 2 deletions(-) create mode 100644 cpp/tol/plugin/rlpowered_network.cpp create mode 100644 cpp/tol/plugin/rlpowered_network.h diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index d45392a..ef21039 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -67,6 +67,7 @@ file(GLOB_RECURSE tol/plugin/rlpower.cpp tol/plugin/simple_split_brain.cpp tol/plugin/extended_neural_network.cpp + tol/plugin/rlpowered_network.cpp ) add_library(tolworldcontrol SHARED ${TOL_WORLD_SRC}) diff --git a/cpp/tol/plugin/RobotController.cpp b/cpp/tol/plugin/RobotController.cpp index 361afcf..ba4c692 100644 --- a/cpp/tol/plugin/RobotController.cpp +++ b/cpp/tol/plugin/RobotController.cpp @@ -9,6 +9,7 @@ #include "rlpower.h" #include "simple_split_brain.h" #include "extended_neural_network.h" +#include "rlpowered_network.h" #include @@ -37,9 +38,9 @@ void RobotController::LoadBrain(sdf::ElementPtr sdf) std::cerr << "Brain does not define type, this is probably an error." << std::endl; return; } - if (brain->GetAttribute("algorithm")->GetAsString() == "rlpower") { - brain_.reset(new tol::RLPower(this->model->GetName(), brain,evaluator_, motors_, sensors_)); +// brain_.reset(new tol::RLPower(this->model->GetName(), brain,evaluator_, motors_, sensors_)); + brain_.reset(new tol::RLPowerNet(this->model->GetName(), brain,evaluator_, motors_, sensors_)); // brain_. reset(new tol::ExtNN(this->model->GetName(), evaluator_, brain, motors_, sensors_)); // brain_.reset(new tol::ExtendedNeuralNetwork(this->model->GetName(), evaluator_, brain, motors_, sensors_)); } else { diff --git a/cpp/tol/plugin/rlpowered_network.cpp b/cpp/tol/plugin/rlpowered_network.cpp new file mode 100644 index 0000000..766d9ea --- /dev/null +++ b/cpp/tol/plugin/rlpowered_network.cpp @@ -0,0 +1,81 @@ +// +// Created by Milan Jelisavcic on 28/03/16. +// + +#include "rlpowered_network.h" +#include "simple_split_brain.h" +#include "helper.h" +#include "revolve/gazebo/motors/Motor.h" +#include "revolve/gazebo/sensors/Sensor.h" + +namespace tol { + + std::vector forController(std::vector> toConvert) { + return toConvert[0]; + } + std::vector> forLearner(std::vector toConvert) { + return std::vector>(1,toConvert); + } + + RLPowerNet::RLPowerNet(std::string modelName, + sdf::ElementPtr brain, + EvaluatorPtr evaluator, + std::vector &actuators, + std::vector &sensors) : + revolve::brain::ConvSplitBrain, std::vector>>(&forController, &forLearner) { + boost::shared_ptr swap1(new revolve::brain::ExtNNController(modelName, + ExtNN::parseSDF(brain, actuators, sensors), + evaluator, + Helper::createWrapper(actuators), + Helper::createWrapper(sensors))); + controller = boost::static_pointer_cast>>(swap1); + boost::shared_ptr swap2(new revolve::brain::RLPowerLearner(modelName, + parseSDF(brain), + 1)); + learner = boost::static_pointer_cast>>>(swap2); + evaluator_ = evaluator; + } + + RLPowerNet::~RLPowerNet() { } + + void RLPowerNet::update(const std::vector &actuators, + const std::vector &sensors, + double t, + double step) { + revolve::brain::ConvSplitBrain,std::vector>>::update( + Helper::createWrapper(actuators), + Helper::createWrapper(sensors), + t, step + ); + } + + revolve::brain::RLPowerLearner::Config RLPowerNet::parseSDF(sdf::ElementPtr brain) { + revolve::brain::RLPowerLearner::Config config; + + // Read out brain configuration attributes + config.algorithm_type = brain->HasAttribute("type") ? brain->GetAttribute("type")->GetAsString() : "A"; + + config.evaluation_rate = brain->HasAttribute("evaluation_rate") ? + std::stod(brain->GetAttribute("evaluation_rate")->GetAsString()) : + revolve::brain::RLPowerLearner::EVALUATION_RATE; + config.interpolation_spline_size = brain->HasAttribute("interpolation_spline_size") ? + std::stoul(brain->GetAttribute("interpolation_spline_size")->GetAsString()) : + revolve::brain::RLPowerLearner::INTERPOLATION_CACHE_SIZE; + config.max_evaluations = brain->HasAttribute("max_evaluations") ? + std::stoul(brain->GetAttribute("max_evaluations")->GetAsString()) : + revolve::brain::RLPowerLearner::MAX_EVALUATIONS; + config.max_ranked_policies = brain->HasAttribute("max_ranked_policies") ? + std::stoul(brain->GetAttribute("max_ranked_policies")->GetAsString()) : + revolve::brain::RLPowerLearner::MAX_RANKED_POLICIES; + config.noise_sigma = 10; + config.sigma_tau_correction = brain->HasAttribute("sigma_tau_correction") ? + std::stod(brain->GetAttribute("sigma_tau_correction")->GetAsString()) : + revolve::brain::RLPowerLearner::SIGMA_TAU_CORRECTION; + config.source_y_size = 6; + config.update_step = 0; + config.policy_load_path = ""; + + return config; + } + +} /* namespace tol */ diff --git a/cpp/tol/plugin/rlpowered_network.h b/cpp/tol/plugin/rlpowered_network.h new file mode 100644 index 0000000..c2480ec --- /dev/null +++ b/cpp/tol/plugin/rlpowered_network.h @@ -0,0 +1,61 @@ +// +// Created by Milan Jelisavcic on 28/03/16. +// + +#ifndef REVOLVE_GAZEBO_BRAIN_REINFORCEDLEARNING_NETWORK_H +#define REVOLVE_GAZEBO_BRAIN_REINFORCEDLEARNING_NETWORK_H + +#include "brain/split_cpg/converting_split_brain.h" +#include "brain/split_cpg/rlpower_learner.h" +#include "brain/split_cpg/extended_neural_network_controller.h" +#include "evaluator.h" +#include "revolve/gazebo/brain/Brain.h" + +#include +#include + +#include +#include + +namespace tol { + + class RLPowerNet : public revolve::gazebo::Brain, private revolve::brain::ConvSplitBrain,std::vector>> { + + public: + /** + * The RLPower constructor reads out configuration file, deretmines which algorithm type to apply and + * initialises new policy. + * @param modelName: name of a robot + * @param brain: configuration file + * @param evaluator: pointer to fitness evaluatior + * @param n_actuators: number of actuators + * @param n_sensors: number of sensors + * @return pointer to the RLPower class object + */ + RLPowerNet(std::string modelName, + sdf::ElementPtr brain, + tol::EvaluatorPtr evaluator, + std::vector &actuators, + std::vector &sensors); + + virtual ~RLPowerNet(); + + /** + * Method for updating sensors readings, actuators positions, ranked list of policies and generating new policy + * @param actuators: vector list of robot's actuators + * @param sensors: vector list of robot's sensors + * @param t: + * @param step: + */ + virtual void update(const std::vector &actuators, + const std::vector &sensors, + double t, + double step); + + static revolve::brain::RLPowerLearner::Config parseSDF(sdf::ElementPtr brain); + }; + +} /* namespace tol */ + +#endif //REVOLVE_GAZEBO_BRAIN_REINFORCEDLEARNING_NETWORK_H +