jsonData=json.loads(ant['resultJSON'])#read the result as JSON
elementList=jsonData['elementList']#find the route of JSON
#loop through the elements
forelementinelementList:
elementClass=element['_class']#get the class
#id the class is Job
ifelementClass=='Dream.Job':
results=element['results']
delay=float(results.get('delay',"0"))
totalDelay+=delay
returntotalDelay
'''
Below are initial lists of scheduling rules to be considered for each of the queues/machine, these could be entered at GUI level
I believe the ability to attribute each of these lists to a queue object is the only requirements at GUI level. Everything henceforth is a ManPy and Optimization business.
'''
#M1Options = ['EDD','WINQ','LPT','SPT','SRR','ERD','PCO','MS'] #initial list of scheduling rules that are to be randomly used for each of the machines
M1Options=['EDD','NextStage','EOD','Priority','RPC','MinSlack','NumStages']#initial list of scheduling rules that are to be randomly used for each of the machines
#Optimization takes over from here and it calls ManPy simulation at intervals using the sim function
defmain():
start=time.time()# start counting execution time
modelJSONFile=open("C:\Users\George\dream\dream\simulation\JSONInputs\Topology20.JSON","r")#the JSON of the model. To be sent from GUI
modelJSONData=modelJSONFile.read()
modelJSON=json.loads(modelJSONData)
modelJSON=json.dumps(modelJSON,indent=True)
collated={'Q1':M2Options,'Q2':M3Options,'Q3':M4Options,'Q4':M4Options,'Q5':M5Options}#the list of options collated into a dictionary for ease of referencing in ManPy
ants=[]#list of ants for keeping track of their performance
foriinrange(6):#Number of times new ants are to be created, i.e. number of generations (a generation can have more than 1 ant)
forjinrange(8):#number of ants created per generation
ant={}#an ant dictionary to contain rule to queue assignment information
forkincollated.keys():#for each of the machines, rules are randomly picked from the options list
ant[str(k)]=random.choice(collated[str(k)])
ants.append(ant)#the current ant to be simulated (evaluated) is added to the ants list
ants=ranking(ants,4)#the ants in this generation are ranked based on their scores and the best 4 are selected
forlinants:#update the options list to ensure that good performing queue-rule combinations have increased representation and good chance of being selected in the next generation
formincollated.keys():#e.g. if using EDD gave good performance for Queue 1, then another 'EDD' is added to M1Options so there is a higher chance that it is selected by the next ants.
collated[m].append(l[m])
#print collated#to verify that the list of options was updated accordingly