Originally posted by: 黃紹軒
Hi Alex,
Thanks for your advice, the code can run now. But, it had already run for over 9 hours. Is it still normal for that long running?
Or is there any coding skills I can use to alleviate the time of compiling the code?
I also want to ask another question about the code of desicion variables. The relation of Xi and Yij is that the decision variable Yij is determined by the decision variable Xi.
eg.
if the optimal solution is X1=X3=X7=1, else Xi equal to 0,
then Yij have to be Y13=Y37=1, else Yij equal to 0.
The follow is the content of .mod file:
using CP;
int n=...;// no. of time_point
int m=...;// no. of bus_stop
range time=1..n;//time window of a day operating bus
range stop=1..m;//no. of bus_stop in the route
float T[time][stop]=...;//time of arriving each stop
float H[time][stop]=...;//adjusted passenger no. of each stop
float P[time][stop]=...;//real passenger no. of each stop
int capacity=...;//capacity of the bus
int F=...;//frequency of bus in one day
int f[i in 1..n-2]=i+2;
tuple pick{int start;int end;}
{pick} pick_point={<i,j>|i in 1..n-1,j in i+1..n};
{pick}select_pair={<i,j>|i in 1..n-2,j in (f[i]..n)};
{int}itv[is in select_pair]={e|e in is.start+1..is.end-1};
//variable
dvar boolean x[time];// determine at which time to departure the bus
dvar boolean y[pick_point];//determine the pair of two adjacent buses to calculate the objective function
dexpr float cost= sum (j in stop,<i,k> in pick_point)
y[<i,k>]*(((T[k][j]-T[i][j])/(T[n][j]-T[1][j]))/((capacity-P[i][j])/capacity));//objective function form
minimize cost;
subject to {
cons01:
x[1]==1;//first bus must be chosen to departure
cons02:
sum(i in time) x[i]==F;//fixed frequency is given
cons03:
sum(<i,j> in pick_point)y[<i,j>]==F-1;//no. of pairs of two adjacent buses is also fixed due to fixed frequency
forall(<i,j> in select_pair)
cons04:
sum(mid in itv[<i,j>])x[mid]*y[<i,j>]==0;//ensure the chosen pairs of buses is adjencent, no other chosen bus is among the pair of buses
forall(i in time)
cons05:
sum(j in stop) x[i]*P[i][j]<=sum(d in stop) x[i]*H[i][d];//ensure the new timetable will not overflow the original demand
}
Thank you very much, and sorry to bother you so many times,
Best regards,
Shao Hsuan
#DecisionOptimization#OPLusingCPLEXOptimizer