Commit 8faf45d2 authored by xzjin's avatar xzjin
Browse files

changed language_compare

parent 9d655724
......@@ -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)
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
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
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment