Forráskód Böngészése

before json change

Willi Zschiebsch 4 éve
szülő
commit
4d6ae23c76

+ 14 - 1
lib/include/Connector.h

@@ -3,6 +3,11 @@
 #include "memory"
 #include "json.hpp"
 
+#include <filesystem>
+#include <iostream>
+#include <iomanip>
+#include <fstream>
+
 #include "Input.h"
 #include "Output.h"
 
@@ -18,8 +23,10 @@ namespace mdd {
 		IProcessor::Ptr _root;
 		const std::map<const std::string, std::function<json(const json&)>> _ops = {//const std::map<const std::string, const json& (Connector::*)(const json&)> _ops = {
 			{"add", std::bind(&Connector::add,this,std::placeholders::_1) },
-			{"remove", std::bind(&Connector::remove,this,std::placeholders::_1)},
 			{"change", std::bind(&Connector::change,this,std::placeholders::_1)},
+			{"load", std::bind(&Connector::load,this,std::placeholders::_1)},
+			{"remove", std::bind(&Connector::remove,this,std::placeholders::_1)},
+			{"save", std::bind(&Connector::save,this,std::placeholders::_1)},
 			{"state", std::bind(&Connector::state,this,std::placeholders::_1)}
         };
 
@@ -47,6 +54,12 @@ namespace mdd {
 		**/
 		json state(const json& args);
 
+
+
+		json save(const json& args);
+
+		json load(const json& args);
+
 	public:
 		Connector();
 		json decode(const json& request);

+ 2 - 2
lib/include/IInput.h

@@ -21,8 +21,8 @@ namespace mdd{
     {
     public:
         typedef std::shared_ptr<IInput> Ptr;
-        virtual const limits& getLimits() = 0;
-        virtual limits& setLimits() = 0;
+        virtual const std::shared_ptr<limits> getLimits() = 0;
+        virtual std::shared_ptr<limits>& setLimits() = 0;
         virtual std::shared_ptr<IOutput> getConnection() = 0;
         virtual ~IInput() = default;
 

+ 3 - 1
lib/include/IManager.h

@@ -3,10 +3,12 @@
 namespace mdd {
 	class IManager {
 	public:
+		virtual const std::string& getConfiguration() = 0;
 		virtual bool configure(const std::string& config) = 0;
-		virtual std::string getConfiguration() = 0;
 		virtual void load(const json& j) = 0;
 		virtual json dump() = 0;
 		virtual json getIdentifier() = 0;
+	protected:
+		virtual bool configureChild(const json& config) = 0;
 	};
 }

+ 1 - 1
lib/include/IModule.h

@@ -42,4 +42,4 @@ namespace mdd {
         virtual ~IModule() = default;
     };
 }
-#endif //MDD_IMODULE_H
+#endif

+ 6 - 4
lib/include/Input.h

@@ -19,11 +19,13 @@ namespace mdd {
         //std::function<bool(const json &)> _verification;
         std::shared_ptr <IOutput> _output;
         bool _optimizable;
-        limits _limit;//make shared_ptr!!!
+        std::shared_ptr<limits> _limit;
 
     protected:
+        json _base_config;
         std::string type;
         std::string key;
+        bool configureChild(const json& config) override { return true; };
 
     public:
         Input(IModule* parent, const std::string &name, int appendix, const std::vector<double>& default_value);
@@ -47,8 +49,8 @@ namespace mdd {
         bool isOptimizable() override;
         void setOptimizability(bool state) override;
 
-        const limits& getLimits() override;
-        limits& setLimits() override;
+        const std::shared_ptr<limits> getLimits() override;
+        std::shared_ptr<limits>& setLimits() override;
 
         std::shared_ptr<IOutput> getConnection() override;
         
@@ -59,7 +61,7 @@ namespace mdd {
         void disconnect() override;
 
         bool configure(const std::string& config) override;
-        std::string getConfiguration() override;
+        const std::string& getConfiguration() override;
         void load(const json& j) override;
         json dump() override;
         json getIdentifier() override;

+ 5 - 5
lib/include/ModuleBase.h

@@ -12,19 +12,19 @@ namespace mdd {
         std::string _name = "";
         int _appendix = 0;
 
-        
-
     protected:
-        std::string _base_config = "";
+        json _base_config;
         ModuleBase(const std::string& base_config = "{}"); 
         std::string type = "module";
         std::string key;
         std::vector<std::shared_ptr<Input>> inputs;
         std::vector<std::shared_ptr<Output>> outputs;
 
+        bool configureChild(const json& config) override { return true; };
+
     public:
-        bool configure(const std::string& config);
-        std::string getConfiguration() override;
+        bool configure(const std::string& config) override;
+        const std::string& getConfiguration() override;
 
         size_t getNumInputs() override;
         size_t getNumOutputs() override;

+ 4 - 2
lib/include/OptimizerBase.h

@@ -13,7 +13,7 @@ namespace mdd {
 		: public IOptimizer 
 	{
 	protected:
-		std::string _base_config = "";
+		json _base_config;
 		std::shared_ptr<IModule> _module;
 		std::vector<std::shared_ptr<IInput>> _inputs;
 		std::vector<std::shared_ptr<IOutput>> _outputs;
@@ -26,13 +26,15 @@ namespace mdd {
 		};
 		opt_state updateOutputs();
 		OptimizerBase(const std::string& base_config);
+		bool configureChild(const json& config) override;
+
 	public:
 		bool connect(std::shared_ptr<IModule> module) override;
 		void updateLayout();
 		bool setEvaluation(std::string func) override;
 
 		bool configure(const std::string& config) override;
-		std::string getConfiguration() override;
+		const std::string& getConfiguration() override;
 		//virtual std::string getGeneratorID() = 0;
 		void load(const json& j);
 		json dump();

+ 1 - 2
lib/include/OptimizerEvolutionary.h

@@ -36,11 +36,10 @@ namespace mdd {
 		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>());
-
+		bool configureChild(const json& config) override;
 
 	public:
 		OptimizerEvolutionary();
-		bool OptimizerEvolutionary::configure(const std::string& config);
 		/*
 		std::shared_ptr<IModule> module,
 			size_t converges = 0,

+ 3 - 1
lib/include/Output.h

@@ -15,8 +15,10 @@ namespace mdd {
         IModule* _parent;
 
     protected:
+        json _base_config;
         std::string type;
         std::string key;
+        bool configureChild(const json& config) override { return true; };
 
     public:
         Output(IModule* parent, const std::string& name, int appendix, const std::vector<double>& initial);
@@ -42,7 +44,7 @@ namespace mdd {
         void disconnect() override;
 
         bool configure(const std::string& config) override;
-        std::string getConfiguration() override;
+        const std::string& getConfiguration() override;
         void load(const json& j) override;
         json dump() override;
         json getIdentifier() override;

+ 4 - 2
lib/include/Parameter.h

@@ -5,12 +5,14 @@ namespace mdd {
     class Parameter : public ModuleBase {
     private:
         IModule* _parent;
+    
+    protected:
+        bool configureChild(const json& config) override;
+
     public:
         Parameter(IModule* parent);
         state update() override;
         std::string setName(const std::string& type) override;
         std::string setAppendix(int appendix) override;
-        bool configure(const std::string& config) override;
-        std::string getConfiguration() override;
     };
 }

+ 5 - 3
lib/include/ProcessorBase.h

@@ -13,9 +13,9 @@ namespace mdd {
 
         std::string _name = "";
         int _appendix = 0;
-        std::string _base_config = "";
 
     protected:
+        json _base_config;
         ProcessorBase(const std::string& base_config);
         std::string type = "processor";
         std::string key;
@@ -25,9 +25,11 @@ namespace mdd {
         std::vector<std::shared_ptr<Parameter>> inputs;
         std::vector<std::shared_ptr<Parameter>> outputs;
 
+        bool configureChild(const json& config) override;
+
     public:
-        bool configure(const std::string& config);
-        std::string getConfiguration() override;
+        bool configure(const std::string& config) override;
+        const std::string& getConfiguration() override;
 
         std::string getGeneratorKey() override;
         std::string getType() override;

+ 3 - 1
lib/include/ProcessorStandard.h

@@ -25,9 +25,11 @@ namespace mdd {
         std::vector<module_priority> _priority_list;
         int _maxIterations;
         priority _priorityEvaluation;
+    protected:
+        bool configureChild(const json& config) override;
+
     public:
         ProcessorStandard();
-        bool configure(const std::string& config) override;
         std::string addModule(std::shared_ptr<IModule> module) override;
         void removeModule(std::shared_ptr<IModule> module) override;
         std::vector<std::shared_ptr<IModule>> getModulePriority();

+ 37 - 2
lib/src/Connector.cpp

@@ -262,10 +262,45 @@ namespace mdd {
 		return ret;
 	}
 
+	json Connector::save(const json& args) {
+		std::ofstream out("save.json");
+		json jfile;
+		jfile = _root->dump();
+		out << std::setw(4) << jfile << std::endl;
+		json ret;
+		ret["operation"] = "save";
+		return ret;
+	}
+
+	json Connector::load(const json& args) {
+		if (std::filesystem::exists("save.json")) {
+			std::ifstream in("save.json");
+			json jfile;
+			in >> jfile;
+			if (jfile.contains("key"))
+			{
+				_root = regi.generateProcessor(jfile["key"].get<std::string>());
+				_root->load(jfile);
+			}
+		}
+		else
+		{
+			_root = regi.generateProcessor("ProcessorStandard");
+			_root->setName("root");
+		}
+		
+		
+		json ret;
+		ret["operation"] = "state";
+		ret["args"] = encode();
+		return ret;
+	}
+
 	Connector::Connector()
 	{
-		_root = regi.generateProcessor("ProcessorStandard");
-		_root->setName("root");
+		
+		json path;
+		load(path);
 	}
 
 	json Connector::decode(const json& request)

+ 35 - 20
lib/src/Input.cpp

@@ -123,46 +123,61 @@ namespace mdd{
 
     void Input::setOptimizability(bool state) {
         _optimizable = state;
+        if (_optimizable && _limit == nullptr)
+        {
+            _limit = std::make_shared<limits>();
+        }
     }
-    const limits& Input::getLimits()
+    const std::shared_ptr<limits> Input::getLimits()
     {
         return _limit;
     }
-    limits& Input::setLimits()
+    std::shared_ptr<limits>& Input::setLimits()
     {
         return _limit;
     }
 
-    bool Input::configure(const std::string& config) 
+    bool Input::configure(const std::string& config)
     {
         json jconfig = json::parse(config);
-        if (jconfig.contains("name"))
+        bool success = false;
+        auto jit = jconfig.find("name");
+        if (jit != jconfig.end())
         {
-            _name = jconfig["name"].get < std::string >();
+            _name = jit.value().get<std::string>();
+            success = true;
         }
-        if (jconfig.contains("appendix"))
+
+        jit = jconfig.find("appendix");
+        if (jit != jconfig.end())
         {
-            _appendix = jconfig["appendix"].get < int >();
+            _appendix = jit.value().get<int>();
+            success = true;
         }
-        if (jconfig.contains("optimizable"))
+
+        jit = jconfig.find("optimizable");
+        if (jit != jconfig.end())
         {
-            _optimizable = jconfig["optimizable"].get < bool >();
+            _optimizable = jit.value().get<bool>();
+            success = true;
         }
-        if (jconfig.contains("value"))
+
+        jit = jconfig.find("value");
+        if (jit != jconfig.end())
         {
-            _value = jconfig["value"].get <std::vector<double> >();
+            _value = jit.value().get<std::vector<double>>();
+            success = true;
         }
-        return true;
+        return success;
     }
 
-    std::string Input::getConfiguration() 
+    const std::string& Input::getConfiguration()
     {
-        json jconfig;
-        jconfig["value"] = _value;
-        jconfig["optimizable"] = _optimizable;
-        jconfig["type"] = "input";
-        jconfig["key"] = "Input";
-        return jconfig.dump();
+        _base_config["value"] = _value;
+        _base_config["optimizable"] = _optimizable;
+        _base_config["type"] = "input";
+        _base_config["key"] = "Input";
+        return _base_config.dump();
     }
 
     void Input::load(const json& j) 
@@ -173,7 +188,7 @@ namespace mdd{
 
     json Input::dump() 
     {
-        json jdump = json::parse(getConfiguration());
+        json jdump = _base_config;
         jdump["ID"] = getIdentifier();
         return jdump;
     }

+ 59 - 23
lib/src/ModuleBase.cpp

@@ -75,33 +75,36 @@ namespace mdd {
     ModuleBase::ModuleBase(const std::string& base_config)
     {
         json jparse = json::parse(base_config);
-        json jconfig;
         if (jparse.contains("configure"))
         {
-            jconfig = jparse;
+            _base_config = jparse;
         }
         else {
-            jconfig["configure"] = jparse;
+            _base_config["configure"] = jparse;
         }
-
-        
-        _base_config = jconfig.dump();
     }
     bool ModuleBase::configure(const std::string& config) {
-        json j = json::parse(config);
-        json jbase = json::parse(_base_config);
-        if (j.contains("GUI"))
+        json jconfig = json::parse(config);
+        bool res = true;
+        auto jit = jconfig.find("GUI");
+        if (jit != jconfig.end())
         {
-            jbase["GUI"] = j["GUI"];
+            _base_config["GUI"] = jit.value();
         }
-        _base_config = jbase.dump();
-        return true;
+        jit = jconfig.find("configure");
+        if (jit != jconfig.end()) {
+            res = configureChild(jit.value());
+        }
+        return res;
     }
    
+    bool configureThis(const json& config) {
+        return true;
+    }
 
-    std::string ModuleBase::getConfiguration()
+    const std::string& ModuleBase::getConfiguration()
     {
-        return _base_config;
+        return _base_config.dump();
     }
 
     std::string ModuleBase::getType() {
@@ -136,29 +139,62 @@ namespace mdd {
 
     void ModuleBase::load(const json& j)
     {
-        if (j.contains("configure"))
+        configure(j.dump());
+
+        auto it = j.find("inputs");
+        if (it!=j.end())
+        {
+            const size_t start_counter = inputs.size();
+            const json& jin = it.value();
+            std::vector<double> default_val = { 1 };
+            for (size_t i = start_counter; i < jin.size(); i++)
+            {
+                inputs.push_back(std::make_shared<Input>(this, "Value", 0, default_val));
+                inputs.back()->load(jin[i]);
+            }
+            for (size_t i = 0; i < jin.size(); i++)
+            {
+                inputs[i]->setValue()=jin[i]["value"].get<std::vector<double>>();
+            }
+        }
+
+        it = j.find("outputs");
+        if (it != j.end())
         {
-            configure(j["configure"].get<std::string>());
+            const size_t start_counter = outputs.size();
+            const json& jout = it.value();
+            std::vector<double> default_val = { 1 };
+            for (size_t i = start_counter; i < j["outputs"].size(); i++)
+            {
+                outputs.push_back(std::make_shared<Output>(this, "Value", 0, default_val));
+                outputs.back()->load(jout[i]);
+            }
+            for (size_t i = 0; i < jout.size(); i++)
+            {
+                outputs[i]->setValue() = jout[i]["value"].get<std::vector<double>>();
+            }
         }
     }
     json ModuleBase::dump()
     {
-        json ret = json::parse(_base_config);
-        ret["ID"] = getIdentifier(); 
-        ret["type"] = type;
-        ret["key"] = key;
+        _base_config["ID"] = getIdentifier();
+        _base_config["type"] = type;
+        _base_config["key"] = key;
+
+        _base_config["inputs"].clear();
+        _base_config["outputs"].clear();
         
         for (auto& in : inputs)
         {
-            ret["inputs"].push_back(in->dump());
+            _base_config["inputs"].push_back(in->dump());
         }
 
         for (auto& out : outputs)
         {
-            ret["outputs"].push_back(out->dump());
+            _base_config["outputs"].push_back(out->dump());
         }
 
-        return ret;
+        return _base_config;
     }
 
     void ModuleBase::disconnect() {

+ 41 - 58
lib/src/ModuleHTTP.cpp

@@ -31,12 +31,12 @@ namespace mdd{
         state updateInputs();
         state updateOutputs();
 
+        bool configureChild(const json& config) override;
+
     public:
         ModuleHTTP();// std::string fname, std::string id, int port);
         ~ModuleHTTP();
         state update() override;
-        bool configure(const std::string& config) override;
-        std::string ModuleHTTP::getConfiguration() override;
     };
 
     bool ModuleHTTP::connect(){
@@ -153,45 +153,55 @@ namespace mdd{
         setName("HTTP");
     }
 
-    bool ModuleHTTP::configure(const std::string& config) {
-        bool found = false;
-        found = ModuleBase::configure(config);
-        json config_parsed = json::parse(config);
-        json base_config = json::parse(ModuleBase::getConfiguration());
-
-        if (config_parsed.contains("configure"))
-        {
-            config_parsed = config_parsed["configure"];
-        }
-
-        if (config_parsed.contains("url"))
+    bool ModuleHTTP::configureChild(const json& config) {
+        bool changed = true;
+        bool found = true;
+        auto jit = config.find("url");
+        if (jit != config.end())
         {
-            _id = config_parsed["url"]["value"].get<std::string>();
-            base_config["configure"]["url"]["value"] = _fname;
+            _id = jit.value()["value"].get<std::string>();
+            json& jbase = _base_config["configure"]["url"]["value"];
+            if (_id != jbase.get<std::string>())
+            {
+                jbase = _id;
+                changed = true;
+            }
             found = true;
         }
         
-        if (config_parsed.contains("port"))
+        jit = config.find("port");
+        if (jit != config.end())
         {
-            json jval = config_parsed["port"]["value"];
+            json jval = jit.value()["value"];
             if (jval.is_string())
             {
                 jval = json::parse(jval.get<std::string>());
             }
             _port = jval.get<int>();
-            base_config["configure"]["port"]["value"] = jval;
+            json& jbase = _base_config["configure"]["port"]["value"];
+            if (_port != jbase.get<int>())
+            {
+                jbase = jval;
+                changed = true;
+            }
             found = true;
         }
         
-        if (config_parsed.contains("file"))
+        jit = config.find("file");
+        if (jit != config.end())
         {
-            _fname = config_parsed["file"]["value"].get<std::string>();
-            base_config["configure"]["file"]["value"] = _fname;
+            _fname = jit.value()["value"].get<std::string>();
+            json& jbase = _base_config["configure"]["file"]["value"];
+            if (_fname != jbase.get<std::string>())
+            {
+                jbase = _fname;
+                changed = true;
+            }
             found = true;
         }
         
 
-        if (!_fname.empty()) {
+        if (!_fname.empty() && changed) {
             if (std::filesystem::exists(_fname))
             {
                 _child = std::make_unique<child>("python3 " + _fname + " " + std::to_string(_port));
@@ -201,44 +211,17 @@ namespace mdd{
                 return false;
             }
         }
-        while (!connect()) {
-            std::this_thread::sleep_for(std::chrono::microseconds(500));
-        }
-        updateInputs();
-        updateOutputs();
-        _base_config = base_config.dump();
-        return found;
-    }
 
-    std::string ModuleHTTP::getConfiguration() {
-        json ret = json::parse(ModuleBase::getConfiguration());
-        for (size_t i = 0; i < ret.size(); i++)
+        if (changed)
         {
-            if (ret[i].contains("name"))
+            if (connect())
             {
-                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();
+                updateInputs();
+                updateOutputs();
+                //_base_config = base_config.dump();
+            } 
+        }  
+        return found;
     }
 
     ModuleHTTP::~ModuleHTTP()

+ 8 - 29
lib/src/ModuleMath.cpp

@@ -23,11 +23,10 @@ namespace mdd {
         std::function<double(double, double)> _operation;
 
         std::vector<double> applyOperation(const std::vector<double>& val1, const std::vector<double>& val2);
+        bool configureChild(const json& config) override;
 
     public:
         ModuleMath();
-        bool configure(const std::string& config) override;
-        std::string getConfiguration();
         state update() override;
     };
 
@@ -61,41 +60,21 @@ namespace mdd {
         setName("Math");
     }
 
-    bool ModuleMath::configure(const std::string& config)
+    bool ModuleMath::configureChild(const json& config)
     {
-        bool success = false;
-        success = ModuleBase::configure(config);
-        json config_parsed = json::parse(config);
-        json base_config = json::parse(ModuleBase::getConfiguration());
-        if (config_parsed.contains("configure"))
+        auto jit = config.find("operation");
+        if (jit != config.end())
         {
-            config_parsed = config_parsed["configure"];
-        }
-        if (config_parsed.contains("operation"))
-        {
-            const std::string op = config_parsed["operation"]["value"].get<std::string>();
+            const std::string op = jit.value()["value"].get<std::string>();
             auto it = _ops.find(op);
             if (it != _ops.end())
             {
                 _operation = it->second;
-                base_config["configure"]["operation"]["value"] = op;
-            }
-        }
-        _base_config = base_config.dump();
-        return true;
-    }
-
-    std::string ModuleMath::getConfiguration() {
-        json ret = json::parse(ModuleBase::getConfiguration());
-        for (auto it = _ops.begin(); it != _ops.end(); it++)
-        {
-            //test by doing the operation with two given values
-            if (it->second(256,2) == _operation(256, 2)) {
-                ret[0]["value"] = it->first;
-                break;
+                _base_config["configure"]["operation"]["value"] = op;
+                return true;
             }
         }
-        return ret.dump();
+        return false;
     }
 
     std::vector<double> ModuleMath::applyOperation(const std::vector<double>&val1, const std::vector<double>&val2) {

+ 8 - 14
lib/src/ModuleMerge.cpp

@@ -4,13 +4,13 @@
 namespace mdd {
 	class ModuleMerge : public ModuleBase {
 	private:
+		bool configureChild(const json& config) override;
 
 	public:
 		ModuleMerge();
 		int addModuleInput();
 		int removeModuleInput();
 		std::string setInputName(const std::string& input_id, const std::string& new_name);
-		bool configure(const std::string& config) override;
 		state update() override;
 	};
 	ModuleMerge::ModuleMerge()
@@ -50,18 +50,12 @@ namespace mdd {
 		return "";
 	}
 
-	bool ModuleMerge::configure(const std::string& config) {
+	bool ModuleMerge::configureChild(const json& config) {
 		bool success = false;
-		success = ModuleBase::configure(config);
-		json config_parsed = json::parse(config);
-		json base_config = json::parse(ModuleBase::getConfiguration());
-		if (config_parsed.contains("configure"))
+		auto jit = config.find("inputs");
+		if (jit != config.end())
 		{
-			config_parsed = config_parsed["configure"];
-		}
-		if (config_parsed.contains("inputs"))
-		{
-			json jval = config_parsed["inputs"]["value"];
+			json jval = jit.value()["value"];
 			if (jval.is_string())
 			{
 				jval = json::parse(jval.get<std::string>());
@@ -78,10 +72,10 @@ namespace mdd {
 					inputs.push_back(std::make_shared<Input>(this, "Value", j, std::vector<double> {1}));
 				}
 			}
-			base_config["configure"]["inputs"]["value"] = jval;
+			_base_config["configure"]["inputs"]["value"] = jval;
+			return true;
 		}
-		_base_config =  base_config.dump();
-		return true;
+		return false;
 	}
 
 	state ModuleMerge::update() {

+ 8 - 30
lib/src/ModuleSQL.cpp

@@ -17,11 +17,12 @@ namespace mdd {
 		};
 		std::vector<_entity> _content;
 
+	protected:
+		bool configureChild(const json& config) override;
+
 	public:
 		ModuleSQL();
 		~ModuleSQL();
-		bool configure(const std::string& config) override;
-		std::string getConfiguration() override;
 		state update() override;
 	};
 
@@ -92,18 +93,11 @@ namespace mdd {
 		sqlite3_close(_db);
 	}
 
-	bool ModuleSQL::configure(const std::string& config) {
-		bool success = false;
-		success = ModuleBase::configure(config);
-		json config_parsed = json::parse(config);
-		json base_config = json::parse(ModuleBase::getConfiguration());
-		if (config_parsed.contains("configure"))
-		{
-			config_parsed = config_parsed["configure"];
-		}
-		if (config_parsed.contains("database"))
+	bool ModuleSQL::configureChild(const json& config) {
+		auto jit = config.find("database");
+		if (jit != config.end())
 		{
-			_dbname = config_parsed["database"]["value"].get<std::string>();
+			_dbname = jit.value()["value"].get<std::string>();
 		}
 		else
 		{
@@ -219,23 +213,7 @@ namespace mdd {
 			outputs.push_back(std::make_shared<Output>(this, cont.key, outputs.size(), std::vector<double>{1}));
 		}
 
-		base_config["configure"]["database"]["value"] = _dbname;
-		_base_config = base_config.dump();
+		_base_config["configure"]["database"]["value"] = _dbname;
 		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();
-	}
 }

+ 9 - 31
lib/src/ModuleSwitch.cpp

@@ -3,10 +3,10 @@
 
 namespace mdd{
     class ModuleSwitch : public ModuleBase {
+    protected:
+        bool configureChild(const json& config) override;
     public:
         ModuleSwitch();
-        bool configure(const std::string& config) override;
-        std::string getConfiguration() override;
         state update() override;
     };
     ModuleSwitch::ModuleSwitch()
@@ -24,18 +24,11 @@ namespace mdd{
         key = "ModuleSwitch";
         setName("Switch");
     }
-    bool ModuleSwitch::configure(const std::string& config) {
-        bool success = false;
-        success = ModuleBase::configure(config);
-        json config_parsed = json::parse(config);
-        json base_config = json::parse(ModuleBase::getConfiguration());
-        if (config_parsed.contains("configure"))
+    bool ModuleSwitch::configureChild(const json& config) {
+        auto jit = config.find("size");
+        if (jit != config.end())
         {
-            config_parsed = config_parsed["configure"];
-        }
-        if (config_parsed.contains("size"))
-        {
-            json jval = config_parsed["size"]["value"];
+            json jval = jit.value()["value"];
             if (jval.is_string())
             {
                 jval = json::parse(jval.get<std::string>());
@@ -62,25 +55,10 @@ namespace mdd{
                     inputs.back()->setName("Default");
                 }
             }
-            base_config["configure"]["size"]["value"] = jval;
-        }
-        _base_config = base_config.dump();
-        return true;
-    }
-
-    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;
-                }
-            }
+            _base_config["configure"]["size"]["value"] = jval;
+            return true;
         }
-        return ret.dump();
+        return false;
     }
 
     state ModuleSwitch::update(){

+ 11 - 12
lib/src/OptimizerBase.cpp

@@ -65,22 +65,21 @@ namespace mdd{
 	}
 	
 	bool OptimizerBase::configure(const std::string& config) {
-		json config_parsed = json::parse(config);
-		for (size_t i = 0; i < config_parsed.size(); i++)
+		json jconfig = json::parse(config);
+		auto jit = jconfig.find("configure");
+		if (jit != jconfig.end())
 		{
-			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 configureChild(jit.value());
 		}
 		return false;
 	}
-	std::string OptimizerBase::getConfiguration() {
-		return _base_config;
+
+	bool OptimizerBase::configureChild(const json& config) {
+		return true;
+	}
+
+	const std::string& OptimizerBase::getConfiguration() {
+		return _base_config.dump();
 	}
 	//virtual std::string getGeneratorID() = 0;
 	void OptimizerBase::load(const json& j) {

+ 39 - 35
lib/src/OptimizerEvolutionary.cpp

@@ -73,41 +73,38 @@ namespace mdd {
 		_precision = 0.001;
 	}
 
-	bool OptimizerEvolutionary::configure(const std::string& config) {
-		json config_parsed = json::parse(config);
+	bool OptimizerEvolutionary::configureChild(const json& config) {
 		bool found = false;
-		for (size_t i = 0; i < config_parsed.size(); i++)
+		auto jit = config.find("converges");
+		if (jit != config.end())
 		{
-			if (config_parsed[i].contains("name"))
-			{
-				if (config_parsed[i]["name"].get<std::string>() == "converges")
-				{
-					_converges = config_parsed[i]["value"].get<int>();
-					found = true;
-				}
-				else if (config_parsed[i]["name"].get<std::string>() == "grow generation")
-				{
-					_grow_generation = config_parsed[i]["value"].get<int>();
-					found = true;
-				}
-				else if (config_parsed[i]["name"].get<std::string>() == "max fitness")
-				{
-					_max_fitness = config_parsed[i]["value"].get<int>();
-					found = true;
-				}
-				else if (config_parsed[i]["name"].get<std::string>() == "min generations")
-				{
-					_min_generations = config_parsed[i]["value"].get<int>();
-					found = true;
-				}
-				else if (config_parsed[i]["name"].get<std::string>() == "precision")
-				{
-					_precision = config_parsed[i]["value"].get<double>();
-					found = true;
-				}
-			}
+			_converges = jit.value()["value"].get<int>();
+			found = true;
+		}
+		jit = config.find("grow generation");
+		if (jit != config.end())
+		{
+			_grow_generation = jit.value()["value"].get<int>();
+			found = true;
+		}
+		jit = config.find("max fitness");
+		if (jit != config.end())
+		{
+			_max_fitness = jit.value()["value"].get<int>();
+			found = true;
+		}
+		jit = config.find("min generations");
+		if (jit != config.end())
+		{
+			_min_generations = jit.value()["value"].get<int>();
+			found = true;
+		}
+		jit = config.find("precision");
+		if (jit != config.end())
+		{
+			_precision = jit.value()["value"].get<double>();
+			found = true;
 		}
-
 		return found;
 	}
 
@@ -143,7 +140,7 @@ namespace mdd {
 				}
 			}
 			
-			++gen;
+ 			++gen;
 			check = gen < _min_generations || _bests[0].fitness > _max_fitness;
 			if (!check && _converges > 0)
 			{
@@ -177,7 +174,7 @@ namespace mdd {
 	std::vector<double> OptimizerEvolutionary::mutateGene(std::shared_ptr<IInput> input, std::vector<double> seed)
 	{
 	
-		limits limit = input->getLimits();
+		const limits limit = *(input->getLimits());
 		auto ret = seed;
 		
 		if (!limit.elements.empty())
@@ -243,7 +240,14 @@ namespace mdd {
 
 					exprtk::parser<double> parser;
 					parser.compile(limit.rule, func_expr);
-					check = (bool)func_expr.value();
+					double func_val = func_expr.value();
+					if (func_val < 0.5)
+					{
+						check = false;
+					}
+					else {
+						check = true;
+					}
 				}
 			} while (!check);
 			return ret; 

+ 28 - 17
lib/src/Output.cpp

@@ -130,33 +130,44 @@ namespace mdd {
     bool Output::configure(const std::string& config)
     {
         json jconfig = json::parse(config);
-        if (jconfig.contains("name"))
+        bool success = false;
+        auto jit = jconfig.find("name");
+        if (jit != jconfig.end())
         {
-            _name = jconfig["name"].get < std::string >();
+            _name = jit.value().get<std::string>();
+            success = true;
         }
-        if (jconfig.contains("appendix"))
+
+        jit = jconfig.find("appendix");
+        if (jit != jconfig.end())
         {
-            _appendix = jconfig["appendix"].get < int >();
+            _appendix = jit.value().get < int >();
+            success = true;
         }
-        if (jconfig.contains("optimizable"))
+
+        jit = jconfig.find("optimizable");
+        if (jit != jconfig.end())
         {
-            _optimizable = jconfig["optimizable"].get < bool >();
+            _optimizable = jit.value().get < bool >();
+            success = true;
         }
-        if (jconfig.contains("value"))
+
+        jit = jconfig.find("value");
+        if (jit != jconfig.end())
         {
-            _value = jconfig["value"].get <std::vector<double> >();
+            _value = jit.value().get <std::vector<double> >();
+            success = true;
         }
-        return true;
+        return success;
     }
 
-    std::string Output::getConfiguration()
+    const std::string& Output::getConfiguration()
     {
-        json jconfig;
-        jconfig["optimizable"] = _optimizable;
-        jconfig["value"] = _value;
-        jconfig["type"] = "output";
-        jconfig["key"] = "Output";
-        return jconfig.dump();
+        _base_config["optimizable"] = _optimizable;
+        _base_config["value"] = _value;
+        _base_config["type"] = "output";
+        _base_config["key"] = "Output";
+        return _base_config.dump();
     }
 
     void Output::load(const json& j)
@@ -167,7 +178,7 @@ namespace mdd {
 
     json Output::dump()
     {
-        json jdump = json::parse(getConfiguration());
+        json jdump = _base_config;
         jdump["ID"] = getIdentifier();
         return jdump;
     }

+ 7 - 25
lib/src/Parameter.cpp

@@ -33,36 +33,18 @@ namespace mdd {
         outputs[0]->setAppendix(appendix);
         return ModuleBase::setAppendix(appendix);
     }
-    bool Parameter::configure(const std::string& config)
+
+    bool Parameter::configureChild(const json& config)
     {
-        json config_parsed = json::parse(config);
-        for (size_t i = 0; i < config_parsed.size(); i++)
+        auto jit = config.find("name");
+        if (jit != config.end())
         {
-            if (config_parsed[i].contains("name"))
+            if (jit.value().get<std::string>() == "appendix")
             {
-                if (config_parsed[i]["name"].get<std::string>() == "appendix")
-                {
-                    setAppendix(config_parsed[i]["value"].get<int>());
-                }
+                setAppendix(jit.value()["value"].get<int>());
+                _base_config["configure"]["appendix"]["value"] = getAppendix();
             }
         }
-
         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();
-    }
 }

+ 172 - 66
lib/src/ProcessorBase.cpp

@@ -9,91 +9,85 @@ namespace mdd{
             _base_config = base_config;
         }
         else {
-            json jconfig;
-            jconfig["configure"] = jparse;
-            _base_config = jconfig.dump();
+            _base_config["configure"] = jparse;
         }
     }
 
     bool ProcessorBase::configure(const std::string& config) {
-        json j = json::parse(config);
-        json jbase = json::parse(_base_config);
-        if (j.contains("GUI"))
+        json jconfig = json::parse(config);
+        bool sucess = false;
+        auto jit = jconfig.find("GUI");
+        if (jit != jconfig.end())
         {
-            jbase["GUI"] = j["GUI"];
+            _base_config["GUI"] = jit.value();
         }
-        _base_config = jbase.dump();
-        for (size_t i = 0; i < j.size(); i++)
+        jit = jconfig.find("params");
+        if (jit != jconfig.end())
         {
-            if (j.contains("params"))
-            {
-                if (j["params"].contains("inputs"))
-                {
-                    for (size_t i = 0; i < j["inputs"].size(); i++)
-                    {
-                        inputs.push_back(std::make_shared<Parameter>(this));
-                        inputs.back()->setName(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.push_back(std::make_shared<Parameter>(this));
-                        outputs.back()->setName(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++)
+            auto jit2 = jit.value().find("inputs");
+            if (jit2 != jit.value().end())
+            {
+                for (size_t i = 0; i < jit.value().size(); i++)
                 {
-                    addModule(regi.generateModule(j["modules"][i]["id"].get<std::string>()));
-                    modules.back()->setName(j["modules"][i]["type"].get<std::string>());
-                    modules.back()->setAppendix(j["modules"][i]["appendix"].get<int>());
-                    modules.back()->load(j["modules"][i]["load"]);
+                    inputs.push_back(std::make_shared<Parameter>(this));
+                    inputs.back()->setName(jit2.value()["type"].get<std::string>());
+                    inputs.back()->setAppendix(jit2.value()["appendix"].get<int>());
                 }
+                sucess = true;
             }
-            if (j.contains("connections")) {
-                for (size_t i = 0; i < j["connections"].size(); i++)
+
+            jit2 = jit.value().find("outputs");
+            if (jit2 != jit.value().end())
+            {
+                for (size_t i = 0; i < jit.value().size(); i++)
                 {
-                    connect(j["connections"][i]["output"].get<std::string>(), j["connections"][i]["inputs"].get<std::vector<std::string>>());
+                    outputs.push_back(std::make_shared<Parameter>(this));
+                    outputs.back()->setName(jit2.value()["type"].get<std::string>());
+                    outputs.back()->setAppendix(jit2.value()["appendix"].get<int>());
                 }
+                sucess = true;
             }
         }
-        return true;
-    }
 
-    std::string ProcessorBase::getConfiguration() {
-        //update module apendix ?
+        jit = jconfig.find("modules");
+        if (jit != jconfig.end()) {
+            auto regi = Registration();
+            for (size_t i = 0; i < jit.value().size(); i++)
+            {
+                const json& jmodule = jit.value()[i];
+                addModule(regi.generateModule(jmodule["id"].get<std::string>()));
+                modules.back()->setName(jmodule["type"].get<std::string>());
+                modules.back()->setAppendix(jmodule["appendix"].get<int>());
+                modules.back()->load(jmodule["load"]);
+            }
+            sucess = true;
+        }
 
-        json ret = json::parse(_base_config);
-        json sub_ret;
-        sub_ret["params"];
-        sub_ret["params"]["inputs"];
-        for (size_t i = 0; i < inputs.size(); i++)
-        {
-            json sub;
-            sub["type"] = inputs[i]->getType();
-            sub["appendix"] = inputs[i]->getAppendix();
-            sub_ret["params"]["inputs"].push_back(sub);
+        jit = jconfig.find("connections");
+        if (jit != jconfig.end()) {
+            for (size_t i = 0; i < jit.value().size(); i++)
+            {
+                const json& jconn = jit.value()[i];
+                connect(jconn["output"].get<std::string>(), jconn["inputs"].get<std::vector<std::string>>());
+            }
+            sucess = true;
         }
 
-        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();
-            sub_ret["params"]["outputs"].push_back(sub);
+        jit = jconfig.find("configuration");
+        if (jit != jconfig.end()) {
+            sucess = configureChild(jit.value());
         }
+        return sucess;
+    }
 
-        
-        ret.push_back(sub_ret);
-        return ret.dump();
+    bool ProcessorBase::configureChild(const json& config) {
+        return true;
+    }
+
+    const std::string& ProcessorBase::getConfiguration() {
+        //update module apendix ?
+        return _base_config.dump();
     }
 
     std::string ProcessorBase::getType() {
@@ -242,15 +236,127 @@ namespace mdd{
     }
 
     void ProcessorBase::load(const json& j) {
-        
+        if (j.contains("ID"))
+        {
+            setAppendix(j["ID"]["appendix"].get<int>());
+            setName(j["ID"]["name"].get<std::string>());
+            j["ID"]["type"];
+
+        }
+        if (j.contains("key"))
+        {
+
+        }
+        if (j.contains("type"))
+        {
+
+        }
+        if (j.contains("configure"))
+        {
+
+        }
+
+        if (j.contains("modules"))
+        {
+            Registration regi = Registration();
+            for (json jmodule : j["modules"])
+            {
+                if (jmodule["type"].get<std::string>() == "module")
+                {
+                    addModule(regi.generateModule(jmodule["key"]));
+                }
+                else if (jmodule["type"].get<std::string>() == "processor")
+                {
+                    addModule(regi.generateProcessor(jmodule["key"]));
+                }
+                modules.back()->load(jmodule);
+                int check = 0;
+            }
+        }
+
+        if (j.contains("inputs"))
+        {
+            const size_t start_counter = processor_inputs.size();
+            for (size_t i = start_counter; i < j["inputs"].size(); i++)
+            {
+
+            }
+        }
+
+        if (j.contains("outputs"))
+        {
+            const size_t start_counter = processor_outputs.size();
+            for (size_t i = start_counter; i < j["outputs"].size(); i++)
+            {
+
+            }
+        }
+
+        if (j.contains("connections"))
+        {
+            for(json jcon : j["connections"])
+            {
+                json jout = jcon["output"];
+                IModule::Ptr module_out_ptr = getModule(jout["prefix"].back().get<std::string>());
+                IOutput::Ptr out_ptr = nullptr;
+                std::string id = jout["name"].get<std::string>() + std::to_string(jout["appendix"].get<int>());
+                for (size_t i = 0; i < module_out_ptr->getNumOutputs(); i++)
+                {
+                    auto out = module_out_ptr->getOutput(i);
+                    if (out->getID() == id)
+                    {
+                        out_ptr = out;
+                        break;
+                    }
+                }
+                for (json jin : jcon["inputs"])
+                {
+                    IModule::Ptr module_in_ptr = getModule(jin["prefix"].back().get<std::string>());
+                    IInput::Ptr in_ptr = nullptr;
+                    std::string id = jin["name"].get<std::string>() + std::to_string(jin["appendix"].get<int>());
+                    for (size_t i = 0; i < module_in_ptr->getNumInputs(); i++)
+                    {
+                        auto in = module_in_ptr->getInput(i);
+                        if (in->getID() == id)
+                        {
+                            in_ptr = in;
+                            break;
+                        }
+                    }
+                    if (in_ptr != nullptr && out_ptr != nullptr)
+                    {
+                        in_ptr->connect(out_ptr);
+                    }
+                }
+            }
+        }
     }
 
     json ProcessorBase::dump() {
-        json ret = json::parse(_base_config);
+        json ret = _base_config;
         ret["ID"] = getIdentifier();
         ret["type"] = type;
         ret["key"] = key;
 
+        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);
+        }
+
         for (auto& in : processor_inputs)
         {
             ret["inputs"].push_back(in->dump());

+ 12 - 16
lib/src/ProcessorStandard.cpp

@@ -24,23 +24,17 @@ namespace mdd {
         _priorityEvaluation = MANUAL;
         _maxIterations = -1;
         
-        key = "StandardProcessor";
+        key = "ProcessorStandard";
         setName(key);
         processor_outputs.push_back(std::make_shared<Output>(this, "Iterator", 0, std::vector<double>{0}));
     }
 
-    bool ProcessorStandard::configure(const std::string& config) {
+    bool ProcessorStandard::configureChild(const json& config) {
         bool found = false;
-        found = ProcessorBase::configure(config);
-        json config_parsed = json::parse(config);
-        json base_config = json::parse(ProcessorBase::getConfiguration());
-        if (config_parsed.contains("configure"))
+        auto jit = config.find("priority");
+        if (jit != config.end())
         {
-            config_parsed = config_parsed["configure"];
-        }
-        if (config_parsed.contains("priority"))
-        {
-            std::string op = config_parsed["priority"]["value"].get<std::string>();
+            std::string op = jit.value()["value"].get<std::string>();
             found = true;
             if (op == "manual") {
                 _priorityEvaluation = MANUAL;
@@ -58,15 +52,17 @@ namespace mdd {
             {
                 found = false;
             }
-            base_config["configure"]["priority"]["value"] = _priorityEvaluation;
+            _base_config["configure"]["priority"]["value"] = _priorityEvaluation;
         }
-        if (config_parsed.contains("iterations"))
+
+        jit = config.find("iterations");
+        if (jit != config.end())
         {
-            _maxIterations = config_parsed["iterations"]["value"].get<int>();
+            _maxIterations = jit.value()["value"].get<int>();
             found = true;
-            base_config["configure"]["iterations"]["value"] = _maxIterations;
+            _base_config["configure"]["iterations"]["value"] = _maxIterations;
         }
-        ProcessorBase::configure(base_config.dump());
+
         return found;
     }
 

+ 6 - 3
lib/test/server/gfk_plate.py

@@ -106,7 +106,8 @@ def sim_rotor(materials, angles, outer_diameter=0.250, inner_diameter=0.050, thi
     mapdl.mshape(0, "3D")
     mapdl.mshkey(1)
     mapdl.vmesh("ALL")
-    # mapdl.eplot("ALL")
+
+    mapdl.eplot("ALL")
 
     for j in range(1, len(angles)+1):
         for i in range(0, 20*4):
@@ -141,7 +142,7 @@ def sim_rotor(materials, angles, outer_diameter=0.250, inner_diameter=0.050, thi
 
     result = mapdl.result
     # result.plot_nodal_solution(0, 'z', show_displacement=True)
-    # result.plot_principal_nodal_stress(0, 'S1', show_edges=True, show_axes=True)
+    result.plot_principal_nodal_stress(0, 'S1', show_edges=True, show_axes=True)
 
     # """
     nodenump, stress = result.principal_nodal_stress(0)
@@ -183,6 +184,7 @@ def sim_rotor(materials, angles, outer_diameter=0.250, inner_diameter=0.050, thi
     return s1max, s2max, srmax, stmax, f[0], f[1], f[2]
 
 
+"""
 print(sim_rotor(
     [{
         "e11":      42.5E9  ,
@@ -207,4 +209,5 @@ print(sim_rotor(
         "d11":      4.4E-3,
         "d22":      3.1E-3,
         "d33":      3.1E-3
-    }], [90, 0, 0, 0, 0, 0]))
+    }], [90, 90, 90, 0, 90, 90]))
+# """

+ 219 - 85
lib/test/test_Ansys.cpp

@@ -8,20 +8,48 @@
 #include <math.h>
 #include <thread>
 
+#include <windows.h>
+#include <string>
+#include <iostream>
+
 using namespace mdd;
 namespace TEST_ANSYS { 
     auto regi = Registration();
+
+
+    std::string ExePath() {
+        TCHAR buffer[MAX_PATH] = { 0 };
+        GetModuleFileName(NULL, buffer, MAX_PATH);
+        std::string::size_type pos = std::string(buffer).find_last_of("\\/");
+        return std::string(buffer).substr(0, pos);
+    }
+
+    void evaluateIndividuum(OptimizerEvolutionary& optimizer, IModule::Ptr module_ptr, OptimizerEvolutionary::Individual& ind) {
+        auto start = std::chrono::steady_clock::now();
+        json j;
+        j = ind.dna[0];
+        std::cout << j.dump() << ": " << optimizer.evaluateFitness(ind);
+        std::cout << "\t| " << module_ptr->getOutput(0)->getValue()[0] << "\t| " << module_ptr->getOutput(1)->getValue()[0] << "\t| " << module_ptr->getOutput(2)->getValue()[0] << "\t| " << module_ptr->getOutput(3)->getValue()[0] << std::endl;
+        std::cout << "\t| " << module_ptr->getOutput(4)->getValue()[0] << "\t| " << module_ptr->getOutput(5)->getValue()[0] << std::endl;
+        auto end = std::chrono::steady_clock::now();
+        std::cout << "\t| " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms" << std::endl;
+        std::cout << std::endl;
+    }
+    
+    
+    /*
     TEST(ModuleHTTP, test_ansys_sql_server) {
+        std::cout << ExePath() << std::endl;
         auto sql = regi.generateModule("ModuleSQL");
-        json config = json::parse(sql->getConfiguration());
-        config[0]["value"] = "../../../lib/test/db/materials.db";
-        sql->configure(config.dump());
+        json config = sql->getConfiguration();
+        config["configure"]["database"]["value"] = "../../../../../lib/test/db/materials.db";
+        sql->configure(config);
 
         auto http = regi.generateModule("ModuleHTTP");// ("", "localhost", 8888);
-        config = json::parse(http->getConfiguration());
-        config[0]["value"] = "";
-        config[1]["value"] = "localhost";
-        config[2]["value"] = 8888;
+        config = http->getConfiguration())["configure"];
+        config["file"]["value"] = "";
+        config["url"]["value"] = "localhost";
+        config["port"]["value"] = 8888;
         http->configure(config.dump());
         //../../../lib/test/server/server-ansys.py
 
@@ -41,7 +69,7 @@ namespace TEST_ANSYS {
         limit.max = { 90, 90, 90, 90, 90, 90 };
         limit.rule = "val[0] != val[5] || val[1] != val[4] || val[2] != val[3]";
         http->getInput(http->getNumInputs() - 1)->setLimits() = limit;
-        http->getInput(http->getNumInputs() - 1)->setValue() = { 90,90,0,90,0,90 };
+        http->getInput(http->getNumInputs() - 1)->setValue() = { 0,0,0,0,0,90 };
 
         http->getOutput(0)->setOptimizability(true);
 
@@ -54,21 +82,21 @@ namespace TEST_ANSYS {
         }
 
         http->update();
-        EXPECT_FLOAT_EQ(http->getOutput(3)->getValue()[0], 31.204228291286723);
+        EXPECT_FLOAT_EQ(http->getOutput(3)->getValue()[0], 37.154861);
     }
 
     TEST(ModuleHTTP, test_configurations) {
         auto sql = regi.generateModule("ModuleSQL");
-        json config = json::parse(sql->getConfiguration());
-        config[0]["value"] = "../../../lib/test/db/materials.db";
-        sql->configure(config.dump());
+        json config = sql->getConfiguration();
+        config["configure"]["database"]["value"] = "../../../../../lib/test/db/materials.db";
+        sql->configure(config);
 
         auto http = regi.generateModule("ModuleHTTP");// ("", "localhost", 8888);
-        config = json::parse(http->getConfiguration());
-        config[0]["value"] = "";
-        config[1]["value"] = "localhost";
-        config[2]["value"] = 8888;
-        http->configure(config.dump());
+        config = http->getConfiguration();
+        config["configure"]["file"]["value"] = "";
+        config["configure"]["url"]["value"] = "localhost";
+        config["configure"]["port"]["value"] = 8888;
+        http->configure(config);
         //../../../lib/test/server/server-ansys.py
 
         sql->getInput(0)->setValue() = { 1 };
@@ -95,11 +123,11 @@ namespace TEST_ANSYS {
         processor->addModule(http);
 
         OptimizerEvolutionary optimizer;
-        config = json::parse(optimizer.getConfiguration());
-        config[0]["value"] = 3;
-        config[1]["value"] = 20;
-        config[2]["value"] = 0.13;
-        config[3]["value"] = 5;
+        config = optimizer.getConfiguration());
+        config["configure"]["converges"]["value"] = 3;
+        config["configure"]["grow generation"]["value"] = 20;
+        config["configure"]["max fitness"]["value"] = 0.13;
+        config["configure"]["min generations"]["value"] = 5;
         optimizer.configure(config.dump());
         optimizer.connect(processor);
         optimizer.setEvaluation("out0");
@@ -109,87 +137,55 @@ namespace TEST_ANSYS {
         auto start = std::chrono::steady_clock::now();
         auto end = std::chrono::steady_clock::now();
 
-        /*
         ind.dna = { { 0,0,0,0,0,0 } };
-        start = std::chrono::steady_clock::now();
-        std::cout << "{ 0,0,0,0,0,0 }: " << optimizer.evaluateFitness(ind);
-        end = std::chrono::steady_clock::now();
-        std::cout << " | " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms" << std::endl;
-
+        evaluateIndividuum(optimizer, http, ind);
+        
         ind.dna = { { 90,90,90,90,90,90 } };
-        start = std::chrono::steady_clock::now();
-        std::cout << "{ 90,90,90,90,90,90 }: " << optimizer.evaluateFitness(ind);
-        end = std::chrono::steady_clock::now();
-        std::cout << " | " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms" << std::endl;
-        //*/
+        evaluateIndividuum(optimizer, http, ind);
+
         ind.dna = { { 90,0,0,0,0,0 } };
-        start = std::chrono::steady_clock::now();
-        std::cout << "{ 90,0,0,0,0,0 }: " << optimizer.evaluateFitness(ind);
-        end = std::chrono::steady_clock::now();
-        std::cout << " | " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms" << std::endl;
+        evaluateIndividuum(optimizer, http, ind);
 
         ind.dna = { { 0,0,0,0,0,90 } };
-        start = std::chrono::steady_clock::now();
-        std::cout << "{ 0,0,0,0,0,90 }: " << optimizer.evaluateFitness(ind);
-        end = std::chrono::steady_clock::now();
-        std::cout << " | " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms" << std::endl;
+        evaluateIndividuum(optimizer, http, ind);
 
         ind.dna = { { 0,90,90,90,90,90 } };
-        start = std::chrono::steady_clock::now();
-        std::cout << "{ 0,90,90,90,90,90 }: " << optimizer.evaluateFitness(ind);
-        end = std::chrono::steady_clock::now();
-        std::cout << " | " << std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count() << "ms" << std::endl;
+        evaluateIndividuum(optimizer, http, ind);
 
         ind.dna = { { 90,90,90,90,90,0 } };
-        start = std::chrono::steady_clock::now();
-        std::cout << "{ 90,90,90,90,90,0 }: " << optimizer.evaluateFitness(ind);
-        end = std::chrono::steady_clock::now();
-        std::cout << " | " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms" << std::endl;
+        evaluateIndividuum(optimizer, http, ind);
 
         ind.dna = { { 90,0,0,0,90,0 } };
-        start = std::chrono::steady_clock::now();
-        std::cout << "{ 90,0,0,0,90,0 }: " << optimizer.evaluateFitness(ind);
-        end = std::chrono::steady_clock::now();
-        std::cout << " | " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms" << std::endl;
+        evaluateIndividuum(optimizer, http, ind);
 
         ind.dna = { { 90,0,0,0,90,0 } };
-        start = std::chrono::steady_clock::now();
-        std::cout << "{ 90,0,0,0,90,0 }: " << optimizer.evaluateFitness(ind);
-        end = std::chrono::steady_clock::now();
-        std::cout << " | " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms" << std::endl;
-     
+        evaluateIndividuum(optimizer, http, ind);
+
         ind.dna = { { 90,0,0,0,90,0 } };
-        start = std::chrono::steady_clock::now();
-        std::cout << "{ 90,0,0,0,90,0 }: " << optimizer.evaluateFitness(ind);
-        end = std::chrono::steady_clock::now();
-        std::cout << " | " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms" << std::endl;
+        evaluateIndividuum(optimizer, http, ind);
 
         ind.dna = { { 0,0,90,90,90,90 } };
-        start = std::chrono::steady_clock::now();
-        std::cout << "{ 0,0,90,90,90,90 }: " << optimizer.evaluateFitness(ind);
-        end = std::chrono::steady_clock::now();
-        std::cout << " | " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms" << std::endl;
+        evaluateIndividuum(optimizer, http, ind);
 
         ind.dna = { { 0,0,90,90,90,90 } };
-        start = std::chrono::steady_clock::now();
-        std::cout << "{ 0,0,90,90,90,90 }: " << optimizer.evaluateFitness(ind);
-        end = std::chrono::steady_clock::now();
-        std::cout << " | " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms" << std::endl;
+        evaluateIndividuum(optimizer, http, ind);
+
         EXPECT_TRUE(ind.fitness <= 100.0);
     }
+    
 
     TEST(ModuleHTTP, test_ansys_server) {
         auto sql = regi.generateModule("ModuleSQL");
-        json config = json::parse(sql->getConfiguration());
-        config[0]["value"] = "../../../lib/test/db/materials.db";
-        sql->configure(config.dump());
+        json config = sql->getConfiguration();
+        config["configure"]["database"]["value"] = "../../../../../lib/test/db/materials.db";
+        sql->configure(config);
 
         auto http = regi.generateModule("ModuleHTTP");// ("", "localhost", 8888);
-        config = json::parse(http->getConfiguration());
-        config[0]["value"] = "";
-        config[1]["value"] = "localhost";
-        config[2]["value"] = 8888;
-        http->configure(config.dump());
+        config = http->getConfiguration();
+        config["configure"]["file"]["value"] = "";
+        config["configure"]["url"]["value"] = "localhost";
+        config["configure"]["port"]["value"] = 8888;
+        http->configure(config);
         //../../../lib/test/server/server-ansys.py
 
         sql->getInput(0)->setValue() = { 1 };
@@ -206,7 +202,7 @@ namespace TEST_ANSYS {
         limits limit;
         limit.min = { 0, 0, 0, 0, 0, 0 };
         limit.max = { 90, 90, 90, 90, 90, 90 };
-        limit.rule = "val[0] != val[5] || val[1] != val[4] || val[2] != val[3]";
+        limit.rule = "val[0] != val[5] or val[1] != val[4] or val[2] != val[3]";
         http->getInput(http->getNumInputs() - 1)->setLimits() = limit;
 
         http->getOutput(0)->setOptimizability(true);
@@ -216,12 +212,12 @@ namespace TEST_ANSYS {
         processor->addModule(http);
 
         OptimizerEvolutionary optimizer;
-        config = json::parse(optimizer.getConfiguration());
-        config[0]["value"] = 3;
-        config[1]["value"] = 20;
-        config[2]["value"] = 13.4;
-        config[3]["value"] = 5;
-        optimizer.configure(config.dump());
+        config = optimizer.getConfiguration();
+        config["configure"]["converges"]["value"] = 3;
+        config["configure"]["grow generation"]["value"] = 20;
+        config["configure"]["max fitness"]["value"] = 0.13;
+        config["configure"]["min generations"]["value"] = 5;
+        optimizer.configure(config);
         optimizer.connect(processor);
         optimizer.setEvaluation("out0");
         auto start = std::chrono::steady_clock::now();
@@ -232,5 +228,143 @@ namespace TEST_ANSYS {
         std::cout << optimizer.evaluateFitness(optimizer.getBests()[0]) << std::endl;
         EXPECT_TRUE(optimizer.getBests()[0].fitness <= 100.0);
     }
+    
+
+    TEST(ModuleHTTP, test_configurations) {
+        auto sql = regi.generateModule("ModuleSQL");
+        json config = sql->getConfiguration();
+        config["configure"]["database"]["value"] = "../../../../../lib/test/db/materials.db";
+        sql->configure(config);
+    
+        auto http = regi.generateModule("ModuleHTTP");// ("", "localhost", 8888);
+        config = http->getConfiguration();
+        config["configure"]["file"]["value"] = "";
+        config["configure"]["url"]["value"] = "localhost";
+        config["configure"]["port"]["value"] = 8888;
+        http->configure(config);
+        //../../../lib/test/server/server-ansys.py
+    
+        sql->getInput(0)->setValue() = { 1 };
+    
+        for (size_t i = 0; i < http->getNumInputs(); i++)
+        {
+            std::cout << http->getInput(i)->getValue()[0] << std::endl;
+        }
+        for (size_t i = 2; i < sql->getNumOutputs(); i++)//0: ID 1: Name
+        {
+            http->getInput(i - 2)->connect(sql->getOutput(i));
+        }
+        http->getInput(http->getNumInputs() - 1)->setOptimizability(true);
+        limits limit;
+        limit.min = { 0, 0, 0, 0, 0, 0 };
+        limit.max = { 90, 90, 90, 90, 90, 90 };
+        limit.rule = "val[0] != val[5] || val[1] != val[4] || val[2] != val[3]";
+        http->getInput(http->getNumInputs() - 1)->setLimits() = limit;
+    
+        http->getOutput(0)->setOptimizability(true);
+        http->getOutput(4)->setOptimizability(true);
+    
+        std::shared_ptr<ProcessorStandard> processor = std::make_shared<ProcessorStandard>();;
+        processor->addModule(sql);
+        processor->addModule(http);
+    
+        OptimizerEvolutionary optimizer;
+        config = optimizer.getConfiguration();
+        config["configure"]["converges"]["value"] = 3;
+        config["configure"]["grow generation"]["value"] = 20;
+        config["configure"]["max fitness"]["value"] = 0.13;
+        config["configure"]["min generations"]["value"] = 5;
+        optimizer.configure(config);
+        optimizer.connect(processor);
+        optimizer.setEvaluation("2^(-35+out0)+4.2233*10^(-11)*exp(-out1^5/643634300000)*out1^5");
+    
+        //auto res = optimizer.update();
+        OptimizerEvolutionary::Individual ind;
+    
+        ind.dna = { { 0,0,0,0,0,0 } };
+        evaluateIndividuum(optimizer, http, ind);
+    
+        ind.dna = { { 90,90,90,90,90,90 } };
+        evaluateIndividuum(optimizer, http, ind);
+    
+        ind.dna = { { 90,0,0,0,0,0 } };
+        evaluateIndividuum(optimizer, http, ind);
+    
+        ind.dna = { { 0,0,0,0,0,90 } };
+        evaluateIndividuum(optimizer, http, ind);
+    
+        ind.dna = { { 0,90,90,90,90,90 } };
+        evaluateIndividuum(optimizer, http, ind);
+    
+        ind.dna = { { 0,0,90,90,90,90 } };
+        evaluateIndividuum(optimizer, http, ind);
+    
+        ind.dna = { { 90,90,90,0,90,90 } };
+        evaluateIndividuum(optimizer, http, ind);
+    
+        ind.dna = { { 0,0,0,90,0,0 } };
+        evaluateIndividuum(optimizer, http, ind);
+    
+        ind.dna = { { 0,0,90,0,90,0 } };
+        evaluateIndividuum(optimizer, http, ind);
+    
+        EXPECT_TRUE(ind.fitness <= 100.0);
+    }
+
+    TEST(ModuleHTTP, test_ansys_server) {
+        auto sql = regi.generateModule("ModuleSQL");
+        json config = sql->getConfiguration();
+        config["configure"]["database"]["value"] = "../../../../../lib/test/db/materials.db";
+        sql->configure(config);
+    
+        auto http = regi.generateModule("ModuleHTTP");// ("", "localhost", 8888);
+        config = http->getConfiguration();
+        config["configure"]["file"]["value"] = "";
+        config["configure"]["url"]["value"] = "localhost";
+        config["configure"]["port"]["value"] = 8888;
+        http->configure(config);
+        //../../../lib/test/server/server-ansys.py
+
+        sql->getInput(0)->setValue() = { 1 };
+
+        for (size_t i = 0; i < http->getNumInputs(); i++)
+        {
+            std::cout << http->getInput(i)->getValue()[0] << std::endl;
+        }
+        for (size_t i = 2; i < sql->getNumOutputs(); i++)//0: ID 1: Name
+        {
+            http->getInput(i - 2)->connect(sql->getOutput(i));
+        }
+        http->getInput(http->getNumInputs() - 1)->setOptimizability(true);
+        limits limit;
+        limit.min = { 0, 0, 0, 0, 0, 0 };
+        limit.max = { 90, 90, 90, 90, 90, 90 };
+        limit.rule = "val[0] != val[5] or val[1] != val[4] or val[2] != val[3]";
+        http->getInput(http->getNumInputs() - 1)->setLimits() = limit;
+
+        http->getOutput(0)->setOptimizability(true);
+        http->getOutput(4)->setOptimizability(true);
+
+        std::shared_ptr<ProcessorStandard> processor = std::make_shared<ProcessorStandard>();;
+        processor->addModule(sql);
+        processor->addModule(http);
+
+        OptimizerEvolutionary optimizer;
+        config = optimizer.getConfiguration();
+        config["configure"]["converges"]["value"] = 3;
+        config["configure"]["grow generation"]["value"] = 20;
+        config["configure"]["max fitness"]["value"] = 0.13;
+        config["configure"]["min generations"]["value"] = 5;
+        optimizer.configure(config);
+        optimizer.connect(processor);
+        optimizer.setEvaluation("2^(-35+out0)+4.2233*10^(-11)*exp(-out1^5/643634300000)*out1^5");
+        auto start = std::chrono::steady_clock::now();
+        auto res = optimizer.update();
+        auto end = std::chrono::steady_clock::now();
+        std::cout << optimizer.getBests()[0].fitness;
+        std::cout << " | " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms" << std::endl;
+        std::cout << optimizer.evaluateFitness(optimizer.getBests()[0]) << std::endl;
+        EXPECT_TRUE(optimizer.getBests()[0].fitness <= 10.0);
+    }
     //*/
 }

+ 15 - 15
lib/test/test_ModuleHTTP.cpp

@@ -10,7 +10,7 @@ using namespace mdd;
 using namespace httplib;
 
 namespace TEST_MODULE_HTTP{
-
+    /*
 void serverThread()
 {
     Server svr;
@@ -89,10 +89,10 @@ auto regi = Registration();
 TEST(ModuleHTTP, updateLayout_intern){
     std::thread server (serverThread);
     auto mod = regi.generateModule("ModuleHTTP");// ("", "localhost", 8888);
-    json config = json::parse(mod->getConfiguration());
-    config[0]["value"] = "";
-    config[1]["value"] = "localhost";
-    config[2]["value"] = 8888;
+    json config = mod->getConfiguration();
+    config["path"]["value"] = "";
+    config["url"]["value"] = "localhost";
+    config["port"]["value"] = 8888;
     mod->configure(config.dump());
 
     Client cli("localhost",8888);
@@ -114,11 +114,11 @@ TEST(ModuleHTTP, updateLayout_intern){
 
 TEST(ModuleHTTP, updateLayout_extern){
     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());
+    json config = mod->getConfiguration();
+    config["path"]["value"] = "../../../lib/test/server/server.py";
+    config["url"]["value"] = "localhost";
+    config["port"]["value"] = 8889;
+    mod->configure(config);
    
     for (int i = 0; i < mod->getNumInputs(); ++i) {
         EXPECT_EQ(mod->getInput(i)->getType(), "INPUT");
@@ -137,11 +137,11 @@ TEST(ModuleHTTP, updateLayout_extern){
 TEST(ModuleHTTP, update_intern){
     std::thread server (serverThread);
     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());
+    json config = mod->getConfiguration();
+    config["configure"]["path"]["value"] = "";
+    config["configure"]["url"]["value"] = "localhost";
+    config["configure"]["port"]["value"] = 8888;
+    mod->configure(config);
 
     for (int i = 0; i < mod->getNumInputs(); ++i) {
         mod->getInput(i)->setValue() = { (double)(10 - i) };

+ 9 - 9
lib/test/test_ModuleMath.cpp

@@ -91,9 +91,9 @@ TEST(ModuleMath, ARRAY_PLUS_INT){
 
 TEST(ModuleMath, ARRAY_MINUS_ARRAY){
     IModule::Ptr test = regi.generateModule("ModuleMath");
-    json config = json::parse(test->getConfiguration());
-    config[0]["value"] = "subtract";
-    test->configure(config.dump());
+    json config = test->getConfiguration();
+    config["configure"]["operation"]["value"] = "subtract";
+    test->configure(config);
     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 };
@@ -105,9 +105,9 @@ TEST(ModuleMath, ARRAY_MINUS_ARRAY){
 TEST(ModuleMath, ARRAY_MAL_ARRAY){
     IModule::Ptr test = regi.generateModule("ModuleMath");
 
-    json config = json::parse(test->getConfiguration());
-    config[0]["value"] = "multiply";
-    test->configure(config.dump());
+    json config = test->getConfiguration();
+    config["configure"]["operation"]["value"] = "multiply";
+    test->configure(config);
 
     test->getInput(0)->setValue() = {10,30,-3.5,45};
     test->getInput(1)->setValue() = {1,2.5,2.25,20};
@@ -120,9 +120,9 @@ TEST(ModuleMath, ARRAY_MAL_ARRAY){
 TEST(ModuleMath, ARRAY_DURCH_ARRAY){
     IModule::Ptr test = regi.generateModule("ModuleMath");
 
-    json config = json::parse(test->getConfiguration());
-    config[0]["value"] = "divide";
-    test->configure(config.dump());
+    json config = test->getConfiguration();
+    config["configure"]["operation"]["value"] = "divide";
+    test->configure(config);
 
     test->getInput(0)->setValue() = { 10,30,-3.5,45 };
     test->getInput(1)->setValue() = {4,2.5,2,20};

+ 35 - 20
lib/test/test_ModuleSQL.cpp

@@ -8,9 +8,22 @@
 #include <sqlite3.h> 
 
 
+#include <windows.h>
+#include <string>
+#include <iostream>
+
 using namespace mdd;
 namespace TEST_MODULE_SQL {
+    const char* db_path = "../../../../../lib/test/db/materials.db";
     
+    std::string ExePath() {
+        TCHAR buffer[MAX_PATH] = { 0 };
+        GetModuleFileName(NULL, buffer, MAX_PATH);
+        std::string::size_type pos = std::string(buffer).find_last_of("\\/");
+        return std::string(buffer).substr(0, pos);
+    }
+
+
     static int callback(void* data, int argc, char** argv, char** azColName) {
         int i;
         fprintf(stderr, "%s: ", (const char*)data);
@@ -37,13 +50,13 @@ namespace TEST_MODULE_SQL {
         }
     }
 
-    void create_test_db() {
+    void create_test_db(std::string path) {
             sqlite3* db;
             int rc;
             char* sql;
 
             // Open database
-            rc = sqlite3_open("../../../lib/test/db/materials.db", &db);
+            rc = sqlite3_open(path.c_str(), &db);
 
             if (rc) {
                 fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
@@ -102,8 +115,8 @@ namespace TEST_MODULE_SQL {
     auto regi = Registration();
 
     TEST(ModuleSQL, TestSQL) {
-        if (!std::filesystem::exists("../../../lib/test/db/materials.db")) {
-            create_test_db();
+        if (!std::filesystem::exists(db_path)) {
+            create_test_db(db_path);
         }
 
         sqlite3* db;
@@ -113,7 +126,7 @@ namespace TEST_MODULE_SQL {
         const char* data = "Callback function called";
 
         // Open database
-        rc = sqlite3_open("../../../lib/test/db/materials.db", &db);
+        rc = sqlite3_open(db_path, &db);
 
         if (rc) {
             fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
@@ -138,13 +151,13 @@ namespace TEST_MODULE_SQL {
         }
         sqlite3_close(db);
 
-        EXPECT_TRUE(std::filesystem::exists("../../../lib/test/db/materials.db"));
+        EXPECT_TRUE(std::filesystem::exists(db_path));
     }
 
    
     TEST(ModuleSQL, TestGetSQLTableStructure) {
-        if (!std::filesystem::exists("../../../lib/test/db/materials.db")) {
-            create_test_db();
+        if (!std::filesystem::exists(db_path)) {
+            create_test_db(db_path);
         }
 
         sqlite3* db;
@@ -154,7 +167,7 @@ namespace TEST_MODULE_SQL {
         const char* data = "Callback function called";
 
         // Open database
-        rc = sqlite3_open("../../../lib/test/db/materials.db", &db);
+        rc = sqlite3_open(db_path, &db);
 
         if (rc) {
             fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
@@ -181,24 +194,26 @@ namespace TEST_MODULE_SQL {
         }
         sqlite3_close(db);
 
-        EXPECT_TRUE(std::filesystem::exists("../../../lib/test/db/materials.db"));
+        EXPECT_TRUE(std::filesystem::exists(db_path));
     }
 
     TEST(ModuleSQL, OpenDB) {
-        if (!std::filesystem::exists("../../../lib/test/db/materials.db")) {
-            create_test_db();
+        if (!std::filesystem::exists(db_path)) {
+            create_test_db(db_path);
         }
+
+        std::cout << ExePath() << std::endl;
         IModule::Ptr mod = regi.generateModule("ModuleSQL");
-        json config = json::parse(mod->getConfiguration());
-        config[0]["value"] = "../../../lib/test/db/materials.db";
-        mod->configure(config.dump());
+        json config = mod->getConfiguration();
+        config["configure"]["database"]["value"] = db_path;
+        mod->configure(config);
 
-        EXPECT_TRUE(std::filesystem::exists("../../../lib/test/db/materials.db"));
+        EXPECT_TRUE(std::filesystem::exists(db_path));
     }
 
     TEST(ModuleSQL, TestDataExists) {
-        if (!std::filesystem::exists("../../../lib/test/db/materials.db")) {
-            create_test_db();
+        if (!std::filesystem::exists(db_path)) {
+            create_test_db(db_path);
         }
 
         sqlite3* db;
@@ -208,7 +223,7 @@ namespace TEST_MODULE_SQL {
         const char* data = "Callback function called";
 
         // Open database
-        rc = sqlite3_open("../../../lib/test/db/materials.db", &db);
+        rc = sqlite3_open(db_path, &db);
 
         if (rc) {
             fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
@@ -233,7 +248,7 @@ namespace TEST_MODULE_SQL {
         }
         sqlite3_close(db);
 
-        EXPECT_TRUE(std::filesystem::exists("../../../lib/test/db/materials.db"));
+        EXPECT_TRUE(std::filesystem::exists(db_path));
     }
     //*/
 }

+ 15 - 15
lib/test/test_ModuleSwitch.cpp

@@ -10,9 +10,9 @@ namespace TEST_MODULE_SWITCH {
     auto regi = Registration();
     TEST(ModuleSwitch, EasySwitch){
         IModule::Ptr sModule = regi.generateModule("ModuleSwitch");
-        json config = json::parse(sModule->getConfiguration());
-        config[0]["value"] = 2;
-        sModule->configure(config.dump());
+        json config = sModule->getConfiguration();
+        config["configure"]["size"]["value"] = 2;
+        sModule->configure(config);
 
         sModule->getInput(0)->setValue() = { 0 };
         sModule->getInput(1)->setValue() = { 1 };
@@ -40,33 +40,33 @@ namespace TEST_MODULE_SWITCH {
 
     TEST(ModuleSwitch, ConnectTest){
         IModule::Ptr f0 = regi.generateModule("ModuleMath");
-        json config = json::parse(f0->getConfiguration());
-        config[0]["value"] = "multiply";
-        f0->configure(config.dump());
+        json config = f0->getConfiguration();
+        config["configure"]["operation"]["value"] = "multiply";
+        f0->configure(config);
        
         f0->getInput(0)->setValue() = { 1 };
         f0->getInput(1)->setValue() = { 1 };
 
         IModule::Ptr f1 = regi.generateModule("ModuleMath");
-        config = json::parse(f1->getConfiguration());
-        config[0]["value"] = "multiply";
-        f1->configure(config.dump());
+        config = f1->getConfiguration();
+        config["configure"]["operation"]["value"] = "multiply";
+        f1->configure(config);
 
         f1->getInput(0)->setValue() = { 2 };
         f1->getInput(1)->setValue() = { 3 };
 
         IModule::Ptr f2 = regi.generateModule("ModuleMath");
-        config = json::parse(f2->getConfiguration());
-        config[0]["value"] = "multiply";
-        f2->configure(config.dump());
+        config = f2->getConfiguration();
+        config["configure"]["operation"]["value"] = "multiply";
+        f2->configure(config);
 
         f2->getInput(0)->setValue() = { 5 };
         f2->getInput(1)->setValue() = { 7 };
 
         IModule::Ptr sModule = regi.generateModule("ModuleSwitch");
-        config = json::parse(sModule->getConfiguration());
-        config[0]["value"] = 2;
-        sModule->configure(config.dump());
+        config = sModule->getConfiguration();
+        config["configure"]["size"]["value"] = 2;
+        sModule->configure(config);
 
         sModule->getInput(0)->connect(f0->getOutput(0));
         sModule->getInput(1)->connect(f1->getOutput(0));

+ 14 - 14
lib/test/test_OptimizerEvolutionary.cpp

@@ -13,16 +13,16 @@ namespace TEST_OPTIMIZER_EVOLUTION {
         //optimize f(x)=a*b
         IModule::Ptr f1 = regi.generateModule("ModuleMath");
     
-        json config = json::parse(f1->getConfiguration());
-        config[0]["value"] = "multiply";
+        json config = f1->getConfiguration();
+        config["configure"]["operation"]["value"] = "multiply";
         f1->configure(config.dump());
         limits limit;
         limit.min = { -10 };
         limit.max = { 10 };
         limit.step = { 1 };
     
-        f1->getInput(0)->setLimits() = limit;
-        f1->getInput(1)->setLimits() = limit;
+        f1->getInput(0)->setLimits() = std::make_shared<limits>(limit);
+        f1->getInput(1)->setLimits() = std::make_shared<limits>(limit);
     
         f1->getInput(0)->setOptimizability(true);
         f1->getInput(1)->setOptimizability(true);
@@ -30,8 +30,8 @@ namespace TEST_OPTIMIZER_EVOLUTION {
     
         OptimizerEvolutionary optimizer;
         optimizer.connect(f1);
-        config = json::parse(optimizer.getConfiguration());
-        config[0]["value"] = 3;
+        config = optimizer.getConfiguration();
+        config[0]["value"] = 5;
         optimizer.configure(config.dump());
     
         optimizer.setEvaluation("out0");
@@ -46,17 +46,17 @@ namespace TEST_OPTIMIZER_EVOLUTION {
         //optimize f(x)=a*b
         IModule::Ptr f1 = regi.generateModule("ModuleMath");
     
-        json config = json::parse(f1->getConfiguration());
-        config[0]["value"] = "multiply";
-        f1->configure(config.dump());
+        json config = f1->getConfiguration();
+        config["configure"]["operation"]["value"] = "multiply";
+        f1->configure(config);
         limits limit;
         limit.min = { -10 };
         limit.max = { 10 };
         limit.step = { 1 };
         limit.rule = "val[0] != -10";
     
-        f1->getInput(0)->setLimits() = limit;
-        f1->getInput(1)->setLimits() = limit;
+        f1->getInput(0)->setLimits() = std::make_shared<limits>(limit);
+        f1->getInput(1)->setLimits() = std::make_shared<limits>(limit);
     
         f1->getInput(0)->setOptimizability(true);
         f1->getInput(1)->setOptimizability(true);
@@ -64,9 +64,9 @@ namespace TEST_OPTIMIZER_EVOLUTION {
     
         OptimizerEvolutionary optimizer;
         optimizer.connect(f1);
-        config = json::parse(optimizer.getConfiguration());
-        config[0]["value"] = 3;
-        optimizer.configure(config.dump());
+        config = optimizer.getConfiguration();
+        config["converges"]["value"] = 5;
+        optimizer.configure(config);
     
         optimizer.setEvaluation("out0");
     

+ 58 - 61
lib/test/test_ProcessorStandard.cpp

@@ -14,35 +14,35 @@ namespace TEST_PROCESSOR_STANDARD {
 TEST(ProcessorStandard, CalculateSimpleFormula){
     //f4:(f3:(f1:(5*3)-f2:(4+5))/2)==(15-9)/2==6/2==3
     auto f1 = regi.generateModule("ModuleMath");
-    json config = json::parse(f1->getConfiguration());
-    config[0]["value"] = "multiply";
-    f1->configure(config.dump());
+    json config = f1->getConfiguration();
+    config["configure"]["operation"]["value"] = "multiply";
+    f1->configure(config);
     f1->getInput(0)->setValue() = { 5 };
     f1->getInput(1)->setValue() = { 3 };
 
     auto f2 = regi.generateModule("ModuleMath");
-    config = json::parse(f2->getConfiguration());
-    config[0]["value"] = "add";
-    f2->configure(config.dump());
+    config = f2->getConfiguration();
+    config["configure"]["operation"]["value"] = "add";
+    f2->configure(config);
     f2->getInput(0)->setValue() = { 4 };
     f2->getInput(1)->setValue() = { 5 };
 
     auto f3 = regi.generateModule("ModuleMath");
-    config = json::parse(f3->getConfiguration());
-    config[0]["value"] = "subtract";
-    f3->configure(config.dump());
+    config = f3->getConfiguration();
+    config["configure"]["operation"]["value"] = "subtract";
+    f3->configure(config);
     f3->getInput(0)->connect(f1->getOutput(0));
     f3->getInput(1)->connect(f2->getOutput(0));
 
     auto f4 = regi.generateModule("ModuleMath");
-    config = json::parse(f4->getConfiguration());
-    config[0]["value"] = "divide";
+    config = f4->getConfiguration();
+    config["configure"]["operation"]["value"] = "divide";
     f4->configure(config.dump());
     f4->getInput(0)->connect(f3->getOutput(0));
     f4->getInput(1)->setValue() = { 2 };
 
     auto processor = std::make_shared<ProcessorStandard>();
-        //regi.generateModule("ProcessorStandard");;
+    //regi.generateModule("ProcessorStandard");
     processor->addModule(f1);
     processor->addModule(f2);
     processor->addModule(f3);
@@ -54,11 +54,8 @@ TEST(ProcessorStandard, CalculateSimpleFormula){
     processor->update();
 
     EXPECT_EQ(f1->getOutput(0)->getValue()[0], 15);
-
     EXPECT_EQ(f2->getOutput(0)->getValue()[0], 9);
-
     EXPECT_EQ(f3->getOutput(0)->getValue()[0], 6);
-
     EXPECT_EQ(f4->getOutput(0)->getValue()[0], 3);
 
     EXPECT_EQ(processor->getOutput(1)->getValue()[0], 3);
@@ -68,30 +65,30 @@ TEST(ProcessorStandard, CalculateSimpleFormula){
 TEST(ProcessorStandard, CalculateAdvancedFormula){
     //f4:(f3:(f1:(5*3)-f2:(4+5))/2)==(15-9)/2==6/2==3
     auto f1 = regi.generateModule("ModuleMath");
-    json config = json::parse(f1->getConfiguration());
-    config[0]["value"] = "multiply";
-    f1->configure(config.dump());
+    json config = f1->getConfiguration();
+    config["configure"]["operation"]["value"] = "multiply";
+    f1->configure(config);
     f1->getInput(0)->setValue() = { 5 };
     f1->getInput(1)->setValue() = { 3 };
 
     auto f2 = regi.generateModule("ModuleMath");
-    config = json::parse(f2->getConfiguration());
-    config[0]["value"] = "add";
-    f2->configure(config.dump());
+    config = f2->getConfiguration();
+    config["configure"]["operation"]["value"] = "add";
+    f2->configure(config);
     f2->getInput(0)->setValue() = { 4 };
     f2->getInput(1)->setValue() = { 5 };
 
     auto f3 = regi.generateModule("ModuleMath");
-    config = json::parse(f3->getConfiguration());
-    config[0]["value"] = "subtract";
-    f3->configure(config.dump());
+    config = f3->getConfiguration();
+    config["configure"]["operation"]["value"] = "subtract";
+    f3->configure(config);
     f3->getInput(0)->connect(f1->getOutput(0));
     f3->getInput(1)->connect(f2->getOutput(0));
 
     auto f4 = regi.generateModule("ModuleMath");
-    config = json::parse(f4->getConfiguration());
-    config[0]["value"] = "divide";
-    f4->configure(config.dump());
+    config = f4->getConfiguration();
+    config["configure"]["operation"]["value"] = "divide";
+    f4->configure(config);
     f4->getInput(0)->connect(f3->getOutput(0));
     f4->getInput(1)->setValue() = { 2 };
 
@@ -111,13 +108,13 @@ TEST(ProcessorStandard, CalculateAdvancedFormula){
 TEST(ProcessorStandard, CalculateExtremeFormula){
     //x_0=8, x_i=x_{i-1}/2
     auto switchModule = regi.generateModule("ModuleSwitch");
-    json config = json::parse(switchModule->getConfiguration());
-    config[0]["value"] = 2;
+    json config = switchModule->getConfiguration();
+    config["configure"]["size"]["value"] = 2;
     switchModule->configure(config.dump());  
 
     auto calcModule = regi.generateModule("ModuleMath");
-    config = json::parse(calcModule->getConfiguration());
-    config[0]["value"] = "divide";
+    config = calcModule->getConfiguration();
+    config["configure"]["operation"]["value"] = "divide";
     calcModule->configure(config.dump());
 
     std::shared_ptr<ProcessorStandard> processor = std::make_shared<ProcessorStandard>();
@@ -142,37 +139,37 @@ TEST(ProcessorStandard, CalculateExtremeFormula){
 TEST(ProcessorStandard, CalculateAdvancedFormulaWithSTATIC) {
     //f4:(f3:(f1:(5*3)-f2:(4+5))/2)==(15-9)/2==6/2==3
     auto f1 = regi.generateModule("ModuleMath");
-    json config = json::parse(f1->getConfiguration());
-    config[0]["value"] = "multiply";
-    f1->configure(config.dump());
+    json config = f1->getConfiguration();
+    config["configure"]["operation"]["value"] = "multiply";
+    f1->configure(config);
     f1->getInput(0)->setValue() = { 5 };
     f1->getInput(1)->setValue() = { 3 };
 
     auto f2 = regi.generateModule("ModuleMath");
-    config = json::parse(f2->getConfiguration());
-    config[0]["value"] = "add";
-    f2->configure(config.dump());
+    config = f2->getConfiguration();
+    config["configure"]["operation"]["value"] = "add";
+    f2->configure(config);
     f2->getInput(0)->setValue() = { 4 };
     f2->getInput(1)->setValue() = { 5 };
 
     auto f3 = regi.generateModule("ModuleMath");
-    config = json::parse(f3->getConfiguration());
-    config[0]["value"] = "subtract";
-    f3->configure(config.dump());
+    config = f3->getConfiguration();
+    config["configure"]["operation"]["value"] = "subtract";
+    f3->configure(config);
     f3->getInput(0)->connect(f1->getOutput(0));
     f3->getInput(1)->connect(f2->getOutput(0));
 
     auto f4 = regi.generateModule("ModuleMath");
-    config = json::parse(f4->getConfiguration());
-    config[0]["value"] = "divide";
-    f4->configure(config.dump());
+    config = f4->getConfiguration();
+    config["configure"]["operation"]["value"] = "divide";
+    f4->configure(config);
     f4->getInput(0)->connect(f3->getOutput(0));
     f4->getInput(1)->setValue() = { 2 };
 
     auto processor = std::make_shared<ProcessorStandard>();
-    config = json::parse(processor->getConfiguration());
-    config[0]["value"] = "static";
-    processor->configure(config.dump());
+    config = processor->getConfiguration();
+    config["configure"]["priority"]["value"] = "static";
+    processor->configure(config);
 
     processor->addModule(f4);
     processor->addModule(f3);
@@ -188,38 +185,38 @@ TEST(ProcessorStandard, CalculateAdvancedFormulaWithSTATIC) {
 TEST(ProcessorStandard, PrioritySTATIC) {
     //f4:(f3:(f1:(5*3)-f2:(4+5))/2)==(15-9)/2==6/2==3
     auto f1 = regi.generateModule("ModuleMath");
-    json config = json::parse(f1->getConfiguration());
-    config[0]["value"] = "multiply";
-    f1->configure(config.dump());
+    json config = f1->getConfiguration();
+    config["configure"]["operation"]["value"] = "multiply";
+    f1->configure(config);
     f1->getInput(0)->setValue() = { 5 };
     f1->getInput(1)->setValue() = { 3 };
 
     auto f2 = regi.generateModule("ModuleMath");
-    config = json::parse(f2->getConfiguration());
-    config[0]["value"] = "add";
-    f2->configure(config.dump());
+    config = f2->getConfiguration();
+    config["configure"]["operation"]["value"] = "add";
+    f2->configure(config);
     f2->getInput(0)->setValue() = { 4 };
     f2->getInput(1)->setValue() = { 5 };
 
     auto f3 = regi.generateModule("ModuleMath");
-    config = json::parse(f3->getConfiguration());
-    config[0]["value"] = "subtract";
-    f3->configure(config.dump());
+    config = f3->getConfiguration();
+    config["configure"]["operation"]["value"] = "subtract";
+    f3->configure(config);
     f3->getInput(0)->connect(f1->getOutput(0));
     f3->getInput(1)->connect(f2->getOutput(0));
 
     auto f4 = regi.generateModule("ModuleMath");
-    config = json::parse(f4->getConfiguration());
-    config[0]["value"] = "divide";
-    f4->configure(config.dump());
+    config = f4->getConfiguration();
+    config["configure"]["operation"]["value"] = "divide";
+    f4->configure(config);
     f4->getInput(0)->connect(f3->getOutput(0));
     f4->getInput(1)->setValue() = { 2 };
 
     auto process_manual = std::make_shared<ProcessorStandard>();
     auto process_static = std::make_shared<ProcessorStandard>();
-    config = json::parse(process_static->getConfiguration());
-    config[0]["value"] = "static";
-    process_static->configure(config.dump());
+    config = process_static->getConfiguration();
+    config["configure"]["priority"]["value"] = "static";
+    process_static->configure(config);
 
     process_manual->addModule(f1);
     process_manual->addModule(f2);

+ 0 - 3
server/src/main.cpp

@@ -186,9 +186,6 @@ public:
                 get_request(jcontext["get"]);
             }
         }
-        //  Do some 'work'
-        Sleep(1000);
-       
     }
 
 };