-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharc.py
45 lines (40 loc) · 1.16 KB
/
arc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from place import Place
from transition import Transition
class Arc:
def __init__(self, to, frm, weight=1, name=None):
self.weight = weight
self._validate(to, frm)
self._validate(frm,to)
self.to = to
self.frm = frm
self.to.inArcs.append(self)
self.frm.outArcs.append(self)
self.type = "Arc"
self.name = name
def update(self, value):
if value<=0:
value = 1
self.weight = value
@staticmethod
def _validate(to, frm):
if type(to)==Place:
if type(frm)==Place:
raise TypeError
elif type(to)==Transition:
if type(frm)==Transition:
raise TypeError
class InhibitorArc(Arc):
def __init__(self,to, frm, weight=1, name=None):
self.weight = weight
self._validate(to,frm)
self.to = to
self.frm = frm
self.to.inArcs.append(self)
self.frm.outArcs.append(self)
self.type = "InhibitorArc"
self.name = name
@staticmethod
def _validate(to ,frm):
if type(to)==Place:
raise TypeError
assert(type(frm)==Place)