Skip to content

Commit

Permalink
figure generation scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Paytonco committed Jan 30, 2022
2 parents 4cf4b16 + a21cf56 commit 63493fa
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 9 deletions.
27 changes: 18 additions & 9 deletions evacsim.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ def __init__(self, len, speedlim, out):
self._speedlim = speedlim
minutesonroad = (len / speedlim) * 60
timestepsonroad = minutesonroad/timestep
self._peoplearr = [0] * int(timestepsonroad+ 0.5)
self._peoplearr = [0] * round(timestepsonroad+ 0.5)

self._out = out
self._capacityperelement = int(path.capacityperkm * (len / len(self._peoplearr)) )
self._capacityperelement = int(path.capacityperkm * (len / self._peoplearr.__len__()) )

def timestep(self):
i = len(self._peoplearr) - 1

#Try and move the people out at the end
for i in range(self._peoplearr[i]):
if self._out.acceptperson() == True:
for j in range(self._peoplearr[i]):
if self._out.accept() == True:
self._peoplearr[i] -= 1
i -= 1

#Try to drive foreward.
while i >= 0:
self._driveforeward(i)
i += 1
i -= 1

def _driveforeward(self, i):
for i in range(self._peoplearr[i]):
Expand All @@ -35,13 +35,20 @@ def _driveforeward(self, i):
self._peoplearr[i+1] += 1

#Returns true if person is accepted.
def _acceptperson(self):
def accept(self):
if(self._peoplearr[0] >= self._capacityperelement):
return False
else:
self._peoplearr[0] += 1
return True

def isempty(self):
total = 0
for x in self._peoplearr:
total += x

return total <= 0


class neighborhood:
#Rate people leave, in fraction per timestep.
Expand All @@ -55,7 +62,7 @@ def __init__(self, numpeople, out):

self._leavingpertimestep = []
for x in neighborhood.leavingrates:
self._leavingpertimestep.append(x * numpeople)
self._leavingpertimestep.append(int(x * numpeople + 0.5))

#People who are trying to leave but are blocked by traffic.
self._numpeoplequeued = 0
Expand All @@ -81,7 +88,7 @@ def timestep(self):
self._stepssinceevac += 1


def peopleleft(self):
def isempty(self):
return self._numpeopleleft <= 0


Expand All @@ -91,4 +98,6 @@ def __init__(self):

def accept(self):
self.numevacuated += 1
return True
return True


44 changes: 44 additions & 0 deletions topModel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import numpy as np
import matplotlib.pyplot as plt
import model
from evacsim import evaczone
from evacsim import path
from evacsim import neighborhood


initialState = np.zeros((100,200))
initialState[49,57] = 0.1
Expand All @@ -26,3 +30,43 @@
im = plt.imshow(burnTimes,cmap=plt.get_cmap('RdBu'))
fig.colorbar(im)
plt.show()
#fig, ax1 = plt.imshow(burnTimes,cmap=plt.get_cmap('inferno'))

#Run simulation
totalpeople = 1000

#Create paths and neighborhoods
end = evaczone()

paths = {}

paths["a"] = path(0.354, 35, end)
paths["b"] = path(0.172, 35, paths["a"])
paths["c"] = path(0.072, 35, paths["b"])
paths["d"] = path(0.175, 25, paths["c"])
paths["e"] = path(0.197, 25, paths["c"])
paths["f"] = path(0.091, 25, paths["e"])
paths["g"] = path(0.175, 25, paths["f"])

neighborhoods = {}
neighborhoods["17,1"] = neighborhood(30, paths["b"])
neighborhoods["16,1"] = neighborhood(30, paths["e"])
neighborhoods["16,2"] = neighborhood(30, paths["g"])
neighborhoods["17,2"] = neighborhood(30, paths["d"])

#Evaccomplete > 0 means not all are evacuated.
evaccomplete = 1
#Run timesteps, check if everyone is evacuated.
while evaccomplete > 0:
for n in neighborhoods:
neighborhoods[n].timestep()
for p in paths:
paths[p].timestep()

evaccomplete = 0

for n in neighborhoods:
evaccomplete += not neighborhoods[n].isempty()
for p in paths:
evaccomplete += not paths[p].isempty()
>>>>>>> a21cf560d4138428872e8becea63fc2ba23c431e

0 comments on commit 63493fa

Please sign in to comment.