-
Notifications
You must be signed in to change notification settings - Fork 0
/
AttributePNet.py
96 lines (80 loc) · 3.14 KB
/
AttributePNet.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import datetime
class Place (object):
"""!
Class to represent a place in a Petri Net
Tokens are represented by Integer values
input and output arcs are represented as sets of possible transitions
date attribute refers to a timestamp - дата первого перехода в позицию --- ЗАЧЕМ ТУТ??
isFinal - specify if this place can be final
"""
def __init__(self, name, final, tokens=0):
"""!
Constructor method.
@param name: name of the place
@param final: specify if this place can be final
"""
self.name = str(name)
self.tokens = tokens
self.inArcs = {}
self.outArcs = {}
self.date = datetime.date(datetime.MINYEAR, 1, 1) # ?????
self.isFinal = final
def add_token(self):
self.tokens = self.tokens + 1
def remove_token(self):
self.tokens = self.tokens - 1
def set_date(self, timestamp):
self.date = datetime.datetime.strptime(timestamp, "%d.%m.%y")
class Transition (object):
"""!
Class to represent a transition ib a Petri Net
"""
def __init__(self, name, fires, maxtime, hidden, weight=1):
"""!
Constructor method.
@param name: name of the transition
@param fires: legal number of firing for the transition
@param maxtime: legal gap before transition firing
@param weight: penalty for transition firing
"""
self.name = str(name)
self.inArcs = {}
self.outArcs = {}
self.legalFires = fires
self.firingCounter = 0
self.maxTime = datetime.timedelta(days=maxtime)
self.weight = weight
self.hidden = hidden
def fire(self):
self.firingCounter = self.firingCounter + 1
class AttributePetriNet (object):
def __init__(self):
self.startPlace = Place("start", False, tokens=1)
self.finishPlace = Place("final", True)
self.places = {
"start": self.startPlace,
"final": self.finishPlace
}
self.transitions = {}
def addPlace(self, name, final):
newPlace = Place(name, final)
self.places[name] = newPlace
def addTransition (self, name, fires, maxtime, hidden, weight):
newTransition = Transition(name, fires, maxtime, hidden, weight)
self.transitions[name] = newTransition
def addInputArc(self, placeName, transitionName):
"""!
Method that add arcs from place to transition
"""
currentPlace = self.places[placeName]
currentTransition = self.transitions[transitionName]
currentPlace.outArcs[transitionName] = currentTransition
currentTransition.inArcs[placeName] = currentPlace
def addOutputArc(self, transitionName, placeName):
"""!
Method that add arcs from transitions to places
"""
currentPlace = self.places[placeName]
currentTransition = self.transitions[transitionName]
currentPlace.inArcs[transitionName] = currentTransition
currentTransition.outArcs[placeName] = currentPlace