Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Algorithms Library Toolkit Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
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
Container Registry
Model registry
Monitor
Service Desk
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
Algorithms Library Toolkit
Algorithms Library Toolkit Core
Commits
193b51d3
Commit
193b51d3
authored
9 years ago
by
Jan Trávníček
Browse files
Options
Downloads
Patches
Plain Diff
format code
parent
1879523c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
alib2algo/src/automaton/determinize/DeterminizeIDPDAPart.cxx
+42
-37
42 additions, 37 deletions
alib2algo/src/automaton/determinize/DeterminizeIDPDAPart.cxx
alib2algo/src/automaton/determinize/DeterminizeNFAPart.cxx
+78
-68
78 additions, 68 deletions
alib2algo/src/automaton/determinize/DeterminizeNFAPart.cxx
with
120 additions
and
105 deletions
alib2algo/src/automaton/determinize/DeterminizeIDPDAPart.cxx
+
42
−
37
View file @
193b51d3
...
...
@@ -17,56 +17,61 @@ namespace automaton {
namespace
determinize
{
automaton
::
InputDrivenDPDA
Determinize
::
determinize
(
const
automaton
::
InputDrivenNPDA
&
nfa
)
{
// 1, 4
automaton
::
State
initialState
(
createDFAState
({
nfa
.
getInitialState
()}));
automaton
::
InputDrivenDPDA
res
(
initialState
,
nfa
.
getInitialSymbol
());
res
.
setInputAlphabet
(
nfa
.
getInputAlphabet
());
res
.
setStackAlphabet
(
nfa
.
getStackAlphabet
());
res
.
setPushdownStoreOperations
(
nfa
.
getPushdownStoreOperations
());
// 2
std
::
deque
<
automaton
::
State
>
todo
;
todo
.
push_back
(
std
::
move
(
initialState
));
automaton
::
InputDrivenDPDA
Determinize
::
determinize
(
const
automaton
::
InputDrivenNPDA
&
nfa
)
{
// 1, 4
automaton
::
State
initialState
(
createDFAState
(
{
nfa
.
getInitialState
(
)
}
)
);
automaton
::
InputDrivenDPDA
res
(
initialState
,
nfa
.
getInitialSymbol
(
)
);
res
.
setInputAlphabet
(
nfa
.
getInputAlphabet
(
)
);
res
.
setStackAlphabet
(
nfa
.
getStackAlphabet
(
)
);
res
.
setPushdownStoreOperations
(
nfa
.
getPushdownStoreOperations
(
)
);
// 2
std
::
deque
<
automaton
::
State
>
todo
;
todo
.
push_back
(
std
::
move
(
initialState
)
);
do
{
// 3a, c
automaton
::
State
state
=
std
::
move
(
todo
.
front
());
todo
.
pop_front
();
// 3b
for
(
const
alphabet
::
Symbol
&
input
:
nfa
.
getInputAlphabet
())
{
std
::
set
<
automaton
::
State
>
targetIDPDAStates
;
for
(
automaton
::
State
nfaState
:
std
::
make_moveable_set
(
recreateNFAStates
(
state
)))
{
auto
iter
=
nfa
.
getTransitions
().
find
(
std
::
make_pair
(
std
::
move
(
nfaState
),
input
));
if
(
iter
!=
nfa
.
getTransitions
().
end
())
{
targetIDPDAStates
.
insert
(
iter
->
second
.
begin
(),
iter
->
second
.
end
());
}
// 3a, c
automaton
::
State
state
=
std
::
move
(
todo
.
front
(
)
);
todo
.
pop_front
(
);
// 3b
for
(
const
alphabet
::
Symbol
&
input
:
nfa
.
getInputAlphabet
(
)
)
{
std
::
set
<
automaton
::
State
>
targetIDPDAStates
;
for
(
automaton
::
State
nfaState
:
std
::
make_moveable_set
(
recreateNFAStates
(
state
)
)
)
{
auto
iter
=
nfa
.
getTransitions
(
).
find
(
std
::
make_pair
(
std
::
move
(
nfaState
),
input
)
);
if
(
iter
!=
nfa
.
getTransitions
(
).
end
(
)
)
targetIDPDAStates
.
insert
(
iter
->
second
.
begin
(
),
iter
->
second
.
end
(
)
);
}
automaton
::
State
dfaState
=
createDFAState
(
std
::
move
(
targetIDPDAStates
));
// 4
bool
existed
=
!
res
.
addState
(
dfaState
);
automaton
::
State
dfaState
=
createDFAState
(
std
::
move
(
targetIDPDAStates
)
);
if
(
!
existed
)
todo
.
push_back
(
dfaState
);
// 4
bool
existed
=
!
res
.
addState
(
dfaState
);
// 3b
res
.
addTransition
(
std
::
move
(
state
),
input
,
std
::
move
(
dfaState
));
}
}
while
(
!
todo
.
empty
());
if
(
!
existed
)
todo
.
push_back
(
dfaState
);
// 5
for
(
const
automaton
::
State
&
dfaState
:
res
.
getStates
())
{
std
::
set
<
automaton
::
State
>
nfaStates
=
recreateNFAStates
(
dfaState
);
if
(
std
::
any_of
(
nfaStates
.
begin
(),
nfaStates
.
end
(),
[
&
](
const
automaton
::
State
&
nfaState
)
{
return
nfa
.
getFinalStates
().
count
(
nfaState
);
}))
{
res
.
addFinalState
(
dfaState
);
// 3b
res
.
addTransition
(
std
::
move
(
state
),
input
,
std
::
move
(
dfaState
)
);
}
}
while
(
!
todo
.
empty
(
)
);
// 5
for
(
const
automaton
::
State
&
dfaState
:
res
.
getStates
(
)
)
{
std
::
set
<
automaton
::
State
>
nfaStates
=
recreateNFAStates
(
dfaState
);
if
(
std
::
any_of
(
nfaStates
.
begin
(
),
nfaStates
.
end
(
),
[
&
]
(
const
automaton
::
State
&
nfaState
)
{
return
nfa
.
getFinalStates
(
).
count
(
nfaState
);
}
)
)
res
.
addFinalState
(
dfaState
);
}
return
res
;
}
auto
DeterminizeInputDrivenNPDA
=
Determinize
::
RegistratorWrapper
<
automaton
::
InputDrivenDPDA
,
automaton
::
InputDrivenNPDA
>
(
Determinize
::
getInstance
(
),
Determinize
::
determinize
);
auto
DeterminizeInputDrivenNPDA
=
Determinize
::
RegistratorWrapper
<
automaton
::
InputDrivenDPDA
,
automaton
::
InputDrivenNPDA
>
(
Determinize
::
getInstance
(
),
Determinize
::
determinize
);
}
/* namespace determinize */
...
...
This diff is collapsed.
Click to expand it.
alib2algo/src/automaton/determinize/DeterminizeNFAPart.cxx
+
78
−
68
View file @
193b51d3
...
...
@@ -16,103 +16,113 @@ namespace automaton {
namespace
determinize
{
automaton
::
DFA
Determinize
::
determinize
(
const
automaton
::
MultiInitialStateNFA
&
nfa
)
{
// 1, 4
automaton
::
State
initialState
(
createDFAState
(
nfa
.
getInitialStates
()));
automaton
::
DFA
res
(
initialState
);
res
.
setInputAlphabet
(
nfa
.
getInputAlphabet
());
automaton
::
DFA
Determinize
::
determinize
(
const
automaton
::
MultiInitialStateNFA
&
nfa
)
{
// 1, 4
automaton
::
State
initialState
(
createDFAState
(
nfa
.
getInitialStates
(
)
)
);
automaton
::
DFA
res
(
initialState
);
// 2
std
::
deque
<
automaton
::
State
>
todo
;
todo
.
push_back
(
std
::
move
(
initialState
));
res
.
setInputAlphabet
(
nfa
.
getInputAlphabet
(
)
);
// 2
std
::
deque
<
automaton
::
State
>
todo
;
todo
.
push_back
(
std
::
move
(
initialState
)
);
do
{
// 3a, c
automaton
::
State
state
=
std
::
move
(
todo
.
front
());
todo
.
pop_front
();
// 3b
for
(
const
alphabet
::
Symbol
&
input
:
nfa
.
getInputAlphabet
())
{
std
::
set
<
automaton
::
State
>
targetNFAStates
;
for
(
automaton
::
State
nfaState
:
std
::
make_moveable_set
(
recreateNFAStates
(
state
)))
{
auto
iter
=
nfa
.
getTransitions
().
find
(
std
::
make_pair
(
std
::
move
(
nfaState
),
input
));
if
(
iter
!=
nfa
.
getTransitions
().
end
())
{
targetNFAStates
.
insert
(
iter
->
second
.
begin
(),
iter
->
second
.
end
());
}
// 3a, c
automaton
::
State
state
=
std
::
move
(
todo
.
front
(
)
);
todo
.
pop_front
(
);
// 3b
for
(
const
alphabet
::
Symbol
&
input
:
nfa
.
getInputAlphabet
(
)
)
{
std
::
set
<
automaton
::
State
>
targetNFAStates
;
for
(
automaton
::
State
nfaState
:
std
::
make_moveable_set
(
recreateNFAStates
(
state
)
)
)
{
auto
iter
=
nfa
.
getTransitions
(
).
find
(
std
::
make_pair
(
std
::
move
(
nfaState
),
input
)
);
if
(
iter
!=
nfa
.
getTransitions
(
).
end
(
)
)
targetNFAStates
.
insert
(
iter
->
second
.
begin
(
),
iter
->
second
.
end
(
)
);
}
automaton
::
State
dfaState
=
createDFAState
(
std
::
move
(
targetNFAStates
));
// 4
bool
existed
=
!
res
.
addState
(
dfaState
);
automaton
::
State
dfaState
=
createDFAState
(
std
::
move
(
targetNFAStates
)
);
if
(
!
existed
)
todo
.
push_back
(
std
::
move
(
dfaState
));
// 4
bool
existed
=
!
res
.
addState
(
dfaState
);
// 3b
res
.
addTransition
(
std
::
move
(
state
),
input
,
std
::
move
(
dfaState
));
}
}
while
(
!
todo
.
empty
());
if
(
!
existed
)
todo
.
push_back
(
std
::
move
(
dfaState
)
);
// 5
for
(
const
automaton
::
State
&
dfaState
:
res
.
getStates
())
{
std
::
set
<
automaton
::
State
>
nfaStates
=
recreateNFAStates
(
dfaState
);
if
(
std
::
any_of
(
nfaStates
.
begin
(),
nfaStates
.
end
(),
[
&
](
const
automaton
::
State
&
nfaState
)
{
return
nfa
.
getFinalStates
().
count
(
nfaState
);
}))
{
res
.
addFinalState
(
dfaState
);
// 3b
res
.
addTransition
(
std
::
move
(
state
),
input
,
std
::
move
(
dfaState
)
);
}
}
while
(
!
todo
.
empty
(
)
);
// 5
for
(
const
automaton
::
State
&
dfaState
:
res
.
getStates
(
)
)
{
std
::
set
<
automaton
::
State
>
nfaStates
=
recreateNFAStates
(
dfaState
);
if
(
std
::
any_of
(
nfaStates
.
begin
(
),
nfaStates
.
end
(
),
[
&
]
(
const
automaton
::
State
&
nfaState
)
{
return
nfa
.
getFinalStates
(
).
count
(
nfaState
);
}
)
)
res
.
addFinalState
(
dfaState
);
}
return
res
;
}
auto
DeterminizeMultiInitialStateNFA
=
Determinize
::
RegistratorWrapper
<
automaton
::
DFA
,
automaton
::
MultiInitialStateNFA
>
(
Determinize
::
getInstance
(
),
Determinize
::
determinize
);
auto
DeterminizeMultiInitialStateNFA
=
Determinize
::
RegistratorWrapper
<
automaton
::
DFA
,
automaton
::
MultiInitialStateNFA
>
(
Determinize
::
getInstance
(
),
Determinize
::
determinize
);
automaton
::
DFA
Determinize
::
determinize
(
const
automaton
::
NFA
&
nfa
)
{
// 1, 4
automaton
::
State
initialState
(
createDFAState
({
nfa
.
getInitialState
()}));
automaton
::
DFA
res
(
initialState
);
res
.
setInputAlphabet
(
nfa
.
getInputAlphabet
());
automaton
::
DFA
Determinize
::
determinize
(
const
automaton
::
NFA
&
nfa
)
{
// 1, 4
automaton
::
State
initialState
(
createDFAState
(
{
nfa
.
getInitialState
(
)
}
)
);
automaton
::
DFA
res
(
initialState
);
// 2
std
::
deque
<
automaton
::
State
>
todo
;
todo
.
push_back
(
std
::
move
(
initialState
));
res
.
setInputAlphabet
(
nfa
.
getInputAlphabet
(
)
);
// 2
std
::
deque
<
automaton
::
State
>
todo
;
todo
.
push_back
(
std
::
move
(
initialState
)
);
do
{
// 3a, c
automaton
::
State
state
=
std
::
move
(
todo
.
front
());
todo
.
pop_front
();
// 3b
for
(
const
alphabet
::
Symbol
&
input
:
nfa
.
getInputAlphabet
())
{
std
::
set
<
automaton
::
State
>
targetNFAStates
;
for
(
automaton
::
State
nfaState
:
std
::
make_moveable_set
(
recreateNFAStates
(
state
)))
{
auto
iter
=
nfa
.
getTransitions
().
find
(
std
::
make_pair
(
std
::
move
(
nfaState
),
input
));
if
(
iter
!=
nfa
.
getTransitions
().
end
())
{
targetNFAStates
.
insert
(
iter
->
second
.
begin
(),
iter
->
second
.
end
());
}
// 3a, c
automaton
::
State
state
=
std
::
move
(
todo
.
front
(
)
);
todo
.
pop_front
(
);
// 3b
for
(
const
alphabet
::
Symbol
&
input
:
nfa
.
getInputAlphabet
(
)
)
{
std
::
set
<
automaton
::
State
>
targetNFAStates
;
for
(
automaton
::
State
nfaState
:
std
::
make_moveable_set
(
recreateNFAStates
(
state
)
)
)
{
auto
iter
=
nfa
.
getTransitions
(
).
find
(
std
::
make_pair
(
std
::
move
(
nfaState
),
input
)
);
if
(
iter
!=
nfa
.
getTransitions
(
).
end
(
)
)
targetNFAStates
.
insert
(
iter
->
second
.
begin
(
),
iter
->
second
.
end
(
)
);
}
automaton
::
State
dfaState
=
createDFAState
(
std
::
move
(
targetNFAStates
));
// 4
bool
existed
=
!
res
.
addState
(
dfaState
);
automaton
::
State
dfaState
=
createDFAState
(
std
::
move
(
targetNFAStates
)
);
if
(
!
existed
)
todo
.
push_back
(
dfaState
);
// 4
bool
existed
=
!
res
.
addState
(
dfaState
);
// 3b
res
.
addTransition
(
std
::
move
(
state
),
input
,
std
::
move
(
dfaState
));
}
}
while
(
!
todo
.
empty
());
if
(
!
existed
)
todo
.
push_back
(
dfaState
);
// 5
for
(
const
automaton
::
State
&
dfaState
:
res
.
getStates
())
{
std
::
set
<
automaton
::
State
>
nfaStates
=
recreateNFAStates
(
dfaState
);
if
(
std
::
any_of
(
nfaStates
.
begin
(),
nfaStates
.
end
(),
[
&
](
const
automaton
::
State
&
nfaState
)
{
return
nfa
.
getFinalStates
().
count
(
nfaState
);
}))
{
res
.
addFinalState
(
dfaState
);
// 3b
res
.
addTransition
(
std
::
move
(
state
),
input
,
std
::
move
(
dfaState
)
);
}
}
while
(
!
todo
.
empty
(
)
);
// 5
for
(
const
automaton
::
State
&
dfaState
:
res
.
getStates
(
)
)
{
std
::
set
<
automaton
::
State
>
nfaStates
=
recreateNFAStates
(
dfaState
);
if
(
std
::
any_of
(
nfaStates
.
begin
(
),
nfaStates
.
end
(
),
[
&
]
(
const
automaton
::
State
&
nfaState
)
{
return
nfa
.
getFinalStates
(
).
count
(
nfaState
);
}
)
)
res
.
addFinalState
(
dfaState
);
}
return
res
;
}
auto
DeterminizeNFA
=
Determinize
::
RegistratorWrapper
<
automaton
::
DFA
,
automaton
::
NFA
>
(
Determinize
::
getInstance
(
),
Determinize
::
determinize
);
auto
DeterminizeNFA
=
Determinize
::
RegistratorWrapper
<
automaton
::
DFA
,
automaton
::
NFA
>
(
Determinize
::
getInstance
(
),
Determinize
::
determinize
);
}
/* namespace determinize */
...
...
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