-
Notifications
You must be signed in to change notification settings - Fork 1
/
simulation.py
155 lines (128 loc) · 5.11 KB
/
simulation.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/python
import threading
import time
import numpy as np
import pygtk
import gtk
import cairo
import os
#pygtk.require("2.0")
import observer as o
import model as m
import petri_net as pn
import event
import place
import transition
import arc
import inputarc
import outputarc
import model as m
import petri_net
#import numpy as np
import petri_net_data
import stoichiometry as stoich_1
import algorithm as al
import matplotlib.pyplot as plt
import invariants
class Simulation(o.Observer, threading.Thread):
_simulation_data = None
_pn_data = None
_stop = False
_model = None
_path_collection = None
_frame = None
def __init__(self, model):
#super(ViewMain, self).__init__()
o.Observer.__init__(self)
threading.Thread.__init__(self)
self._model = model
@property
def frame(self):
return self._frame
@frame.setter
def frame(self, f):
self._frame = f
@property
def petri_net_data(self):
return self._pn_data
@petri_net_data.setter
def petri_net_data(self, data):
self._pn_data = data
@property
def simulation_data(self):
return self._simulation_data
@simulation_data.setter
def simulation_data(self, data):
self._simulation_data = data
def go_to_iteration(self, itr):
pass
def stop(self):
pass
def next(self):
#itr = self._scale.get_value()
for i in range(self._iteration_pos, int(len(self._simulation_data.markings))):
#itr += 1
#self._scale.set_value(int(itr))
for j in range(len(self._pn_data.places)):
if self._simulation_data.markings[i, j] != self._simulation_data.markings[i - 1, j]:
# path vum vorheriga place zum aktuella place
place = self._model.get_data().get_place(self._pn_data.places[j])
place.set_marking(int(self._simulation_data.markings[i, j]))
# update auch labels!!!
if place != None:
if self._path_collection != None:
for path in self._path_collection:
for item in path:
item.set_rgb_edge(0, 0, 0)
self._model.get_data().update(item, item.get_key())
self._path_collection = self._model.get_data().get_path(place)
print self._path_collection
self._add_console_text(str(self._path_collection))
if self._path_collection != None:
for path in self._path_collection:
for item in path:
item.set_rgb_edge(255, 0, 0)
self._model.get_data().update(item, item.get_key())
#self._frame.add_text("Test", str(self._iteration_pos))
self._frame.refresh()
self._iteration_pos = i + 1
return
def previous(self):
pass
def run(self):
#itr = self._scale.get_value()
#while not self.finished.isSet():
# iterator counter + daten speichern und bei jedem klick auf weiter - next
#for i in range(self._iteration_pos, int(len(self._simulation_data.markings))):
for i in range(0, int(len(self._simulation_data.markings))):
#itr += 1
#self._scale.set_value(int(itr))
for j in range(len(self._pn_data.places)):
#time.sleep(1)
print self._simulation_data.markings[i]
if self._simulation_data.markings[i, j] != self._simulation_data.markings[i - 1, j]:
#print p.places[j]
# path vum vorheriga place zum aktuella place
place = self._model.get_data().get_place(self._pn_data.places[j])
place.set_marking(int(self._simulation_data.markings[i, j]))
# update auch labels!!!
if place != None:
if self._path_collection != None:
for path in self._path_collection:
for item in path:
item.set_rgb_edge(0, 0, 0)
self._model.get_data().update(item, item.get_key())
self._path_collection = self._model.get_data().get_path(place)
if self._path_collection != None:
for path in self._path_collection:
for item in path:
item.set_rgb_edge(255, 0, 0)
self._model.get_data().update(item, item.get_key())
print "update"
#self._model.notify()
self._frame.refresh()
time.sleep(1)
if __name__ == "__main__":
sim = Simulation(None)
sim.start()
sim.join()