def run(args): #single GA job logging.basicConfig(level=logging.DEBUG) template = job.JobTemplate(runGASimple) #All these values are required defaults = {} #Cast params to proper datatype for e in args: split = e.split('=') if split[0] == "number_of_runs" or split[0]=="tournsize" or split[0]=="popSize" or split[0]=="ngen": defaults[str(split[0])] = int(split[1]) elif split[0] == "paramName": defaults[str(split[0])] = split[1] else: defaults[str(split[0])] = float(split[1]) print(defaults) template.setDefaults(indpb=defaults.get('indpb'), tournsize=defaults.get('tournsize'), popSize=defaults.get('popSize'), cxpb=defaults.get('cxpb'), mutpb=defaults.get('mutpb'), ngen=defaults.get('ngen'), number_of_runs=defaults.get('number_of_runs'), verbose=False) if(arguments["--addRange"]): jobCreator = job.JobCreator() jobCreator.addRange(defaults.get('paramName'), start=defaults.get("start"), end=defaults.get("end"), stepSize=defaults.get("stepSize")) elif(arguments["--addSpecific"]): defaults.__delitem__('indpb') defaults.__delitem__('tournsize') defaults.__delitem__('popSize') defaults.__delitem__('cxpb') defaults.__delitem__('mutpb') defaults.__delitem__('ngen') defaults.__delitem__('number_of_runs') jobCreator = job.JobCreator() jobCreator.addSpecific(defaults.get('paramName'),defaults) ajob = job.Job(template) #TODO: batchJob = job.BatchJob(jobs, 5) jobResult = ajob.run() if(arguments["--saveLogbook"]): print("Saving to logbook") util.saveLogbook(arguments.get("--logbookFilename"), results.LogBookTools.createLogbookFrom(jobResult)) if(arguments["--saveCSV"]): print("Saving to CSV") util.saveCSV(arguments.get("--csvFilename"), jobResult.logbook) if(arguments["--saveToDB"]): print("Saving to DB") def update(jr): print 'Writing to database...' dbh = jobResult.DatabaseResults(arguments.get("--dbUser"), arguments.get("--dbPass"), arguments.get("--dbHost"),arguments.get("--dbName"),arguments.get("--dbTable")) dbh.persistRun(jobResult, callback=update) pass
def demo3( indpb, tournsize, popsize, cxpb, mutpb, ngen, number_of_runs, verbose, logbook_lgb_filename, logbook_csv_filename ): # SAVE RESULT TO PICKLE logging.basicConfig(level=logging.DEBUG) template = job.JobTemplate(runGASimple) # template.setDefaults(indpb=0.8, tournsize=20, popSize=20, cxpb=0.5, mutpb=0.5, ngen=20, number_of_runs=2, verbose=False) template.setDefaults( indpb=indpb, tournsize=tournsize, popSize=popsize, cxpb=cxpb, mutpb=mutpb, ngen=ngen, number_of_runs=number_of_runs, verbose=verbose, ) ajob = job.Job(template) jobResult = ajob.run() print jobResult.logbook util.saveLogbook(logbook_lgb_filename, results.LogBookTools.createLogbookFrom(jobResult)) util.saveCSV(logbook_csv_filename, jobResult.logbook) pass
def demo3(): # SAVE RESULT TO PICKLE logging.basicConfig(level=logging.DEBUG) template = job.JobTemplate(runGASimple) template.setDefaults( indpb=0.8, tournsize=20, popSize=20, cxpb=0.5, mutpb=0.5, ngen=20, number_of_runs=2, verbose=False ) ajob = job.Job(template) jobResult = ajob.run() print jobResult.logbook util.saveLogbook("demoLogbook.lgb", results.LogBookTools.createLogbookFrom(jobResult)) util.saveCSV("demoLogbook.csv", jobResult.logbook) pass