Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
aidge_core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Cyril Moineau
aidge_core
Commits
ef99c24e
Commit
ef99c24e
authored
1 year ago
by
Maxence Naud
Browse files
Options
Downloads
Patches
Plain Diff
Reduce graph regex matching time with the help of
@vincentlorrain
parent
6379a891
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/graphRegex/GraphRegex.cpp
+13
-9
13 additions, 9 deletions
src/graphRegex/GraphRegex.cpp
with
13 additions
and
9 deletions
src/graphRegex/GraphRegex.cpp
+
13
−
9
View file @
ef99c24e
#include
"aidge/graphRegex/GraphRegex.hpp"
#include
"aidge/graphRegex/GraphRegex.hpp"
using
namespace
Aidge
;
using
namespace
Aidge
;
void
GraphRegex
::
setKeyFromGraph
(
std
::
shared_ptr
<
GraphView
>
ref
){
void
GraphRegex
::
setKeyFromGraph
(
std
::
shared_ptr
<
GraphView
>
ref
){
...
@@ -27,7 +27,7 @@ void GraphRegex::setKeyFromGraph(std::shared_ptr<GraphView> ref){
...
@@ -27,7 +27,7 @@ void GraphRegex::setKeyFromGraph(std::shared_ptr<GraphView> ref){
// void GraphRegex::addQuery(const std::string query){
// void GraphRegex::addQuery(const std::string query){
// //TODO one query only but the same string is a same query but
// //TODO one query only but the same string is a same query but
// //2 different string it's maybe the same query , we need to check the AST
// //2 different string it's maybe the same query , we need to check the AST
// mQueryRecipe[query] = nullptr;
// mQueryRecipe[query] = nullptr;
// }
// }
...
@@ -52,7 +52,7 @@ void GraphRegex::_generateCombinationsStart(const std::set<NodePtr>& elements, s
...
@@ -52,7 +52,7 @@ void GraphRegex::_generateCombinationsStart(const std::set<NodePtr>& elements, s
}
}
}
}
// factorial(n) tree searched optimized with a stopping condition
void
GraphRegex
::
_findLargestCompatibleSet
(
void
GraphRegex
::
_findLargestCompatibleSet
(
const
std
::
vector
<
std
::
shared_ptr
<
MatchSolution
>>&
solutions
,
const
std
::
vector
<
std
::
shared_ptr
<
MatchSolution
>>&
solutions
,
std
::
set
<
std
::
shared_ptr
<
MatchSolution
>>&
currentSet
,
std
::
set
<
std
::
shared_ptr
<
MatchSolution
>>&
currentSet
,
...
@@ -75,6 +75,10 @@ void GraphRegex::_findLargestCompatibleSet(
...
@@ -75,6 +75,10 @@ void GraphRegex::_findLargestCompatibleSet(
currentSet
.
insert
(
solutions
[
i
]);
currentSet
.
insert
(
solutions
[
i
]);
_findLargestCompatibleSet
(
solutions
,
currentSet
,
largestSet
,
i
+
1
);
_findLargestCompatibleSet
(
solutions
,
currentSet
,
largestSet
,
i
+
1
);
currentSet
.
erase
(
solutions
[
i
]);
currentSet
.
erase
(
solutions
[
i
]);
// cut the size of the graph of possibilities
if
((
currentSet
.
size
()
+
solutions
.
size
()
-
currentIndex
)
<=
largestSet
.
size
())
{
return
;
}
}
}
}
}
}
}
...
@@ -101,14 +105,14 @@ std::set<std::shared_ptr<MatchSolution>> GraphRegex::match(std::shared_ptr<Graph
...
@@ -101,14 +105,14 @@ std::set<std::shared_ptr<MatchSolution>> GraphRegex::match(std::shared_ptr<Graph
std
::
shared_ptr
<
GraphFsmInterpreter
>
fsmGenerator
=
std
::
make_shared
<
GraphFsmInterpreter
>
(
query
,
mAllTest
);
std
::
shared_ptr
<
GraphFsmInterpreter
>
fsmGenerator
=
std
::
make_shared
<
GraphFsmInterpreter
>
(
query
,
mAllTest
);
std
::
shared_ptr
<
FsmGraph
>
fsm
=
fsmGenerator
->
interpret
();
std
::
shared_ptr
<
FsmGraph
>
fsm
=
fsmGenerator
->
interpret
();
// generate all the start possibility
// generate all the start possibility
std
::
size_t
nb_startSt
=
fsm
->
getNbStart
();
std
::
size_t
nb_startSt
=
fsm
->
getNbStart
();
std
::
set
<
std
::
vector
<
NodePtr
>>
combinations
;
std
::
set
<
std
::
vector
<
NodePtr
>>
combinations
;
std
::
vector
<
NodePtr
>
current
;
std
::
vector
<
NodePtr
>
current
;
_generateCombinationsStart
(
ref
->
getNodes
(),
nb_startSt
,
0
,
current
,
combinations
);
_generateCombinationsStart
(
ref
->
getNodes
(),
nb_startSt
,
0
,
current
,
combinations
);
// all start
// all start
for
(
const
auto
&
combination
:
combinations
)
{
for
(
const
auto
&
combination
:
combinations
)
{
std
::
vector
<
std
::
shared_ptr
<
MatchSolution
>>
solution
=
fsm
->
test
(
combination
);
std
::
vector
<
std
::
shared_ptr
<
MatchSolution
>>
solution
=
fsm
->
test
(
combination
);
solutions
.
insert
(
solutions
.
end
(),
solution
.
begin
(),
solution
.
end
());
solutions
.
insert
(
solutions
.
end
(),
solution
.
begin
(),
solution
.
end
());
...
@@ -133,7 +137,7 @@ void GraphRegex::setNodeKey(const std::string key, const std::string conditional
...
@@ -133,7 +137,7 @@ void GraphRegex::setNodeKey(const std::string key, const std::string conditional
void
GraphRegex
::
setNodeKey
(
const
std
::
string
key
,
std
::
function
<
bool
(
NodePtr
)
>
f
){
void
GraphRegex
::
setNodeKey
(
const
std
::
string
key
,
std
::
function
<
bool
(
NodePtr
)
>
f
){
//we can applied to all key but it's not efficient
//we can applied to all key but it's not efficient
if
(
mAllLambda
.
find
(
key
)
!=
mAllLambda
.
end
()){
if
(
mAllLambda
.
find
(
key
)
!=
mAllLambda
.
end
()){
throw
std
::
runtime_error
(
key
+
" is define"
);
throw
std
::
runtime_error
(
key
+
" is define"
);
}
}
...
@@ -142,7 +146,7 @@ void GraphRegex::setNodeKey(const std::string key,std::function<bool(NodePtr)> f
...
@@ -142,7 +146,7 @@ void GraphRegex::setNodeKey(const std::string key,std::function<bool(NodePtr)> f
}
}
void
GraphRegex
::
_majConditionalInterpreterLambda
(){
void
GraphRegex
::
_majConditionalInterpreterLambda
(){
for
(
const
auto
&
test
:
mAllTest
)
{
for
(
const
auto
&
test
:
mAllTest
)
{
for
(
const
auto
&
pair
:
mAllLambda
)
{
for
(
const
auto
&
pair
:
mAllLambda
)
{
const
std
::
string
&
key
=
pair
.
first
;
const
std
::
string
&
key
=
pair
.
first
;
...
@@ -151,7 +155,7 @@ void GraphRegex::_majConditionalInterpreterLambda(){
...
@@ -151,7 +155,7 @@ void GraphRegex::_majConditionalInterpreterLambda(){
if
(
!
test
->
isLambdaRegister
(
key
)){
if
(
!
test
->
isLambdaRegister
(
key
)){
test
->
insertLambda
(
key
,
lambda
);
test
->
insertLambda
(
key
,
lambda
);
}
}
}
}
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment