Originally posted by: SystemAdmin
Thanks Philippe and Alex,
I am able to run my model ,
I have few question about CP models ,
1. How can we run it quick for large instance , for my problem if I don’t set any cp param it run for more than 10 minutes and continuously running….
Then I set up the CP param as shown in below model file
It does give result in 10 second,
How could I set CP Param for large instance of data.
My model is
{
using CP;
// A tuple have all information about a route
tuple Route {
key int routeid;
int carrierid;
int loadtime;
int paperworktime;
};
{Route} RouteData = ...;
// A tuple have information about warehouse
int numberofdocks = ...;
int planstarttime= ...;
int planendtime= ...;
{Route} routeVisits = { v | v in RouteData : v.routeid!=4 && v.routeid!=0};
// A tuple have information about carrier
tuple Carrier{
key int carrierid;
float waitingcost;
};
{Carrier} CarrierData = ...;
// A generated table has all time windows of customer for a route
tuple RouteCustTimeWindows{
key int routeid;
key int custid;
key int timewindowid;
int starttime;
int endtime;
};
{RouteCustTimeWindows} RouteCustTimeWindowsData = ...;
// A generate table has customer visiting sequence for a route
tuple RouteCust{
key int routeid;
key int custid;
int unloadtime;
int paperworktime;
int traveltime;
int starttime;
int endtime;
};
{RouteCust} RouteCustData = ...;
// tuple of only customers
{RouteCust} routecust = { v | v in RouteCustData : v.custid!=0 };
execute{
writeln("routecust = ", routecust);
}
tuple triplet { int c1; int c2; int d; };
{triplet} Dist = { <r1.routeid, r2.routeid, 0> |
r1,r2 in RouteData: r1.routeid!=r2.routeid && r1.routeid != 4 && r2.routeid != 0};
// calculate the interval time of visit reach and leave for every customers
dvar interval visit
r in routeVisits in planstarttime..planendtime size r.loadtime+r.paperworktime;
// an interval variable which will
dvar interval day_span
http://n in 1..numberofdocks optional;
// interval of each route
dvar interval tvisit
http://n in 1..numberofdocksr in RouteData optional(r.routeid!=4 && r.routeid!=0);
// sequence variable for each day warehouse use
dvar sequence route
http://t in 1..numberofdocks in all(r in RouteData)tvisit[t][r] types all(r in RouteData) r.routeid;
// reach and start time at each customer by a route
dvar interval cvixit
rcd in RouteCustData in rcd.starttime..rcd.endtime size rcd.unloadtime+rcd.paperworktime;
dvar int+ truckwaitingtime
routecust;
dvar boolean OnlyoneTime
RouteCustTimeWindowsData;
execute {
cp.param.NoOverlapInferenceLevel = "Medium";
cp.param.ElementInferenceLevel = "Low";
//cp.param.TemporalRelaxation = "Off";
cp.param.TimeMode = "ElapsedTime";
cp.param.TimeLimit = 10;
cp.param.Workers = 1;
var f = cp.factory;
cp.setSearchPhases(f.searchPhase(route));
writeln("Using",numberofdocks, " docks");
}
// objective function
dexpr float objective = sum(rc in routecust)truckwaitingtime
rc;
// minimize objective function
minimize objective;
subject to
{
forall(n in 1..numberofdocks)
{
// fixing the total span of the sequence of all the route
span (day_span[n], all(r in routeVisits) tvisit[n][r]);
startOf(tvisit[n]
<0>)==0;
last (route[n],tvisit[n]
<4>);
noOverlap(route[n], Dist);
}
forall(r in routeVisits)
{
alternative(visit[r], all(n in 1..numberofdocks)tvisit[n][r]);
forall(rcd in RouteCustData)
{
if(r.routeid == rcd.routeid && rcd.custid ==0)
{
startOf(cvixit
rcd) == endOf(visit[r]);
}
if(r.routeid == rcd.routeid && rcd.custid > 0)
{
startOf(cvixit
rcd) == endOf(cvixit
prev(RouteCustData, rcd)) + rcd.traveltime + truckwaitingtime
rcd ;
}
}
}
forall(rcd in routecust)
{
sum(rctw in RouteCustTimeWindowsData: rcd.routeid == rctw.routeid
&& rcd.custid == rctw.custid)OnlyoneTime
rctw == 1;
}
forall(rcd in routecust)
{
sum(rctw in RouteCustTimeWindowsData: rcd.routeid == rctw.routeid
&& rcd.custid == rctw.custid)OnlyoneTime
rctw*rctw.starttime <= startOf(cvixit
rcd);
endOf(cvixit
rcd) <= sum(rctw in RouteCustTimeWindowsData: rcd.routeid == rctw.routeid
&& rcd.custid == rctw.custid)OnlyoneTime
rctw*rctw.endtime;
}
}
}
And Data are
numberofdocks = 2;
planstarttime = 0;
planendtime = 420;
// A tuple have all information about a route
RouteData = {
<0, 0, 0, 0>,
<1, 1, 100, 30>,
<2, 1, 120, 40>,
<3, 2, 150, 90>,
<4, 0, 0, 0>,
};
RouteCustData = {
<1, 0, 0, 0, 0, 0, 3000>,
<1, 1, 10, 3, 10, 10, 3000>,
<1, 2, 10, 3, 10, 20, 3000>,
<2, 0, 0, 0, 0, 0, 3000>,
<2, 3, 12, 4, 10, 10, 3000>,
<3, 0, 0, 0, 0, 0, 3000>,
<3, 1, 15, 9, 10, 10, 3000>,
<3, 2, 15, 9, 10, 20, 3000>,
<3, 3, 15, 9, 10, 30, 3000>,
};
RouteCustTimeWindowsData =
{
<1, 1, 1, 400, 1000>,
<1, 1, 2, 1500, 2500>,
<1, 2, 1, 300, 700>,
<1, 2, 2, 900, 1300>,
<2, 3, 1, 200, 400>,
<2, 3, 2, 500, 700>,
<2, 3, 3, 800, 1000>,
<2, 3, 4, 1100, 1300>,
<3, 1, 1, 300, 400>,
<3, 1, 2, 800, 1100>,
<3, 2, 1, 900, 1000>,
<3, 2, 2, 1100, 1400>,
<3, 2, 3, 1600, 2500>,
<3, 3, 1, 1000, 1020>,
<3, 3, 2, 1100, 1500>,
};
CarrierData = {
<1, 10>,
<2, 12>,
};
A very small instance where as numberofdocks could be 20 or 30
And RouteData could be 100.
Also I have one question about the constraint which I have created.
In my model the interval variable dvar interval cvixit should take values out of number of time windows
To do that I have done what we do in MIP, defined an integer variable and set it to choose 1 time window out of many ..like
{
forall(rcd in routecust)
{
sum(rctw in RouteCustTimeWindowsData: rcd.routeid == rctw.routeid
&& rcd.custid == rctw.custid)OnlyoneTime
rctw == 1;
}
}
Than the upper and lower bound constraint for the interval time for the selected time window…like
{
forall(rcd in routecust)
{
sum(rctw in RouteCustTimeWindowsData: rcd.routeid == rctw.routeid
&& rcd.custid == rctw.custid)OnlyoneTime
rctw*rctw.starttime <= startOf(cvixit
rcd);
endOf(cvixit
rcd) <= sum(rctw in RouteCustTimeWindowsData: rcd.routeid == rctw.routeid
&& rcd.custid == rctw.custid)OnlyoneTime
rctw*rctw.endtime;
}
}
I want to know is there any direct way to do while initializing the interval variable dvar interval cvixit
Or using function like alternative
So that it can run little faster.
Hope I put well my problem.
Please help ,
Thanks
Arun Lila
#ConstraintProgramming-General#DecisionOptimization