Decision Optimization

Decision Optimization

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


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

Convert an integer expression (CP objects) to an integer (Python objects) in Python

  • 1.  Convert an integer expression (CP objects) to an integer (Python objects) in Python

    Posted 01/03/19 10:32 PM

    Originally posted by: ORHU


     


    #CPOptimizer
    #DecisionOptimization


  • 2.  Re: Convert an integer expression (CP objects) to an integer (Python objects) in Python

    Posted 01/04/19 03:33 AM

    Hi,

    let me share what I would do.

    If the expression is part of the objective then you could do

    costs2 = msol.get_objective_values()
    print("type(costs2) = ",type(costs2))
    print("costs2 = ",costs2)

    after some solve like

    msol = mdl.solve(TimeLimit=10)

    and you would get

    type(costs2) =  <class 'tuple'>
    costs2 =  (1383,)

    Otherwise if the expression is total_cost, in the constraint part you could write

    total_cost_var = mdl.integer_var(0,10000000,name='totalCost')
    mdl.add(total_cost==total_cost_var);

    in order to turn your expression into a variable and then

    cost=msol[total_cost_var]
    print("type(cost) = ",type(cost))
    print("cost = ",cost)

    gives

     

    type(cost) =  <class 'int'>
    cost =  1383

    I hope this helps.

    NB:

    I used the example facility.py from the CPO docplex examples

     

    regards

     

    https://www.linkedin.com/pulse/%E4%BC%98%E5%8C%96%E5%B0%91%E8%8A%B1%E9%92%B1%E5%A4%9A%E5%8A%9E%E4%BA%8B-%E5%8A%A8%E7%89%A9%E5%9B%AD%E5%85%AC%E5%85%B1%E6%B1%BD%E8%BD%A6%E5%92%8C%E5%84%BF%E7%AB%A5-alex-fleischer/


    #CPOptimizer
    #DecisionOptimization