def unitTestRemoveInsert2(info, solutionOld): import testSolutions import time er = testSolutions.testSolution(None, solutionOld, info) er.testReportSolution() RIP = SingleRouteRemoveInsertProcedure(info) solution = deepcopy(solutionOld) while True: routeI = solution[1]['Solution'] t1 = time.clock() removalInsertionNeighbourhood1 = RIP.removeInsertAllArcs(routeI) e1 = time.clock() - t1 t2 = time.clock() removalInsertionNeighbourhood2 = RIP.removeInsertAllDoubleArcs(routeI) e2 = time.clock() - t2 t3 = time.clock() removalInsertionNeighbourhood3 = RIP.exchangeAllArcs(routeI) e3 = time.clock() - t3 t4 = time.clock() removalInsertionNeighbourhood4 = RIP.exchangeAllDoubleArcs(routeI) e4 = time.clock() - t4 break print(len(removalInsertionNeighbourhood1)) print((len(routeI)-2)*(len(routeI)-3)) print(min(removalInsertionNeighbourhood1)[0]) print(e1) print('') print(len(removalInsertionNeighbourhood2)) print((len(routeI)-3)*(len(routeI)-4)) print(min(removalInsertionNeighbourhood2)[0]) print(e2) print('') print(len(removalInsertionNeighbourhood3)) print((len(routeI)-3)*(len(routeI)-4)/2) print(min(removalInsertionNeighbourhood3)[0]) print(e3) print('') print(len(removalInsertionNeighbourhood4)) print((len(routeI)-5)*(len(routeI)-6)/2) print(min(removalInsertionNeighbourhood4)[0]) print(e4) print('') for neighbour in removalInsertionNeighbourhood4[0:5]: solution = deepcopy(solutionOld) bestNeighbour = neighbour solution[1]['Solution'] = bestNeighbour[1][2] solution[1]['Cost'] += bestNeighbour[0] #This is not working!!!!! solution['Total cost'] += bestNeighbour[0] er = testSolutions.testSolution(None, solution, info) er.checkFeasibility() print(er.errorReport['Exceptions']['Total exception'],bestNeighbour[0])
def unitTest3(info, solution): import testSolutions er = testSolutions.testSolution(info, solution) er.checkFeasibility() er.testReportSolution() print('') Reduce = ReduceNumberOfVehicleRoutes(info) (solution, reductionPossible) = Reduce.iterativeReduction(solution) print('') print(reductionPossible) er = testSolutions.testSolution(info, solution) er.checkFeasibility() er.testReportSolution()
def improve_initial_solutions(self, initialSolution): print('') print('Start local search') print('') LS = LocalSearchImprove.LocalSearchIFs(self.info) if self.localSearchHeuristic == 'Multi_move_local_search': LS.neighbourSearchStrategy = 'MultiLocalSearch' (solution, nTrips) = LS.localSearch(initialSolution) print('') print(' Solution cost : %d' % solution['Total cost']) print(' n Trips : %d' % nTrips) if self.testSolutions == True: TestReport = TEST.testSolution(self.info, solution) TestReport.checkFeasibilityIFs() if TestReport.raiseException: TestReport.testReportSolution() print( '**************************************************************' ) print( 'Exceptions were raised while improving the initial solution' ) print( '**************************************************************' ) raw_input('...Press any key to continue...') return (solution, nTrips)
def generate_initial_solutions(self): if self.constructiveHeuristic == 'Efficient_Merge': MERGE = MergeConstruct.MergeHeuristic(self.info) (solution, nTrips) = MERGE.mergeHeuristicIFs() elif self.constructiveHeuristic == 'EPS_balanced': EPS = EPSConstruct.EPSinitialSolution(self.info) (solution, nTrips) = EPS.completeInitialSolution('Real')[0] elif self.constructiveHeuristic == 'ULUSOY': ULUSOY = UlusoyConstruct.UlusoysIFs(self.info) (solution, nTrips) = ULUSOY.genCompleteSolution()[0] if self.testSolutions == True: TestReport = TEST.testSolution(self.info, solution) TestReport.checkFeasibilityIFs() if TestReport.raiseException: TestReport.testReportSolution() print( '**************************************************************' ) print( 'Exceptions were raised while generating the initial solution' ) print( '**************************************************************' ) raw_input('...Press any key to continue...') return (solution, nTrips)
def unitTest(info, solution): import testSolutions FS = LocalSearchIFs(info) # FS.neighbourSearchStrategy = 'MultiLocalSearch' FS.neighbourSearchStrategy = 'MultiLocalSearch' #FS.neighbourSearchStrategy = 'FullLocalSearch' if not solution[1].get('Subtrip cost'): solution = transformSolution.transformSolution(info).newRoute(solution) er = testSolutions.testSolution(info, solution) er.checkFeasibilityIFs() er.testReportSolutionIFs() print('') t1 = time.clock() (solution, nTrips) = FS.localSearch(solution) e1 = time.clock() - t1 print(e1) print('') er = testSolutions.testSolution(info, solution) er.checkFeasibilityIFs() er.testReportSolutionIFs()
def unitTestRemoveInsert(info, solutionOld): import testSolutions er = testSolutions.testSolution(None, solutionOld, info) er.testReportSolution() RIP = SingleRouteRemoveInsertProcedure(info) solution = solutionOld.copy() while True: routeI = solution[1]['Solution'] best = [] removalInsertionNeighbourhood1 = RIP.removeInsertAllDoubleArcs(routeI) best += removalInsertionNeighbourhood1 removalInsertionNeighbourhood2 = RIP.removeInsertAllArcs(routeI) best += removalInsertionNeighbourhood2 removalInsertionNeighbourhood3 = RIP.exchangeAllArcs(routeI) best += removalInsertionNeighbourhood3 removalInsertionNeighbourhood4 = RIP.exchangeAllDoubleArcs(routeI) best += removalInsertionNeighbourhood4 bestNeighbour = min(best) print(bestNeighbour[0],bestNeighbour[-1]) if bestNeighbour[0] >= 0: break solution[1]['Solution'] = bestNeighbour[1][2] solution[1]['Cost'] = solution[1]['Cost'] + bestNeighbour[0] solution['Total cost'] = solution['Total cost'] + bestNeighbour[0]
def unitTestRemoveInsertAllRoutes(info, solutionOld): print('unitTestRemoveInsertAllRoutes') print('') import testSolutions import time er = testSolutions.testSolution(None, solutionOld, info) er.testReportSolution() RIPij = MultipleRouteRemoveInsertProcedure(info) solution = deepcopy(solutionOld) while True: routeI = solution[1]['Solution'] routeJ = solution[2]['Solution'] routes = [routeI,routeJ] t1 = time.clock() removalInsertionNeighbourhood1 = RIPij.removeInsertAllArcsRouteAllRoutes(routes) e1 = time.clock() - t1 t2 = time.clock() removalInsertionNeighbourhood2 = RIPij.removeInsertAllDoubleArcsAllRoutes(routes) e2 = time.clock() - t2 t3 = time.clock() removalInsertionNeighbourhood3 = RIPij.exchangeAllArcsAllRoutes(routes) e3 = time.clock() - t3 t4 = time.clock() removalInsertionNeighbourhood4 = RIPij.exchangeAllDoubleArcsAllRoutes(routes) e4 = time.clock() - t4 break print(len(removalInsertionNeighbourhood1)) print(2*(len(routeI)-2)*(len(routeJ)-2)) print(min(removalInsertionNeighbourhood1)[0]) print(e1) print('') print(len(removalInsertionNeighbourhood2)) print((len(routeI)-3)*(len(routeJ)-2)) print(min(removalInsertionNeighbourhood2)[0]) print(e2) print('') print(len(removalInsertionNeighbourhood3)) print((len(routeI)-2)*(len(routeJ)-2)) print(min(removalInsertionNeighbourhood3)[0]) print(e3) print('') print(len(removalInsertionNeighbourhood4)) print((len(routeI)-3)*(len(routeJ)-4)) print(min(removalInsertionNeighbourhood4)[0]) print(e4) print('') #print(solutionOld) for neighbour in removalInsertionNeighbourhood4: solution = deepcopy(solutionOld) bestNeighbour = neighbour modifications = bestNeighbour[1] (routeI,routeJ) = modifications['routes'] routeI += 1 routeJ += 1 (solution[routeI]['Solution'],solution[routeJ]['Solution']) = modifications['modifiedRoutes'] (costIdelta, costJdelta) = modifications['costDelta'] (serviceIdelta, serviceJdelta) = modifications['serviceDelta'] solution[routeI]['Cost'] += costIdelta + serviceIdelta solution[routeJ]['Cost'] += costJdelta + serviceJdelta (loadIdelta, loadJdelta) = modifications['loadDelta'] solution[routeI]['Load'] += loadIdelta solution[routeJ]['Load'] += loadJdelta solution['Total cost'] += bestNeighbour[0] er = testSolutions.testSolution(None, solution, info) er.checkFeasibility() print(er.errorReport['Exceptions']['Total exception'],costIdelta,costJdelta,solution[routeI]['Cost']+solution[routeJ]['Cost'],solution['Total cost']) if er.errorReport['Exceptions']['Total exception']: er.testReportSolution() print(solution)
self.outputLines.append(line) line = ' # Trips : %d' % bestSolutionNvehicles print(line) self.outputLines.append(line) line = ' ' print(line) self.outputLines.append(line) line = ' Min trips solution : %d' % minVehiclesBestSolutionCost print(line) self.outputLines.append(line) line = ' # Trips : %d' % bestSolutionNvehicles print(line) self.outputLines.append(line) return ((bestSolution, bestSolutionNvehicles), (minVehiclesBestSolution, bestSolutionNvehicles)) if __name__ == "__main__": # import psyco # psyco.full() print('start load') info = LARP.ReadProblemDataIFs( 'cen_IF_ProblemInfo/Centurion_a_pickled.dat') # info.maxTrip = 43200 print('loaded') y = EPSinitialSolution(info) y.completeInitialSolution('Real') solutionDict = y.EPSsolution e = testSolutions.testSolution(info, solutionDict) e.testReportSolutionIFs()