fpom / snakes

SNAKES is the Net Algebra Kit for Editors and Simulators
https://snakes.ibisc.univ-evry.fr
Other
89 stars 29 forks source link

Drawing graphs does not work due to missing identifiers #23

Closed DonRichie closed 3 years ago

DonRichie commented 3 years ago

Hello,

I am currently trying to draw a simple Petri Net using snakes, but I am missing the "draw" function in the PetriNet Class. Did the api change somehow or did I make a mistake? I think I loaded the plugin correctly.

To make my problem short:

Code:

import snakes.plugins
from snakes.nets import *
snakes.plugins.load('gv', 'snakes.nets', 'nets')

S = "{ p1, p2, p3, p4, p5, p6, p7}"
T = "{ t1, t2, t3, t4, t5, t6}"
F = "{ (p1, t1),( p2, t2),( p3, t3),( p4, t1),( p4, t4), ( p5, t5),( p6, t6),( p7, t4), ( t1, p2),( t2, p3),( t3, p1),( t3, p4),( t4, p5),( t5, p6),( t6, p4), ( t6, p7)}"

F=F.replace(" ","").replace("{","").replace("}","")
S=S.replace(" ","").replace("{","").replace("}","")
T=T.replace(" ","").replace("{","").replace("}","")

S = S.split(",")
T = T.split(",")

n = PetriNet('N')

for place in S:
    n.add_place(Place(place))

for transition in T:
    n.add_transition(Transition(transition))

n.draw('graphviz-net.png')

Error:

~> python3 test.py
Traceback (most recent call last):
  File "/home/user/test.py", line 28, in <module>
    n.draw('graphviz-net.png')
AttributeError: 'PetriNet' object has no attribute 'draw'
fpom commented 3 years ago

You need to replace

from snakes.nets import *
snakes.plugins.load('gv', 'snakes.nets', 'nets')

with

snakes.plugins.load('gv', 'snakes.nets', 'xxxx')
from xxxx import *

in order to import from the package that was build by the plugins loader. (I've changer its name to xxxx in order to make it explicit that the plugins loader builds package with the name one provides.)

DonRichie commented 3 years ago

@fpom: That was fast, thank you. It works as expected, although I didn't expect it works like this :).