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

clean and remove old graph matching

parent 717a683e
No related branches found
No related tags found
No related merge requests found
/********************************************************************************
* Copyright (c) 2023 CEA-List
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
********************************************************************************/
#include <iostream>
#include <map>
#include <memory>
#include <vector>
#include <utility>
#include <cassert>
#include <catch2/catch_test_macros.hpp>
//test
#include "aidge/graphmatching/SeqStm.hpp"
#include "aidge/graphmatching/NodeRegex.hpp"
//use
#include "aidge/backend/OperatorImpl.hpp"
#include "aidge/operator/GenericOperator.hpp"
#include "aidge/operator/Producer.hpp"
using namespace Aidge;
TEST_CASE("Create good init SeqStm", "[SeqStm]") {
//init all iniput for SeqStm
int stmIdx = 0;
//matrix that in B->C
std::vector<std::vector<int>> transitionMatrix {
{ -1, 1, -1 },
{ -1, -1, 2 },
{ -1, -1, -1 } };
//std::cout << transitionMatrix.size() << "\n";
// init the nodes Regex map
std::map<std::string,NodeRegex*> nodesRegex ;
std::vector<std::string> nodeTypeKey {"A","B","C"};
for (const std::string& key : nodeTypeKey) {
nodesRegex[key] = new NodeRegex(key);
}
//
std::map<NodeTypeKey,int> typeToIdxTransition;
std::vector<NodeTypeKey> nodeTypeCommonTag {{"A",""},{"B",""},{"C",""}};
//init nodeTypeCommonTag
int idx = 0;
for (const NodeTypeKey& key : nodeTypeCommonTag) {
typeToIdxTransition[key] = idx;
idx += 1;
}
int actSt = 0;
std::set<NodeTmp> allNodeValidated;
std::set<NodeTmp> allNodeTested;
std::set<std::pair<NodeTmp,std::string>> allCommonNode;
bool stmIsValid =false;
SeqStm stm(
stmIdx,
transitionMatrix,
nodesRegex,
typeToIdxTransition,
actSt,
allNodeValidated,
allNodeTested,
allCommonNode,
stmIsValid);
REQUIRE(stm.getStmIdx() == 0);
REQUIRE(stm.isValid() == false);
REQUIRE(stm.getAllCommonNode().size() == 0);
REQUIRE(stm.getAllNodeTested().size() == 0);
REQUIRE(stm.getAllNodeValidated().size() == 0);
for (const std::string& key : nodeTypeKey) {
delete nodesRegex[key];
}
}
TEST_CASE("Test testNode function", "[SeqStm]") {
int stmIdx = 0;
std::map<NodeTypeKey,int> typeToIdxTransition;
std::vector<NodeTypeKey> nodeTypeCommonTag {{"A",""},{"B",""},{"C",""}};
//init nodeTypeCommonTag
int idx = 0;
for (const NodeTypeKey& key : nodeTypeCommonTag) {
typeToIdxTransition[key] = idx;
idx += 1;
}
//matrix that in B->C
std::vector<std::vector<int>> transitionMatrix {
{ -1, 1, -1 },
{ -1, -1, 2 },
{ -1, -1, -1 } };
//std::cout << transitionMatrix.size() << "\n";
// init the nodes Regex map
std::map<std::string,NodeRegex*> nodesRegex ;
std::vector<std::string> nodeTypeKey {"A","B","C"};
for (const std::string& key : nodeTypeKey) {
nodesRegex[key] = new NodeRegex(key);
}
//
int actSt = 0;
std::set<NodeTmp> allNodeValidated;
std::set<NodeTmp> allNodeTested;
std::set<std::pair<NodeTmp,std::string>> allCommonNode;
bool stmIsValid =false;
SeqStm stm(
stmIdx,
transitionMatrix,
nodesRegex,
typeToIdxTransition,
actSt,
allNodeValidated,
allNodeTested,
allCommonNode,
stmIsValid);
REQUIRE(stm.getStmIdx() == 0);
//test a node
std::shared_ptr<Node> nodeB = GenericOperator("B", 1, 1, 1);
std::shared_ptr<Node> nodeC = GenericOperator("C", 1, 1, 1);
//set use to test the state of the smt
std::set<NodeTmp> testAllNodeTested;
std::set<NodeTmp> testAllNodeValidated;
stm.testNode(nodeB);
REQUIRE(stm.isValid() == false);
REQUIRE(stm.getState() == 1);
REQUIRE(stm.isStmBlocked() == false);
testAllNodeTested.insert(nodeB);
testAllNodeValidated.insert(nodeB);
REQUIRE(stm.getAllNodeTested() == testAllNodeTested);
REQUIRE(stm.getAllNodeValidated() == testAllNodeValidated);
stm.testNode(nodeC);
REQUIRE(stm.isValid() == true);
REQUIRE(stm.getState() == 2);
REQUIRE(stm.isStmBlocked() == false);
testAllNodeTested.insert(nodeC);
testAllNodeValidated.insert(nodeC);
REQUIRE(stm.getAllNodeTested() == testAllNodeTested);
REQUIRE(stm.getAllNodeValidated() == testAllNodeValidated);
stm.testNode(nodeC);
REQUIRE(stm.isValid() == true);
REQUIRE(stm.getState() == -1);
REQUIRE(stm.isStmBlocked() == true);
REQUIRE(stm.getAllNodeTested() == testAllNodeTested);
REQUIRE(stm.getAllNodeValidated() == testAllNodeValidated);
for (const std::string& key : nodeTypeKey) {
delete nodesRegex[key];
}
}
\ No newline at end of file
/********************************************************************************
* Copyright (c) 2023 CEA-List
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
********************************************************************************/
#include <iostream>
#include <map>
#include <memory>
#include <vector>
#include <utility>
#include <cassert>
#include <catch2/catch_test_macros.hpp>
//test
#include "aidge/graphmatching/StmFactory.hpp"
#include "aidge/graphmatching/NodeRegex.hpp"
//use
#include "aidge/backend/OperatorImpl.hpp"
#include "aidge/operator/GenericOperator.hpp"
#include "aidge/operator/Producer.hpp"
using namespace Aidge;
TEST_CASE("Create good init StmFactory", "[StmFactory]") {
// init the nodes Regex map
std::map<std::string,NodeRegex*> nodesRegex ;
std::vector<std::string> nodeTypeKey {"A","B","C"};
for (const std::string& key : nodeTypeKey) {
nodesRegex[key] = new NodeRegex(key);
}
StmFactory stmF(nodesRegex);
REQUIRE(stmF.getNumberOfStm() == 0);
for (const std::string& key : nodeTypeKey) {
delete nodesRegex[key];
}
}
TEST_CASE("Test in makeNewStm the getStmIdx StmFactory", "[SeqStm]") {
std::map<std::string,NodeRegex*> nodesRegex ;
std::vector<std::string> nodeTypeKey {"A","B","C"};
for (const std::string& key : nodeTypeKey) {
nodesRegex[key] = new NodeRegex(key);
}
StmFactory stmF(nodesRegex);
std::string seq1 = "A->B+->A#;";
SeqStm* stm = stmF.makeNewStm(seq1);
REQUIRE(stm->getStmIdx() == 0);
REQUIRE(stm->isValid() == false);
REQUIRE(stm->getAllCommonNode().size() == 0);
REQUIRE(stm->getAllNodeTested().size() == 0);
REQUIRE(stm->getAllNodeValidated().size() == 0);
std::string seq2 = "A->B;";
SeqStm* stm2 = stmF.makeNewStm(seq2);
REQUIRE(stm2->getStmIdx() == 1);
REQUIRE(stm2->isValid() == false);
REQUIRE(stm2->getAllCommonNode().size() == 0);
REQUIRE(stm2->getAllNodeTested().size() == 0);
REQUIRE(stm2->getAllNodeValidated().size() == 0);
//test the number of stm
REQUIRE(stmF.getNumberOfStm() == 2);
for (const std::string& key : nodeTypeKey) {
delete nodesRegex[key];
}
}
TEST_CASE("Test in makeNewStm the stm StmFactory", "[SeqStm]") {
std::map<std::string,NodeRegex*> nodesRegex ;
std::vector<std::string> nodeTypeKey {"A","B","C"};
for (const std::string& key : nodeTypeKey) {
nodesRegex[key] = new NodeRegex(key);
}
StmFactory stmF(nodesRegex);
std::string seq1 = "B->C;";
SeqStm* stm = stmF.makeNewStm(seq1);
//test the number of stm
REQUIRE(stmF.getNumberOfStm() == 1);
//std::shared_ptr<Node> nodeB = GenericOperator("B",1,1,1);
//std::shared_ptr<Node> nodeC = GenericiOperator("C",1,1,1);
std::shared_ptr<Node> nodeB = GenericOperator("B", 1, 1, 1);
std::shared_ptr<Node> nodeC = GenericOperator("C", 1, 1, 1);
//set use to test the state of the smt
std::set<NodeTmp> testAllNodeTested;
std::set<NodeTmp> testAllNodeValidated;
REQUIRE(stm->isValid() == false);
REQUIRE(stm->getState() == 0);
REQUIRE(stm->isStmBlocked() == false);
REQUIRE(stm->getAllNodeTested() == testAllNodeTested);
REQUIRE(stm->getAllNodeValidated() == testAllNodeValidated);
stm->testNode(nodeB);
REQUIRE(stm->isValid() == false);
REQUIRE(stm->getState() == 1);
REQUIRE(stm->isStmBlocked() == false);
testAllNodeTested.insert(nodeB);
testAllNodeValidated.insert(nodeB);
REQUIRE(stm->getAllNodeTested() == testAllNodeTested);
REQUIRE(stm->getAllNodeValidated() == testAllNodeValidated);
stm->testNode(nodeC);
REQUIRE(stm->isValid() == true);
REQUIRE(stm->getState() == 2);
REQUIRE(stm->isStmBlocked() == false);
testAllNodeTested.insert(nodeC);
testAllNodeValidated.insert(nodeC);
REQUIRE(stm->getAllNodeTested() == testAllNodeTested);
REQUIRE(stm->getAllNodeValidated() == testAllNodeValidated);
stm->testNode(nodeC);
REQUIRE(stm->isValid() == true);
REQUIRE(stm->getState() == -1);
REQUIRE(stm->isStmBlocked() == true);
REQUIRE(stm->getAllNodeTested() == testAllNodeTested);
REQUIRE(stm->getAllNodeValidated() == testAllNodeValidated);
for (const std::string& key : nodeTypeKey) {
delete nodesRegex[key];
}
}
TEST_CASE("Test in duplicateStm StmFactory", "[SeqStm]") {
std::map<std::string,NodeRegex*> nodesRegex ;
std::vector<std::string> nodeTypeKey {"A","B","C"};
for (const std::string& key : nodeTypeKey) {
nodesRegex[key] = new NodeRegex(key);
}
StmFactory stmF(nodesRegex);
std::string seq1 = "B->C;";
SeqStm* stm = stmF.makeNewStm(seq1);
SeqStm* stmD = stmF.duplicateStm(stm);
std::shared_ptr<Node> nodeB = GenericOperator("B", 1, 1, 1);
std::shared_ptr<Node> nodeC = GenericOperator("C", 1, 1, 1);
//set use to test the state of the smt
std::set<NodeTmp> testAllNodeTested;
std::set<NodeTmp> testAllNodeValidated;
//run the stm
REQUIRE(stm->isValid() == false);
REQUIRE(stm->getState() == 0);
REQUIRE(stm->isStmBlocked() == false);
REQUIRE(stm->getAllNodeTested() == testAllNodeTested);
REQUIRE(stm->getAllNodeValidated() == testAllNodeValidated);
stm->testNode(nodeB);
REQUIRE(stm->isValid() == false);
REQUIRE(stm->getState() == 1);
REQUIRE(stm->isStmBlocked() == false);
testAllNodeTested.insert(nodeB);
testAllNodeValidated.insert(nodeB);
REQUIRE(stm->getAllNodeTested() == testAllNodeTested);
REQUIRE(stm->getAllNodeValidated() == testAllNodeValidated);
stm->testNode(nodeC);
REQUIRE(stm->isValid() == true);
REQUIRE(stm->getState() == 2);
REQUIRE(stm->isStmBlocked() == false);
testAllNodeTested.insert(nodeC);
testAllNodeValidated.insert(nodeC);
REQUIRE(stm->getAllNodeTested() == testAllNodeTested);
REQUIRE(stm->getAllNodeValidated() == testAllNodeValidated);
stm->testNode(nodeC);
REQUIRE(stm->isValid() == true);
REQUIRE(stm->getState() == -1);
REQUIRE(stm->isStmBlocked() == true);
REQUIRE(stm->getAllNodeTested() == testAllNodeTested);
REQUIRE(stm->getAllNodeValidated() == testAllNodeValidated);
//check if stmD not move
REQUIRE(stmD->isValid() == false);
REQUIRE(stmD->getState() == 0);
REQUIRE(stmD->isStmBlocked() == false);
REQUIRE(stmD->getAllNodeTested().size() == 0);
REQUIRE(stmD->getAllNodeValidated().size() == 0);
for (const std::string& key : nodeTypeKey) {
delete nodesRegex[key];
}
}
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