Originally posted by: Arnautarrago
I have some errors regarding a CPLEX code that I'm trying to write. The errors are on the constraints 2 and 3. Thank you in advance.
Here is the code:
using CP;
// NETWORK+PARAMETERS
int trucks=...; // set of trucks
range truck= 1..trucks;
int capacity [truck]=...; // capacity of a truck
tuple nodeinfo {
string name; // name of a node
int starttime; // available start time
int endtime; // available end time
float demand; // demand from a node
}
{nodeinfo} departurenode=...; //size=4
{nodeinfo} arrivalnode=...; //size=4
{nodeinfo} startingnode=...; //size=4
// OPTION 2: vector of nodes
//each node has tuple structure nodeinfo
//length of the vector is length of dataset
//read data from dataset
//void* node = new {nodeinfo} [k];
tuple arc {
nodeinfo departurenode; //departure node of an arc
nodeinfo arrivalnode; // arrival node of an arc
nodeinfo startingnode; // starting node of an arc
int traveltime; // travel time of an arc
}
{arc} arcs=...; //number of arcs (24)
float cost [arcs][truck]=...; //cost of using an arc by a truck
// option2: int arc[i in departurenode,j in arrivalnode,k in startingnode]=...; //arcs (size=24)
// how can i create a setof arcs taking into account the info from each arc??
// VARIABLES
dvar boolean x [arcs,truck]; // 1 if truck uses the arc, 0 otherwise (array of size 24x7)
dvar int+ arrivaltime [arrivalnode,truck]; //arrival time of a truck at a node (array size of 4x7)
// OBJECTIVE FUNCTION
dexpr float totalcost =
sum (a in arcs, t in truck) x [a,t] * cost [a,t];
minimize totalcost;
// CONSTRAINTS
subject to {
forall (n in arrivalnode,t in truck) n.starttime<=arrivaltime[n][t]<=n.endtime; //arrivaltime has to be inbetween the working time zone of a node
forall (n in arrivalnode, a in arcs, t in truck) n.demand= sum (x [a,t] * capacity [t]); // the demand for each node has to be equal to the sum of the
//arcs chosen multiplied by the capacity of the truck (CONSTRAINT 2)
forall (n in arrivalnode,t in truck, a in arcs) x [a,t] * (arrivaltime [n][t] + a.traveltime) <= arrivaltime [n][t]; // the arrival time of a truck to a node i + the travel time of this truck to a node j must be equal or less than the arrival time to a node j (CONSTRAINT 3)
};
execute {
writeln(arcs);
};
#DecisionOptimization#OPLusingCPLEXOptimizer