#include #include #include #define IlcTraceConstraint ((IlcUInt) 2) #define IlcTraceProcess ((IlcUInt) 4) #define IlcTraceVars ((IlcUInt) 8) #define IlcTraceFail ((IlcUInt) 16) #define IlcTraceNoEvent ((IlcUInt) 32) #define IlcTraceAllEvents ((IlcUInt) 31) /* an example of how to organise customised search: see lines 84 - 455, where I am defining various functions, as well as lines 1486 - 1502, where I am using them. To use the code, compile it and type VrpSched52.exe, then supply all the necessary input, including the example data file test.dat, which is a 5x5 job shop instance. */ ILOSTLBEGIN IloUnaryResourceArray unarResources; IloActivityArray activities; IloNumVarArray selected; IloNumVarArray costOnResource, selectedMachinesVarArr; IloNumVarArray minStart, maxEnd; IloArray< IloAltResConstraint > alternativeArr; IloArray AddedConstraintsArr; int GlobalNumberOfAddedConstraints; int ReadFirstSolutionFromFile; unsigned int GlobSeed; bool activateAltVRPCriterion = false; IloInt SetupActivityDuration; IloInt TeardownActivityDuration; IloInt NbMachines; IloInt MinTransition; IloInt SummedDurationSaved = 0; IloInt SummedDuration = 0; IloInt NbCustomers; IloInt BasicTimeLimit; unsigned int BasicFailLimit;// = 100000; IloInt TrueCost; //IloInt Criterion,CriterionOld; IloInt HorizonGlob, OriginGlob; //IloInt DesiredNbMachinesUsed; IloInt DiffNb,SameNb, PrecedenceNb; IloBool VRPFlag = IloTrue; IloNum SpeedParameter; IloNumVar CriterionVar; char * Problem; char * StandFormatFile; char SolFile[128]; char ProblemTransformed[128]; IloInt NbFailsSummed; IloInt GlobalVarTimeLimit; IloInt NbChoicePointsSummed; IloInt LastNbOfMachinesUsed = 0; IloInt DiscrepancyCount; 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 (both setup/teardown and the actual customer visits) IloNum** VrpData; IloInt** TransMatrRead; IloInt* Capacities; IloInt* DiffArr; IloInt* SameArr; IloInt* PrecedenceArr; // for the different search goals below (see lines IlcBool maxCapacitySelector(IlcResource& resource, const IlcAltResConstraint alternative) { if (!alternative.isResourceSelected()) { IlcInt max = 0; for (IlcPossibleAltResIterator ite(alternative); ite.ok(); ++ite) { IlcInt cap = ite.getCapacity(); if (cap > max) { max = cap; resource = *ite; } } return IlcTrue; } return IlcFalse; } IlcBool randResourceSelector(IlcResource& resource, const IlcAltResConstraint alternative) { if (!alternative.isResourceSelected()) { IlcInt max = 0; IlcInt ctr = 0; for (IlcPossibleAltResIterator ite(alternative); ite.ok(); ++ite) { ctr++; } IlcInt index = rand()*ctr/(1+RAND_MAX); ctr = 0; for (IlcPossibleAltResIterator ite_(alternative); ite_.ok(); ++ite_) { if (ctr==index) { resource = *ite_; return IlcTrue; } ctr++; } } return IlcFalse; } IlcBool minPossibleSelector(IlcAltResConstraint& alternative, const IlcAltResSet resources) { IlcInt min = IlcIntMax; IlcBool ok = IlcFalse; for (IlcAltResConstraintIterator ite(resources); ite.ok(); ++ite) { IlcInt nb = (*ite).getNumberOfPossible(); if (nb > 1 && nb < min) { ok = IlcTrue; min = nb; alternative = *ite; } } return ok; } IlcBool randPossibleSelector(IlcAltResConstraint& alternative, const IlcAltResSet resources) { IlcBool ok = IlcFalse; IlcInt ctr = 0; for (IlcAltResConstraintIterator ite(resources); ite.ok(); ++ite) { if ((*ite).getNumberOfPossible() > 1) ctr++; } IlcInt index = rand()*ctr/(1+RAND_MAX); ctr = 0; for (IlcAltResConstraintIterator ite_(resources); ite_.ok(); ++ite_) { if (index == ctr) { ok = IlcTrue; alternative = *ite_; } ctr++; } return ok; } ILOCPGOALWRAPPER1(MyAssignAlternative, solver, IlcSchedule, sched) { // return IlcAssignAlternative(sched, maxCapacitySelector, minPossibleSelector); return IlcAssignAlternative(sched, randResourceSelector, minPossibleSelector); } /////////////////////////////////////////////////////////////////// // // TEXTURE CHOICE POINT FOR SCHEDULING WITH ALTERNATIVES // /////////////////////////////////////////////////////////////////// //see Solver 5.1 User Manual for a detailed description class AltTextureGoalI : public IlcGoalI { private: IlcSchedule _schedule; protected: IlcResourceTexture chooseResource(); IlcBool choosePair(IlcResourceTexture, IlcResourceConstraint&, IlcResourceConstraint&, IlcFloat&); IlcBool chooseSequence(IlcResourceConstraint&, IlcResourceConstraint&, IlcResourceConstraint, IlcResourceConstraint); IlcBool calcBiasedSlack(IlcResourceConstraint, IlcResourceConstraint, IlcFloat&, IlcFloat&); IlcBool chooseAlternative(IlcResourceTexture, IlcResourceConstraint&, IlcFloat&); public: AltTextureGoalI(IlcSchedule s) : IlcGoalI(s.getSolver()), _schedule(s) {} ~AltTextureGoalI() {} virtual IlcGoal execute(); }; IlcGoal AltTextureGoalI::execute() { // cout<<"execute"< criticality) { // cout<<"point3"< 0); ++j) { if (!rcTextures[j].hasAlternatives()) { rctB = rcTextures[j].getResourceConstraint(); if (!rctA.isSucceededBy(rctB) && !rctB.isSucceededBy(rctA)) { // found the pair to sequence return IlcTrue; } } } } } // cout<<"end choose Pair"< (env,NbCustomers); //here we scan the input file where for a particular activity //there is a list of indexes of those resources that can perform //the activity IloAltResSet ResourcesAltSet(env); for (j=0;j>vehID>>visID1>>x>>y; if (visID1!=0) { // cout<15 || argc<14) { cout<.exe \n"; cout<<" \n"; cout<<" ResourceSelector <1..4> ResConstrSelector <1..4>\n"; cout<<" AltResSelector <1..4> DiscrepancyCount <1,2,..> TimeLimit FailLimit \n"; cout<<" OutputStartFlag<1/0> ReadInFirstSolution<1> RandSeed\n"; cout<.exe \n"; cout<<" \n"; cout<<" ResourceSelector <1..4> ResConstrSelector <1..4>\n"; cout<<" AltResSelector <1..4> DiscrepancyCount <1,2,..> TimeLimit FailLimit \n"; cout<<" OutputStartFlag<1/0> ReadInFirstSolution<0> RandSeed\n"; return 0; } ofstream fout,fout1,fout2; ifstream fin1; FILE* fin; IloBool startFlag; if (argc==15) { startFlag = atoi(argv[12]); Problem = argv[1]; if ((fin=fopen(Problem,"r"))==NULL) { cout<<"Couldn't open "<>VrpData[0][3]>>VrpData[0][4]>>VrpData[0][5]>>VrpData[0][6]; int** arrayOfAllowedVehicles; arrayOfAllowedVehicles = new int* [NbCustomers]; for (i=0;i (env,10000); IloModel model; model = DefineModel(env, VRPFlag, costOnResource, transCostSum, transCostArr, selectedMachines, selectedMachinesVarArr, ttParam, tcParam, arrayOfAllowedVehicles, solution, fin1, fout,makespan, CriterionVar); if (ReadFirstSolutionFromFile) ReadInSolutions(model,NbMachines,NbCustomers,fin1,fout); // Algorithm IloSolver solver(model); IlcScheduler scheduler(solver); solver.setTraceMode(IlcTrue); IlcPrintTrace trace(solver,IlcTraceFail); solver.setTrace(trace); IloGoal goal; //The Search Goal if (!activateAltVRPCriterion) { // goal = IloRankForward(env,rSel,rcSel) &&IloAssignAlternative(env,prSel); // goal = IloRankForward(env,rSel,rcSel) &&IloAssignAlternative(env,prSel); // goal = MyAssignAlternative(env,scheduler)&&IloRankForward(env,rSel,rcSel) ; // goal = IloAssignAlternative(env,prSel) && IloRankForward(env,rSel,rcSel) && IloSetTimesForward(env); goal = AltTextureIloGoal(env,makespan); } else { if (VRPFlag) { goal = IloAssignAlternative(env,prSel) && IloRankForward(env,rSel,rcSel) && IloSetTimesForward(env); } else { goal = IloRankForward(env,rSel,rcSel) && IloSetTimesForward(env) && IloAssignAlternative(env,prSel); } } //Applying LDS // goal = IloApply (env, goal, IloLDSEvaluator(env, DiscrepancyCount)); //these are needed for storing statistics: #backtracks, #choice points, time, etc. 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(additionalConstraint) && IloLimitSearch(env, goal, IloTimeLimit(env,TimeLimit)))) { fout<