Skip to content
This repository has been archived by the owner on Nov 22, 2018. It is now read-only.

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystucki committed Nov 17, 2016
2 parents 97bb1ab + 298f093 commit ea47a92
Show file tree
Hide file tree
Showing 68 changed files with 2,041 additions and 785 deletions.
10 changes: 9 additions & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
configuration:
- Release

build_script:
- msbuild %solution_name%
- msbuild %solution_name%

test_script:
- C:\projects\jnf-neat\x64\Release\xor_two_bits.exe
- C:\projects\jnf-neat\x64\Release\xor_three_bits.exe
- C:\projects\jnf-neat\x64\Release\EvenNumbers.exe
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -410,3 +410,5 @@ cmake_install.cmake
install_manifest.txt
Testing/
*.cmake
cmake-build-debug/

7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ addons:
sources:
- ubuntu-toolchain-r-test
script:
- cmake -DCMAKE_CXX_COMPILER=g++-6 CMakeLists.txt
- make
- travis_wait make test
- cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=g++-6 .
- make
- ctest --verbose

7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,20 @@ endif()

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/out/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/out/tests)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall")

set(CMAKE_C_FLAGS -fPIC)
set(CMAKE_CXX_FLAGS -fPIC)

add_subdirectory(Core)

add_library(Hippocrates SHARED $<TARGET_OBJECTS:Core>)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)

target_link_libraries(Hippocrates -lstdc++fs)
target_link_libraries(Hippocrates Threads::Threads)

enable_testing()
add_subdirectory(Tests)

