I am having troubles with creating an instance in python. I tried to rewrite this in many ways, followed the tips from stack but somehow the code still gives me an error that my created instance is not an instance of PetriNet (namedtuple). Could anyone give me a hint what might be wrong? I also add the test code for errors, and error which I got.
PetriNet = namedtuple(typename='PetriNet', field_names=['places', 'transitions', 'arcs'])
Place = namedtuple('Place', ['label', 'marking'])
Arc = namedtuple('Arc', ['source', 'target', 'weight'])
# You can use the ploting function to plot your petri net for S
example = PetriNet(places={Place('p1', 1), Place('p2', 0)},
transitions={'t1'},
arcs={Arc('p1', 't1', 1), Arc('t1', 'p2', 1)})
def make_synchronized_petri_net_S():
PetriNet = namedtuple(typename='PetriNet', field_names=['places', 'transitions', 'arcs'])
Place = namedtuple('Place', ['label', 'marking'])
Arc = namedtuple('Arc', ['source', 'target', 'weight'])
pet_places = [{Place('p11', 1), Place('p12', 0), Place('p21',1), Place('p22',0)}]
pet_transitions = [{'a','b','c','d','e'}]
pet_arcs = [{Arc('p11', 'a', 1), Arc('a', 'p12', 1), Arc('p12', 'b', 0), Arc('b', 'p11', 1), Arc('p12', 'c', 0), Arc('c', 'p12', 0), Arc('p21', 'c', 1), Arc('c', 'p22', 1), Arc('p22', 'e', 0), Arc('e', 'p21', 1), Arc('p22', 'd', 0), Arc('d', 'p21', 1)}]
places = set()
transitions = set()
arcs = set()
S = PetriNet(places,transitions,arcs)
S = S._replace(places= pet_places, transitions=pet_transitions, arcs =pet_arcs)
print("Our S is",S)
return S
this is a code to test the error :
S = make_synchronized_petri_net_S()
assert isinstance(S, PetriNet)
assert isinstance(S.places.pop(), Place)
assert isinstance(S.arcs.pop(), Arc)
and finally the error: AssertionError in assert isinstance(S, PetriNet)
Thank you very much for any advices.
NameError: name 'namedtuple' is not defined. If I addfrom collections import namedtuple, I getNameError: name 'PetriNet' is not defined. Please provide a minimal reproducible example.