Decision Optimization

Decision Optimization

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

 View Only
  • 1.  solve a relaxed version of a model

    Posted Tue June 16, 2020 02:50 AM
    Hi,

    Is it possible to solve a relaxed version of an ilp model using only a built-in method? I am using python API, docplex.mp. 
    I found LinearRelaxer in docplex.mp.relax_linear , however I keep getting this error message:

    ####
    from docplex.mp.utils import DocplexLinearRelaxationError
    ImportError: cannot import name 'DocplexLinearRelaxationError' from 'docplex.mp.utils' (C/...)
    ​####

    Any ideas?

    best,​
    #DecisionOptimization


  • 2.  RE: solve a relaxed version of a model

    Posted Tue June 16, 2020 03:02 AM
    There are two types of relaxations:
    1. The original model in which all binary and integer variables have been converted to continuous variables.
    2. The original model in which all other constraints are allowed to be violated.
    Which of the two do you want to solve?

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



  • 3.  RE: solve a relaxed version of a model

    Posted Tue June 16, 2020 05:07 AM
    Edited by System Admin Fri January 20, 2023 04:12 PM
    Hi Daniel,

    Thanks for your reaction. 
    Well, at first I was only thinking of the first type.
    However, the second type can also be helpful. I am implementing a branch and price algorithm.

    In other words, if there is a method that could do the first type, then I am taking it, and if there is another one that do both then I am also happy to know about it.

    Best,




  • 4.  RE: solve a relaxed version of a model

    Posted Tue June 16, 2020 08:17 AM
    Edited by System Admin Fri January 20, 2023 04:12 PM
    Hi,

    in https://www.linkedin.com/pulse/making-optimization-simple-python-alex-fleischer/

    you have a relaxation example in docplex

    AlexFleischerParis/zoodocplex

    and for linear relaxation

    from docplex.mp.model import Model
    from docplex.mp.relax_linear  import LinearRelaxer
    
    
    
    mdl = Model(name='buses')
    nbbus40 = mdl.integer_var(name='nbBus40')
    nbbus30 = mdl.integer_var(name='nbBus30')
    
    mdl.add_constraint(nbbus40*40 + nbbus30*30 >= 300, 'kids')
    
    
    mdl.minimize(nbbus40*500 + nbbus30*400)
    
    mdl.solve()
    
    for v in mdl.iter_integer_vars():
        print(v," = ",v.solution_value)
    
    mdl.report()
    
    
    print()
    print("------- starting linear relaxation")
    print()
    
    rx=LinearRelaxer()
    mdl2=rx.linear_relaxation(mdl)
    
    mdl2.solve()
    
    for v in mdl2.iter_continuous_vars():
        print(v," = ",v.solution_value)​


    regards

    ------------------------------
    ALEX FLEISCHER
    ------------------------------



  • 5.  RE: solve a relaxed version of a model

    Posted Tue June 16, 2020 08:50 AM
    Edited by System Admin Fri January 20, 2023 04:45 PM
    Hi Alex,

    Thanks for your reaction.
    As you can see in my first post, when importing the LinearRelaxer() ,i get this error message : 
    ####
    from docplex.mp.utils import DocplexLinearRelaxationError
    ImportError: cannot import name 'DocplexLinearRelaxationError' from 'docplex.mp.utils' (C/...)
    ​####

    The same error message appears when copying pasting your code.
    Do you have an idea how to fix this ? 

    Best,





  • 6.  RE: solve a relaxed version of a model

    Posted Tue June 16, 2020 09:19 AM
    Hi

    you should move to a more recent docplex version.
    See https://pypi.org/project/docplex/#history

    regards

    ------------------------------
    ALEX FLEISCHER
    ------------------------------



  • 7.  RE: solve a relaxed version of a model

    Posted Tue June 16, 2020 10:48 AM
    Edited by System Admin Fri January 20, 2023 04:14 PM
    Hi ALex,

    thanks for your reaction !

    I get this error message again:
    Found existing installation: docplex 2.11.176
    Cannot uninstall 'docplex'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

    Tried on the terminal, settings of PyCharm , pip install --upgrade docplex==2.14.186, and pip install docplex==2.14.186 and tried to uinstall it as well. got the same message

    Any ideas? 
    best,






  • 8.  RE: solve a relaxed version of a model

    Posted Tue June 16, 2020 10:53 AM
    Hi

    before instal can you try


    pip install --ignore-installed --upgrade docplex​


    ------------------------------
    ALEX FLEISCHER
    ------------------------------



  • 9.  RE: solve a relaxed version of a model

    Posted Tue June 16, 2020 11:02 AM
    Edited by System Admin Fri January 20, 2023 04:44 PM
    Hi Alex,

    Thanks a lot ! works perfect !

    best,