422,952 Members | 2,321 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 422,952 IT Pros & Developers. It's quick & easy.

coding in CPLEX (from a mathematical model)

P: 1
Hi,

i have some doubts related to a CPLEX code that i'm trying to write. The code itself (model) seems to be well written, but when it comes to fill the data i have an error. ***NOTE: there are no constraints in the model because i'm trying to make a trial of the model just to see that it works.***

Here is the code:

using CP;

// NETWORK+PARAMETERS

int trucks=...;
range truck= 1..trucks;

int capacity [truck]=...;

tuple nodeinfo {
string name;
int starttime;
int endtime;
float demand;
}

{nodeinfo} departurenode=...;

{nodeinfo} arrivalnode=...;

{nodeinfo} startingnode=...;

tuple arc {
nodeinfo departurenode;
nodeinfo arrivalnode;
nodeinfo startingnode;
int traveltime;
}

{arc} arcs=...;

float cost [arcs][truck];

// VARIABLES

dvar boolean x [arcs,truck];

dvar int+ arrivaltime [arrivalnode,truck];

// OBJECTIVE FUNCTION

dexpr float totalcost =
sum (i in arcs, j in truck) x [i,j] * cost [i,j];

minimize totalcost;

// CONSTRAINTS

subject to {}

execute {
writeln(arcs);
};

Here is the data:

trucks= 2;

departurenode= [[A,0,10000,0],[B,0,10000,0],[C,0,10000,10],[D,0,10000,10]];

arrivalnode= [[A,0,10000,0],[B,0,10000,0],[C,0,10000,10],[D,0,10000,10]];

startingnode=[[A,0,10000,0],[B,0,10000,0],[C,0,10000,10],[D,0,10000,10]];

arcs= [[<A,0,10000,0>,<A,0,10000,0>,<C,0,10000,10>,5], [<A,0,10000,0>,<A,0,10000,0>,<D,0,10000,10>,5],
[<B,0,10000,0>,<B,0,10000,0>,<C,0,10000,10>,5], [<B,0,10000,0>,<B,0,10000,0>,<D,0,10000,10>,5],
[<C,0,10000,0>,<C,0,10000,0>,<A,0,10000,10>,5], [<C,0,10000,0>,<C,0,10000,0>,<B,0,10000,10>,5],
[<D,0,10000,0>,<D,0,10000,0>,<A,0,10000,10>,5], [<D,0,10000,0>,<D,0,10000,0>,<B,0,10000,10>,5]]

***NOTE: in each gap of the arc before the travel time (last gap value=5) must be the data from departurenode, arrival node and startingnode but it's not shown and i don't know why ***


cost= [<1,1>,<1,1>,<1,1>,<1,1>,<1,1>,<1,1>,<1,1>,<1,1>]

Another doubt: regarding the constraints of the model i don't know how to write them into CPLEX.

1) starttime <= arrivaltime <= endtime //(for each arrivalnode)

2) x * (arrivaltime (node i) + traveltime) <= arrivaltime (node j)

3) Initialize the variable arrivaltime for each truck to 0. (at the beginning of the simulation)

4)The demand for each arrival node has to be equal to the sum of (the arcs chosen * capacity of the truck)

Thank you so much.
1 Week Ago #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.