Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
Expand all | Collapse all

Having difficulties with element method

  • 1.  Having difficulties with element method

    Posted 07/25/16 08:46 AM

    Originally posted by: MohammadAbdollahi


    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.


    #CPOptimizer
    #DecisionOptimization


  • 2.  Re: Having difficulties with element method

    Posted 07/25/16 09:37 AM

    Originally posted by: PhilippeLaborie


    Hello,

    I'm not sure of which programming language you are using to implement your model. Is it c++, java, python? Or maybe just some pseudo-code?

    Anyway, for modeling the travel time expression, you should also use an "element" expression. Assuming travelTime_i[j] is an array of integers giving the travel time between node i and node j, using your notations, the expression you are looking for is just: model.element(travelTime_i, next).

    Note that depending on your problem, you may be interested to consider an alternative model using interval variables, see https://www.ibm.com/developerworks/community/forums/html/topic?id=5efb1db1-c642-4877-af60-b330f959a534&ps=25.

     


    #CPOptimizer
    #DecisionOptimization


  • 3.  Re: Having difficulties with element method

    Posted 07/25/16 11:28 AM

    Originally posted by: MohammadAbdollahi


    Thank you Philippe for your response and your help. It is working in the way you described. BTW I'm using Java to model the problem. Using interval variables is a great idea, however I'm developing some algorithm which I'm afraid I'll be having difficulty using interval variables.


    #CPOptimizer
    #DecisionOptimization