Skip to content
Snippets Groups Projects
Commit 4e953d8a authored by Cyril Moineau's avatar Cyril Moineau
Browse files

[FsmGraph] Fix issue with badly updated set.

parent 43e06e57
No related branches found
No related tags found
1 merge request!31Build fix
Pipeline #32946 passed
#include "aidge/graphRegex/matchFsm/FsmGraph.hpp" #include "aidge/graphRegex/matchFsm/FsmGraph.hpp"
using namespace Aidge; using namespace Aidge;
...@@ -14,7 +14,7 @@ FsmGraph::FsmGraph(/* args */){ ...@@ -14,7 +14,7 @@ FsmGraph::FsmGraph(/* args */){
if(startNodes.size() != startNodesFsm.size()){ if(startNodes.size() != startNodesFsm.size()){
throw std::runtime_error("bad number of Start nodes"); throw std::runtime_error("bad number of Start nodes");
} }
std::vector<std::shared_ptr<FsmRunTimeContext>> walks; std::vector<std::shared_ptr<FsmRunTimeContext>> walks;
for(std::size_t i = 0; i < startNodes.size(); i++){ for(std::size_t i = 0; i < startNodes.size(); i++){
walks.push_back(std::make_shared<FsmRunTimeContext>(startNodesFsm[i],startNodes[i])); walks.push_back(std::make_shared<FsmRunTimeContext>(startNodesFsm[i],startNodes[i]));
...@@ -32,16 +32,16 @@ FsmGraph::FsmGraph(/* args */){ ...@@ -32,16 +32,16 @@ FsmGraph::FsmGraph(/* args */){
for(auto fsmContext : walks){ for(auto fsmContext : walks){
allContextSee.push_back(fsmContext); allContextSee.push_back(fsmContext);
//if we are in a valid st we save it //if we are in a valid st we save it
//it's one solution of the posible solution of the matching //it's one solution of the posible solution of the matching
if(fsmContext->isOnValidState()){ if(fsmContext->isOnValidState()){
//not save 2 time the same end point //not save 2 time the same end point
if(!std::any_of(allValidContext.begin(), allValidContext.end(), if(!std::any_of(allValidContext.begin(), allValidContext.end(),
[&](std::shared_ptr<Aidge::FsmRunTimeContext> oldValid) { [&](std::shared_ptr<Aidge::FsmRunTimeContext> oldValid) {
return fsmContext->areEqual(oldValid); return fsmContext->areEqual(oldValid);
})){ })){
allValidContext.push_back(fsmContext); allValidContext.push_back(fsmContext);
} }
} }
//dont test 2 time a fsmContext //dont test 2 time a fsmContext
...@@ -60,15 +60,15 @@ FsmGraph::FsmGraph(/* args */){ ...@@ -60,15 +60,15 @@ FsmGraph::FsmGraph(/* args */){
walks.swap(nextWalks); walks.swap(nextWalks);
nextWalks.clear(); nextWalks.clear();
} }
return std::make_shared<MatchResult>(allValidContext,getNbSubFsm()); return std::make_shared<MatchResult>(allValidContext,getNbSubFsm());
} }
/////////////// ///////////////
// FSM construction // FSM construction
/////////////// ///////////////
const std::set<std::shared_ptr<FsmEdge>>& FsmGraph::getEdge(void){ const std::set<std::shared_ptr<FsmEdge>>& FsmGraph::getEdge(void){
return mEdges; return mEdges;
...@@ -140,7 +140,7 @@ void FsmGraph::mergeOneStartOneValid(const std::shared_ptr<FsmGraph> fsmGraph){ ...@@ -140,7 +140,7 @@ void FsmGraph::mergeOneStartOneValid(const std::shared_ptr<FsmGraph> fsmGraph){
} }
unionG(fsmGraph); unionG(fsmGraph);
//for loop useless but for future merge it's coudl be used //for loop useless but for future merge it's coudl be used
for(auto valid : validNodes){ for(auto valid : validNodes){
valid->unValid(); valid->unValid();
for(auto start : startNodes){ for(auto start : startNodes){
...@@ -159,9 +159,11 @@ void FsmGraph::incOrigineAllNodeBy(std::size_t incr){ ...@@ -159,9 +159,11 @@ void FsmGraph::incOrigineAllNodeBy(std::size_t incr){
for(auto node :nodes){ for(auto node :nodes){
node->incOrigine(incr); node->incOrigine(incr);
} }
std::set<std::size_t> updatedOrigin;
for(auto origin : mAllOrigine){ for(auto origin : mAllOrigine){
origin += incr; updatedOrigin.insert(origin + incr);
} }
mAllOrigine.swap(updatedOrigin);
} }
void FsmGraph::_mergeNode(std::shared_ptr<FsmNode> source,std::shared_ptr<FsmNode> dest){ void FsmGraph::_mergeNode(std::shared_ptr<FsmNode> source,std::shared_ptr<FsmNode> dest){
...@@ -189,7 +191,7 @@ void FsmGraph::_mergeNode(std::shared_ptr<FsmNode> source,std::shared_ptr<FsmNod ...@@ -189,7 +191,7 @@ void FsmGraph::_mergeNode(std::shared_ptr<FsmNode> source,std::shared_ptr<FsmNod
} }
} }
//check is source is not in graph //check is source is not in graph
nodes = getNodes(); nodes = getNodes();
if(nodes.find(source) != nodes.end() ){ if(nodes.find(source) != nodes.end() ){
throw std::runtime_error("FsmGraph merge node not effective"); throw std::runtime_error("FsmGraph merge node not effective");
......
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