Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
MDESops
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
M-DES-tools
MDESops
Commits
8faf45d2
Commit
8faf45d2
authored
2 years ago
by
xzjin
Browse files
Options
Downloads
Patches
Plain Diff
changed language_compare
parent
9d655724
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
DESops/automata/DFA.py
+3
-3
3 additions, 3 deletions
DESops/automata/DFA.py
DESops/basic_operations/language_equivalence.py
+35
-1
35 additions, 1 deletion
DESops/basic_operations/language_equivalence.py
tests/test_Automata.py
+17
-0
17 additions, 0 deletions
tests/test_Automata.py
with
55 additions
and
4 deletions
DESops/automata/DFA.py
+
3
−
3
View file @
8faf45d2
...
...
@@ -3,7 +3,7 @@ import igraph as ig
from
DESops
import
error
from
DESops.automata.automata
import
_Automata
from
DESops.automata.event
import
Event
from
DESops.basic_operations.language_equivalence
import
compare_language
#
from DESops.basic_operations.language_equivalence import compare_language
# MUST HAVE A DEFINITION NFA TO DFA
# CHECKS IF THERE IS NONDETERMINISM
...
...
@@ -180,5 +180,5 @@ class DFA(_Automata):
out_event
=
lambda
v
:
{
el
[
1
]
for
el
in
v
}
return
[
len
(
out_event
(
v
))
==
len
(
v
)
for
v
in
self
.
_graph
.
vs
[
"
out
"
]]
def
__eq__
(
self
,
other
):
return
isinstance
(
other
,
DFA
)
and
compare_language
(
self
,
other
)
#
def __eq__(self, other):
#
return isinstance(other, DFA) and compare_language(self, other)
This diff is collapsed.
Click to expand it.
DESops/basic_operations/language_equivalence.py
+
35
−
1
View file @
8faf45d2
import
DESops.automata
as
automata
from
DESops
import
error
from
.composition
import
observer
from
.construct_complement
import
complement
from
.product_NFA
import
product_NFA
def
compare_language
(
g1
,
g2
):
def
compare_language
_generated
(
g1
,
g2
):
# https://cs.stackexchange.com/questions/48136/testing-two-dfas-generate-the-same-language-by-trying-all-strings-upto-a-certain
# https://cs.stackexchange.com/questions/81813/is-the-equality-of-two-dfas-a-decidable-problem/81815#81815
"""
...
...
@@ -97,3 +100,34 @@ def composition(v1, v2, nx_v1, nx_v2, index, vertice_number):
index
=
index
+
1
marking
=
nx_v1
[
"
marked
"
]
and
nx_v2
[
"
marked
"
]
return
name
,
transition
,
index
,
marking
,
new
def
inclusion
(
g
,
h
,
Eo
):
h_det
=
observer
(
h
)
complement
(
h_det
,
inplace
=
True
,
events
=
Eo
)
prod
=
product_NFA
([
g
,
h_det
],
save_marked_states
=
True
)
opaque
=
True
for
v
in
prod
.
vs
:
if
v
[
"
marked
"
]:
opaque
=
False
break
return
opaque
def
compare_language_marked
(
g1
,
g2
,
Eo1
=
None
,
Eo2
=
None
):
#active_events must be provided if there exists any observable event that doesn't appear in any transition
if
Eo1
==
None
:
Eo1
=
g1
.
events
.
difference
(
g1
.
Euo
)
if
Eo2
==
None
:
Eo2
=
g2
.
events
.
difference
(
g2
.
Euo
)
if
Eo1
!=
Eo2
:
return
False
return
inclusion
(
g1
,
g2
,
Eo1
)
and
inclusion
(
g2
,
g1
,
Eo1
)
def
compare_language
(
g1
,
g2
,
Eo1
=
None
,
Eo2
=
None
,
type
=
"
generated
"
):
if
(
type
==
"
generated
"
):
return
compare_language_generated
(
g1
,
g2
)
elif
(
type
==
"
marked
"
):
return
compare_language_marked
(
g1
,
g2
,
Eo1
,
Eo2
)
# pass
elif
(
type
==
"
both
"
):
return
compare_language_generated
(
g1
,
g2
)
and
compare_language_marked
(
g1
,
g2
,
Eo1
,
Eo2
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
tests/test_Automata.py
+
17
−
0
View file @
8faf45d2
import
DESops
as
d
import
tests.util
as
util
from
DESops.basic_operations.language_equivalence
import
compare_language
def
test_type
():
...
...
@@ -114,3 +115,19 @@ def test_complement():
assert
g
.
ecount
()
==
12
assert
(
3
,
d
.
Event
(
"
b
"
))
in
g
.
vs
[
0
][
"
out
"
]
assert
g
.
vs
[
"
marked
"
]
==
[
False
,
True
,
False
,
True
]
def
test_compare_language
():
g
=
d
.
DFA
()
a
=
d
.
Event
(
"
a
"
)
b
=
d
.
Event
(
"
b
"
)
c
=
d
.
Event
(
"
c
"
)
g
.
add_vertices
(
3
,
marked
=
[
False
,
True
,
False
])
g
.
add_edges
([(
0
,
1
),(
0
,
2
),(
1
,
0
),(
1
,
2
),(
2
,
1
)],
[
a
,
b
,
c
,
a
,
b
])
f
=
d
.
DFA
()
f
.
add_vertices
(
3
,
marked
=
[
False
,
True
,
True
])
f
.
add_edges
([(
0
,
1
),(
0
,
2
),(
1
,
0
),(
1
,
2
),(
2
,
1
)],
[
a
,
b
,
c
,
a
,
b
])
assert
compare_language
(
g
,
f
)
assert
compare_language
(
g
,
g
,
type
=
"
marked
"
)
assert
not
compare_language
(
g
,
f
,
type
=
"
marked
"
)
assert
not
compare_language
(
g
,
f
,
type
=
"
both
"
)
\ No newline at end of file
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