forked from RyanAshbaugh/AnimatSimulationMSU
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clusterSimEngine.py
48 lines (36 loc) · 1.35 KB
/
clusterSimEngine.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
__author__ = 'RJ'
"""
Simulation Engine for running on cluster
Does not use threads
Does not copy objects to send back to driver, only stores states in list form
"""
import time
import World
import pp
import SimParam
class clusterSimEngine():
def __init__(self):
self.stateList = [] # list for storing states (time,state)
self.timeStep = 1 # time
self.clockStart = -1 # real world clock time, used to benchmark
self.writeInterval = 500 # store every 500 "cycles" = 500 simulated ms
self.world = 0 # place holder for world variable
self.foodLocs = 0
def initializeEngine(self,simParam,simLength):
self.clockStart = time.clock()
self.world = World.World(simParam)
self.foodLocs = self.world.getFoodLocs()
self.stateList.append((0,self.world.copyDynamicState())) #store initial world state
for t in xrange(1,simLength+1):
self.simulate(t)
return True
def simulate(self,t):
self.world.update(t,self.timeStep)
if (t%self.writeInterval == 0):
self.stateList.append((t,self.world.copyDynamicState()))
def getFoodLocs(self):
return self.foodLocs
def setWriteInterval(self,interval):
self.writeInterval = interval
def getResults(self):
return self.stateList