Commit 119b3595 authored by Georgios Dagkakis's avatar Georgios Dagkakis

CapacityStationController to be able to prioritize projects that can...

CapacityStationController to be able to prioritize projects that can befinished in a station (if it is given as input)
parent 5a83d2b1
......@@ -33,13 +33,15 @@ from Globals import G
class CapacityStationController(EventGenerator):
def __init__(self, id=id, name=None, start=None, stop=None, interval=None,
duration=None, method=None, argumentDict=None, dueDateThreshold=float('inf')):
duration=None, method=None, argumentDict=None, dueDateThreshold=float('inf'), prioritizeIfCanFinish=False):
EventGenerator.__init__(self, id, name, start, stop, interval,
duration, method, argumentDict)
# attribute used by optimization in calculateWhatIsToBeProcessed
# only the projects that are within this threshold from the one with EDD in the same bufffer
# will be considered to move at first
self.dueDateThreshold=dueDateThreshold
# attribute that shows if we prioritize entities that can finish work in this station in the next interval
self.prioritizeIfCanFinish=prioritizeIfCanFinish
def initialize(self):
EventGenerator.initialize(self)
......@@ -187,6 +189,7 @@ class CapacityStationController(EventGenerator):
# loop through the capacity station buffers
for buffer in G.CapacityStationBufferList:
activeObjectQueue=buffer.getActiveObjectQueue()
# sort entities according to due date
activeObjectQueue.sort(key=lambda x: x.capacityProject.dueDate)
station=buffer.next[0] # get the station
......@@ -255,8 +258,19 @@ class CapacityStationController(EventGenerator):
entitiesToBeBroken=list(entitiesWithinThreshold)
# loop through the entities
for entity in entitiesToBeBroken:
# consider only entities that can move - not tose waiting for assembly or earliest start
if self.checkIfProjectCanStartInStation(entity.capacityProject, station) and\
(not self.checkIfProjectNeedsToBeAssembled(entity.capacityProject, buffer)):
# if we prioritize an entity that can completely finish then check for this
if self.checkIfAProjectCanBeFinishedInStation(entity, station, totalAvailableCapacity)\
and self.prioritizeIfCanFinish:
# set that the entity can move
entity.shouldMove=True
# update the values
totalAvailableCapacity-=entity.requiredCapacity
totalRequestedCapacity-=entity.requiredCapacity
# else break the entity according to rule
else:
self.breakEntity(entity, buffer, station, totalAvailableCapacity, totalRequestedCapacity)
# breaks an entity in the part that should move and the one that should stay
......@@ -366,11 +380,12 @@ class CapacityStationController(EventGenerator):
return True
# checks if the whole project can be finished in one station in the next time period
def checkIfAProjectCanBeFinishedInStation(self, entity, station):
def checkIfAProjectCanBeFinishedInStation(self, entity, station, availableCapacity):
required=entity.requiredCapacity
alreadyWorked=entity.capacityProject.alreadyWorkedDict[station.id]
total=entity.capacityProject.capacityRequirementDict[station.id]
if total-(alreadyWorked+required)<0.001: # a small value to avoid mistakes due to rounding
# return true if all the work can be finished and if there is available capacity
if total-(alreadyWorked+required)<0.001 and availableCapacity>=required: # a small value to avoid mistakes due to rounding
return True
return False
......@@ -870,11 +870,13 @@ def createObjects():
interval = float(element.get('interval') or 1)
duration = float(element.get('duration') or 0)
dueDateThreshold = float(element.get('dueDateThreshold') or float('inf'))
prioritizeIfCanFinish = bool(element.get('prioritizeIfCanFinish', 0))
argumentDict=(element.get('argumentDict', {})) # get the arguments of the method as a dict / default {}
# create the CapacityStationController object
CSC = CapacityStationController(id, name, start=start, stop=stop, interval=interval,
duration=duration, argumentDict=argumentDict, dueDateThreshold=dueDateThreshold)
duration=duration, argumentDict=argumentDict, dueDateThreshold=dueDateThreshold,
prioritizeIfCanFinish=prioritizeIfCanFinish)
# calling the getSuccessorList() method on the repairman
G.EventGeneratorList.append(CSC) # add the Event Generator to the RepairmanList
G.CapacityStationControllerList.append(CSC)
......
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