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

cleanup in the method that calculates what is to be processed

parent dca04b5e
...@@ -189,49 +189,26 @@ class CapacityStationController(EventGenerator): ...@@ -189,49 +189,26 @@ 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():
if self.checkIfProjectCanStartInStation(entity.capacityProject, station) and\
(not self.checkIfProjectNeedsToBeAssembled(entity.capacityProject, buffer)):
totalRequestedCapacity+=entity.requiredCapacity
# if there is enough capacity for all the entities set them that they all should move
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\
totalRequestedCapacity+=entity.requiredCapacity (not self.checkIfProjectNeedsToBeAssembled(entity.capacityProject, buffer)):
# if there is enough capacity for all the entities set them that they all should move entity.shouldMove=True
if totalRequestedCapacity<=totalAvailableCapacity: # else calculate the capacity for every entity and create the entities
for entity in buffer.getActiveObjectQueue():
if 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:
if self.checkIfProjectCanStartInStation(entity.capacityProject, station):
self.breakEntity(entity, buffer, station, totalAvailableCapacity, totalRequestedCapacity)
# if the buffer is assembly there are different calculations
else: else:
# calculate the total capacity that is requested entitiesInBuffer=list(buffer.getActiveObjectQueue())
# note that only the assembled projects do request capacity # loop through the entities
totalRequestedCapacity=0 for entity in entitiesInBuffer:
for entity in buffer.getActiveObjectQueue(): if self.checkIfProjectCanStartInStation(entity.capacityProject, station) and\
if self.checkIfProjectAssembledInBuffer(entity.capacityProject, buffer) and\ (not self.checkIfProjectNeedsToBeAssembled(entity.capacityProject, buffer)):
self.checkIfProjectCanStartInStation(entity.capacityProject, station): self.breakEntity(entity, buffer, station, totalAvailableCapacity, totalRequestedCapacity)
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)
# 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):
...@@ -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