Commit 33ed93d2 authored by Georgios Dagkakis's avatar Georgios Dagkakis

cleanup in the method that calculates what is to be processed

parent dca04b5e
...@@ -189,48 +189,25 @@ class CapacityStationController(EventGenerator): ...@@ -189,48 +189,25 @@ class CapacityStationController(EventGenerator):
if totalAvailableCapacity<=0: if totalAvailableCapacity<=0:
continue continue
# if the buffer is not assembly # if the buffer is not assembly
if not buffer.requireFullProject:
# calculate the total capacity that is requested # calculate the total capacity that is requested
totalRequestedCapacity=0 totalRequestedCapacity=0
for entity in buffer.getActiveObjectQueue(): for entity in buffer.getActiveObjectQueue():
if self.checkIfProjectCanStartInStation(entity.capacityProject, station): if self.checkIfProjectCanStartInStation(entity.capacityProject, station) and\
(not self.checkIfProjectNeedsToBeAssembled(entity.capacityProject, buffer)):
totalRequestedCapacity+=entity.requiredCapacity totalRequestedCapacity+=entity.requiredCapacity
# if there is enough capacity for all the entities set them that they all should move # 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():
if self.checkIfProjectCanStartInStation(entity.capacityProject, station): if self.checkIfProjectCanStartInStation(entity.capacityProject, station) and\
(not self.checkIfProjectNeedsToBeAssembled(entity.capacityProject, buffer)):
entity.shouldMove=True entity.shouldMove=True
# else calculate the capacity for every entity and create the entities # else calculate the capacity for every entity and create the entities
else: else:
entitiesInBuffer=list(buffer.getActiveObjectQueue()) entitiesInBuffer=list(buffer.getActiveObjectQueue())
# loop through the entities # loop through the entities
for entity in entitiesInBuffer: for entity in entitiesInBuffer:
if self.checkIfProjectCanStartInStation(entity.capacityProject, station): if self.checkIfProjectCanStartInStation(entity.capacityProject, station) and\
self.breakEntity(entity, buffer, station, totalAvailableCapacity, totalRequestedCapacity) (not self.checkIfProjectNeedsToBeAssembled(entity.capacityProject, buffer)):
# if the buffer is assembly there are different calculations
else:
# calculate the total capacity that is requested
# note that only the assembled projects do request capacity
totalRequestedCapacity=0
for entity in buffer.getActiveObjectQueue():
if self.checkIfProjectAssembledInBuffer(entity.capacityProject, buffer) and\
self.checkIfProjectCanStartInStation(entity.capacityProject, station):
totalRequestedCapacity+=entity.requiredCapacity
# if there is enough capacity for all the assembled entities set them that they all should move
if totalRequestedCapacity<=totalAvailableCapacity:
for entity in buffer.getActiveObjectQueue():
if self.checkIfProjectAssembledInBuffer(entity.capacityProject, buffer) and\
self.checkIfProjectCanStartInStation(entity.capacityProject, station):
entity.shouldMove=True
# else calculate the capacity for every entity and create the entities
else:
entitiesInBuffer=list(buffer.getActiveObjectQueue())
# loop through the entities
for entity in entitiesInBuffer:
# break only the assembled projects
if self.checkIfProjectAssembledInBuffer(entity.capacityProject, buffer) and\
self.checkIfProjectCanStartInStation(entity.capacityProject, station):
self.breakEntity(entity, buffer, station, totalAvailableCapacity, totalRequestedCapacity) self.breakEntity(entity, buffer, station, totalAvailableCapacity, totalRequestedCapacity)
# 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
...@@ -307,6 +284,17 @@ class CapacityStationController(EventGenerator): ...@@ -307,6 +284,17 @@ class CapacityStationController(EventGenerator):
return False return False
return True return True
# checks if a project cannot move because it needs to be assembled first
def checkIfProjectNeedsToBeAssembled(self, project, buffer):
# if we are not in assembly return false
if not buffer.requireFullProject:
return False
# if project is already assembled return false
if self.checkIfProjectAssembledInBuffer(project, buffer):
return False
# at any other case return true
return True
# checks if the given project is all in the buffer # checks if the given project is all in the buffer
def checkIfProjectAssembledInBuffer(self, project, buffer): def checkIfProjectAssembledInBuffer(self, project, buffer):
# loop through all the stations of the system # loop through all the stations of the system
......
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