From 9efaf6e6f4b126b9a9b6f57839215a240caaccf0 Mon Sep 17 00:00:00 2001 From: vl241552 <vincent.lorrain@cea.fr> Date: Tue, 26 Sep 2023 11:15:50 +0000 Subject: [PATCH] fix getNodeDelta --- include/aidge/graphRegex/matchFsm/MatchResult.hpp | 8 +++++++- src/graph/Node.cpp | 4 ++-- src/graphRegex/matchFsm/MatchResult.cpp | 15 +++++++++++++++ unit_tests/graph/Test_get.cpp | 12 +++++++++--- unit_tests/graphRegex/Test_FsmMatch.cpp | 14 ++++++-------- 5 files changed, 39 insertions(+), 14 deletions(-) diff --git a/include/aidge/graphRegex/matchFsm/MatchResult.hpp b/include/aidge/graphRegex/matchFsm/MatchResult.hpp index 4376d0ce3..c3f42aded 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 a23d3c66f..ce1275d05 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 5e5b4220b..c35f1a734 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 bc54fc83f..afd1f42ee 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 bed7e860d..132a8606e 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 -- GitLab