/* 09/10/01 This is an encoding of the delivery variant of the vehicle routing problem with one base and a homogeneous fleet reformulated as an instance of the open shop scheduling problem. In this representation we have nonzero transition times, alternative resources and no precedence constraints on activities. Each vehicle is considered a machine on th4e factory floor and is represented as a pair: . Each visit is an activity. PRECONDITIONS: 1. ILOG Scheduler 5.0; 2. Data file in the following format: ************************************* 0 x_base y_base 0 earliest_start latest_end 0 1 x_1 y_1 demand_1 earliest_start_1 lateststart_1 service_time_1 ... i x_i y_i demand_i earliest_start_i lateststart_i service_time_i ... ************************************* The base and customers each are described by seven numbers in a separate line, in this order: (i) index (0 - for the base), (ii and iii) x and y coordinates of the base in the 2D right Cartesian reference frame; (iv) demand>=0 (0 for the base); (v) earliest start; (vi) latest end (for the base) and latest start (for customers); and (vii) service time. 3. Output file 1 (here we store all the information about the obtained solutions); 4. Output file 2 (here we store in a concise form the indexes of solutions, cost values and comutational expenses); 5. Turn on/off the edge finder algorithm. 6. Resource selector <1..4> for forward ranking resource constraints; 7. Resource constraint selector <1..4> for forward ranking resource constraints; 8. Alternative resource selector <1..4>; 9. Activity selector for assigning start times <1..4>; 10. Discrepancy count <1,2,..> for limited discrepancy search; 11. Time limit in seconds. POSTCONDITIONS: 1. Output file 1. Solutions in the format: **************************** No. of solution Cost vehicle_1: tour .. vehicle_i: tour .. sum of transition costs on vehicle_1 .. sum of transition costs on vehicle_i .. **************************** 2. Output file 2. Solutions in the format: ************************************************************************* Solution# Cost Veh Fails ChoicePts FailsSummed ChoicePtsSummed ************************************************************************* Here Veh is the number of used vehicles, Fails is the number of fails for this solution, ChoicePts is the number of choice points for this solution, FailsSummed is the overall number of fails, ChoicePtsSummed is the overall number of choice points. */ #include #include #include #include #include ILOSTLBEGIN const IloInt Capacity = 200; const IloInt SetupActivityDuration = 1; const IloInt TeardownActivityDuration = 1; const IloInt NbMachines = 25; const IloInt NbCustomers = 100; IloInt BasicTimeLimit; //in seconds, overall amount of time spent on search IloInt NbFailsSummed; IloInt NbChoicePointsSummed; IloInt DiscrepancyCount; IloBool isEdgeFinderOn; IloInt ResourceSelector, ResourceConstraintSelector, PossibleResourceSelector, ActivitySelector; IloInt NbActPerTour; //the maximum number of activities per tour (setup + all the customers + teardown) IloInt NbAct; //the overall number of activities (group 1 and group 2 ones) IloNum VrpData [150*7]; inline IloInt computeDistance(IloInt i, IloInt j) { return (IloInt) IloPower((VrpData[i*7+1]-VrpData[j*7+1])* (VrpData[i*7+1]-VrpData[j*7+1])+ (VrpData[i*7+2]-VrpData[j*7+2])* (VrpData[i*7+2]-VrpData[j*7+2]), 0.5); } inline IloNum getDemand (IloInt i) { return VrpData[i*7+3]; } inline IloNum getEarliestStartTime (IloInt i) { return VrpData[i*7+4]; } inline IloNum getLatestCompletionTime (IloInt i) { return VrpData[i*7+5]; } inline IloNum getActivityDuration (IloInt i) { return VrpData[i*7+6]; } IloModel DefineModel(const IloEnv env, IloNumVar& transCostSum, IloNumVarArray& transCostArr, IloTransitionParam& ttParam, ofstream& fout) { IloModel model(env); IloInt i,j; char buffer[128]; IloNum origin = VrpData[4]; IloNum horizon = VrpData[5]; IloSchedulerEnv schedEnv(env); schedEnv.getResourceParam().setCapacityEnforcement(IloHigh); schedEnv.setHorizon(horizon); //Initializing two pairs of resources representing two machines IloDiscreteResourceArray capResources(env,NbMachines); IloUnaryResourceArray unarResources(env,NbMachines); for (i = 0;i.exe \n"; cout<<" isEdgeFindingOn <0/1>\n"; cout<<" ResourceSelector <1..4> ResConstrSelector <1..4>\n"; cout<<" AltResSelector <1..4> SetStartTimesActivitySelector <1..4>\n"; cout<<" DiscrepancyCount <1,2,..> TimeLimit \n"; return 0; } ofstream fout,fout1; ifstream fin; fin.open(argv[1], ios::in); fout.open(argv[2], ios::out); fout1.open(argv[3], ios::out); fout1 << "Solution\tCost\tNbMachines\tFails\tChoicePoints\tFailsSummed\tChoicePointsSummed"<>VrpData[i]; else VrpData[i] = VrpData[i-7*NbActPerTour+7]; //additional line corresponding to teardown activity, repeats the first one } //transCostSum variable is to store the sum of transition //costs on all machines (more precisely, on all unary //resources associated with machines); //An element of the transCostArr array stores the sum of transition //costs on a particular machine (more precisely, on the //respective unary resource IloNumVar transCostSum(env,0,IloInfinity,ILOINT); IloNumVarArray transCostArr(env,NbMachines,0,IloInfinity,ILOINT); IloSchedulerSolution solution(env); IloTransitionParam ttParam; IloModel model = DefineModel(env, transCostSum, transCostArr, ttParam, fout); // Algorithm IloSolver solver(model); IlcScheduler scheduler(solver); //The Search Goal IloGoal goal = IloRankForward(env,rSel,rcSel) //ranking resource constraints on resources is critical for future //assignments of resource constraints to resources &&IloAssignAlternative(env,prSel) //picking out an alternative resource and assigning it to //a resource constraint && IloSetTimesForward(env,aSel); //assigning a start time to all activities in the schedule //Applying LDS goal = IloApply (env, goal, IloLDSEvaluator(env, DiscrepancyCount)); if (isEdgeFinderOn) goal = MakePrecedenceGraphConstraints(env,fout) && goal; //Getting the First Solution //(getting it separately is necessary //to obtain the first value of the objective function) NbFailsSummed = 0; NbChoicePointsSummed = 0; struct tm *ptr; time_t lt; clock_t start,finish; start = clock(); lt = time(NULL); ptr = localtime(<); fout<0 && solver.solve(IloAddConstraint(transCostSum <= solver.getIntVar(transCostSum).getMin()-1) && IloLimitSearch(env, goal, IloTimeLimit(env,TimeLimit)))) { env.out()<