Commit b5de2456 authored by Georgios Dagkakis's avatar Georgios Dagkakis

enumeration to stop if total delay gets increased

parent 4d53e46b
......@@ -37,7 +37,7 @@ class CapacityStationsEnumeration(Enumeration):
return totalDelay
# creates the collated scenarios, i.e. the list
# of options collated into a dictionary for ease of referencing in ManPy
# of options collated into a list for ease of referencing in ManPy
def createScenarioList(self,data):
scenarioList=[]
step=data['general'].get('thresholdStep',7)
......@@ -60,7 +60,18 @@ class CapacityStationsEnumeration(Enumeration):
scenarioData['graph']['node']['CSC']['dueDateThreshold']=scenario['threshold']
return scenarioData
# checks if the algorithm should terminate. Default is set to False so that the algorithm
# terminates only when all scenarios are considered
# checks if the algorithm should terminate.
# in this case terminate if the total delat is increased
def checkIfShouldTerminate(self,data,scenarioList):
if len(scenarioList)<2:
return False
index=0
for i in range(len(scenarioList)):
if scenarioList[i].get('score',None)==None:
index=i-1
break
if index:
if scenarioList[index]['score']>scenarioList[index-1]['score']:
scenarioList = scenarioList[:index+1]
return True
return False
......@@ -35,7 +35,6 @@ class Enumeration(plugin.ExecutionPlugin):
def checkIfShouldTerminate(self,data,scenarioList):
return False
def run(self, data):
# distributor_url = data['general'].get('distributorURL',None)
# distributor = None
......@@ -45,18 +44,21 @@ class Enumeration(plugin.ExecutionPlugin):
start = time.time() # start counting execution time
numberOfSolutions = int(data['general'].get('numberOfSolutions',3))
numberOfSolutions = int(data['general'].get('numberOfSolutions',15))
assert numberOfSolutions >= 1
scenarioList=self.createScenarioList(data)
i=0
for scenario in scenarioList:
scenario['input']=self.createScenarioData(data, scenario)
scenario['result'] = self.runOneScenario(scenario['input'])['result']
scenario['score'] = self.calculateScenarioScore(scenario)
if self.checkIfShouldTerminate(data, scenarioList):
scenarioList = scenarioList[:i+1]
break
i+=1
# rand the scenarios based on their score and take only the numberOfSolutions best
# rank the scenarios based on their score and take only the numberOfSolutions best
scenariosToReturn = sorted(scenarioList,key=operator.itemgetter('score'))[:numberOfSolutions]
# return the number of scenarios that need to be returned
......
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