Skip to content
Snippets Groups Projects
Commit 9efaf6e6 authored by vincent  lorrain's avatar vincent lorrain
Browse files

fix getNodeDelta

parent 5273949f
No related branches found
No related tags found
1 merge request!14Graph regex
Pipeline #32095 failed
......@@ -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);
};
......
......@@ -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);
}
......
......@@ -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
......@@ -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
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment