Decision Optimization

 View Only
  • 1.  use get_duals() / get_constraints_by_index docplex

    Posted Thu June 18, 2020 04:44 AM
    Edited by System Fri January 20, 2023 04:40 PM
    Hi ,
    I am using docplex.mp and trying to get the duals of a relaxed model.
    I am trying to use the method get_duals(), however I am having trouble with the argument it needs.
    So I have a model, mdl, and I relaxed it and called the new model mdl2. Now, I try to do the following:
    c = mdl2.get_constraint_by_index(0)
    mdl2.get_duals(cts), # edit : mdl2.get_duals(c)
    however  I receive the  following error message:
    TypeError: 'LinearConstraint' object is not iterable

    Any ideas how to fix this?

    best,​​
    #DecisionOptimization


  • 2.  RE: use get_duals() / get_constraints_by_index docplex

    Posted Thu June 18, 2020 04:50 AM
    What is 'cts'? Is it a single constraint, a list of constraints, ...? It looks like you are calling a method that expects a list of constraints and you are passing a single constraint.

    In any case, are you aware that a constraint object has a property `dual_value` which should return the dual value of that constraint? That might be an easier way to get that information.

    ------------------------------
    Daniel Junglas
    ------------------------------



  • 3.  RE: use get_duals() / get_constraints_by_index docplex

    Posted Thu June 18, 2020 05:02 AM
    Edited by System Fri January 20, 2023 04:50 PM
    Hi Daniel,

    You are right. in my first post, I meant the following:
    mdl2.get_duals(c)
    Changing c to [c] gives the dual  as a list.
    also c.dual_value do the trick.

    Thanks for your help!
    Is there a nicer way to get all the constraints from the relaxed model? rather than using get_constraint_by_index for each constraint?
    best,





  • 4.  RE: use get_duals() / get_constraints_by_index docplex

    Posted Thu June 18, 2020 06:08 AM
    Hi,

    Is there a nicer way to get all the constraints from the relaxed model? rather than using get_constraint_by_index for each constraint?

    best,

    ------------------------------
    s charaf
    ------------------------------



  • 5.  RE: use get_duals() / get_constraints_by_index docplex

    Posted Thu June 18, 2020 08:38 AM

    In the documentation you can find that the Model class has member functions like  iter_range_constraints(), iter_binary_constraints(), iter_linear_constraints(), ...

    Maybe this is what you are looking for?



    ------------------------------
    Daniel Junglas
    ------------------------------



  • 6.  RE: use get_duals() / get_constraints_by_index docplex

    Posted Wed June 24, 2020 09:48 AM
    Hi Daniel,
    Yes that is what I was looking for! thank you !

    best

    ------------------------------
    s charaf
    ------------------------------