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

[GraphRegex] new interface class

parent d06572e2
No related branches found
No related tags found
1 merge request!29GraphRegex interface class
Pipeline #33926 failed
......@@ -10,6 +10,8 @@ FetchContent_MakeAvailable(Catch2)
file(GLOB_RECURSE src_files "*.cpp")
#file(GLOB_RECURSE src_files "graphRegex/Test_GraphRegex.cpp")
add_executable(tests${module_name} ${src_files})
target_link_libraries(tests${module_name} PUBLIC ${module_name})
......
......@@ -14,10 +14,10 @@ using namespace Aidge;
TEST_CASE("matchFSM", "FsmEdge") {
std::shared_ptr<FsmNode> nodeA = std::make_shared<FsmNode>(true,false);
std::shared_ptr<FsmNode> nodeB = std::make_shared<FsmNode>(false,true);
std::shared_ptr<ConditionalInterpreter> toTest = std::make_shared<ConditionalInterpreter>("true==true");
FsmEdgeUnique EdgeToTest(nodeA,nodeB,toTest);
std::shared_ptr<FsmNode> nodeA = std::make_shared<FsmNode>(true,false);
std::shared_ptr<FsmNode> nodeB = std::make_shared<FsmNode>(false,true);
std::shared_ptr<ConditionalInterpreter> toTest = std::make_shared<ConditionalInterpreter>("A","true==true");
FsmEdgeUnique EdgeToTest(nodeA,nodeB,toTest);
SECTION("FsmEdgeUnique constructor") {
REQUIRE(EdgeToTest.getSourceNode() == nodeA);
......@@ -28,7 +28,7 @@ TEST_CASE("matchFSM", "FsmEdge") {
SECTION("FsmEdgeCommon constructor") {
std::shared_ptr<FsmNode> nodeA = std::make_shared<FsmNode>(true,false);
std::shared_ptr<FsmNode> nodeB = std::make_shared<FsmNode>(false,true);
std::shared_ptr<ConditionalInterpreter> toTest = std::make_shared<ConditionalInterpreter>("true==true");
std::shared_ptr<ConditionalInterpreter> toTest = std::make_shared<ConditionalInterpreter>("A","true==true");
FsmEdgeCommon EdgeToTest(nodeA,nodeB,toTest,"A");
......@@ -40,7 +40,7 @@ TEST_CASE("matchFSM", "FsmEdge") {
SECTION("FsmEdgeRef constructor") {
std::shared_ptr<FsmNode> nodeA = std::make_shared<FsmNode>(true,false);
std::shared_ptr<FsmNode> nodeB = std::make_shared<FsmNode>(false,true);
std::shared_ptr<ConditionalInterpreter> toTest = std::make_shared<ConditionalInterpreter>("true==true");
std::shared_ptr<ConditionalInterpreter> toTest = std::make_shared<ConditionalInterpreter>("A","true==true");
FsmEdgeRef EdgeToTest(nodeA,nodeB,0,-1);
......@@ -52,7 +52,7 @@ TEST_CASE("matchFSM", "FsmEdge") {
SECTION("FsmEdgeEmpty constructor") {
std::shared_ptr<FsmNode> nodeA = std::make_shared<FsmNode>(true,false);
std::shared_ptr<FsmNode> nodeB = std::make_shared<FsmNode>(false,true);
std::shared_ptr<ConditionalInterpreter> toTest = std::make_shared<ConditionalInterpreter>("true==true");
std::shared_ptr<ConditionalInterpreter> toTest = std::make_shared<ConditionalInterpreter>("A","true==true");
FsmEdgeEmpty EdgeToTest(nodeA,nodeB);
......@@ -65,9 +65,9 @@ TEST_CASE("matchFSM", "FsmEdge") {
SECTION("FsmEdgeFactory"){
std::map<std::string, std::shared_ptr<ConditionalInterpreter>> allTest = {
{"A",std::make_shared<ConditionalInterpreter>("true==true")},
{"B",std::make_shared<ConditionalInterpreter>("true==true")},
{"C",std::make_shared<ConditionalInterpreter>("true==true")}
{"A",std::make_shared<ConditionalInterpreter>("A","true==true")},
{"B",std::make_shared<ConditionalInterpreter>("B","true==true")},
{"C",std::make_shared<ConditionalInterpreter>("C","true==true")}
};
// make(std::shared_ptr<FsmNode> source, std::shared_ptr<FsmNode> dest,
......@@ -103,11 +103,11 @@ TEST_CASE("matchFSM", "FsmEdge") {
std::shared_ptr<FsmNode> nodeC = std::make_shared<FsmNode>(false,true);
//make the edges
std::shared_ptr<ConditionalInterpreter> toTest = std::make_shared<ConditionalInterpreter>("true==true");
std::shared_ptr<ConditionalInterpreter> toTest = std::make_shared<ConditionalInterpreter>("A","true==true");
std::shared_ptr<FsmEdge> edgeAB = std::make_shared<FsmEdgeUnique>(nodeA,nodeB,toTest);
std::shared_ptr<FsmEdge> edgeBC = std::make_shared<FsmEdgeUnique>(nodeB,nodeC,toTest);
std::shared_ptr<FsmGraph> graph = std::make_shared<FsmGraph>();
std::shared_ptr<FsmGraph> graph = std::make_shared<FsmGraph>("");
graph->addEdge(edgeAB);
graph->addEdge(edgeBC);
......@@ -120,7 +120,7 @@ TEST_CASE("matchFSM", "FsmEdge") {
SECTION("graph merge") {
std::shared_ptr<ConditionalInterpreter> toTest = std::make_shared<ConditionalInterpreter>("true==true");
std::shared_ptr<ConditionalInterpreter> toTest = std::make_shared<ConditionalInterpreter>("A","true==true");
//make the nodes
std::shared_ptr<FsmNode> nodeA = std::make_shared<FsmNode>(false,true);
......@@ -132,7 +132,7 @@ TEST_CASE("matchFSM", "FsmEdge") {
std::shared_ptr<FsmEdge> edgeAB = std::make_shared<FsmEdgeUnique>(nodeA,nodeB,toTest);
std::shared_ptr<FsmEdge> edgeBC = std::make_shared<FsmEdgeUnique>(nodeB,nodeC,toTest);
std::shared_ptr<FsmGraph> graph = std::make_shared<FsmGraph>();
std::shared_ptr<FsmGraph> graph = std::make_shared<FsmGraph>("");
graph->addEdge(edgeAB);
graph->addEdge(edgeBC);
......@@ -149,7 +149,7 @@ TEST_CASE("matchFSM", "FsmEdge") {
std::shared_ptr<FsmEdge> edge2AB = std::make_shared<FsmEdgeUnique>(node2A,node2B,toTest);
std::shared_ptr<FsmEdge> edge2BC = std::make_shared<FsmEdgeUnique>(node2B,node2C,toTest);
std::shared_ptr<FsmGraph> graph2 = std::make_shared<FsmGraph>();
std::shared_ptr<FsmGraph> graph2 = std::make_shared<FsmGraph>("");
graph2->addEdge(edge2AB);
......@@ -184,7 +184,7 @@ TEST_CASE("matchFSM", "FsmEdge") {
// std::shared_ptr<ConditionalInterpreter> toTest = std::make_shared<ConditionalInterpreter>("true==true");
// std::shared_ptr<FsmEdgeUnique> edge = std::make_shared<FsmEdgeUnique>(nodeA,nodeB,toTest);
// std::shared_ptr<FsmGraph> graph = std::make_shared<FsmGraph>();
// std::shared_ptr<FsmGraph> graph = std::make_shared<FsmGraph>("");
// graph->addEdge(edge);
......
......@@ -14,14 +14,14 @@ using namespace Aidge;
TEST_CASE("FsmMatch") {
SECTION("Construction") {
std::map<std::string,std::shared_ptr<ConditionalInterpreter>> allTest = {
{"A",std::make_shared<ConditionalInterpreter>("isConv($)==true")},
{"B",std::make_shared<ConditionalInterpreter>("isConv($)==true")},
{"C",std::make_shared<ConditionalInterpreter>("true==true")}
std::vector<std::shared_ptr<ConditionalInterpreter>> allTest = {
std::make_shared<ConditionalInterpreter>("A","isConv($)==true"),
std::make_shared<ConditionalInterpreter>("B","isConv($)==true"),
std::make_shared<ConditionalInterpreter>("C","true==true")
};
allTest["A"]->insertLambda("isConv",+[](NodePtr NodeOp){return NodeOp->type() == "Conv";});
allTest["B"]->insertLambda("isConv",+[](NodePtr NodeOp){return NodeOp->type() == "Conv";});
allTest[0]->insertLambda("isConv",+[](NodePtr NodeOp){return NodeOp->type() == "Conv";});
allTest[1]->insertLambda("isConv",+[](NodePtr NodeOp){return NodeOp->type() == "Conv";});
std::shared_ptr<GraphFsmInterpreter> fsmGenerator = std::make_shared<GraphFsmInterpreter>("A->A",allTest);
std::shared_ptr<FsmGraph> fsm = fsmGenerator->interpret();
......@@ -41,14 +41,14 @@ TEST_CASE("FsmMatch") {
g1->addChild(conv1, "c");
REQUIRE(allTest["A"]->test(conv) == true);
REQUIRE(allTest["B"]->test(conv) == true);
REQUIRE(allTest[0]->test(conv) == true);
REQUIRE(allTest[1]->test(conv) == true);
std::vector<std::shared_ptr<Node>> startNodes = {conv};
auto result = fsm->test(startNodes);
REQUIRE( result->getBiggerSolution() == std::set<NodePtr>{conv,conv1});
REQUIRE( result[0]->getAll() == std::set<NodePtr>{conv,conv1});
}
......@@ -70,19 +70,20 @@ TEST_CASE("FsmMatch") {
/////////////
std::map<std::string,std::shared_ptr<ConditionalInterpreter>> allTest = {
{"A",std::make_shared<ConditionalInterpreter>("isConv($)==true")},
{"B",std::make_shared<ConditionalInterpreter>("isFc($)==true")}
std::vector<std::shared_ptr<ConditionalInterpreter>> allTest = {
std::make_shared<ConditionalInterpreter>("A","isConv($)==true"),
std::make_shared<ConditionalInterpreter>("B","isFc($)==true")
};
allTest["A"]->insertLambda("isConv",+[](NodePtr NodeOp){return NodeOp->type() == "Conv";});
allTest["B"]->insertLambda("isFc",+[](NodePtr NodeOp){return NodeOp->type() == "Fc";});
allTest[0]->insertLambda("isConv",+[](NodePtr NodeOp){return NodeOp->type() == "Conv";});
allTest[1]->insertLambda("isFc",+[](NodePtr NodeOp){return NodeOp->type() == "Fc";});
std::shared_ptr<GraphFsmInterpreter> fsmGenerator = std::make_shared<GraphFsmInterpreter>("A#->A; A#->B",allTest);
std::shared_ptr<FsmGraph> fsm = fsmGenerator->interpret();
std::vector<std::shared_ptr<Node>> startNodes = {conv,conv};
auto result = fsm->test(startNodes);
REQUIRE( result->getBiggerSolution() == std::set<NodePtr>{conv,conv1,conv2});
REQUIRE( result[0]->getAll() == std::set<NodePtr>{conv,conv1,conv2});
}
......
......@@ -8,10 +8,10 @@ using namespace Aidge;
TEST_CASE("GraphFsmInterpreter", "GraphFsmInterpreter") {
SECTION("Construction") {
std::map<std::string,std::shared_ptr<ConditionalInterpreter>> allTest = {
{"A",std::make_shared<ConditionalInterpreter>("true==true")},
{"B",std::make_shared<ConditionalInterpreter>("true==true")},
{"C",std::make_shared<ConditionalInterpreter>("true==true")}
std::vector<std::shared_ptr<ConditionalInterpreter>> allTest = {
std::make_shared<ConditionalInterpreter>("A","true==true"),
std::make_shared<ConditionalInterpreter>("B","true==true"),
std::make_shared<ConditionalInterpreter>("C","true==true")
};
//GraphFsmInterpreter("A->B",allTest);
......
......@@ -2,14 +2,83 @@
#include <catch2/catch_test_macros.hpp>
#include "aidge/graphRegex/GraphRegex.hpp"
#include "aidge/operator/Conv.hpp"
#include "aidge/operator/GenericOperator.hpp"
using namespace Aidge;
TEST_CASE("GraphRegex") {
TEST_CASE("GraphRegexUser") {
SECTION("INIT") {
const std::string query = "Conv->FC";
std::shared_ptr<GraphRegex> sut = std::make_shared<GraphRegex>();
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> fc = GenericOperator("FC", 1, 1, 1, "c1");
std::shared_ptr<Node> conv2 = GenericOperator("Conv", 1, 1, 1, "c2");
std::shared_ptr<Node> fc2 = GenericOperator("FC", 1, 1, 1, "c3");
g1->add(conv);
g1->addChild(fc, "c");
g1->addChild(conv2, "c1");
g1->addChild(fc2, "c2");
SECTION("Empty") {
sut->setKeyFromGraph(g1);
sut->addQuery(query);
for (const auto& solution : sut->match(g1)) {
REQUIRE(solution->getQuery() == query);
if(solution->getStartNode() == std::vector<NodePtr>{conv}){
REQUIRE(solution->at("Conv") == std::set<NodePtr>{conv} );
REQUIRE(solution->at("FC") == std::set<NodePtr>{fc} );
}else if (solution->getStartNode() == std::vector<NodePtr>{conv2})
{
REQUIRE(solution->at("Conv") == std::set<NodePtr>{conv2} );
REQUIRE(solution->at("FC") == std::set<NodePtr>{fc2} );
}
}
//REQUIRE( sut->match(g1)[1]->getAll() == std::set<NodePtr>{conv,fc});
}
// SECTION("CC") {
std::shared_ptr<GraphRegex> sut = std::make_shared<GraphRegex>();
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");
g1->add(conv);
g1->addChild(conv1, "c");
g1->addChild(conv2, "c1");
g1->addChild(conv3, "c2");
sut->setKeyFromGraph(g1);
const std::string query = "Conv->Conv";
const std::string query2 = "Conv->FC";
//sut->setNodeKey("FC","getType($) =='FC'");
sut->addQuery(query);
sut->addQuery(query2);
for (const auto& solution : sut->match(g1)) {
REQUIRE(solution->getQuery() == query);
}
//}
}
\ No newline at end of file
......@@ -13,7 +13,7 @@ TEST_CASE("ConditionalInterpreter", "ConditionalInterpreter") {
SECTION("custom Lambda") {
const std::string test = " !toto($) == true " ;
ConditionalInterpreter conditionalParser = ConditionalInterpreter(test);
ConditionalInterpreter conditionalParser = ConditionalInterpreter("A",test);
conditionalParser.insertLambda("toto",+[](NodePtr NodeOp){return false;});
std::shared_ptr<Node> nodeOp = GenericOperator("conv", 0, 0, 0, "Gop1");
......@@ -24,7 +24,7 @@ TEST_CASE("ConditionalInterpreter", "ConditionalInterpreter") {
SECTION("syntax error") {
const std::string test = "'A' == 'A' ,&& ";
REQUIRE_THROWS_AS( ConditionalInterpreter(test), std::runtime_error);
REQUIRE_THROWS_AS( ConditionalInterpreter("A",test), std::runtime_error);
}
......@@ -32,7 +32,7 @@ TEST_CASE("ConditionalInterpreter", "ConditionalInterpreter") {
SECTION("test false int ") {
const std::string test = " 10 == 11 " ;
ConditionalInterpreter conditionalParser = ConditionalInterpreter(test);
ConditionalInterpreter conditionalParser = ConditionalInterpreter("A",test);
std::shared_ptr<Node> nodeOp = GenericOperator("conv", 0, 0, 0, "Gop1");
bool result = conditionalParser.test(nodeOp);
REQUIRE(result == false);
......@@ -40,7 +40,7 @@ TEST_CASE("ConditionalInterpreter", "ConditionalInterpreter") {
SECTION("test true int ") {
const std::string test = " 42 == 42 " ;
ConditionalInterpreter conditionalParser = ConditionalInterpreter(test);
ConditionalInterpreter conditionalParser = ConditionalInterpreter("A",test);
std::shared_ptr<Node> nodeOp = GenericOperator("conv", 0, 0, 0, "Gop1");
bool result = conditionalParser.test(nodeOp);
REQUIRE(result == true);
......@@ -48,7 +48,7 @@ TEST_CASE("ConditionalInterpreter", "ConditionalInterpreter") {
SECTION("test false str ") {
const std::string test = " 'toto' == 'Corgi' " ;
ConditionalInterpreter conditionalParser = ConditionalInterpreter(test);
ConditionalInterpreter conditionalParser = ConditionalInterpreter("A",test);
std::shared_ptr<Node> nodeOp = GenericOperator("conv", 0, 0, 0, "Gop1");
bool result = conditionalParser.test(nodeOp);
REQUIRE(result == false);
......@@ -57,7 +57,7 @@ TEST_CASE("ConditionalInterpreter", "ConditionalInterpreter") {
SECTION("test true str ") {
const std::string test = " 'Corgi' == 'Corgi' " ;
ConditionalInterpreter conditionalParser = ConditionalInterpreter(test);
ConditionalInterpreter conditionalParser = ConditionalInterpreter("A",test);
std::shared_ptr<Node> nodeOp = GenericOperator("conv", 0, 0, 0, "Gop1");
bool result = conditionalParser.test(nodeOp);
REQUIRE(result == true);
......
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