2 changes: 1 addition & 1 deletion Core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
file(GLOB SOURCES Sources/Headers/*.h Sources/Implementations/*.cpp)
file(GLOB_RECURSE SOURCES [RELATIVE Sources] *.cpp *.hpp *.c *.h)
add_library(Core SHARED OBJECT ${SOURCES})
41 changes: 26 additions & 15 deletions Core/Core.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,15 @@
<AdditionalIncludeDirectories>
</AdditionalIncludeDirectories>
<AdditionalOptions>/DLL %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions> _UNICODE;UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions> _UNICODE;UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
Expand All @@ -94,6 +96,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions> _UNICODE;UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
Expand All @@ -107,40 +110,48 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions> _UNICODE;UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="Sources\Headers\body.h" />
<ClInclude Include="Sources\Headers\gene.h" />
<ClInclude Include="Sources\Headers\genome.h" />
<ClInclude Include="Sources\Headers\logger.h" />
<ClInclude Include="Sources\Headers\neural_network.h" />
<ClInclude Include="Sources\Headers\neural_network_trainer.h" />
<ClInclude Include="Sources\Headers\neuron.h" />
<ClInclude Include="Sources\Headers\organism.h" />
<ClInclude Include="Sources\Headers\species.h" />
<ClInclude Include="Sources\Headers\species_manager.h" />
<ClInclude Include="Sources\Headers\supervised_training_body.h" />
<ClInclude Include="Sources\Headers\trained_neural_network.h" />
<ClInclude Include="Sources\Headers\training_data.h" />
<ClInclude Include="Sources\Headers\training_parameters.h" />
<ClInclude Include="Sources\Headers\body.hpp" />
<ClInclude Include="Sources\Headers\gene.hpp" />
<ClInclude Include="Sources\Headers\genome.hpp" />
<ClInclude Include="Sources\Headers\innovation_cacher.hpp" />
<ClInclude Include="Sources\Headers\jsmn.h" />
<ClInclude Include="Sources\Headers\logger.hpp" />
<ClInclude Include="Sources\Headers\neural_network.hpp" />
<ClInclude Include="Sources\Headers\neural_network_trainer.hpp" />
<ClInclude Include="Sources\Headers\neuron.hpp" />
<ClInclude Include="Sources\Headers\organism.hpp" />
<ClInclude Include="Sources\Headers\species.hpp" />
<ClInclude Include="Sources\Headers\species_manager.hpp" />
<ClInclude Include="Sources\Headers\supervised_training_body.hpp" />
<ClInclude Include="Sources\Headers\trained\classifier.hpp" />
<ClInclude Include="Sources\Headers\trained\trained_neural_network.hpp" />
<ClInclude Include="Sources\Headers\training_data.hpp" />
<ClInclude Include="Sources\Headers\training_parameters.hpp" />
<ClInclude Include="Sources\Headers\type.hpp" />
<ClInclude Include="Sources\Headers\utility.hpp" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="Sources\Implementations\gene.cpp" />
<ClCompile Include="Sources\Implementations\genome.cpp" />
<ClCompile Include="Sources\Implementations\innovation_cacher.cpp" />
<ClCompile Include="Sources\Implementations\jsmn.c" />
<ClCompile Include="Sources\Implementations\logger.cpp" />
<ClCompile Include="Sources\Implementations\neural_network.cpp" />
<ClCompile Include="Sources\Implementations\neural_network_trainer.cpp" />
<ClCompile Include="Sources\Implementations\neuron.cpp" />
<ClCompile Include="Sources\Implementations\organism.cpp" />
<ClCompile Include="Sources\Implementations\species.cpp" />
<ClCompile Include="Sources\Implementations\species_manager.cpp" />
<ClCompile Include="Sources\Implementations\trained_neural_network.cpp" />
<ClCompile Include="Sources\Implementations\training_parameters.cpp" />
<ClCompile Include="Sources\Implementations\utility.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
58 changes: 41 additions & 17 deletions Core/Core.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -9,48 +9,66 @@
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Headers\trained">
<UniqueIdentifier>{1b3a181c-c7b8-45a2-a69a-d9d44c2916a2}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Sources\Headers\body.h">
<ClInclude Include="Sources\Headers\utility.hpp">
<Filter>Headers</Filter>
</ClInclude>
<ClInclude Include="Sources\Headers\body.hpp">
<Filter>Headers</Filter>
</ClInclude>
<ClInclude Include="Sources\Headers\gene.hpp">
<Filter>Headers</Filter>
</ClInclude>
<ClInclude Include="Sources\Headers\gene.h">
<ClInclude Include="Sources\Headers\genome.hpp">
<Filter>Headers</Filter>
</ClInclude>
<ClInclude Include="Sources\Headers\genome.h">
<ClInclude Include="Sources\Headers\logger.hpp">
<Filter>Headers</Filter>
</ClInclude>
<ClInclude Include="Sources\Headers\logger.h">
<ClInclude Include="Sources\Headers\neural_network.hpp">
<Filter>Headers</Filter>
</ClInclude>
<ClInclude Include="Sources\Headers\neural_network.h">
<ClInclude Include="Sources\Headers\neural_network_trainer.hpp">
<Filter>Headers</Filter>
</ClInclude>
<ClInclude Include="Sources\Headers\neural_network_trainer.h">
<ClInclude Include="Sources\Headers\neuron.hpp">
<Filter>Headers</Filter>
</ClInclude>
<ClInclude Include="Sources\Headers\neuron.h">
<ClInclude Include="Sources\Headers\organism.hpp">
<Filter>Headers</Filter>
</ClInclude>
<ClInclude Include="Sources\Headers\organism.h">
<ClInclude Include="Sources\Headers\species.hpp">
<Filter>Headers</Filter>
</ClInclude>
<ClInclude Include="Sources\Headers\species.h">
<ClInclude Include="Sources\Headers\species_manager.hpp">
<Filter>Headers</Filter>
</ClInclude>
<ClInclude Include="Sources\Headers\trained_neural_network.h">
<ClInclude Include="Sources\Headers\supervised_training_body.hpp">
<Filter>Headers</Filter>
</ClInclude>
<ClInclude Include="Sources\Headers\training_parameters.h">
<ClInclude Include="Sources\Headers\training_data.hpp">
<Filter>Headers</Filter>
</ClInclude>
<ClInclude Include="Sources\Headers\species_manager.h">
<ClInclude Include="Sources\Headers\training_parameters.hpp">
<Filter>Headers</Filter>
</ClInclude>
<ClInclude Include="Sources\Headers\supervised_training_body.h">
<ClInclude Include="Sources\Headers\jsmn.h">
<Filter>Headers</Filter>
</ClInclude>
<ClInclude Include="Sources\Headers\training_data.h">
<ClInclude Include="Sources\Headers\innovation_cacher.hpp">
<Filter>Headers</Filter>
</ClInclude>
<ClInclude Include="Sources\Headers\trained\classifier.hpp">
<Filter>Headers\trained</Filter>
</ClInclude>
<ClInclude Include="Sources\Headers\trained\trained_neural_network.hpp">
<Filter>Headers\trained</Filter>
</ClInclude>
<ClInclude Include="Sources\Headers\type.hpp">
<Filter>Headers</Filter>
</ClInclude>
</ItemGroup>
Expand Down Expand Up @@ -79,14 +97,20 @@
<ClCompile Include="Sources\Implementations\species.cpp">
<Filter>Implementations</Filter>
</ClCompile>
<ClCompile Include="Sources\Implementations\trained_neural_network.cpp">
<Filter>Implementations</Filter>
</ClCompile>
<ClCompile Include="Sources\Implementations\training_parameters.cpp">
<Filter>Implementations</Filter>
</ClCompile>
<ClCompile Include="Sources\Implementations\species_manager.cpp">
<Filter>Implementations</Filter>
</ClCompile>
<ClCompile Include="Sources\Implementations\jsmn.c">
<Filter>Implementations</Filter>
</ClCompile>
<ClCompile Include="Sources\Implementations\utility.cpp">
<Filter>Implementations</Filter>
</ClCompile>
<ClCompile Include="Sources\Implementations\innovation_cacher.cpp">
<Filter>Implementations</Filter>
</ClCompile>
</ItemGroup>
</Project>
9 changes: 5 additions & 4 deletions Core/Sources/Headers/body.h → Core/Sources/Headers/body.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once
#include <vector>
#include "type.hpp"

namespace Hippocrates {

Expand All @@ -14,16 +15,16 @@ class IBody {
virtual auto operator=(IBody&&)&->IBody& = default;

virtual auto Reset() -> void = 0;
virtual auto Update(const std::vector<float>& networkOutputs) -> void = 0;
virtual auto Update(const Type::neuron_values_t& networkOutputs) -> void = 0;
virtual auto HasFinishedTask() const -> bool = 0;
virtual auto GetFitness() const -> double = 0;
virtual auto GetFitness() const -> Type::fitness_t = 0;

virtual auto ProvideNetworkWithInputs() const -> std::vector<float> = 0;
virtual auto ProvideNetworkWithInputs() const -> Type::neuron_values_t= 0;

virtual auto GetInputCount() const -> std::size_t = 0;
virtual auto GetOutputCount() const -> std::size_t = 0;

virtual auto GetMaximumFitness() const -> double = 0;
virtual auto GetMaximumFitness() const ->Type::fitness_t = 0;
};

}
14 changes: 8 additions & 6 deletions Core/Sources/Headers/gene.h → Core/Sources/Headers/gene.hpp
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
#pragma once
#include <cstddef>
#include <string>
#include "../Headers/utility.hpp"
#include "../Headers/type.hpp"

namespace Hippocrates {

struct Gene {
public:
Gene();
Gene(const Gene& other) = default;
Gene(Gene&& other) = default;
Gene(std::string json);
~Gene() = default;

auto operator=(const Gene& other) -> Gene& = default;
auto operator=(Gene&& other) -> Gene& = default;
auto operator==(const Gene& other) const -> bool;

auto SetRandomWeight() -> void;
auto GetJSON() const->std::string;

std::size_t from = 0;
std::size_t to = 0;
float weight = 0.0f;
std::size_t historicalMarking = numberOfExistingGenes++;
Type::connection_weight_t weight = 0.0f;
static constexpr auto invalidHistoricalMarking = std::numeric_limits<std::size_t>::max();
std::size_t historicalMarking = invalidHistoricalMarking;
bool isEnabled = true;
bool isRecursive = false;

private:
static std::size_t numberOfExistingGenes;
};

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "gene.h"
#include "training_parameters.h"
#include "gene.hpp"
#include "training_parameters.hpp"
#include <vector>

namespace Hippocrates {
Expand All @@ -13,11 +13,15 @@ class Genome {
std::size_t inputCount = 0U;
std::size_t outputCount = 0U;
std::size_t neuronCount = 0U;
auto ParseGenesJson(std::string json) -> std::vector<Gene>;

public:
explicit Genome(std::size_t inputCount, std::size_t outputCount, TrainingParameters parameters);
explicit Genome(std::string json);
explicit Genome() = default;
Genome(const Genome& other) = default;
Genome(Genome&& other) = default;

~Genome() = default;

auto operator=(const Genome& other) -> Genome& = default;
Expand All @@ -41,7 +45,7 @@ class Genome {
auto InsertGeneAt(Gene gene, size_t index) -> void;

auto GetTrainingParameters() const -> const TrainingParameters& { return parameters; }
auto GetGeneticalDistanceFrom(const Genome& other) const -> double;
auto GetGeneticalDistanceFrom(const Genome& other) const -> Type::connection_weight_t;
auto DoesContainGene(const Gene& gene) const -> bool;
auto GetJSON() const->std::string;

Expand Down
24 changes: 24 additions & 0 deletions Core/Sources/Headers/innovation_cacher.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once
#include <vector>
#include <type_traits>
#include "genome.hpp"

namespace Hippocrates {

class InnovationCacher {
public:
auto AssignAndCacheHistoricalMarkings(Genome& genome) -> void;
auto AssignAndCacheHistoricalMarking(Gene& gene) -> void;
auto Clear() -> void;

private:
std::vector<Gene> cache;
using cache_iterator = decltype(cache)::iterator;
std::size_t nextHighestHistoricalMarking = 0;

private:
auto GetAndIncrementNextHighestHistoricalMarking() -> std::size_t;
auto FindGeneInCache(const Gene& gene) -> cache_iterator;
};

}
Loading

0 comments on commit ea47a92

Please sign in to comment.