Franck Pommereau

fixed long standing bug in StateGraph => version 0.9.22

1 -0.9.21 1 +0.9.22
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
19 @contact: franck.pommereau@ibisc.univ-evry.fr 19 @contact: franck.pommereau@ibisc.univ-evry.fr
20 """ 20 """
21 21
22 -version = "0.9.21" 22 +version = "0.9.22"
23 defaultencoding = "utf-8" 23 defaultencoding = "utf-8"
24 24
25 """## Module `snakes` 25 """## Module `snakes`
......
...@@ -4361,8 +4361,10 @@ class StateGraph (object) : ...@@ -4361,8 +4361,10 @@ class StateGraph (object) :
4361 def _create_edge (self, source, target, label) : 4361 def _create_edge (self, source, target, label) :
4362 if target in self._succ[source] : 4362 if target in self._succ[source] :
4363 self._succ[source][target].add(label) 4363 self._succ[source][target].add(label)
4364 + if source == 18 : print " add", source, "=>", target
4364 else : 4365 else :
4365 self._succ[source][target] = set([label]) 4366 self._succ[source][target] = set([label])
4367 + if source == 18 : print " new", source, "=>", target
4366 if source in self._pred[target] : 4368 if source in self._pred[target] :
4367 self._pred[target][source].add(label) 4369 self._pred[target][source].add(label)
4368 else : 4370 else :
...@@ -4377,10 +4379,10 @@ class StateGraph (object) : ...@@ -4377,10 +4379,10 @@ class StateGraph (object) :
4377 def __contains__ (self, marking) : 4379 def __contains__ (self, marking) :
4378 return marking in self._state 4380 return marking in self._state
4379 def successors (self, state=None) : 4381 def successors (self, state=None) :
4380 - """Return the successors of the current state. The value 4382 + """Return the successors of the current state. The value returned is a
4381 - returned is a dictionnary mapping the numbers of successor 4383 + iterator over triples `(succ, trans, mode)` representing the
4382 - states to pairs `(trans, mode)` representing the name of the 4384 + number of the successor, the name of the transition and the
4383 - transition and the binding needed to reach the new state. 4385 + binding needed to reach the new state.
4384 4386
4385 >>> n = PetriNet('N') 4387 >>> n = PetriNet('N')
4386 >>> n.add_place(Place('p', [0])) 4388 >>> n.add_place(Place('p', [0]))
...@@ -4390,18 +4392,18 @@ class StateGraph (object) : ...@@ -4390,18 +4392,18 @@ class StateGraph (object) :
4390 >>> g = StateGraph(n) 4392 >>> g = StateGraph(n)
4391 >>> g.build() 4393 >>> g.build()
4392 >>> g.goto(2) 4394 >>> g.goto(2)
4393 - >>> g.successors() 4395 + >>> list(g.successors())
4394 - {3: (Transition('t', Expression('x<5')), Substitution(x=2))} 4396 + [(3, Transition('t', Expression('x<5')), Substitution(x=2))]
4397 +
4398 + @return: iterator of triples successor/transition/mode to them
4399 + @rtype: generator of `(int, str, Substitution)`
4395 4400
4396 - @return: the dictionnary of successors and transitions to them
4397 - @rtype: `dict` mapping non-negative `int` to `tuple` holding a
4398 - `str` and a `Substitution`
4399 """ 4401 """
4400 if state is None : 4402 if state is None :
4401 state = self.current() 4403 state = self.current()
4402 self._process(state) 4404 self._process(state)
4403 - return dict((succ, label) for succ in self._succ[state] 4405 + return ((succ, trans, mode) for succ in self._succ[state]
4404 - for label in self._succ[state][succ]) 4406 + for trans, mode in self._succ[state][succ])
4405 def predecessors (self, state=None) : 4407 def predecessors (self, state=None) :
4406 """Return the predecessors states. The returned value is as in 4408 """Return the predecessors states. The returned value is as in
4407 `successors`. Notice that if the graph is not complete, this 4409 `successors`. Notice that if the graph is not complete, this
...@@ -4416,18 +4418,16 @@ class StateGraph (object) : ...@@ -4416,18 +4418,16 @@ class StateGraph (object) :
4416 >>> g = StateGraph(n) 4418 >>> g = StateGraph(n)
4417 >>> g.build() 4419 >>> g.build()
4418 >>> g.goto(2) 4420 >>> g.goto(2)
4419 - >>> g.predecessors() 4421 + >>> list(g.predecessors())
4420 - {1: (Transition('t', Expression('x<5')), Substitution(x=1))} 4422 + [(1, Transition('t', Expression('x<5')), Substitution(x=1))]
4421 4423
4422 - @return: the dictionnary of predecessors and transitions to 4424 + @return: iterator of triples predecessor/transition/mode to them
4423 - them 4425 + @rtype: generator of `(int, str, Substitution)`
4424 - @rtype: `dict` mapping non-negative `int` to `tuple` holding a
4425 - `str` and a `Substitution`
4426 """ 4426 """
4427 if state is None : 4427 if state is None :
4428 state = self.current() 4428 state = self.current()
4429 - return dict((pred, label) for pred in self._pred[state] 4429 + return ((pred, trans, mode) for pred in self._pred[state]
4430 - for label in self._pred[state][pred]) 4430 + for trans, mode in self._pred[state][pred])
4431 def _fire (self, trans, mode) : 4431 def _fire (self, trans, mode) :
4432 "Fire trans with the given mode" 4432 "Fire trans with the given mode"
4433 trans.fire(mode) 4433 trans.fire(mode)
...@@ -4450,6 +4450,7 @@ class StateGraph (object) : ...@@ -4450,6 +4450,7 @@ class StateGraph (object) :
4450 if target is None : 4450 if target is None :
4451 target = self._create_state(new_marking, state, trans, mode) 4451 target = self._create_state(new_marking, state, trans, mode)
4452 if state in self._marking : 4452 if state in self._marking :
4453 + if state == 18 : print "+", state, "=>", target, "=", trans
4453 self._create_edge(state, target, (trans, mode)) 4454 self._create_edge(state, target, (trans, mode))
4454 self.net.set_marking(marking) 4455 self.net.set_marking(marking)
4455 if state not in self._marking : 4456 if state not in self._marking :
......