Decision Optimization

 View Only
Expand all | Collapse all

Quad Constraints in DOCplex 2.11

  • 1.  Quad Constraints in DOCplex 2.11

    Posted Tue December 08, 2020 01:03 PM
    Is possible to solve MP model with quadratic constraints in docplex (python cplex) version 2.11? This is the latest version included in the education plan package.
    #DecisionOptimization


  • 2.  RE: Quad Constraints in DOCplex 2.11

    Posted Wed December 09, 2020 01:27 AM
    Hi

    from docplex.mp.model import Model  
    
    mdl = Model(name='qpex1')
    
    #decision variables
    x = {b: mdl.continuous_var(0,40,name="x"+str(b)) for b in range(0,3)}
    
    
    # Constraint
    mdl.add_constraint( - x[0] +     x[1] + x[2] <= 20, 'ct1')
    mdl.add_constraint(x[0] - 3 * x[1] + x[2] <= 30,'ct2')
    
    mdl.add_constraint(x[0] * x[0] <= 30,'quad')
    
    
    # Objective
    mdl.maximize(x[0] + 2 * x[1] + 3 * x[2]-\
                 0.5 * ( 33*x[0]*x[0] + 22*x[1]*x[1] + 11*x[2]*x[2] -\
                         12*x[0]*x[1] - 23*x[1]*x[2] ))
    
    msol=mdl.solve()
    
    # Dislay solution
    for v in mdl.iter_continuous_vars():
       print(v," = ",v.solution_value)
    
    print("objective : ",msol.get_objective_value() ) ​


    works fine

    regards



    ------------------------------
    [Alex] [Fleischer]
    [EMEA CPLEX Optimization Technical Sales]
    [IBM]
    ------------------------------