/* 24 Jan 2002 TSP graph Transformations due to Chris Beck (transform1) and Patrick Prosser (transform2). After writing footnotes 698,699 and checking the validity of the transformation for more than 1 route. Fixed a small but harmful bug to do with capacity constraint encoding Checked Chris' transformation. Checking Patrick's transformation. Lex, maxmin, minmin - checked; NOT CHECKED: TIME WINDOWS AFTER PATRICK'S TRANSFORMATION!!! */ #include #include #include #include #include ILOSTLBEGIN IloInt Capacity; IloInt SetupActivityDuration; IloInt TeardownActivityDuration; IloInt NbMachines; IloInt MinTransition; IloInt SummedDurationSaved = 0; IloInt SummedDuration = 0; IloInt NbCustomers; IloInt BasicTimeLimit; IloInt TrueCost; char Problem[128]; //in seconds, overall amount of time spent on search IloInt NbFailsSummed; IloInt NbChoicePointsSummed; IloBool TransformFlag, TransformIndex; 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 (group 1 and group 2 ones) IloNum VrpData [400*7]; IloNum* VrpDataSaved; IloInt** TransMatrSaved; /* inline IloInt computeDistance(IloInt i, IloInt j) { return (IloInt) IloFloor(0.5 + 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 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 getLatestStartTime (IloInt i) { return VrpData[i*7+5]; } inline IloNum getActivityDuration (IloInt i) { return VrpData[i*7+6]; } IloInt MakeTransformation(IloTransitionParam& ttParam, IloInt order, ofstream& fout) { // cout<<"by Patrick"<2) { NbEdges += ctr-1; NbVehiclesUsed++; } } //increase trueCost by the sum of the performed activities //bearing in mind that with each new vehicle used //we have to add the duration of the starting activity; //SummedDuration is the sum of durations of all visits to //customers + base; fout<<"NbVehiclesUsed = "<.exe \n"; cout<<" NbMachines NbCustomers VehicleCapacity \n"; cout<<" TransformFlag \n"; cout<<" TransformIndex<1 - Chris,2 - lex,3 - maxmin,4 - minmin>\n"; cout<<" ResourceSelector <1..4> ResConstrSelector <1..4>\n"; cout<<" AltResSelector <1..4> DiscrepancyCount <1,2,..> TimeLimit \n"; cout<<" OutputStartFlag <0/1>\n"; /* cout<.exe \n"; cout<<" NbMachines NbCustomers VehicleCapacity \n"; cout<<" TransformFlag \n"; cout<<" ResourceSelector <1..4> ResConstrSelector <1..4>\n"; cout<<" AltResSelector <1..4> DiscrepancyCount <1,2,..> TimeLimit \n"; cout<<" OutputStartFlag <0/1>\n"; */ return 0; } ofstream fout,fout1; ifstream fin; IloBool startFlag; startFlag = atoi(argv[14]); fin.open(argv[1], ios::in); sprintf(Problem,argv[1]); fout.open(argv[2], ios::out); if (startFlag) { fout1.open(argv[3], ios::out); } else { fout1.open(argv[3], ios::app); } NbMachines = atoi(argv[4]); fout<<"NbMachines : "<>VrpData[i]; else VrpData[i] = VrpData[i-7*NbActPerTour+7]; //additional line corresponding to teardown activity, repeats the first one } fout<0 && solver.solve(IloAddConstraint(transCostSum <= solver.getIntVar(transCostSum).getMin()-1) && IloLimitSearch(env, goal, IloTimeLimit(env,TimeLimit)))) { fout<