0

I'm having hard time regarding how to model a constraint. I'm trying to solve a transportation problem and one of the constraints is as follows:

t[s[i]] >= t[i] + travelTime (i, s[i])

which t is the time at which node i is visited and s is the successor variable of node i ( t and s are variables).

I also have a travel time matrix :

int time = travelTime(int origin, int destination) 

which defines the travel time between pair of nodes. I have defined the constraint as below:

for (int i : set){
  IloIntExpr expr = model.linearIntExpr();
  expr = model.sum(model.element(t, s[i]), model.prod(t[i], -1));
  IloIntExpr next = model.element(range(0, nbNodes), s[i]);
  model.addGe(expr, travelTime(i, next));
}

***range function generates [0,1, ... ,nbNodes] and [size(s) = size(t) = nbNodes]

now the problem is that next is returning IloIntExpr and I want it to be int to pass it to travelTime(int, int), and also IloIntExpr is not castable to int. What can be the possible solution for my problem. I really appreciate any help in this regard.

  • It would help if you provided a [minimal, complete, and verifiable example](http://stackoverflow.com/help/mcve). Of course, the problem with `travelTime` won't compile (as you've pointed out, it expects an `int` and you're giving it an `IloIntExpr`), but does the rest of your snippet actually compile (I suspect not)? With that said, `linearIntExpr` returns a `IloLinearIntExpr`, which has a `getConstant` method (see [here](http://www.ibm.com/support/knowledgecenter/SSSA5P_12.6.3/ilog.odms.cplex.help/refjavacplex/html/ilog/concert/IloLinearIntExpr.html)). Perhaps, that helps.... – rkersh Jul 22 '16 at 16:40
  • Thank you for your answer. Yes it does compile. If I simply change 'travelTime' to some numbers like 10 it compiles without any error. Also 'getConstant' method that you mentioned just gets the constant of an expression for example 'x+y+10' is an expression and 'getConstant' returns 10. – Mohammad Abdollahi Jul 23 '16 at 04:18
  • What information do you want out of 'next'? What do you want to cast to an int? A variable index? – rkersh Jul 23 '16 at 05:43
  • Yest I need exatly a variable index.for example : `next == element(s0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])` here if the successor of node 0 is 7 `next` should return 7., and then I calculate for example the distance between 0 and 7 which is `travelTime(0,7)` – Mohammad Abdollahi Jul 24 '16 at 21:44

0 Answers0