Commit d6cc276e authored by Georgios Dagkakis's avatar Georgios Dagkakis Committed by Jérome Perrin

work in CapacityEntitiesController

parent 0eafc667
...@@ -43,6 +43,7 @@ class CapacityEntity(Entity): ...@@ -43,6 +43,7 @@ class CapacityEntity(Entity):
def initialize(self): def initialize(self):
Entity.initialize(self) Entity.initialize(self)
self.shouldMove=False
from Globals import G from Globals import G
# find the project that the capacity entity is part of # find the project that the capacity entity is part of
for project in G.CapacityProjectList: for project in G.CapacityProjectList:
......
...@@ -28,6 +28,7 @@ event generator that controls the capacity station objects ...@@ -28,6 +28,7 @@ event generator that controls the capacity station objects
import simpy import simpy
from EventGenerator import EventGenerator from EventGenerator import EventGenerator
from CapacityEntity import CapacityEntity
from Globals import G from Globals import G
class CapacityStationController(EventGenerator): class CapacityStationController(EventGenerator):
...@@ -61,7 +62,8 @@ class CapacityStationController(EventGenerator): ...@@ -61,7 +62,8 @@ class CapacityStationController(EventGenerator):
# Send canDispose to all the Stations # Send canDispose to all the Stations
print 2 print 2
for station in G.CapacityStationList: for station in G.CapacityStationList:
station.canDispose.succeed() if len(station.getActiveObjectQueue())>0:
station.canDispose.succeed()
# give control until all the Stations become empty # give control until all the Stations become empty
print 3 print 3
while not self.checkIfStationsEmpty(): while not self.checkIfStationsEmpty():
...@@ -82,14 +84,26 @@ class CapacityStationController(EventGenerator): ...@@ -82,14 +84,26 @@ class CapacityStationController(EventGenerator):
print 7 print 7
for station in G.CapacityStationList: for station in G.CapacityStationList:
station.isLocked=False station.isLocked=False
# Send canDispose to all the StationBuffers
print 8 print 8, 9
for buffer in G.CapacityStationBufferList: # loop through the stations
buffer.canDispose.succeed() for station in G.CapacityStationList:
# give control until all StationBuffers hold only Entities that are not to be given buffer=station.previous[0] # take the buffer
print 9 buffer.sortEntities() # sort the entities of the buffer so the ones to move go in front
while not self.checkIfBuffersFinished(): # loop though the entities
yield self.env.timeout(0) entitiesToCheck=list(buffer.getActiveObjectQueue())
for entity in entitiesToCheck:
print entity.name, entity.shouldMove
if not entity.shouldMove: # when the first entity that should not move is reached break
break
station.isRequested.succeed(buffer) # send is requested to station
# wait until the entity is removed
yield buffer.entityRemoved
buffer.entityRemoved=self.env.event()
print 10 print 10
# for every station update the remaining interval capacity so that it is ready for next loop # for every station update the remaining interval capacity so that it is ready for next loop
for station in G.CapacityStationList: for station in G.CapacityStationList:
...@@ -108,20 +122,49 @@ class CapacityStationController(EventGenerator): ...@@ -108,20 +122,49 @@ class CapacityStationController(EventGenerator):
def calculateWhatIsToBeProcessed(self): def calculateWhatIsToBeProcessed(self):
# loop through the capacity station buffers # loop through the capacity station buffers
for buffer in G.CapacityStationBufferList: for buffer in G.CapacityStationBufferList:
totalRequestedCapacity=0 station=buffer.next[0] # get the station
print buffer.next totalAvailableCapacity=station.remainingIntervalCapacity[0] # get the available capacity of the station
totalAvailableCapacity=buffer.next[0].remainingIntervalCapacity[0] # for this interval
# if there is no capacity continue with the next buffer
if totalAvailableCapacity<=0:
continue
# calculate the total capacity that is requested
totalRequestedCapacity=0
for entity in buffer.getActiveObjectQueue(): for entity in buffer.getActiveObjectQueue():
totalRequestedCapacity+=entity.requiredCapacity totalRequestedCapacity+=entity.requiredCapacity
# if there is enough capacity for all the entities set them that they all should move
if totalRequestedCapacity<=totalAvailableCapacity: if totalRequestedCapacity<=totalAvailableCapacity:
for entity in buffer.getActiveObjectQueue(): for entity in buffer.getActiveObjectQueue():
pass entity.shouldMove=True
#entity.shouldMove=True # else calculate the capacity for every entity and create the entities
else:
def checkIfBuffersFinished(self): entitiesInBuffer=list(buffer.getActiveObjectQueue())
for buffer in G.CapacityStationBufferList: # loop through the entities
for entity in buffer.getActiveObjectQueue(): for entity in entitiesInBuffer:
if entity.shouldMove: # calculate what is the capacity that should proceed and what that should remain
return False capacityToMove=totalAvailableCapacity*(entity.requiredCapacity)/float(totalRequestedCapacity)
capacityToStay=entity.requiredCapacity-capacityToMove
# remove the capacity entity by the buffer so that the broken ones are created
buffer.getActiveObjectQueue().remove(entity)
entityToMoveName=entity.capacityProjectId+'_'+station.objName+'_'+str(capacityToMove)
entityToMove=CapacityEntity(name=entityToMoveName, capacityProjectId=entity.capacityProjectId, requiredCapacity=capacityToMove)
entityToMove.initialize()
entityToMove.currentStation=buffer
entityToMove.shouldMove=True
entityToStayName=entity.capacityProjectId+'_'+station.objName+'_'+str(capacityToStay)
entityToStay=CapacityEntity(name=entityToStayName, capacityProjectId=entity.capacityProjectId, requiredCapacity=capacityToStay)
entityToStay.initialize()
entityToStay.currentStation=buffer
import Globals
Globals.setWIP([entityToMove,entityToStay]) #set the new components as wip
buffer.sortEntities()
print '-'
for entity in buffer.getActiveObjectQueue():
print entity.name, entity.shouldMove
print '-'
def checkIfBufferFinished(self, buffer):
if buffer.getActiveObjectQueue():
return False
return True return 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