Click here to Skip to main content
14,173,097 members
Rate this:
Please Sign up or sign in to vote.
See more:

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;


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];


dvar boolean x [arcs,truck];

dvar int+ arrivaltime [arrivalnode,truck];


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

minimize totalcost;


subject to {}

execute {

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]];


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.

What I have tried:

I have tried to implement the code shown above into CPLEX but as said I have some doubts and i need to solve the errors shown.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.190524.3 | Last Updated 9 Jul 2018
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100