Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Why the objective is not added into Cplex model?

    Posted 11/04/14 10:11 AM

    Originally posted by: Wendy717


    I'm dealing with a truck assignment problem. There are several bases, each with a number of trucks. The trucks are assigned to cover some customers. 

    In a simplified model, there is only one set of integer decision variables, with range [0,40], which are the number of packages of customer z assigned to truck j in base i. There are two sets of constraints, one for truck capacity and the other one for customer demand fulfillment. There is one objective, which is to minimise the total travel cost.

    When I solve the model with Cplex12.6, it always gives 0 as the optimal objective value. When I look into the .lp file, I found that there is no objective inside. My model file and lp file are attached.  

    Appreciate if anybody could help me look into the issue.


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Why the objective is not added into Cplex model?

    Posted 11/04/14 10:56 AM

    Are you sure the constructObjectives() function is invoked at all? At first glance the function looks correct to me.

    Maybe add

    System.out.println("shippingCost = " + shippingCost);

    right before the call to _cplex.addMinimize(shippingCost) to see what expression gets added. Does that expression look fine or is it maybe empty? If the expression is empty then probably one of your loops is wrong.

    A general remark: I see that you are building your expressions like this:

    IloNumExpr shippingCost = _cplex.numExpr();
    for (...) { shippingCost = _cplex.sum(shippingCost, ...); }

    It should be much more efficient to do it like this:

    IloLinearNumExpr shippingCost = _cplex.linearNumExpr();
    for (...) { shippingCost.addTerm(...); }

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Why the objective is not added into Cplex model?

    Posted 11/04/14 11:15 AM

    There also is this suspicious statement:

    IloNumExpr unitFuel = _cplex.prod(Fv, _cplex.prod(volume, 1/capacityVhl));

    Since '1' is an integer and 'capacityVhl' is also an integer, this performs integer division and 1/capacityVhl will always be 0. Thus all coefficients in your objective will be 0. Does it work better if you do '1.0/capacityVhl' instead?


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Why the objective is not added into Cplex model?

    Posted 11/04/14 05:09 PM

    Originally posted by: Mark L. Stone


    Integer division.  There's a gotcha.  FORTRAN lives.


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Why the objective is not added into Cplex model?

    Posted 11/04/14 09:01 PM

    Originally posted by: Wendy717


    Daniel, thanks a lot! It is the integer division causing the problem.

    Also thanks for the general remark. May I know the difference between the two expression? Is it also applicable to IloIntExpr? Do it also improve efficiency when using the recommended expression in building constraints?


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Why the objective is not added into Cplex model?

    Posted 11/10/14 02:25 AM

    Yes, my suggestions apply to IloIntExpr and for building constraints as well. Something like

    expr = cplex.sum(expr, ...);

    has to create a new object while

    expr.addTerm(...);

    only has to update an existing object. Moreover, the IloLinearNumExpr and IloLinearIntExpr types have a richer API than the IloNumExpr and IloIntExpr types. This usually allows for cleaner code. As a rule of thumb, I usually try to use IloLinear*Expr types as long as I can (there are some cases in which you have to switch to Ilo*Expr types no matter whar).


    #CPLEXOptimizers
    #DecisionOptimization