-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathSaveSimulationToFile.py
More file actions
37 lines (27 loc) · 998 Bytes
/
SaveSimulationToFile.py
File metadata and controls
37 lines (27 loc) · 998 Bytes
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
''' Example of saving the system object to a file and then loading
it back. Same methods can be used to store and load almost any Python
object.
System object contains all of the devices used in the simulation and
all of the collected data so far.
'''
import os
from simprocesd.model import System
from simprocesd.model.factory_floor import Source, PartProcessor, Sink
from simprocesd.utils import save_object, load_object
def main():
file_name = 'SystemSimulation.save'
system = System()
source = Source()
M1 = PartProcessor('PartProcessor', [source], 1)
sink = Sink(upstream = [M1])
system.simulate(simulation_duration = 100)
loaded_system = None
try:
save_object(system, file_name)
loaded_system = load_object(file_name)
finally:
os.remove(file_name)
machines = loaded_system.find_assets(type_ = PartProcessor)
print(f'Machines from loaded system: {[m.name for m in machines]}')
if __name__ == '__main__':
main()