def initClasses(param): # The Network class net = network.Network(param) # The Genetic Algorithm class ga = genetic.geneticAlgorithm(param) # The class with comparison functions com = network.compare() return net, ga, com
def initClasses(param, MPI, groupSize, networkFitness): # The Network class net = network.Network(param) # The Genetic Algorithm class ga = genetic.geneticAlgorithm(param) # The class with comparison functions com = network.compare(networkFitness) # The MPI class pd = parallel.parallelDistributed(MPI, groupSize, param) return net, ga, com, pd
def find_tour(): global last_update_ts global traffic_analyzer curr_ts = time() if curr_ts - last_update_ts > 1000: # update traffic data traffic_analyzer = TrafficAnalyzer() last_update_ts = curr_ts print('Traffic data updated at', str(datetime.now())) try: data = request.get_json() W = data['W'] R = data['R'] if 'custom_hour' not in data: traffic_analyzer.scale_weights(W, R) else: get_analyzer(int(data['custom_hour'])).scale_weights(W, R) tour = geneticAlgorithm(W, int(len(W)**2)) res = {'tour': tour} return make_response(jsonify(res), 200) except: return make_response('{"code": 1, "message": "fail"}', 400)
# visualization print("Best Found [(score, genrow)]:", best, ", Mutation number:", count+1) time.sleep(0.5) # continue with new gene row to mutate bestMel = orderedTuple[-1][1] lastGen = generation[-1][1] count += 1 return ("Winning Generation[(score, genrow), (nextBestScore, nextBestGenRow), ...]:"), generation, ("Amount of mutations needed:"), count # print(mutateGood(data.mel, 2, [])) print(geneticAlgorithm(1000, data.mel, data.mir)) # testArray1 = [2,3,1,4,5] # testArray2 = [3,2,1,5,4] # testArray3 = [1,2,3,4,5] # print(scoreTest2(testArray1)) # print(scoreTest2(testArray2)) # print(scoreTest2(testArray3)) def experimentGraph(length): # while length > 3: for j in range(10): title = "steepestAscend; N = " + str(length) gen1 = [*range(1,length + 1)] gen2 = [*range(1,length + 1)]