12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- #include <gtest/gtest.h>
- #include <json.hpp>
- //#define private public
- #include <OptimizerEvolutionary.h>
- #include <Registration.h>
- using namespace mdd;
- namespace TEST_OPTIMIZER_EVOLUTION {
- auto regi = Registration();
-
- TEST(OptimizerEvolutionary, OptimizeSimpleFormula) {
- //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());
- limits limit;
- limit.min = { -10 };
- limit.max = { 10 };
- limit.step = { 1 };
-
- f1->getInput(0)->setLimits() = limit;
- f1->getInput(1)->setLimits() = limit;
-
- f1->getInput(0)->setOptimizability(true);
- f1->getInput(1)->setOptimizability(true);
- f1->getOutput(0)->setOptimizability(true);
-
- OptimizerEvolutionary optimizer;
- optimizer.connect(f1);
- config = json::parse(optimizer.getConfiguration());
- config[0]["value"] = 3;
- optimizer.configure(config.dump());
-
- optimizer.setEvaluation("out0");
-
- optimizer.update();
- auto res = optimizer.getBests()[0].dna;
- //std::cout << res.dump() << std::endl;
- EXPECT_EQ(res[0][0]* res[1][0],-100);
- }
-
- TEST(OptimizerEvolutionary, OptimizeSimpleFormulaWithSimpleRestriction) {
- //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());
- 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)->setOptimizability(true);
- f1->getInput(1)->setOptimizability(true);
- f1->getOutput(0)->setOptimizability(true);
-
- OptimizerEvolutionary optimizer;
- optimizer.connect(f1);
- config = json::parse(optimizer.getConfiguration());
- config[0]["value"] = 3;
- optimizer.configure(config.dump());
-
- optimizer.setEvaluation("out0");
-
- optimizer.update();
- auto res = optimizer.getBests()[0].dna;
- //std::cout << res.dump() << std::endl;
- EXPECT_EQ(res[0][0]* res[1][0],-90);
- }
- //*/
- }
|