Decision Optimization

Decision Optimization

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

 View Only
  • 1.  Issue with Solving Equality Constraint Involving Product of Continuous and Binary Variables in CPLEX

    Posted 13 days ago

    Dear IBM Community,

    I am currently working on an optimization model using Pyomo, and I am using CPLEX for solving it. One of the constraints in my model is an equality constraint that involves the product of a continuous variable and a binary variable. The constraint is as follows:


    M_g = read_excel_as_dict(file_path, "M_g")
    model.M_g = Param(model.G, initialize=M_g)

    delta_qbr = read_excel_as_matrix_dict_3d(file_path, 'delta_qbr')
    model.delta_qbr = Param(model.B * model.B * model.B, initialize=delta_qbr)

    d_qr = read_excel_as_matrix_dict_2d(file_path, "d_qr")
    model.d_qr = Param(model.B * model.B, initialize=d_qr)

    model.x_bg = Var(model.B * model.G, domain=Binary)
    model.theta_b = Var(model.B, domain=NonNegativeReals)

    def C30(model, b):
        sum_1 = sum(
            model.delta_qbr[q, b2, r2] *
            (sum(model.M_g[g] * model.x[b,g] *model.theta_b[b] for g in model.G_b[r2])) /
            model.d_qr[q, r2]  
            for b2 in model.B
            for q in model.R_b[b2]
            for r2 in model.B
            if r2 != q and r2 != b2
        )
        
        sum_2 = sum(
            model.delta_qbr[q, b, r] *
            (sum(model.M_g[g] * model.x_bg[r, g] for g in model.G_b[r])) /
            model.d_qr[q, r] 
            for q in model.R_b[b]
            for r in model.B
            if r != q and r != b
        )
     
        return sum_1 == sum_2
     
    model.C30 = Constraint(model.B, rule=C30)

    When I run the model using CPLEX, it fails to solve this constraint. However, when I implement the same model using Gurobi with gurobipy, it is able to solve the constraint without any issues.

    Could anyone explain why CPLEX is unable to handle this type of constraint? Are there specific settings or approaches that I need to use in CPLEX to address this issue?

    Thank you in advance for your help.

    Best regards,

    Aysan



    ------------------------------
    icw suni
    ------------------------------


  • 2.  RE: Issue with Solving Equality Constraint Involving Product of Continuous and Binary Variables in CPLEX

    Posted 13 days ago

    Hi,

    at https://github.com/AlexFleischerParis/howtowithopl/blob/master/multiplybinarybydecisionvariable.mod

    I shared a few ways to do that with the OPL CPLEX API but you can do the same with pyomo

    // suppose we want b * x <= 7 
    
        dvar int x in 2..10;
        dvar boolean b;
    
        dvar int bx;
    
        maximize x;
        subject to
        {
          
        // Linearization  
        bx<=7;
    
         
    
        2*b<=bx;
        bx<=10*b;
    
        bx<=x-2*(1-b);
        bx>=x-10*(1-b);
        
        // if we use CP we could write directly
        // b*x<=7
        
        // or rely on logical constraints within CPLEX
        // (b==1) => (bx==x);
        // (b==0) => (bx==0);
        }


    ------------------------------
    [Alex] [Fleischer]
    [Data and AI Technical Sales]
    [IBM]
    ------------------------------



  • 3.  RE: Issue with Solving Equality Constraint Involving Product of Continuous and Binary Variables in CPLEX

    Posted 11 days ago

    Dear Alex,

    Thank you for your valuable insights on handling binary-continuous variable products in CPLEX. I would like to share additional information based on my own experience.

    I am using CPLEX Studio v22.1, and when I attempt to solve my model with this version, after applying linearization, I encounter an optimality gap of 160% within the 10-hour time limit. In contrast, when I run the same model with Gurobi (using Gurobipy), it reaches a gap of approximately 60%, without the need for linearization.

    Could you provide any insights into why Gurobi performs better without linearization? Additionally, what methods or techniques does Gurobi employ that might explain this discrepancy in performance?

    I would greatly appreciate any advice or suggestions you can offer.

    Thank you again for your assistance!

    Best regards,
    Aysan



    ------------------------------
    icw suni
    ------------------------------



  • 4.  RE: Issue with Solving Equality Constraint Involving Product of Continuous and Binary Variables in CPLEX

    Posted 13 days ago
    Edited by PhR 13 days ago

    The general case can be formulated this way :
    Assume L <= x < = U and b in {0, 1}, the formulation of u = x * b is 

    L (1-b) <= x - u <= U (1-b)
    Lb <= u <= Ub

    This formulation is tight: it gives the convex hull.

    I assumed the variable u is a brand new one introduced for this product.




  • 5.  RE: Issue with Solving Equality Constraint Involving Product of Continuous and Binary Variables in CPLEX

    Posted 10 days ago

    Thank you for your valuable insights on handling binary-continuous variable products in CPLEX. I would like to share additional information based on my own experience.

    I am using CPLEX Studio v22.1, and when I attempt to solve my model with this version, after applying linearization, I encounter an optimality gap of 160% within the 10-hour time limit. In contrast, when I run the same model with Gurobi (using Gurobipy), it reaches a gap of approximately 60%, without the need for linearization.

    Could you provide any insights into why Gurobi performs better without linearization? Additionally, what methods or techniques does Gurobi employ that might explain this discrepancy in performance?

    I would greatly appreciate any advice or suggestions you can offer.

    Thank you again for your assistance!

    Best regards,
    Aysan



    ------------------------------
    icw suni
    ------------------------------



  • 6.  RE: Issue with Solving Equality Constraint Involving Product of Continuous and Binary Variables in CPLEX

    Posted 11 days ago
    Bilinear constraints are non convex and therefore not handled by cplex straight 
    You need to linearize them using big M approach (introduce a new variable and inequalities between the latter and the original ones)