#include #include //running experiments with Dispatcher on the enlarged suite //of problems (originally by Solomon). //We have to feed in distmatrix explicitly. ILOSTLBEGIN IloNum TimeLimit, MoveLimit; IloInt nbOfVisits; IloInt nbOfTrucks; IloInt capacity; IloNum PenaltyFactor; IloInt TabuTenure; IloBool TypeOfMethod;//0-GLS,1-Tabu; /*const IloInt nbOfVisits = 100; const IloInt nbOfTrucks = 25; const IloNum capacity = 200; */ IloNum** DistanceMatrix; IloNum* durations; class MyDistanceI: public IloDistanceI { public: MyDistanceI(IloEnv env); virtual IloNum computeDistance (IloNode node1, IloNode node2, IloVehicle vehicle) const; IloEnv _env; void getDistanceMatrix(IloNum**& DistanceMatrix); }; MyDistanceI::MyDistanceI(IloEnv env) : IloDistanceI(env) { _env = env; } void MyDistanceI::getDistanceMatrix(IloNum**& DistanceMatrix){ } IloNum MyDistanceI::computeDistance(IloNode node1, IloNode node2, IloVehicle vehicle) const { IloInt index1 = 0, index2 = 0; char buffer1[28], buffer2[28], buffer[28]; //cout<.exe \n"; env.out() <<" NbTrucks NbVisits Capacity\n"; env.out() <<" TypeOfMethod <0-GLS,1-TS> SearchParam \n"; env.out() <<" Limit <0-move, 1-time> LimitValue \n"; env.out() <<" DropTime DepotDropTime \n"; return 0; } infile.open(problem, ios::in); outfile.open(output, ios::out); if (StartFlag) { outfile1.open(output1, ios::out); } else { outfile1.open(output1, ios::app); } 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 size = nbOfVisits+1; DistanceMatrix = new (env) IloNum * [size]; for (i=0;i> DistanceMatrix[n.quot][n.rem]; } for (i=0;i> rubbish >> depotX >> depotY >> rubbish >> openTime >> closeTime >> depotDropTime; //distmatrfile >> rubbish >> depotX >> depotY >> rubbish >> openTime >> closeTime >> rubbish; outfile<<"Solutions to "<= openTime); mdl.add(first.getDelayVar(time) == depotDropTime); //may be non-zero (after transformation) SummedDuration +=depotDropTime; IloVisit last(depot, "Depot"); mdl.add(last.getCumulVar(time) <= closeTime); mdl.add(last.getDelayVar(time) == depotDropTime); //may be non-zero (after transformation) SummedDuration +=depotDropTime; char name[16]; sprintf(name, "Vehicle %d", j); IloVehicle vehicle(first, last, name); vehicle.setCost(length, 1.0); vehicle.setCapacity(weight, capacity); mdl.add(vehicle); } for (i = 0; i < nbOfVisits; i++) { IloInt id; // visit identifier IloNum x, y, quantity, minTime, maxTime, dropTime; infile >> id >> x >> y >> quantity >> minTime >> maxTime >> dropTime; char name[16]; sprintf(name, "%d", id); //cout<<"name = "<0) { 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); } } /////////////////////////////////////////// // // outputting the improved solution // /////////////////////////////////////////// Info(dispatcher,outfile); trueCost = dispatcher.getTotalCost(); trueCost += SummedDuration + (dispatcher.getNbOfVehiclesUsed() - 1)*2*depotDropTime - OriginalDropTime*nbOfVisits - (dispatcher.getNbOfVehiclesUsed() - 1)*2*OriginalDepotDropTime; outfile1<