Commit bbe55023 authored by Georgios Dagkakis's avatar Georgios Dagkakis

cleanup and comments

parent ce655c47
...@@ -54,24 +54,26 @@ class CapacityStationsEnumeration(Enumeration): ...@@ -54,24 +54,26 @@ class CapacityStationsEnumeration(Enumeration):
scenarioList.append({'key':str(threshold),'threshold':threshold}) scenarioList.append({'key':str(threshold),'threshold':threshold})
return scenarioList return scenarioList
# creates the ant scenario based on what ACO randomly selected # creates the scenario. Here just set the dueDateThreshold
def createScenarioData(self,data,scenario): def createScenarioData(self,data,scenario):
scenarioData=deepcopy(data) scenarioData=deepcopy(data)
scenarioData['graph']['node']['CSC']['dueDateThreshold']=scenario['threshold'] scenarioData['graph']['node']['CSC']['dueDateThreshold']=scenario['threshold']
return scenarioData return scenarioData
# checks if the algorithm should terminate. # checks if the algorithm should terminate.
# in this case terminate if the total delat is increased # in this case terminate if the total delay is increased
def checkIfShouldTerminate(self,data,scenarioList): def checkIfShouldTerminate(self,data,scenarioList):
# in the first scenario no need to terminate
if len(scenarioList)<2: if len(scenarioList)<2:
return False return False
# find the last scenario that is scored
index=0 index=0
for i in range(len(scenarioList)): for i in range(len(scenarioList)):
if scenarioList[i].get('score',None)==None: if scenarioList[i].get('score',None)==None:
index=i-1 index=i-1
break break
# if the delay of the last scenario is bigger than the previous return true
if index: if index:
if scenarioList[index]['score']>scenarioList[index-1]['score']: if scenarioList[index]['score']>scenarioList[index-1]['score']:
scenarioList = scenarioList[:index+1]
return True return True
return False return False
...@@ -26,7 +26,7 @@ class Enumeration(plugin.ExecutionPlugin): ...@@ -26,7 +26,7 @@ class Enumeration(plugin.ExecutionPlugin):
def createScenarioList(self,data): def createScenarioList(self,data):
raise NotImplementedError("Subclass must define 'createScenarioList' method") raise NotImplementedError("Subclass must define 'createScenarioList' method")
# creates the ant scenario based on what ACO randomly selected # create the scenario
def createScenarioData(self,data,scenario): def createScenarioData(self,data,scenario):
raise NotImplementedError("Subclass must define 'createScenarioData' method") raise NotImplementedError("Subclass must define 'createScenarioData' method")
...@@ -48,11 +48,13 @@ class Enumeration(plugin.ExecutionPlugin): ...@@ -48,11 +48,13 @@ class Enumeration(plugin.ExecutionPlugin):
assert numberOfSolutions >= 1 assert numberOfSolutions >= 1
scenarioList=self.createScenarioList(data) scenarioList=self.createScenarioList(data)
# run the scenario. Only synchronous for now
i=0 i=0
for scenario in scenarioList: for scenario in scenarioList:
scenario['input']=self.createScenarioData(data, scenario) scenario['input']=self.createScenarioData(data, scenario)
scenario['result'] = self.runOneScenario(scenario['input'])['result'] scenario['result'] = self.runOneScenario(scenario['input'])['result']
scenario['score'] = self.calculateScenarioScore(scenario) scenario['score'] = self.calculateScenarioScore(scenario)
# it we should terminate remove the scenarios that are not scored yet
if self.checkIfShouldTerminate(data, scenarioList): if self.checkIfShouldTerminate(data, scenarioList):
scenarioList = scenarioList[:i+1] scenarioList = scenarioList[:i+1]
break break
......
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