Browse Source

tested base modules

Willi Zschiebsch 4 years ago
parent
commit
b3491fb38e

+ 1 - 1
lib/CMakeLists.txt

@@ -31,7 +31,7 @@ add_library(${PROJECT_NAME} STATIC
         src/ModuleHTTP.cpp
         src/ModuleMath.cpp
 	src/ModuleMerge.cpp
-	src/ModuleParameter.cpp
+	src/Parameter.cpp
 	src/ModuleSplitt.cpp
         src/ModuleSQL.cpp
         src/ModuleSwitch.cpp

+ 1 - 6
lib/include/Connector.h

@@ -6,12 +6,7 @@
 #include "Input.h"
 #include "Output.h"
 
-#include "ModuleMerge.h"
-#include "ModuleSplitt.h"
-#include "ModuleSQL.h"
-#include "ModuleSwitch.h"
-
-#include "ProcessorStandard.h"
+#include <Registration.h>
 
 namespace mdd {
 	class Connector {

+ 2 - 2
lib/include/IManager.h

@@ -4,9 +4,9 @@ namespace mdd {
 	class IManager {
 	public:
 		virtual bool configure(const std::string& config) = 0;
-		virtual std::string getBaseConfiguration() = 0;
+		virtual std::string getConfiguration() = 0;
 		//virtual std::string getGeneratorID() = 0;
-		virtual void load(const json& json) = 0;
+		virtual void load(const json& j) = 0;
 		virtual json dump() = 0;
 	};
 }

+ 2 - 0
lib/include/IModule.h

@@ -31,6 +31,8 @@ namespace mdd {
         virtual std::shared_ptr<IOutput> getOutput(const std::string& id) = 0;
         virtual std::shared_ptr<IOutput> getOutput(size_t index) = 0;
 
+        virtual std::vector<std::shared_ptr<IInput>> getOptimizableInputs() = 0;
+        virtual std::vector<std::shared_ptr<IOutput>> getOptimizableOutputs() = 0;
 
         //virtual std::vector <std::vector <std::shared_ptr<IInput>>> getConnectionsOf(Input) = 0;
         //virtual std::vector <std::shared_ptr<IInput>> getOptimizable() = 0;

+ 4 - 1
lib/include/IOptimizer.h

@@ -2,9 +2,12 @@
 #define IOPTIMIZER_H
 #include "json.hpp"
 #include <IModule.h>
+#include "IManager.h"
 
 namespace mdd {
-	class IOptimizer {
+	class IOptimizer
+		: public IManager
+	{
 		public:
 			//virtual bool connect(std::shared_ptr<IModule> module) = 0;
 			/*

+ 3 - 3
lib/include/IProcessor.h

@@ -1,7 +1,7 @@
 #pragma once
 
 #include "IModule.h"
-#include "ModuleParameter.cpp"
+#include "Parameter.cpp"
 #include <vector>
 
 namespace mdd
@@ -11,8 +11,8 @@ namespace mdd
         virtual std::string addModule(std::shared_ptr<IModule> module) = 0;
         virtual void  removeModule(std::shared_ptr<IModule> module) = 0;
 
-        virtual std::vector<std::shared_ptr<ModuleParameter>>& getInputParams() = 0;
-        virtual std::vector<std::shared_ptr<ModuleParameter>>& getOutputParams() = 0;
+        virtual std::vector<std::shared_ptr<Parameter>>& getInputParams() = 0;
+        virtual std::vector<std::shared_ptr<Parameter>>& getOutputParams() = 0;
 
         virtual std::vector<std::shared_ptr<IModule >>& getModules() = 0;
  

+ 4 - 1
lib/include/ModuleBase.h

@@ -23,7 +23,7 @@ namespace mdd {
 
     public:
         bool configure(const std::string& config) { return true; };
-        std::string getBaseConfiguration();
+        std::string getConfiguration() override;
 
         size_t getNumInputs() override;
         size_t getNumOutputs() override;
@@ -32,6 +32,9 @@ namespace mdd {
         std::shared_ptr<IInput> getInput(const std::string& id) override;
         std::shared_ptr<IOutput> getOutput(size_t index) override;
         std::shared_ptr<IOutput> getOutput(const std::string& id) override;
+
+        std::vector<std::shared_ptr<IInput>> getOptimizableInputs() override;
+        std::vector<std::shared_ptr<IOutput>> getOptimizableOutputs() override;
         
         std::string setType(const std::string& type) override;
         std::string getType() override;

+ 11 - 2
lib/include/OptimizerBase.h

@@ -9,8 +9,11 @@ namespace mdd {
 	//Optimization is always minimization!
 	//
 	////////////////////////////////////////////////////////////
-	class OptimizerBase : public IOptimizer {
+	class OptimizerBase 
+		: public IOptimizer 
+	{
 	protected:
+		std::string _base_config = "";
 		std::shared_ptr<IModule> _module;
 		std::vector<std::shared_ptr<IInput>> _inputs;
 		std::vector<std::shared_ptr<IOutput>> _outputs;
@@ -22,10 +25,16 @@ namespace mdd {
 			double opt_value = 0;
 		};
 		opt_state updateOutputs();
-		
+		OptimizerBase(const std::string& base_config);
 	public:
 		void updateLayout();
 		bool setEvaluation(std::string func) override;
+
+		bool configure(const std::string& config);
+		std::string getBaseConfiguration();
+		//virtual std::string getGeneratorID() = 0;
+		void load(const json& j);
+		json dump();
 		//state update() override;
 	};
 }

+ 0 - 49
lib/include/OptimizerEvolutionary.h

@@ -1,49 +0,0 @@
-#ifndef OPTIMIZEREVOLUTIONARY_H
-#define OPTIMIZEREVOLUTIONARY_H
-#include "OptimizerBase.h"
-
-namespace mdd {
-	class OptimizerEvolutionary : public OptimizerBase {
-	public:
-		struct Individual {
-		public:
-			std::vector<std::vector<double>> dna;
-			double fitness = 0;
-			bool operator== (const Individual& ind) {
-				return (dna == ind.dna) && (fitness == ind.fitness);
-			};
-		};
-	protected:
-		static int random_num(double min, double max, double inc = 1.0)
-		{
-			int range = (max - min)/inc + 1;
-			return min + inc*(std::rand() % range);
-		}
-
-		Individual generateIndividual();
-		Individual combine(Individual par1, Individual par2);
-
-		std::vector<Individual> _children;
-		Individual _best;
-		int _min_generations;
-		double _max_fitness;
-		size_t _grow_generation;
-		size_t _converges;
-
-		void evolve(std::vector<Individual> parents);
-		void evaluate(size_t ignore_len = 0);
-		std::vector<double> mutateGene(std::shared_ptr<IInput> input, std::vector<double> seed = std::vector<double>());
-		
-
-	public:
-		OptimizerEvolutionary(std::shared_ptr<IModule> module,
-			size_t converges = 0,
-			size_t grow_generation = 20,
-			double max_fitness = 0.0,
-			int min_generations = -1);
-		std::vector<std::vector<double>> update() override;
-		Individual getBest();
-		double evaluateFitness(const Individual& ind);
-	};
-}
-#endif

+ 12 - 9
lib/include/ProcessorBase.h

@@ -1,5 +1,5 @@
-#ifndef MDD_PROCESSORBASE_H
-#define MDD_PROCESSORBASE_H
+/*
+#pragma once
 
 #include <list>
 #include "Input.h"
@@ -22,12 +22,12 @@ namespace mdd {
         std::vector<std::shared_ptr<Input>>processor_inputs;
         std::vector<std::shared_ptr<Output>> processor_outputs;
         std::vector<std::shared_ptr<IModule>> modules;
-        std::vector<std::shared_ptr<ModuleParameter>> inputs;
-        std::vector<std::shared_ptr<ModuleParameter>> outputs;
+        std::vector<std::shared_ptr<Parameter>> inputs;
+        std::vector<std::shared_ptr<Parameter>> outputs;
 
     public:
-        bool configure(const std::string& config) { return true; };
-        std::string getBaseConfiguration() override;
+        bool configure(const std::string& config);
+        std::string getConfiguration() override;
 
         std::string getID() override ;
         std::string setType(const std::string& type) override;
@@ -39,8 +39,8 @@ namespace mdd {
         std::string addModule(std::shared_ptr<IModule> module) override ;
         void removeModule(std::shared_ptr<IModule> module) override;
 
-        std::vector<std::shared_ptr<ModuleParameter>>& getInputParams() override;
-        std::vector<std::shared_ptr<ModuleParameter>>& getOutputParams() override;
+        std::vector<std::shared_ptr<Parameter>>& getInputParams() override;
+        std::vector<std::shared_ptr<Parameter>>& getOutputParams() override;
 
         size_t getNumInputs() override;
         size_t getNumOutputs() override;
@@ -48,6 +48,9 @@ namespace mdd {
         std::shared_ptr<IInput> getInput(size_t index) override;
         std::shared_ptr<IOutput> getOutput(const std::string& id) override;
         std::shared_ptr<IOutput> getOutput(size_t index) override;
+
+        std::vector<std::shared_ptr<IInput>> getOptimizableInputs() override;
+        std::vector<std::shared_ptr<IOutput>> getOptimizableOutputs() override;
         
         std::vector<std::shared_ptr<IModule >>& getModules();
         size_t getNumModuls() override;
@@ -60,4 +63,4 @@ namespace mdd {
         json dump() override;
     };
 }
-#endif
+//*/

+ 27 - 1
lib/src/ModuleBase.cpp

@@ -54,13 +54,39 @@ namespace mdd {
         return nullptr;
     }
 
+    std::vector<std::shared_ptr<IInput>> ModuleBase::getOptimizableInputs() {
+        std::vector<std::shared_ptr<IInput>> ret;
+        for (size_t i = 0; i < inputs.size(); i++)
+        {
+            if (inputs[i]->isOptimizable())
+            {
+                ret.push_back(inputs[i]);
+            }
+        }
+        
+        return ret;
+    }
+
+    std::vector<std::shared_ptr<IOutput>> ModuleBase::getOptimizableOutputs() {
+        std::vector<std::shared_ptr<IOutput>> ret;
+        for (size_t i = 0; i < outputs.size(); i++)
+        {
+            if (outputs[i]->isOptimizable())
+            {
+                ret.push_back(outputs[i]);
+            }
+        }
+        
+        return ret;
+    }
+
     ModuleBase::ModuleBase(const std::string& base_config)
         : _base_config(base_config)
     {
 
     }
 
-    std::string ModuleBase::getBaseConfiguration()
+    std::string ModuleBase::getConfiguration()
     {
         return _base_config;
     }

+ 43 - 10
lib/src/ModuleHTTP.cpp

@@ -37,6 +37,7 @@ namespace mdd{
         ~ModuleHTTP();
         state update() override;
         bool configure(const std::string& config) override;
+        std::string ModuleHTTP::getConfiguration() override;
     };
 
     bool ModuleHTTP::connect(){
@@ -97,10 +98,10 @@ namespace mdd{
             size_t length = vec.size();
             if (server[length]["value"].is_array())
             {
-                vec.emplace_back(server[length]["type"].get<std::string>(), length, server_inputs[length]["value"].get<std::vector<double>>());
+                vec.push_back(std::make_shared<T>(this, server[length]["type"].get<std::string>(), length, server[length]["value"].get<std::vector<double>>()));
             }
             else {
-                vec.emplace_back(server[length]["type"].get<std::string>(), length, std::vector<double>{server_inputs[length]["value"].get<double>()});
+                vec.push_back(std::make_shared<T>(this, server[length]["type"].get<std::string>(), length, std::vector<double>{server[length]["value"].get<double>()}));
                 std::cout << "Warning: Server expects single values, but mdd work with arrays!" << std::endl;
             }
         }
@@ -117,7 +118,7 @@ namespace mdd{
         });
         assert(res->body.empty());
         body = std::string(R"()") + body;
-        updateVectorOf(inputs, body);
+        return updateVectorOf(inputs, body);
     }
     state ModuleHTTP::updateOutputs() {
         Client cli(_id, _port);
@@ -131,21 +132,22 @@ namespace mdd{
 
         assert(res->body.empty());
         body = std::string(R"()") + body;
-        updateVectorOf(outputs, body);
+        return updateVectorOf(outputs, body);
     }
 
     ModuleHTTP::ModuleHTTP()// std::string fname, std::string id, int port):
         : ModuleBase(R"JSON(
         [{
-            "name":"url",
-            "value":""
+            "name":"file",
+            "value": ""
         },{
-            "name":"port",
-            "value":256
+            "name": "url",
+            "value": ""
         },{
-            "name":"file",
-            "value":""
+            "name":"port",
+            "value": 0
         }])JSON")
+        ,_port(0)
     {
         setType("HTTP");
     }
@@ -200,6 +202,37 @@ namespace mdd{
         return found;
     }
 
+    std::string ModuleHTTP::getConfiguration() {
+        json ret = json::parse(ModuleBase::getConfiguration());
+        for (size_t i = 0; i < ret.size(); i++)
+        {
+            if (ret[i].contains("name"))
+            {
+                if (ret[i]["name"].get<std::string>() == "url")
+                {
+                    ret[i]["value"] = _id;
+                }
+                else if (ret[i]["name"].get<std::string>() == "port")
+                {
+                    ret[i]["value"] = _port;
+                }
+                else if (ret[i]["name"].get<std::string>() == "file")
+                {
+                     ret[i]["value"] = _fname;
+                }
+                else {
+                    std::cout << "ERROR Configure option: " << ret[i]["name"].dump() << " do not exist!" << std::endl;
+                    return false;
+                }
+            }
+            else {
+                std::cout << "ERROR Wrong configure format: " << ret[i].dump() << std::endl;
+                return false;
+            }
+        }
+        return ret.dump();
+    }
+
     ModuleHTTP::~ModuleHTTP()
     {
         if (_child != nullptr)

+ 17 - 4
lib/src/ModuleMath.cpp

@@ -27,6 +27,7 @@ namespace mdd {
     public:
         ModuleMath();
         bool configure(const std::string& config) override;
+        std::string getConfiguration();
         state update() override;
     };
 
@@ -34,7 +35,7 @@ namespace mdd {
         : ModuleBase(R"JSON(
         [{
             "name":"operation",
-            "value":"add"
+            "value":"add",
             "options":  [
                             "add",
                             "subtract",
@@ -52,9 +53,9 @@ namespace mdd {
         _ops.at("add");
         _operation = _ops.find("add")->second;
         std::vector<double> default_val = {1};
-        inputs.emplace_back(this, "Value", 0, default_val);
-        inputs.emplace_back(this, "Value", 1, default_val);
-        outputs.emplace_back(this, "Value", 0, default_val);
+        inputs.push_back(std::make_shared<Input>(this, "Value", 0, default_val));
+        inputs.push_back(std::make_shared<Input>(this, "Value", 1, default_val));
+        outputs.push_back(std::make_shared<Output>(this, "Value", 0, default_val));
         setType("Math");
     }
 
@@ -81,6 +82,18 @@ namespace mdd {
         return false;
     }
 
+    std::string ModuleMath::getConfiguration() {
+        json ret = json::parse(ModuleBase::getConfiguration());
+        for (auto it = _ops.begin(); it != _ops.end(); it++)
+        {
+            if (it->second(256,2) == _operation(256, 2)) {
+                ret[0]["value"] = it->first;
+                break;
+            }
+        }
+        return ret.dump();
+    }
+
     std::vector<double> ModuleMath::applyOperation(const std::vector<double>&val1, const std::vector<double>&val2) {
         std::vector<double> ret; //= json::array();
         size_t length= std::max(val1.size(), val2.size());

+ 30 - 5
lib/src/ModuleMerge.cpp

@@ -11,24 +11,26 @@ namespace mdd {
 		int removeModuleInput();
 		std::string setInputType(const std::string& input_id, const std::string& new_type);
 		bool configure(const std::string& config) override;
+		std::string getConfiguration() override;
 		state update() override;
 	};
 	ModuleMerge::ModuleMerge()
 		:ModuleBase(R"JSON(
         [{
             "name":"inputs",
-            "value":[{"type": "Value", "value": [1]}, {"type": "Value": [1]}]
+            "value":[{"type": "Value", "value": [1]}, {"type": "Value", "value": [1]}]
         }])JSON")
 	{
-		configure(getBaseConfiguration());
 		std::vector<double> default_val = { 1 };
-		outputs.emplace_back(this, "Value", 0, default_val);
+		inputs.push_back(std::make_shared<Input>(this, "Value", 0, default_val));
+		inputs.push_back(std::make_shared<Input>(this, "Value", 1, default_val));
+		outputs.push_back(std::make_shared<Output>(this, "Value", 0, default_val));
 		setType("Merge");
 	}
 
 	int ModuleMerge::addModuleInput() {
 		std::vector<double> default_val = { 1 };
-		inputs.emplace_back(this, "Value", inputs.size(), default_val);
+		inputs.push_back(std::make_shared<Input>(this, "Value", inputs.size(), default_val));
 		return inputs.size();
 	}
 
@@ -58,7 +60,7 @@ namespace mdd {
 					size_t length = inputs.size();
 					for (size_t j = length; j < config_parsed[i]["value"].size(); j++)
 					{
-						inputs.emplace_back(this, config_parsed[i]["value"][j]["type"].get<std::string>(), j, config_parsed[i]["value"][j]["value"].get<std::vector<double>>());
+						inputs.push_back(std::make_shared<Input>(this, config_parsed[i]["value"][j]["type"].get<std::string>(), j, config_parsed[i]["value"][j]["value"].get<std::vector<double>>()));
 					}
 					for (size_t j = 0; j < length; j++)
 					{
@@ -72,6 +74,29 @@ namespace mdd {
 		return false;
 	}
 
+	std::string ModuleMerge::getConfiguration() {
+		json ret = json::parse(ModuleBase::getConfiguration());
+		for (size_t i = 0; i < ret.size(); i++)
+		{
+			if (ret[i].contains("name"))
+			{
+				if (ret[i]["name"].get<std::string>() == "inputs")
+				{
+					size_t length = inputs.size();
+
+					for (size_t j = 0; j < length; j++)
+					{
+						json in;
+						in["type"] = inputs[j]->getType();
+						in["value"] = inputs[j]->getValue();
+						ret[i]["value"].push_back(in);
+					}
+				}
+			}
+		}
+		return ret.dump();
+	}
+
 	state ModuleMerge::update() {
 		std::vector<double>  ret;
 		for (size_t i = 0; i < inputs.size(); i++)

+ 22 - 6
lib/src/ModuleSQL.cpp

@@ -7,6 +7,7 @@
 namespace mdd {
 	class ModuleSQL : public ModuleBase {
 	private:
+		std::string _dbname;
 		sqlite3* _db;
 		std::string _tbname;
 		void erase_keyword(std::string& str, std::string key);
@@ -20,6 +21,7 @@ namespace mdd {
 		ModuleSQL();
 		~ModuleSQL();
 		bool configure(const std::string& config) override;
+		std::string getConfiguration() override;
 		state update() override;
 	};
 
@@ -42,7 +44,6 @@ namespace mdd {
             "value":""
         }])JSON")
 	{
-		configure(getBaseConfiguration());
 		setType("SQL");
 	}
 
@@ -91,19 +92,19 @@ namespace mdd {
 
 	bool ModuleSQL::configure(const std::string& config) {
 		json config_parsed = json::parse(config);
-		std::string dbname;
+		
 		for (size_t i = 0; i < config_parsed.size(); i++)
 		{
 			if (config_parsed[i].contains("name"))
 			{
 				if (config_parsed[i]["name"].get<std::string>() == "database")
 				{
-					dbname = config_parsed[i]["value"].get<std::string>();
+					_dbname = config_parsed[i]["value"].get<std::string>();
 				}
 			}
 		}
 		
-		int rc = sqlite3_open(dbname.c_str(), &_db);
+		int rc = sqlite3_open(_dbname.c_str(), &_db);
 		if (rc) {
 			fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(_db));
 			return false;
@@ -203,12 +204,27 @@ namespace mdd {
 		}
 		sqlite3_finalize(res);
 
-		inputs.emplace_back(this, _content[0].key, inputs.size(), std::vector<double>{0});
+		inputs.push_back(std::make_shared<Input>(this, _content[0].key, inputs.size(), std::vector<double>{0}));
 		for (auto& cont : _content)
 		{
-			outputs.emplace_back(this, cont.key, outputs.size(), std::vector<double>{1});
+			outputs.push_back(std::make_shared<Output>(this, cont.key, outputs.size(), std::vector<double>{1}));
 		}
 		
 		return true;
 	}
+
+	std::string ModuleSQL::getConfiguration() {
+		json ret = json::parse(ModuleBase::getConfiguration());
+		for (size_t i = 0; i < ret.size(); i++)
+		{
+			if (ret[i].contains("name"))
+			{
+				if (ret[i]["name"].get<std::string>() == "database")
+				{
+					ret[i]["value"] = _dbname;
+				}
+			}
+		}
+		return ret.dump();
+	}
 }

+ 22 - 7
lib/src/ModuleSwitch.cpp

@@ -6,6 +6,7 @@ namespace mdd{
     public:
         ModuleSwitch();
         bool configure(const std::string& config) override;
+        std::string getConfiguration() override;
         state update() override;
     };
     ModuleSwitch::ModuleSwitch()
@@ -16,10 +17,9 @@ namespace mdd{
         }])JSON")
     {    
         std::vector<double> default_val = { 1 };
-        inputs.emplace_back(this, "Switch", 0, default_val);
-        inputs.emplace_back(this, "Default", 0, default_val);
-        configure(getBaseConfiguration());
-        outputs.emplace_back(this, "Value", 0, default_val);
+        inputs.push_back(std::make_shared<Input>(this, "Switch", 0, default_val));
+        inputs.push_back(std::make_shared<Input>(this, "Default", 0, default_val));
+        outputs.push_back(std::make_shared<Output>(this, "Value", 0, default_val));
         setType("Switch");
     }
     bool ModuleSwitch::configure(const std::string& config) {
@@ -41,7 +41,7 @@ namespace mdd{
                         
                         for (size_t j = length_before - 1; j < length; j++)
                         {
-                            inputs.emplace_back(this, "Value", inputs.size() - 1, std::vector<double>{1});
+                            inputs.push_back(std::make_shared<Input>(this, "Value", inputs.size() - 1, std::vector<double>{1}));
                         }
                         for (size_t j = length; j < length_before-1; j++)
                         {
@@ -60,6 +60,21 @@ namespace mdd{
         return false;
     }
 
+    std::string ModuleSwitch::getConfiguration() {
+        json ret = json::parse(ModuleBase::getConfiguration());
+        for (size_t i = 0; i < ret.size(); i++)
+        {
+            if (ret[i].contains("name"))
+            {
+                if (ret[i]["name"].get<std::string>() == "size")
+                {
+                    ret[i]["value"] = inputs.size() - 1;
+                }
+            }
+        }
+        return ret.dump();
+    }
+
     state ModuleSwitch::update(){
         std::vector<double> ret;
         size_t length = getInput(0)->getValue().size();
@@ -71,8 +86,8 @@ namespace mdd{
                 index = 1;
             }
 
-            if (index > getInputs().size() - 1) {
-                index = getInputs().size() - 1;
+            if (index > inputs.size() - 1) {
+                index = inputs.size() - 1;
             }
             for (size_t j = 0; j < getInput(index)->getValue().size(); j++)
             {

+ 37 - 0
lib/src/OptimizerBase.cpp

@@ -20,6 +20,10 @@ namespace mdd{
 		return ret;
 	}
 
+	OptimizerBase::OptimizerBase(const std::string& base_config) {
+
+	}
+
 	void OptimizerBase::updateLayout()
 	{
 		_inputs = _module->getOptimizableInputs();
@@ -55,4 +59,37 @@ namespace mdd{
 		return parser.compile(func, _func_expr);
 	}
 	
+	bool OptimizerBase::configure(const std::string& config) {
+		json config_parsed = json::parse(config);
+		for (size_t i = 0; i < config_parsed.size(); i++)
+		{
+			if (config_parsed[i].contains("name"))
+			{
+				if (config_parsed[i]["name"].get<std::string>() == "operation")
+				{
+					const std::string op = config_parsed[i]["value"].get<std::string>();
+					
+				}
+			}
+		}
+
+		return false;
+	}
+	std::string OptimizerBase::getBaseConfiguration() {
+		return _base_config;
+	}
+	//virtual std::string getGeneratorID() = 0;
+	void OptimizerBase::load(const json& j) {
+		if (j.contains("configure"))
+		{
+			configure(j["configure"].get<std::string>());
+		}
+	}
+	json OptimizerBase::dump() {
+		json ret;
+
+		ret["configure"] = _base_config;
+
+		return ret;
+	}
 }

+ 67 - 7
lib/src/OptimizerEvolutionary.cpp

@@ -1,7 +1,53 @@
-#include "OptimizerEvolutionary.h"
 #include <iostream>
+#include "OptimizerBase.h"
 
 namespace mdd {
+	class OptimizerEvolutionary : public OptimizerBase {
+	public:
+		struct Individual {
+		public:
+			std::vector<std::vector<double>> dna;
+			double fitness = 0;
+			bool operator== (const Individual& ind) {
+				return (dna == ind.dna) && (fitness == ind.fitness);
+			};
+		};
+	protected:
+		static int random_num(double min, double max, double inc = 1.0)
+		{
+			int range = (max - min) / inc + 1;
+			return min + inc * (std::rand() % range);
+		}
+
+		Individual generateIndividual();
+		Individual combine(Individual par1, Individual par2);
+
+		std::vector<Individual> _children;
+		Individual _best;
+		int _min_generations;
+		double _max_fitness;
+		size_t _grow_generation;
+		size_t _converges;
+
+		void evolve(std::vector<Individual> parents);
+		void evaluate(size_t ignore_len = 0);
+		std::vector<double> mutateGene(std::shared_ptr<IInput> input, std::vector<double> seed = std::vector<double>());
+
+
+	public:
+		OptimizerEvolutionary();
+		/*
+		std::shared_ptr<IModule> module,
+			size_t converges = 0,
+			size_t grow_generation = 20,
+			double max_fitness = 0.0,
+			int min_generations = -1
+		*/
+		std::vector<std::vector<double>> update() override;
+		Individual getBest();
+		double evaluateFitness(const Individual& ind);
+	};
+
 	void OptimizerEvolutionary::evaluate(size_t ignore_len)
 	{
 		//calculate fitness
@@ -30,13 +76,27 @@ namespace mdd {
 			}
 		}
 	}
-	OptimizerEvolutionary::OptimizerEvolutionary(std::shared_ptr<IModule> module, size_t converges, size_t grow_generation, double max_fitness, int min_generations)
+	OptimizerEvolutionary::OptimizerEvolutionary()
+		:OptimizerBase(R"JSON(
+        [{
+            "name":"converges",
+            "value": 0
+        },{
+            "name":"grow_generation",
+            "value": 20
+        },{
+            "name":"max_fitness",
+            "value": 0.0
+        },{
+            "name":"min_generations",
+            "value": -1
+        }])JSON")
 	{
-		_module = module;
-		_grow_generation = grow_generation;
-		_min_generations = min_generations;
-		_max_fitness = max_fitness;
-		_converges = converges;
+		//_module = module;
+		_grow_generation = 0;
+		_min_generations = 20;
+		_max_fitness = 0.0;
+		_converges = -1;
 	}
 	std::vector<std::vector<double>> OptimizerEvolutionary::update()
 	{

+ 29 - 11
lib/src/ModuleParameter.cpp

@@ -1,46 +1,48 @@
 #include "ModuleBase.h"
 
 namespace mdd {
-    class ModuleParameter : public ModuleBase {
+    class Parameter : public ModuleBase {
     private:
-
+        IModule* _parent;
     public:
-        ModuleParameter();
+        Parameter(IModule* parent);
         state update() override;
         std::string setType(const std::string& type) override;
         std::string setAppendix(int appendix) override;
-        bool configure(const std::string& config);
+        bool configure(const std::string& config) override;
+        std::string getConfiguration() override;
     };
-    ModuleParameter::ModuleParameter()
+    Parameter::Parameter(IModule* parent)
         : ModuleBase(R"JSON(
         [{
             "name":"appendix",
             "value":0
         }])JSON")
     {
+        _parent = parent;
         std::vector<double> default_val = { 1 };
-        inputs.emplace_back("Value", 0, default_val);
-        outputs.emplace_back("Value", 0, default_val);
+        inputs.push_back(std::make_shared<Input>(parent, "Value", 0, default_val));
+        outputs.push_back(std::make_shared<Output>(parent, "Value", 0, default_val));
         setType("Parameter");
     }
 
-    state ModuleParameter::update() {
+    state Parameter::update() {
         return getOutput(0)->setValue(getInput(0)->getValue());
     }
 
-    std::string ModuleParameter::setType(const std::string& type) {
+    std::string Parameter::setType(const std::string& type) {
         inputs[0]->setType(type);
         outputs[0]->setType(type);
         return ModuleBase::setType(type);
     }
 
-    std::string ModuleParameter::setAppendix(int appendix)
+    std::string Parameter::setAppendix(int appendix)
     {
         inputs[0]->setAppendix(appendix);
         outputs[0]->setAppendix(appendix);
         return ModuleBase::setAppendix(appendix);
     }
-    bool ModuleParameter::configure(const std::string& config)
+    bool Parameter::configure(const std::string& config)
     {
         json config_parsed = json::parse(config);
         for (size_t i = 0; i < config_parsed.size(); i++)
@@ -56,4 +58,20 @@ namespace mdd {
 
         return false;
     }
+
+    std::string Parameter::getConfiguration() {
+        json ret = json::parse(ModuleBase::getConfiguration());
+        for (size_t i = 0; i < ret.size(); i++)
+        {
+            if (ret[i].contains("name"))
+            {
+                if (ret[i]["name"].get<std::string>() == "appendix")
+                {
+                    ret[i]["value"] = getAppendix();
+                }
+            }
+        }
+
+        return ret.dump();
+    }
 }

+ 140 - 76
lib/src/ProcessorBase.cpp

@@ -1,17 +1,107 @@
 #include "ProcessorBase.h"
-
+/*
 namespace mdd{
     ProcessorBase::ProcessorBase(const std::string& base_config)
     : _base_config(base_config)
     {
 
     }
-    std::shared_ptr<IModule> ProcessorBase::getModule(size_t index){
-        return modules[index];
+
+    bool ProcessorBase::configure(const std::string& config) {
+        json j = json::parse(config);
+        for (size_t i = 0; i < j.size(); i++)
+        {
+            if (j.contains("params"))
+            {
+                if (j["params"].contains("inputs"))
+                {
+                    for (size_t i = 0; i < j["inputs"].size(); i++)
+                    {
+                        inputs.emplace_back(this);
+                        inputs.back()->setType(j["inputs"][i]["type"].get<std::string>());
+                        inputs.back()->setAppendix(j["inputs"][i]["appendix"].get<int>());
+                    }
+                }
+                if (j["params"].contains("outputs"))
+                {
+                    for (size_t i = 0; i < j["outputs"].size(); i++)
+                    {
+                        outputs.emplace_back(this);
+                        outputs.back()->setType(j["outputs"][i]["type"].get<std::string>());
+                        outputs.back()->setAppendix(j["outputs"][i]["appendix"].get<int>());
+                    }
+                }
+            }
+            
+            if (j.contains("modules")) {
+                auto regi = Registration();
+                for (size_t i = 0; i < j["modules"].size(); i++)
+                {
+                    addModule(regi.generateModule(j["modules"][i]["id"].get<std::string>()));
+                    modules.back()->setType(j["modules"][i]["type"].get<std::string>());
+                    modules.back()->setAppendix(j["modules"][i]["appendix"].get<int>());
+                    modules.back()->load(j["modules"][i]["load"]);
+                }
+            }
+            if (j.contains("connections")) {
+                for (size_t i = 0; i < j["connections"].size(); i++)
+                {
+                    connect(j["connections"][i]["output"].get<std::string>(), j["connections"][i]["inputs"].get<std::vector<std::string>>());
+                }
+            }
+        }
+        return true;
     }
 
-    std::string ProcessorBase::getBaseConfiguration() {
-        return _base_config;
+    std::string ProcessorBase::getConfiguration() {
+        //update module apendix ?
+
+        json ret = json::parse(_base_config);
+        ret["params"];
+        ret["params"]["inputs"];
+        for (size_t i = 0; i < inputs.size(); i++)
+        {
+            json sub;
+            sub["type"] = inputs[i]->getType();
+            sub["appendix"] = inputs[i]->getAppendix();
+            ret["params"]["inputs"].push_back(sub);
+        }
+
+        ret["params"]["outputs"];
+        for (size_t i = 0; i < outputs.size(); i++)
+        {
+            json sub;
+            sub["type"] = outputs[i]->getType();
+            sub["appendix"] = outputs[i]->getAppendix();
+            ret["params"]["outputs"].push_back(sub);
+        }
+
+        ret["modules"];
+        ret["connections"];
+        for (size_t i = 0; i < modules.size(); i++)
+        {
+            json sub;
+            sub["id"] = typeid((*modules[i])).name();
+            sub["type"] = modules[i]->getType();
+            sub["appendix"] = modules[i]->getAppendix();
+            sub["configure"] = modules[i]->dump();
+            ret["modules"].push_back(sub);
+            for (size_t j = 0; j < modules[i]->getNumOutputs(); j++)
+            {
+                auto connections = modules[i]->getOutput(j)->getConnections();
+                if (!connections.empty())
+                {
+                    json connect;
+                    connect["output"] = modules[i]->getOutput(j)->getParentID() + "/" + modules[i]->getOutput(j)->getID();
+                    for (size_t k = 0; k < connections.size(); k++)
+                    {
+                        connect["inputs"].push_back(connections[k]->getParentID() + "/" + connections[k]->getID());
+                    }
+                    ret["connections"].push_back(connect);
+                }
+            }
+        }
+        return ret.dump();
     }
 
     std::string ProcessorBase::getID() {
@@ -53,11 +143,11 @@ namespace mdd{
         }
     }
 
-    std::vector<std::shared_ptr<ModuleParameter>>& ProcessorBase::getInputParams() {
+    std::vector<std::shared_ptr<Parameter>>& ProcessorBase::getInputParams() {
         return inputs;
     }
 
-    std::vector<std::shared_ptr<ModuleParameter>>& ProcessorBase::getOutputParams() {
+    std::vector<std::shared_ptr<Parameter>>& ProcessorBase::getOutputParams() {
         return outputs;
     }
 
@@ -151,95 +241,68 @@ namespace mdd{
     }
 
     void ProcessorBase::load(const json& j) {
-        for (size_t i = 0; i < j["inputs"].size(); i++)
-        {
-            inputs.emplace_back();
-            inputs.back()->setType(j["inputs"][i]["type"].get<std::string>());
-            inputs.back()->setAppendix(j["inputs"][i]["appendix"].get<int>());
-        }
-        for (size_t i = 0; i < j["outputs"].size(); i++)
-        {
-            outputs.emplace_back();
-            outputs.back()->setType(j["outputs"][i]["type"].get<std::string>());
-            outputs.back()->setAppendix(j["outputs"][i]["appendix"].get<int>());
-        }
+        
+    }
 
-        auto regi = Registration();
-        for (size_t i = 0; i < j["modules"].size(); i++)
+    json ProcessorBase::dump() {
+        
+    }
+
+    std::shared_ptr<IOutput> ProcessorBase::getOutput(size_t index) {
+        if (index < processor_outputs.size())
         {
-            addModule(regi.generateModule(j["modules"][i]["id"].get<std::string>()));
-            modules.back()->setType(j["modules"][i]["type"].get<std::string>());
-            modules.back()->setAppendix(j["modules"][i]["appendix"].get<int>());
-            modules.back()->load(j["modules"][i]["load"]);
+            return processor_outputs[index];
         }
-        for (size_t i = 0; i < j["connections"].size(); i++)
+        index -= processor_inputs.size();
+        if (index < outputs.size())
         {
-            connect(j["connections"][i]["output"].get<std::string>(), j["connections"][i]["inputs"].get<std::vector<std::string>>());
+            return outputs[index]->getOutput(0);
         }
-       
+        return nullptr;
     }
 
-    json ProcessorBase::dump() {
-        //update module apendix ?
-
-        json ret;
-        ret["inputs"];
-        for (size_t i = 0; i < inputs.size(); i++)
+    std::vector<std::shared_ptr<IInput>> ProcessorBase::getOptimizableInputs() {
+        std::vector<std::shared_ptr<IInput>> ret;
+        for (size_t i = 0; i < processor_inputs.size(); i++)
         {
-            json sub;
-            sub["type"] = inputs[i]->getType();
-            sub["appendix"] = inputs[i]->getAppendix();
-            ret["inputs"].push_back(sub);
+            if (processor_inputs[i]->isOptimizable())
+            {
+                ret.push_back(processor_inputs[i]);
+            }
         }
-
-        ret["outputs"];
-        for (size_t i = 0; i < outputs.size(); i++)
+        for (size_t i = 0; i < inputs.size(); i++)
         {
-            json sub;
-            sub["type"] = outputs[i]->getType();
-            sub["appendix"] = outputs[i]->getAppendix();
-            ret["outputs"].push_back(sub);
+            auto list = inputs[i]->getOptimizableInputs();
+            ret.insert(ret.end(), list.begin(), list.end());
         }
-
-        ret["modules"];
-        ret["connections"];
         for (size_t i = 0; i < modules.size(); i++)
         {
-            json sub;
-            sub["id"] = typeid((*modules[i])).name();
-            sub["type"] = modules[i]->getType();
-            sub["appendix"] = modules[i]->getAppendix();
-            sub["configure"] = modules[i]->dump();
-            ret["modules"].push_back(sub);
-            for (size_t j = 0; j < modules[i]->getNumOutputs(); j++)
-            {
-                auto connections = modules[i]->getOutput(j)->getConnections();
-                if (!connections.empty())
-                {
-                    json connect;
-                    connect["output"] = modules[i]->getOutput(j)->getParentID() + "/" + modules[i]->getOutput(j)->getID();
-                    for (size_t k = 0; k < connections.size(); k++)
-                    {
-                        connect["inputs"].push_back(connections[k]->getParentID() + "/" + connections[k]->getID());
-                    }
-                    ret["connections"].push_back(connect);
-                }
-            }
+            auto list = modules[i]->getOptimizableInputs();
+            ret.insert(ret.end(), list.begin(), list.end());
         }
         return ret;
     }
 
-    std::shared_ptr<IOutput> ProcessorBase::getOutput(size_t index) {
-        if (index < processor_outputs.size())
+    std::vector<std::shared_ptr<IOutput>> ProcessorBase::getOptimizableOutputs() {
+        std::vector<std::shared_ptr<IOutput>> ret;
+        for (size_t i = 0; i < processor_outputs.size(); i++)
         {
-            return processor_outputs[index];
+            if (processor_outputs[i]->isOptimizable())
+            {
+                ret.push_back(processor_outputs[i]);
+            }
         }
-        index -= processor_inputs.size();
-        if (index < outputs.size())
+        for (size_t i = 0; i < outputs.size(); i++)
         {
-            return outputs[index]->getOutput(0);
+            auto list = outputs[i]->getOptimizableOutputs();
+            ret.insert(ret.end(), list.begin(), list.end());
         }
-        return nullptr;
+        for (size_t i = 0; i < modules.size(); i++)
+        {
+            auto list = modules[i]->getOptimizableOutputs();
+            ret.insert(ret.end(), list.begin(), list.end());
+        }
+        return ret;
     }
    
     std::shared_ptr<IOutput> ProcessorBase::getOutput(const std::string& id){
@@ -293,4 +356,5 @@ namespace mdd{
     }
 
 
-}
+}
+//*/

+ 14 - 14
lib/src/ProcessorStandard.cpp

@@ -1,3 +1,4 @@
+/*
 #include "ProcessorBase.h"
 #include <iostream>
 #include "Output.h"
@@ -54,7 +55,7 @@ namespace mdd {
         _priorityEvaluation = MANUAL;
         _maxIterations = -1;
         setType("StandardProcessor");
-        processor_outputs.emplace_back(this, "Iterator", 0, std::vector<double>{0});
+        processor_outputs.push_back(std::make_shared<Output>(this, "Iterator", 0, std::vector<double>{0}));
     }
 
     bool ProcessorStandard::configure(const std::string& config) {
@@ -66,25 +67,23 @@ namespace mdd {
             {
                 if (config_parsed[i]["name"].get<std::string>() == "priority")
                 {
-                    auto op = config_parsed[i]["value"].get<std::string>();
+                    std::string op = config_parsed[i]["value"].get<std::string>();
                     found = true;
-                    switch (op.c_str())
-                    {
-                    case "manual":
+                    if (op == "manual") {
                         _priorityEvaluation = MANUAL;
                         break;
-                    case "static":
+                    }
+                    else if (op == "static") {
                         _priorityEvaluation = STATIC;
-                        break;
-                    case "dynamic":
+                    }
+                    else if (op == "dynamic") {
                         _priorityEvaluation = DYNAMIC;
-                        break;
-                    case "time":
+                    }
+                    else if (op == "time") {
                         _priorityEvaluation = TIME;
-                        break;
-                    default:
+                    }
+                    else {
                         found = false;
-                        break;
                     }
                 }
                 if (config_parsed[i]["name"].get<std::string>() == "iterations")
@@ -235,4 +234,5 @@ namespace mdd {
         changeCounter = change;
         time_priority = 0;
     }
-}
+}
+//*/

+ 2 - 2
lib/src/Registration.cpp

@@ -11,7 +11,7 @@
 #include "ModuleSQL.cpp"
 #include "ModuleSwitch.cpp"
 
-#include "ProcessorStandard.cpp"
+//#include "ProcessorStandard.cpp"
 
 namespace mdd
 {
@@ -24,7 +24,7 @@ namespace mdd
 		REGISTER(ModuleSQL);
 		REGISTER(ModuleSwitch);
 
-		REGISTER(ProcessorStandard);
+		//REGISTER(ProcessorStandard);
 	}
 	IModule::Ptr Registration::generateModule(const std::string& name)
 	{

+ 0 - 4
lib/test/test_Ansys.cpp

@@ -2,10 +2,6 @@
 #include <json.hpp>
 #include <httplib.h>
 //#define private public
-#include "OptimizerEvolutionary.h"
-#include <ProcessorStandard.h>
-#include <ModuleSQL.h>
-#include <ModuleSwitch.h>
 #include <math.h>
 #include <thread>
 /*

+ 52 - 44
lib/test/test_ModuleHTTP.cpp

@@ -2,15 +2,15 @@
 #include <json.hpp>
 #include <httplib.h>
 //#define private public
-#include <ProcessorStandard.h>
-#include <ModuleSwitch.h>
-#include <Generator.h>
+#include <Registration.h>
 #include <math.h>
 #include <thread>
 
 using namespace mdd;
 using namespace httplib;
-/*
+
+namespace TEST_MODULE_HTTP{
+
 void serverThread()
 {
     Server svr;
@@ -84,76 +84,84 @@ void serverThread()
     std::cout << "server closed"<<std::endl;
 }
 
+auto regi = Registration();
+
 TEST(ModuleHTTP, updateLayout_intern){
     std::thread server (serverThread);
-    auto module = GetGenerators()["mdd::ModuleHTTP"]->Generate();// ("", "localhost", 8888);
+    auto mod = regi.generateModule("ModuleHTTP");// ("", "localhost", 8888);
+    json config = json::parse(mod->getConfiguration());
+    config[0]["value"] = "";
+    config[1]["value"] = "localhost";
+    config[2]["value"] = 8888;
+    mod->configure(config.dump());
 
     Client cli("localhost",8888);
     cli.Get("/stop");
     server.join();
 
-    auto inputs_types = module.getInputs();
-    auto inputs_ids = module.getInputIDs();
-    for (int i = 0; i < 5; ++i) {
-        EXPECT_EQ(inputs_types[i], "INPUT");
-        EXPECT_EQ((int)module.getInput(inputs_ids[i])->getValue()[0], i);
+    for (int i = 0; i < mod->getNumInputs(); ++i) {
+        EXPECT_EQ(mod->getInput(i)->getType(), "INPUT");
+        EXPECT_EQ((int)mod->getInput(i)->getValue()[0], i);
     }
 
-    auto outputs_types = module.getOutputs();
-    auto outputs_ids = module.getOutputIDs();
-    for (int i = 0; i < 3; ++i) {
-        EXPECT_EQ(outputs_types[i], "OUTPUT");
-        EXPECT_EQ((int)module.getOutput(outputs_ids[i])->getValue()[0], i * 2);
+    for (int i = 0; i < mod->getNumOutputs(); ++i) {
+        EXPECT_EQ(mod->getOutput(i)->getType(), "OUTPUT");
+        EXPECT_EQ((int)mod->getOutput(i)->getValue()[0], i * 2);
     }
+    mod->disconnect();
 }
 
+
 TEST(ModuleHTTP, updateLayout_extern){
-    ModuleHTTP module("../../../lib/test/server/server.py","localhost",8889);
+    auto mod = regi.generateModule("ModuleHTTP");// ("", "localhost", 8888);
+    json config = json::parse(mod->getConfiguration());
+    config[0]["value"] = "../../../lib/test/server/server.py";
+    config[1]["value"] = "localhost";
+    config[2]["value"] = 8889;
+    mod->configure(config.dump());
    
-    auto inputs_types = module.getInputs();
-    auto inputs_ids = module.getInputIDs();
-    for(int i = 0; i < 5; ++i){
-        EXPECT_EQ(inputs_types[i], "INPUT");
-        EXPECT_EQ((int)module.getInput(inputs_ids[i])->getValue()[0], i);
+    for (int i = 0; i < mod->getNumInputs(); ++i) {
+        EXPECT_EQ(mod->getInput(i)->getType(), "INPUT");
+        EXPECT_EQ((int)mod->getInput(i)->getValue()[0], i);
     }
 
-    auto outputs_types = module.getOutputs();
-    auto outputs_ids = module.getOutputIDs();
-    for(int i = 0; i < 3; ++i){
-        EXPECT_EQ(outputs_types[i], "OUTPUT");
-        EXPECT_EQ((int)module.getOutput(outputs_ids[i])->getValue()[0], i*2);
+    for (int i = 0; i < mod->getNumOutputs(); ++i) {
+        EXPECT_EQ(mod->getOutput(i)->getType(), "OUTPUT");
+        EXPECT_EQ((int)mod->getOutput(i)->getValue()[0], i * 2);
     }
     Client cli("localhost",8889);
     cli.Get("/stop");
+    mod->disconnect();
 }
 
 TEST(ModuleHTTP, update_intern){
     std::thread server (serverThread);
-    ModuleHTTP module("", "localhost", 8888);
-    //std::cout << "WORKED" << std::endl;
-    auto inputs_types = module.getInputs();
-    auto inputs_ids = module.getInputIDs();
-    for (int i = 0; i < 5; ++i) {
-        module.getInput(inputs_ids[i])->setValue() = { (double)(10 - i) };
+    auto mod = regi.generateModule("ModuleHTTP");// ("", "localhost", 8888);
+    json config = json::parse(mod->getConfiguration());
+    config[0]["value"] = "";
+    config[1]["value"] = "localhost";
+    config[2]["value"] = 8888;
+    mod->configure(config.dump());
+
+    for (int i = 0; i < mod->getNumInputs(); ++i) {
+        mod->getInput(i)->setValue() = { (double)(10 - i) };
     }
-    module.update();
+    mod->update();
 
     Client cli("localhost", 8888);
     cli.Get("/stop");
     server.join();
 
-    inputs_types = module.getInputs();
-    inputs_ids = module.getInputIDs();
-    for (int i = 0; i < 5; ++i) {
-        EXPECT_EQ(inputs_types[i], "INPUT");
-        EXPECT_EQ(module.getInput(inputs_ids[i])->getValue()[0], 10-i);
+    for (int i = 0; i < mod->getNumInputs(); ++i) {
+        EXPECT_EQ(mod->getInput(i)->getType(), "INPUT");
+        EXPECT_EQ(mod->getInput(i)->getValue()[0], 10-i);
     }
     //std::cout << "WORKED" << std::endl;
-    auto outputs_types = module.getOutputs();
-    auto outputs_ids = module.getOutputIDs();
     //std::cout << module.getOutput(outputs_ids[0])->getValue() << std::endl;
-    EXPECT_EQ((int)module.getOutput(outputs_ids[1])->getValue()[0], 64);
-    EXPECT_EQ((int)module.getOutput(outputs_ids[2])->getValue()[0], 1);
-    EXPECT_EQ((int)module.getOutput(outputs_ids[0])->getValue()[0], 19);
+    EXPECT_EQ((int)mod->getOutput(0)->getValue()[0], 19);
+    EXPECT_EQ((int)mod->getOutput(1)->getValue()[0], 64);
+    EXPECT_EQ((int)mod->getOutput(2)->getValue()[0], 1);
+    mod->disconnect();
 }
-//*/
+//*/
+}

+ 62 - 54
lib/test/test_ModuleMath.cpp

@@ -11,6 +11,9 @@
 
 
 using namespace mdd;
+
+namespace TEST_MODULE_MATH {
+
 auto regi = Registration();
 
 TEST(ModuleMath, Create) {
@@ -29,7 +32,7 @@ TEST(ModuleMath, Create) {
 
 TEST(ModuleMath, INT_PLUS_INT){
     IModule::Ptr mod = regi.generateModule("ModuleMath");
-    auto config = mod->getBaseConfiguration();
+    auto config = mod->getConfiguration();
     mod->configure(config);
     mod->update();
     auto output = mod->getOutput(0);
@@ -37,92 +40,97 @@ TEST(ModuleMath, INT_PLUS_INT){
     EXPECT_FLOAT_EQ(res[0], 2.0);
 }
 
-/*
+
 TEST(ModuleMath, FLOAT_PLUS_FLOAT){
-    IModule::Ptr test = GetGenerators()["mdd::ModuleMath"]->Generate();
-    test->configure(test->getBaseConfiguration());
-    test->getInput(test->getInputIDs()[0])->setValue() = { 1.25 };
-    test->getInput(test->getInputIDs()[1])->setValue() = { 3.125 };
+    IModule::Ptr test = regi.generateModule("ModuleMath");
+    test->configure(test->getConfiguration());
+    test->getInput(0)->setValue() = { 1.25 };
+    test->getInput(1)->setValue() = { 3.125 };
     test->update();
 
-    EXPECT_FLOAT_EQ(test->getOutput(test->getOutputIDs()[0])->getValue()[0], 4.375);
+    EXPECT_FLOAT_EQ(test->getOutput(0)->getValue()[0], 4.375);
 }
-//*/
-/*
+
 TEST(ModuleMath, FLOAT_PLUS_FLOAT_HARDER){
-    ModuleMath test = ModuleMath();
-    test.getInput(test.getInputIDs()[0])->setValue() = { 2.2 };
-    test.getInput(test.getInputIDs()[1])->setValue() = { -3.4 };
-    test.update();
+    IModule::Ptr test = regi.generateModule("ModuleMath");
+    test->getInput(0)->setValue() = { 2.2 };
+    test->getInput(1)->setValue() = { -3.4 };
+    test->update();
 
-    EXPECT_FLOAT_EQ(test.getOutput(test.getOutputIDs()[0])->getValue()[0], -1.2);
+    EXPECT_FLOAT_EQ(test->getOutput(0)->getValue()[0], -1.2);
 }
 
 TEST(ModuleMath, ARRAY_PLUS_ARRAY) {
-    ModuleMath test = ModuleMath();
-    test.getInput(test.getInputIDs()[0])->setValue() = { 1,2.5,3.75,45 };
-    test.getInput(test.getInputIDs()[1])->setValue() = { 10,31,23,23 };
+    IModule::Ptr test = regi.generateModule("ModuleMath");
+    test->getInput(0)->setValue() = { 1,2.5,3.75,45 };
+    test->getInput(1)->setValue() = { 10,31,23,23 };
     std::vector<double> expect = { 11, 33.5, 26.75, 68 };
-    test.update();
-    EXPECT_EQ(test.getOutput(test.getOutputIDs()[0])->getValue(), expect);
+    test->update();
+    EXPECT_EQ(test->getOutput(0)->getValue(), expect);
 }
 
 TEST(ModuleMath, INT_PLUS_ARRAY){
-    ModuleMath test = ModuleMath();
-    test.getInput(test.getInputIDs()[0])->setValue() = { 2.5 };
-    test.getInput(test.getInputIDs()[1])->setValue() = {10,31,23,23};
+    IModule::Ptr test = regi.generateModule("ModuleMath");
+    test->getInput(0)->setValue() = { 2.5 };
+    test->getInput(1)->setValue() = {10,31,23,23};
     std::vector<double> expect = { 12.5,33.5,25.5,25.5 };
-    test.update();
+    test->update();
 
-    EXPECT_EQ(test.getOutput(test.getOutputIDs()[0])->getValue(), expect);
+    EXPECT_EQ(test->getOutput(0)->getValue(), expect);
 }
 
 TEST(ModuleMath, ARRAY_PLUS_INT){
-    ModuleMath test = ModuleMath();
-    test.getInput(test.getInputIDs()[0])->setValue() = {10,31,23,23};
-    test.getInput(test.getInputIDs()[1])->setValue() = { 2.5 };
+    IModule::Ptr test = regi.generateModule("ModuleMath");
+    test->getInput(0)->setValue() = {10,31,23,23};
+    test->getInput(1)->setValue() = { 2.5 };
     std::vector<double> expect = { 12.5,33.5,25.5,25.5 };
-    test.update();
+    test->update();
 
-    EXPECT_EQ(test.getOutput(test.getOutputIDs()[0])->getValue(), expect);
+    EXPECT_EQ(test->getOutput(0)->getValue(), expect);
 }
 
 TEST(ModuleMath, ARRAY_MINUS_ARRAY){
-    ModuleMath test = ModuleMath(MathOperation::SUBTRACT);
-    test.getInput(test.getInputIDs()[0])->setValue() = {10,31,3,45};
-    test.getInput(test.getInputIDs()[1])->setValue() = {1,2.5,23,23};
+    IModule::Ptr test = regi.generateModule("ModuleMath");
+    json config = json::parse(test->getConfiguration());
+    config[0]["value"] = "subtract";
+    test->configure(config.dump());
+    test->getInput(0)->setValue() = { 10,31,3,45 };
+    test->getInput(1)->setValue() = {1,2.5,23,23};
     std::vector<double> expect = { 9,28.5,-20,22 };
-    test.update();
+    test->update();
 
-    EXPECT_EQ(test.getOutput(test.getOutputIDs()[0])->getValue(), expect);
+    EXPECT_EQ(test->getOutput(0)->getValue(), expect);
 }
-*/
-/*
+
 TEST(ModuleMath, ARRAY_MAL_ARRAY){
-    IModule::Ptr test = GetGenerators()["mdd::ModuleMath"]->Generate();
+    IModule::Ptr test = regi.generateModule("ModuleMath");
 
-    test->configure(R"JSON(
-    {
-        "operation": "multiply"
-    }
-    )JSON");
-    test->update();
+    json config = json::parse(test->getConfiguration());
+    config[0]["value"] = "multiply";
+    test->configure(config.dump());
 
-    test->getInput(test->getInputIDs()[0])->setValue() = {10,30,-3.5,45};
-    test->getInput(test->getInputIDs()[1])->setValue() = {1,2.5,2.25,20};
+    test->getInput(0)->setValue() = {10,30,-3.5,45};
+    test->getInput(1)->setValue() = {1,2.5,2.25,20};
     std::vector<double> expect = { 10,75.0,-7.875,900 };
     test->update();
 
-    EXPECT_EQ(test->getOutput(test->getOutputIDs()[0])->getValue(), expect);
+    EXPECT_EQ(test->getOutput(0)->getValue(), expect);
 }
-//*/
-/*
+
 TEST(ModuleMath, ARRAY_DURCH_ARRAY){
-    ModuleMath test = ModuleMath(MathOperation::DIVIDE);
-    test.getInput(test.getInputIDs()[0])->setValue() = {10,30,-3.5,45};
-    test.getInput(test.getInputIDs()[1])->setValue() = {4,2.5,2,20};
+    IModule::Ptr test = regi.generateModule("ModuleMath");
+
+    json config = json::parse(test->getConfiguration());
+    config[0]["value"] = "divide";
+    test->configure(config.dump());
+
+    test->getInput(0)->setValue() = { 10,30,-3.5,45 };
+    test->getInput(1)->setValue() = {4,2.5,2,20};
     std::vector<double> expect = { 2.5,12.0,-1.75,2.25 };
-    test.update();
+    test->update();
+
+    EXPECT_EQ(test->getOutput(0)->getValue(), expect);
+}
+//*/
 
-    EXPECT_EQ(test.getOutput(test.getOutputIDs()[0])->getValue(), expect);
-}*/
+}

+ 179 - 176
lib/test/test_ModuleSQL.cpp

@@ -2,235 +2,238 @@
 #include <json.hpp>
 #include <filesystem>
 //#define private public
-#include <ModuleSQL.h>
+#include <Registration.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <sqlite3.h> 
 
 
 using namespace mdd;
-/*
-static int callback(void* data, int argc, char** argv, char** azColName) {
-    int i;
-    fprintf(stderr, "%s: ", (const char*)data);
-    for (i = 0; i < argc; i++) {
-        printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
-    }
-    printf("\n");
-    return 0;
-}
-
-void sqlite3_exec_debug(sqlite3* db, char* sql) {
-    char* zErrMsg = 0;
-    int rc;
-
-    // Execute SQL statement 
-    rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg);
-
-    if (rc != SQLITE_OK) {
-        fprintf(stderr, "SQL error: %s\n", zErrMsg);
-        sqlite3_free(zErrMsg);
-    }
-    else {
-        fprintf(stdout, "Table created successfully\n");
+namespace TEST_MODULE_SQL {
+    
+    static int callback(void* data, int argc, char** argv, char** azColName) {
+        int i;
+        fprintf(stderr, "%s: ", (const char*)data);
+        for (i = 0; i < argc; i++) {
+            printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
+        }
+        printf("\n");
+        return 0;
     }
-}
 
-void create_test_db() {
-        sqlite3* db;
+    void sqlite3_exec_debug(sqlite3* db, char* sql) {
+        char* zErrMsg = 0;
         int rc;
-        char* sql;
 
-        // Open database
-        rc = sqlite3_open("../../../lib/test/db/materials.db", &db);
+        // Execute SQL statement
+        rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg);
 
-        if (rc) {
-            fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
-            return;
+        if (rc != SQLITE_OK) {
+            fprintf(stderr, "SQL error: %s\n", zErrMsg);
+            sqlite3_free(zErrMsg);
         }
         else {
-            fprintf(stdout, "Opened database successfully\n");
+            fprintf(stdout, "Table created successfully\n");
         }
+    }
 
-        // Create SQL statement
-        sql = "CREATE TABLE MATERIAL("  \
-            "ID INTEGER PRIMARY KEY     AUTOINCREMENT," \
-            "NAME           TEXT    NOT NULL," \
+    void create_test_db() {
+            sqlite3* db;
+            int rc;
+            char* sql;
 
-            "E11            FLOAT   NOT NULL," \
-            "E22            FLOAT   NOT NULL," \
-            "E33            FLOAT   NOT NULL," \
+            // Open database
+            rc = sqlite3_open("../../../lib/test/db/materials.db", &db);
 
-            "PR12           FLOAT   NOT NULL," \
-            "PR13           FLOAT   NOT NULL," \
-            "PR23           FLOAT   NOT NULL," \
+            if (rc) {
+                fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
+                return;
+            }
+            else {
+                fprintf(stdout, "Opened database successfully\n");
+            }
 
-            "G12            FLOAT   NOT NULL," \
-            "G13            FLOAT   NOT NULL," \
-            "G23            FLOAT   NOT NULL," \
+            // Create SQL statement
+            sql = "CREATE TABLE MATERIAL("  \
+                "ID INTEGER PRIMARY KEY     AUTOINCREMENT," \
+                "NAME           TEXT    NOT NULL," \
 
-            "DENS           FLOAT           ," \
+                "E11            FLOAT   NOT NULL," \
+                "E22            FLOAT   NOT NULL," \
+                "E33            FLOAT   NOT NULL," \
 
-            "ALP11          FLOAT           ," \
-            "ALP22          FLOAT           ," \
-            "ALP33          FLOAT           ," \
+                "PR12           FLOAT   NOT NULL," \
+                "PR13           FLOAT   NOT NULL," \
+                "PR23           FLOAT   NOT NULL," \
 
-            "K11            FLOAT           ," \
-            "K22            FLOAT           ," \
-            "K33            FLOAT           ," \
+                "G12            FLOAT   NOT NULL," \
+                "G13            FLOAT   NOT NULL," \
+                "G23            FLOAT   NOT NULL," \
 
-            "BET11          FLOAT           ," \
-            "BET22          FLOAT           ," \
-            "BET33          FLOAT           ," \
+                "DENS           FLOAT           ," \
 
-            "D11            FLOAT           ," \
-            "D22            FLOAT           ," \
-            "D33            FLOAT           );";
+                "ALP11          FLOAT           ," \
+                "ALP22          FLOAT           ," \
+                "ALP33          FLOAT           ," \
 
-        sqlite3_exec_debug(db, sql);
-        
-       // Create SQL statement
-        sql = "INSERT INTO MATERIAL (   NAME,           E11,    E22,    E33,    PR12,   PR13,   PR23,   G12,    G13,    G23,    DENS,       ALP11,  ALP22, ALP33, K11,      K22,    K33,    BET11,  BET22,  BET33,  D11,    D22,    D33) "  \
-            "VALUES (                   'EP-E Glas',    42.5,   11,     11,     0.28,   0.28,   0.28,   4.2,    4.2,    2.56,   1950E-6,    5.7E-6, 45E-6, 45E-6, 0.72E3,   0.5E3,  0.5E3,  0E-3,   4E-3,   4E-3,   4.4E3,  3.1E3,  3.1E3); ";
+                "K11            FLOAT           ," \
+                "K22            FLOAT           ," \
+                "K33            FLOAT           ," \
 
-        sqlite3_exec_debug(db, sql);
+                "BET11          FLOAT           ," \
+                "BET22          FLOAT           ," \
+                "BET33          FLOAT           ," \
 
-        sqlite3_close(db);
-}
+                "D11            FLOAT           ," \
+                "D22            FLOAT           ," \
+                "D33            FLOAT           );";
 
+            sqlite3_exec_debug(db, sql);
 
-TEST(ModuleSQL, TestSQL) {
-    if (!std::filesystem::exists("../../../lib/test/db/materials.db")) {
-        create_test_db();
-    }
-    
-    sqlite3* db;
-    char* zErrMsg = 0;
-    int rc;
-    char* sql;
-    const char* data = "Callback function called";
-
-    // Open database 
-    rc = sqlite3_open("../../../lib/test/db/materials.db", &db);
-
-    if (rc) {
-        fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
-        return;
-    }
-    else {
-        fprintf(stderr, "Opened database successfully\n");
+           // Create SQL statement
+            sql = "INSERT INTO MATERIAL (   NAME,           E11,    E22,    E33,    PR12,   PR13,   PR23,   G12,    G13,    G23,    DENS,       ALP11,  ALP22, ALP33, K11,      K22,    K33,    BET11,  BET22,  BET33,  D11,    D22,    D33) "  \
+                "VALUES (                   'EP-E Glas',    42.5,   11,     11,     0.28,   0.28,   0.28,   4.2,    4.2,    2.56,   1950E-6,    5.7E-6, 45E-6, 45E-6, 0.72E3,   0.5E3,  0.5E3,  0E-3,   4E-3,   4E-3,   4.4E3,  3.1E3,  3.1E3); ";
+
+            sqlite3_exec_debug(db, sql);
+
+            sqlite3_close(db);
     }
 
-    // Create SQL statement 
-    sql = "SELECT * from MATERIAL";
+    auto regi = Registration();
 
-    // Execute SQL statement 
-    rc = sqlite3_exec(db, sql, callback, (void*)data, &zErrMsg);
+    TEST(ModuleSQL, TestSQL) {
+        if (!std::filesystem::exists("../../../lib/test/db/materials.db")) {
+            create_test_db();
+        }
 
-    if (rc != SQLITE_OK) {
-        fprintf(stderr, "SQL error: %s\n", zErrMsg);
-        sqlite3_free(zErrMsg);
-    }
-    else {
-        fprintf(stdout, "Operation done successfully\n");
-    }
-    sqlite3_close(db);
+        sqlite3* db;
+        char* zErrMsg = 0;
+        int rc;
+        char* sql;
+        const char* data = "Callback function called";
 
-    EXPECT_TRUE(std::filesystem::exists("../../../lib/test/db/materials.db"));
-}
+        // Open database
+        rc = sqlite3_open("../../../lib/test/db/materials.db", &db);
 
-TEST(ModuleSQL, TestGetSQLTableStructure) {
-    if (!std::filesystem::exists("../../../lib/test/db/materials.db")) {
-        create_test_db();
-    }
+        if (rc) {
+            fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
+            return;
+        }
+        else {
+            fprintf(stderr, "Opened database successfully\n");
+        }
 
-    sqlite3* db;
-    char* zErrMsg = 0;
-    int rc;
-    char* sql;
-    const char* data = "Callback function called";
+        // Create SQL statement
+        sql = "SELECT * from MATERIAL";
 
-    // Open database 
-    rc = sqlite3_open("../../../lib/test/db/materials.db", &db);
+        // Execute SQL statement
+        rc = sqlite3_exec(db, sql, callback, (void*)data, &zErrMsg);
 
-    if (rc) {
-        fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
-        return;
-    }
-    else {
-        fprintf(stderr, "Opened database successfully\n");
+        if (rc != SQLITE_OK) {
+            fprintf(stderr, "SQL error: %s\n", zErrMsg);
+            sqlite3_free(zErrMsg);
+        }
+        else {
+            fprintf(stdout, "Operation done successfully\n");
+        }
+        sqlite3_close(db);
+
+        EXPECT_TRUE(std::filesystem::exists("../../../lib/test/db/materials.db"));
     }
 
-    // Create SQL statement 
-    sql =   "SELECT * "\
-            "FROM   sqlite_master "\
-            "WHERE type = 'table' ";
+   
+    TEST(ModuleSQL, TestGetSQLTableStructure) {
+        if (!std::filesystem::exists("../../../lib/test/db/materials.db")) {
+            create_test_db();
+        }
 
-    // Execute SQL statement 
-    rc = sqlite3_exec(db, sql, callback, (void*)data, &zErrMsg);
+        sqlite3* db;
+        char* zErrMsg = 0;
+        int rc;
+        char* sql;
+        const char* data = "Callback function called";
 
-    if (rc != SQLITE_OK) {
-        fprintf(stderr, "SQL error: %s\n", zErrMsg);
-        sqlite3_free(zErrMsg);
-    }
-    else {
-        fprintf(stdout, "Operation done successfully\n");
-    }
-    sqlite3_close(db);
+        // Open database
+        rc = sqlite3_open("../../../lib/test/db/materials.db", &db);
+
+        if (rc) {
+            fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
+            return;
+        }
+        else {
+            fprintf(stderr, "Opened database successfully\n");
+        }
 
-    EXPECT_TRUE(std::filesystem::exists("../../../lib/test/db/materials.db"));
-}
+        // Create SQL statement
+        sql =   "SELECT * "\
+                "FROM   sqlite_master "\
+                "WHERE type = 'table' ";
 
+        // Execute SQL statement
+        rc = sqlite3_exec(db, sql, callback, (void*)data, &zErrMsg);
 
+        if (rc != SQLITE_OK) {
+            fprintf(stderr, "SQL error: %s\n", zErrMsg);
+            sqlite3_free(zErrMsg);
+        }
+        else {
+            fprintf(stdout, "Operation done successfully\n");
+        }
+        sqlite3_close(db);
 
-TEST(ModuleSQL, OpenDB) {
-    if (!std::filesystem::exists("../../../lib/test/db/materials.db")) {
-        create_test_db();
+        EXPECT_TRUE(std::filesystem::exists("../../../lib/test/db/materials.db"));
     }
-	ModuleSQL module = ModuleSQL("../../../lib/test/db/materials.db");
-    module.update();
-
 
-	EXPECT_TRUE(std::filesystem::exists("../../../lib/test/db/materials.db"));
-}
+    TEST(ModuleSQL, OpenDB) {
+        if (!std::filesystem::exists("../../../lib/test/db/materials.db")) {
+            create_test_db();
+        }
+        IModule::Ptr mod = regi.generateModule("ModuleMath");
+        json config = json::parse(mod->getConfiguration());
+        config[0]["value"] = "../../../lib/test/db/materials.db";
+        mod->configure(config.dump());
 
-TEST(ModuleSQL, TestDataExists) {
-    if (!std::filesystem::exists("../../../lib/test/db/materials.db")) {
-        create_test_db();
+        EXPECT_TRUE(std::filesystem::exists("../../../lib/test/db/materials.db"));
     }
 
-    sqlite3* db;
-    char* zErrMsg = 0;
-    int rc;
-    char* sql;
-    const char* data = "Callback function called";
+    TEST(ModuleSQL, TestDataExists) {
+        if (!std::filesystem::exists("../../../lib/test/db/materials.db")) {
+            create_test_db();
+        }
+
+        sqlite3* db;
+        char* zErrMsg = 0;
+        int rc;
+        char* sql;
+        const char* data = "Callback function called";
 
-    // Open database 
-    rc = sqlite3_open("../../../lib/test/db/materials.db", &db);
+        // Open database
+        rc = sqlite3_open("../../../lib/test/db/materials.db", &db);
 
-    if (rc) {
-        fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
-        return;
-    }
-    else {
-        fprintf(stderr, "Opened database successfully\n");
-    }
+        if (rc) {
+            fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
+            return;
+        }
+        else {
+            fprintf(stderr, "Opened database successfully\n");
+        }
 
-    // Create SQL statement 
-    sql = "SELECT * from MATERIAL";
+        // Create SQL statement
+        sql = "SELECT * from MATERIAL";
 
-    // Execute SQL statement 
-    rc = sqlite3_exec(db, sql, callback, (void*)data, &zErrMsg);
+        // Execute SQL statement
+        rc = sqlite3_exec(db, sql, callback, (void*)data, &zErrMsg);
 
-    if (rc != SQLITE_OK) {
-        fprintf(stderr, "SQL error: %s\n", zErrMsg);
-        sqlite3_free(zErrMsg);
-    }
-    else {
-        fprintf(stdout, "Operation done successfully\n");
-    }
-    sqlite3_close(db);
+        if (rc != SQLITE_OK) {
+            fprintf(stderr, "SQL error: %s\n", zErrMsg);
+            sqlite3_free(zErrMsg);
+        }
+        else {
+            fprintf(stdout, "Operation done successfully\n");
+        }
+        sqlite3_close(db);
 
-    EXPECT_TRUE(std::filesystem::exists("../../../lib/test/db/materials.db"));
-}
-//*/
+        EXPECT_TRUE(std::filesystem::exists("../../../lib/test/db/materials.db"));
+    }
+    //*/
+}

+ 1 - 2
lib/test/test_ModuleSwitch.cpp

@@ -1,8 +1,7 @@
 #include <gtest/gtest.h>
 #include <json.hpp>
 //#define private public
-#include <ProcessorStandard.h>
-#include <ModuleSwitch.h>
+#include <Registration.h>
 
 
 using namespace mdd;

+ 1 - 2
lib/test/test_OptimizerEvolutionary.cpp

@@ -1,8 +1,7 @@
 #include <gtest/gtest.h>
 #include <json.hpp>
 //#define private public
-#include "OptimizerEvolutionary.h"
-#include <ModuleSwitch.h>
+#include <Registration.h>
 
 /*
 using namespace mdd;

+ 1 - 1
lib/test/test_Output.cpp

@@ -7,7 +7,7 @@
 using namespace mdd;
 
 TEST(Output, setValue) {
-    std::shared_ptr<Output> out_ptr = std::make_shared<Output>("TEST", 0, std::vector<double>{0});
+    std::shared_ptr<Output> out_ptr = std::make_shared<Output>(nullptr, "TEST", 0, std::vector<double>{0});
     EXPECT_FLOAT_EQ(out_ptr->getValue()[0], 0.0);
     out_ptr->setValue(std::vector<double>{1});
     EXPECT_FLOAT_EQ(out_ptr->getValue()[0], 1.0);

+ 1 - 2
lib/test/test_ProcessorStandard.cpp

@@ -1,8 +1,7 @@
 #include <gtest/gtest.h>
 #include <json.hpp>
+#include <Registration.h>
 //#define private public
-#include "ProcessorStandard.h"
-#include <ModuleSwitch.h>
 /*
 
 using namespace mdd;