/* 09/10/01 This is an encoding of the job shop problem reformulated as an instance of the vehicle routing problem. A machine is a vehicle, an operation is a visit. Here we have known vehicle-visit assignments, visits sequences for different vehicles (these correspond to jobs), no distances between customers. The only dimension we use here is time. We construct a first solution with the savings heuristic. Then the maximal time of return to base among all the vehicles should be minimised because this corresponds to makespan. To do so we set a deadline equal to the maximal return to base time in the first solution and locally improve it. PRECONDITIONS: 1. ILOG Dispatcher 3.0; 2. Data file in the following format. The first line contains two numbers: number of jobs and number of machines. The subsequent lines (one for each job) contain m pairs of numbers, where m is the number of operations in a job. Each pair consists of the number of machine required by an operation and the duration of this operation. 3. Output file; 4. Method index (enter 0 for guided local search, 1 for tabu search); 5. Method parameter (penalty factor for guided local search, tabu tenure for tabu search); 6. Type of limit on search (0 - limit on the number of moves, 1 - on execution time); 7. Limit value depending on 6. POSTCONDITIONS: 1. The first solution and an improved solution obtained by local search stored in the specified output file in the default Dispatcher 3.0 format. */ #include #include ILOSTLBEGIN IloNum TimeLimit; IloNum MoveLimit; const IloInt MaxSize = 400; IloNum PenaltyFactor; IloInt TabuTenure; IloBool TypeOfMethod;//0-GLS,1-Tabu; void Info(IloDispatcher dispatcher, ofstream& outfile) { IloSolver solver = dispatcher.getSolver(); outfile<< "===============" << endl << "Cost : " << dispatcher.getTotalCost() << endl << "Number of vehicles used : " << dispatcher.getNbOfVehiclesUsed() << endl << "Solution : " << endl << dispatcher << endl; } void improveWithGLS_TimeLimitVersion(IloDispatcher dispatcher, IloRoutingSolution solution, IloNHood nhood, ofstream& fout) { IloNumVar cost = dispatcher.getCostVar(); IloEnv env = dispatcher.getEnv(); IloGoal instantiateCost = IloDichotomize(env, cost, IloFalse); IloRoutingSolution rsol = solution.makeClone(env); IloRoutingSolution best = solution.makeClone(env); IloDispatcherGLS dgls(env, PenaltyFactor); IloSearchSelector sel = IloMinimizeVar(env,dgls.getPenalizedCostVar()); IloGoal move = IloSingleMove(env, rsol, nhood, dgls, sel, instantiateCost); move = move && IloStoreBestSolution(env, best); IloSolver solver = dispatcher.getSolver(); IloCouple(nhood, dgls); clock_t tStart = clock()/CLK_TCK, time = tStart; while (time <= tStart + TimeLimit) { if (solver.solve(move)) { fout << "Cost = "< 165; Apes7x6 -> 183; Lawrence 10x5 -> 2306; Adams 10x10 -> 6363; Lawrence 15x10 -> 6067; Lawrence 15x15 -> 9084; */ IloInt UpperBound = 183; ////////////////////////////////////////////////////// // // Reading in data // ////////////////////////////////////////////////////// if (argc ==7) { problem = argv[1]; output = argv[2]; TypeOfMethod = atoi(argv[3]); if (TypeOfMethod==0) PenaltyFactor = atof(argv[4]); else TabuTenure = atoi(argv[4]); if (atoi(argv[5])==1) { TimeLimit=atoi(argv[6]); } else { MoveLimit=atoi(argv[6]); } } else { env.out() << endl; env.out() <<"Usage: .exe \n"; env.out() <<" TypeOfMethod <0-GLS,1-TS> SearchParam \n"; env.out() <<" Limit <0-move, 1-time> LimitValue \n"; exit(1); } infile.open(problem); outfile.open(output, ios::out); if (!infile) { env.out() << "File not found or not specified: " << problem << endl; env.end(); return 0; } if (!outfile) { env.out() << "Cannot open file for output: " << output << endl; env.end(); return 0; } IloInt nbOfVisits, nbOfTrucks, nbOfJobs; infile>>nbOfJobs; infile>>nbOfTrucks; nbOfVisits = nbOfJobs*nbOfTrucks; IloInt* resourceNumbers; resourceNumbers = new IloInt[MaxSize]; IloInt* durations; durations = new IloInt[MaxSize]; for (int i=0;i>resourceNumbers[index]; infile>>durations[index]; index++; } } /////////////////////////////////////////////////////// // // Specifying parameters and constraints of the model // /////////////////////////////////////////////////////// IloNum capacity = 200; IloNum dropTime = 1; IloNum depotX=0, depotY=0, openTime=0, closeTime=IloInfinity; outfile<<"Solutions to "<= openTime); IloVisit last(depot, "Depot"); mdl.add(last.getCumulVar(time) <= closeTime); char name[16]; sprintf(name, "Vehicle %d", j); IloVehicle vehicle(first, last, name); vehicle.setCost(time, 1.0); vehicles[j]=vehicle; mdl.add(vehicle); } for (i = 0; i < nbOfTrucks*nbOfJobs; i++) { IloInt id=i; IloNum x=0, y=0; IloNode customer(env, x, y); char name[16]; sprintf(name, "%d", id); IloVisit visit(customer, name); mdl.add(visit.getDelayVar(time) == durations[i]); visits[i] = visit; mdl.add(visit); } //Imposing vehicle-visit constraints for (i=0;i0) { improveWithGLS_TimeLimitVersion(dispatcher,solution,nhood,outfile); } else { improveWithGLS_MoveLimitVersion(dispatcher,solution,nhood,outfile); } } else { if (TimeLimit>0) { improveWithTabu_TimeLimitVersion(dispatcher,solution,nhood,outfile); } else { improveWithTabu_MoveLimitVersion(dispatcher,solution,nhood,outfile); } } Info(dispatcher,outfile); } catch(IloException& ex) { cerr << "Error: " << ex << endl; } env.end(); return 0; }