Franck Pommereau

fixed Inhibitor arcs, misc fixes/improvements

......@@ -1637,22 +1637,23 @@ class Inhibitor (Test) :
def __hash__ (self) :
return hash(("inhibitor", self._annotation, self._condition))
def bind (self, binding) :
"""Return the value of the annotation evaluated through
`binding`, or raise `ValueError` of this binding does not
validate the condition.
"""Return no tokens since arc corresponds to an absence of tokens.
Raise `ValueError` if this binding does not validate the
condition.
>>> Inhibitor(Expression('x+1'), Expression('x>0')).bind(Substitution(x=2))
Token(3)
()
>>> try : Inhibitor(Expression('x+1'), Expression('x<0')).bind(Substitution(x=2))
... except ValueError : print(sys.exc_info()[1])
condition not True for {x -> 2}
@param binding: a substitution
@type binding: `Substitution`
@return: a value
@return: empty tuple
"""
if self._condition(binding) :
return self._annotation.bind(binding)
return ()
else :
raise ValueError("condition not True for %s" % str(binding))
def modes (self, values) :
......@@ -2731,6 +2732,9 @@ class Marking (hdict) :
"""
return cls(((child["id"], child.child("tokens").child().to_obj())
for child in tree.get_children("place")))
def __str__ (self) :
base = "{%s}" % ", ".join("%s=%s" % pair for pair in sorted(self.items()))
return base.replace("={dot}", "")
def __call__ (self, place) :
"""Return the marking of `place`. The empty multiset is
returned if `place` is not explicitely given in the marking.
......
......@@ -105,7 +105,7 @@ class Graph (Cluster) :
def dot (self) :
self.done = set()
return "\n".join(self._dot_text(["digraph {",
'charset="UTF-8"',
# 'charset="UTF-8"',
['node [label="N",'
' fillcolor="#FFFFFF",'
' fontcolor="#000000",'
......@@ -120,7 +120,9 @@ class Graph (Cluster) :
return text
else :
return '"%s"' % text.replace('"', r'\"')
def render (self, filename, engine="dot", debug=False) :
def render (self, filename, engine=None, debug=False) :
if engine is None :
engine = getattr(self, "engine", "dot")
if engine not in ("dot", "neato", "twopi", "circo", "fdp") :
raise ValueError("unknown GraphViz engine %r" % engine)
with codecs.open(filename + ".dot", "w", "utf-8") as outfile :
......@@ -134,12 +136,15 @@ class Graph (Cluster) :
"-o" + filename, outfile.name],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
dot.communicate()
stderr=subprocess.STDOUT)
stdout, stderr = dot.communicate()
if not debug :
os.unlink(outfile.name)
if dot.returncode != 0 :
raise IOError("%s exited with status %s" % (engine, dot.returncode))
if stdout.strip() + stderr.strip() :
stdout = "\n*** Original error message follows ***\n " + stdout
raise IOError("%s exited with status %s%s"
% (engine, dot.returncode, stdout))
def layout (self, engine="dot", debug=False) :
if engine not in ("dot", "neato", "twopi", "circo", "fdp") :
raise ValueError("unknown GraphViz engine %r" % engine)
......@@ -226,6 +231,7 @@ def extend (module) :
for num, node in enumerate(self.node()))
g = self._copy(nodemap, self.clusters, cluster_attr,
place_attr, trans_attr)
g.engine = engine
self._copy_edges(nodemap, g, arc_attr)
if graph_attr :
graph_attr(self, g.attr)
......
......@@ -90,8 +90,11 @@ class Builder (object) :
"""raise an exception with appropriate location
"""
if self.stack :
pos = "[%s:%s]: " % (self.stack[-1].lineno,
self.stack[-1].col_offset)
try :
pos = "[%s:%s]: " % (self.stack[-1].lineno,
self.stack[-1].col_offset)
except :
pos = ""
else :
pos = ""
raise error(pos+message)
......
......@@ -297,8 +297,13 @@ def main (args=sys.argv[1:], src=None) :
if options.check :
lineno, trace = Checker(net).run()
if options.simul :
engine = "dot"
for eng in gv_engines :
if getattr(options, "gv%s" % eng) :
engine = eng
break
try :
simul = Simulator(node, net, draw(net, None), options.port)
simul = Simulator(node, net, draw(net, None, engine), options.port)
except :
bug()
simul.start()
......