Commit 7c246a10 authored by Georgios Dagkakis's avatar Georgios Dagkakis

CapacityStationController to consider if projects share workpower

parent e9dd5605
...@@ -48,6 +48,8 @@ class CapacityStationController(EventGenerator): ...@@ -48,6 +48,8 @@ class CapacityStationController(EventGenerator):
self.stepsAreComplete=self.env.event() self.stepsAreComplete=self.env.event()
def run(self): def run(self):
# sort the buffers so if they have shared resources the ones with highest priority will go in front
self.sortBuffers()
yield self.env.timeout(self.start) #wait until the start time yield self.env.timeout(self.start) #wait until the start time
#loop until the end of the simulation #loop until the end of the simulation
while 1: while 1:
...@@ -87,13 +89,15 @@ class CapacityStationController(EventGenerator): ...@@ -87,13 +89,15 @@ class CapacityStationController(EventGenerator):
# lock the exit again # lock the exit again
exit.isLocked=True exit.isLocked=True
# create the entities in the following stations
self.createInCapacityStationBuffers()
# if the last exits led to an empty system then the simulation must be stopped # if the last exits led to an empty system then the simulation must be stopped
# step returns and the generator never yields the stepsAreComplete signal # step returns and the generator never yields the stepsAreComplete signal
if self.checkIfSystemEmpty(): if self.checkIfSystemEmpty():
return return
# create the entities in the following stations
self.createInCapacityStationBuffers()
# if there is need to merge entities in a buffer # if there is need to merge entities in a buffer
self.mergeEntities() self.mergeEntities()
...@@ -141,7 +145,11 @@ class CapacityStationController(EventGenerator): ...@@ -141,7 +145,11 @@ class CapacityStationController(EventGenerator):
# lock the station # lock the station
station.isLocked=True station.isLocked=True
# calculate the utilization # calculate the utilization
periodDict['utilization']=capacityAllocated/float(capacityAvailable) if capacityAvailable:
periodDict['utilization']=capacityAllocated/float(capacityAvailable)
else:
# TODO check how the utilization and mean utilization should be calculated if it is 0
periodDict['utilization']=0
# update the utilisationDict of the station # update the utilisationDict of the station
station.utilisationDict.append(periodDict) station.utilisationDict.append(periodDict)
...@@ -198,8 +206,9 @@ class CapacityStationController(EventGenerator): ...@@ -198,8 +206,9 @@ class CapacityStationController(EventGenerator):
# list to keep entities that have not been already allocated # list to keep entities that have not been already allocated
entitiesNotAllocated=list(activeObjectQueue) entitiesNotAllocated=list(activeObjectQueue)
allCapacityConsumed=False allCapacityConsumed=False
if totalAvailableCapacity==0:
allCapacityConsumed=True
while not allCapacityConsumed: while not allCapacityConsumed:
# list to keep entities that are within a threshold from the EDD # list to keep entities that are within a threshold from the EDD
entitiesWithinThreshold=[] entitiesWithinThreshold=[]
...@@ -230,11 +239,13 @@ class CapacityStationController(EventGenerator): ...@@ -230,11 +239,13 @@ class CapacityStationController(EventGenerator):
for entity in entitiesWithinThreshold: for entity in entitiesWithinThreshold:
if self.checkIfProjectCanStartInStation(entity.capacityProject, station) and\ if self.checkIfProjectCanStartInStation(entity.capacityProject, station) and\
(not self.checkIfProjectNeedsToBeAssembled(entity.capacityProject, buffer)): (not self.checkIfProjectNeedsToBeAssembled(entity.capacityProject, buffer)):
entity.shouldMove=True entity.shouldMove=True
# remove the entity from the none allocated ones # remove the entity from the none allocated ones
entitiesNotAllocated.remove(entity) entitiesNotAllocated.remove(entity)
# check if all the capacity is consumed to update the flag and break the loop # check if all the capacity is consumed to update the flag and break the loop
if totalRequestedCapacity==totalAvailableCapacity: if totalRequestedCapacity==totalAvailableCapacity:
# the capacity will be 0 since we consumed it all
totalAvailableCapacity=0
allCapacityConsumed=True allCapacityConsumed=True
# if we still have available capacity # if we still have available capacity
else: else:
...@@ -245,13 +256,15 @@ class CapacityStationController(EventGenerator): ...@@ -245,13 +256,15 @@ class CapacityStationController(EventGenerator):
(not self.checkIfProjectNeedsToBeAssembled(entity.capacityProject, buffer)): (not self.checkIfProjectNeedsToBeAssembled(entity.capacityProject, buffer)):
haveMoreEntitiesToAllocate=True haveMoreEntitiesToAllocate=True
break break
# otherwise we have to calculate the capacity for next loop
# the remaining capacity will be decreased by the one that was originally requested
totalAvailableCapacity-=totalRequestedCapacity
# if we have more entities break # if we have more entities break
if not haveMoreEntitiesToAllocate: if not haveMoreEntitiesToAllocate:
break break
# otherwise we have to calculate the capacity for next loop
# the remaining capacity will be decreased by the one that was originally requested
totalAvailableCapacity-=totalRequestedCapacity
# else calculate the capacity for every entity and create the entities # else calculate the capacity for every entity and create the entities
else: else:
allCapacityConsumed=True allCapacityConsumed=True
...@@ -272,7 +285,20 @@ class CapacityStationController(EventGenerator): ...@@ -272,7 +285,20 @@ class CapacityStationController(EventGenerator):
# else break the entity according to rule # else break the entity according to rule
else: else:
self.breakEntity(entity, buffer, station, totalAvailableCapacity, totalRequestedCapacity) self.breakEntity(entity, buffer, station, totalAvailableCapacity, totalRequestedCapacity)
# the capacity will be 0 since we consumed it all
totalAvailableCapacity=0
if station.sharedResources:
self.setSharedCapacity(station, totalAvailableCapacity)
def setSharedCapacity(self, station, capacity):
sharedStationsIds=station.sharedResources.get('stationIds', [])
for capacityStation in G.CapacityStationList:
if capacityStation is station:
continue
if capacityStation.id in sharedStationsIds:
capacityStation.remainingIntervalCapacity[0]=capacity
# breaks an entity in the part that should move and the one that should stay # breaks an entity in the part that should move and the one that should stay
def breakEntity(self, entity, buffer, station, totalAvailableCapacity, totalRequestedCapacity): def breakEntity(self, entity, buffer, station, totalAvailableCapacity, totalRequestedCapacity):
# calculate what is the capacity that should proceed and what that should remain # calculate what is the capacity that should proceed and what that should remain
...@@ -388,5 +414,11 @@ class CapacityStationController(EventGenerator): ...@@ -388,5 +414,11 @@ class CapacityStationController(EventGenerator):
if total-(alreadyWorked+required)<0.001 and availableCapacity>=required: # a small value to avoid mistakes due to rounding if total-(alreadyWorked+required)<0.001 and availableCapacity>=required: # a small value to avoid mistakes due to rounding
return True return True
return False return False
# sorts the buffers so if they have shared resources the ones with highest priority will go in front
def sortBuffers(self):
for buffer in G.CapacityStationBufferList:
station=buffer.next[0]
buffer.sharedPriority=station.sharedResources.get('priority', -float('inf'))
G.CapacityStationBufferList.sort(key=lambda x: x.sharedPriority, reverse=True)
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment