diff --git a/include/aidge/graphRegex/matchFsm/MatchResult.hpp b/include/aidge/graphRegex/matchFsm/MatchResult.hpp index 4376d0ce344cc24ec9cf72bf826843b61c9a9ad9..c3f42aded3b51ba724c7d5f18627f14a517ab272 100644 --- a/include/aidge/graphRegex/matchFsm/MatchResult.hpp +++ b/include/aidge/graphRegex/matchFsm/MatchResult.hpp @@ -40,9 +40,15 @@ public: * @brief get the set of the node match for une expression * @return the set of node of the graph that corresponding to an expression */ - std::set<NodePtr> getNodes(void); + std::set<NodePtr> getBiggerSolution(void); private: + +/** + * @brief recurent function use to inite mSolve in the constructor + * + **/ + void _generateCombinationd( std::size_t idxSubStm, std::vector<std::shared_ptr<FsmRunTimeContext>>& precedence); }; diff --git a/src/graph/Node.cpp b/src/graph/Node.cpp index a23d3c66ffe22c26af54fd3db0eeb15e732e3365..ce1275d05126395398c095851f7d3ff1848a0f6f 100644 --- a/src/graph/Node.cpp +++ b/src/graph/Node.cpp @@ -332,7 +332,7 @@ std::set<Aidge::NodePtr> Aidge::Node::getNodeDelta(int delta,std::set<Aidge::Nod }else if (delta > 0){ for (const NodePtr& node : getChildren()) { - if(nodeSee.find(node) == out.end()){ //loop avoidance + if(nodeSee.find(node) == nodeSee.end()){ //loop avoidance for (const NodePtr& ch : node->getNodeDelta(delta-1,nodeSee)){ out.insert(ch); } @@ -340,7 +340,7 @@ std::set<Aidge::NodePtr> Aidge::Node::getNodeDelta(int delta,std::set<Aidge::Nod } }else{ for (const NodePtr& node : getParents()) { - if(nodeSee.find(node) == out.end()){ //loop avoidance + if(nodeSee.find(node) == nodeSee.end()){ //loop avoidance for (const NodePtr& pr : node->getNodeDelta(delta+1,nodeSee)){ out.insert(pr); } diff --git a/src/graphRegex/matchFsm/MatchResult.cpp b/src/graphRegex/matchFsm/MatchResult.cpp index 5e5b4220b47b7e5b703bd7b94fed759dc58a2d1f..c35f1a7348e365baa8a27854ee6b0a833e342ee7 100644 --- a/src/graphRegex/matchFsm/MatchResult.cpp +++ b/src/graphRegex/matchFsm/MatchResult.cpp @@ -13,7 +13,13 @@ MatchResult::MatchResult(std::vector<std::shared_ptr<FsmRunTimeContext>> allVali } std::vector<std::shared_ptr<FsmRunTimeContext>> precedence; + //make all solution posible _generateCombinationd(0,precedence); + //sort by solution number of elements + std::sort(mSolve.begin(), mSolve.end(), [](const std::set<NodePtr>& set1, const std::set<NodePtr>& set2) { + return set1.size() < set2.size(); + }); + } @@ -76,3 +82,12 @@ void MatchResult::_generateCombinationd( std::size_t idxSubStm, std::vector<std: return; } + +std::set<NodePtr> MatchResult::getBiggerSolution(void){ + if(mSolve.empty()){ + return std::set<NodePtr>(); + }else{ + return mSolve[0]; + } + +} \ No newline at end of file diff --git a/unit_tests/graph/Test_get.cpp b/unit_tests/graph/Test_get.cpp index bc54fc83fd672dff5ba0b2e5a0a6397e7026d82b..afd1f42ee9f5d6cd668dd5cab82172cdc298e149 100644 --- a/unit_tests/graph/Test_get.cpp +++ b/unit_tests/graph/Test_get.cpp @@ -38,12 +38,18 @@ TEST_CASE("get Delta") { std::set<Aidge::NodePtr> see; - conv->getNodeDelta(0,see); +conv->getNodeDelta(1,see); - SECTION("Self return") { - + SECTION("Self return") { + see.clear(); REQUIRE(conv->getNodeDelta(0,see) == std::set<std::shared_ptr<Node>>{conv}); } + SECTION("child") { + see.clear(); + REQUIRE(conv->getNodeDelta(1,see) == std::set<std::shared_ptr<Node>>{conv1}); + } + + } \ No newline at end of file diff --git a/unit_tests/graphRegex/Test_FsmMatch.cpp b/unit_tests/graphRegex/Test_FsmMatch.cpp index bed7e860dc21e29ba7e2a5d1493e2c35221425d7..132a8606e7eb26f651ea951f7879817dd7f0e244 100644 --- a/unit_tests/graphRegex/Test_FsmMatch.cpp +++ b/unit_tests/graphRegex/Test_FsmMatch.cpp @@ -36,11 +36,6 @@ TEST_CASE("FsmMatch") { std::shared_ptr<GraphView> g1 = std::make_shared<GraphView>("TestGraph"); std::shared_ptr<Node> conv = GenericOperator("Conv", 1, 1, 1, "c"); std::shared_ptr<Node> conv1 = GenericOperator("Conv", 1, 1, 1, "c1"); - std::shared_ptr<Node> conv2 = GenericOperator("Conv", 1, 1, 1, "c2"); - std::shared_ptr<Node> conv3 = GenericOperator("Conv", 1, 1, 1, "c3"); - std::shared_ptr<Node> conv3_5 = GenericOperator("Conv", 1, 1, 1, "c3.5"); - std::shared_ptr<Node> conv4 = GenericOperator("Conv", 1, 1, 1, "c4"); - std::shared_ptr<Node> conv5 = GenericOperator("Conv", 1, 1, 1, "c5"); g1->add(conv); g1->addChild(conv1, "c"); @@ -51,14 +46,17 @@ TEST_CASE("FsmMatch") { std::vector<std::shared_ptr<Node>> startNodes = {conv}; - fsm->test(startNodes); + auto result = fsm->test(startNodes); - - + REQUIRE( result->getBiggerSolution() == std::set<NodePtr>{conv,conv1}); } + SECTION("split"){ + + } + } \ No newline at end of file