Decision Optimization

 View Only
  • 1.  Error: CPLEX(default) cannot extract expression

    Posted yesterday
    Hi can help to assist on this error? i've tried lots of ways including make the constraint piecewise etc (suggested by claude). Besides iam very new to this. this is my second day. i just don't know where else to find the answer. i keep getting this error. 
    execute {
       cplex.optimalitytarget = 3;
    }
     
    dvar int x in -1..1;
    dvar int y in -1..1;
     
    minimize
        5*x*x + 5*y*y + 4*x*y;
     
    subject to {
       x*x + y*y == 1;
    }
     
    execute {
        writeln("Results:");
        writeln("-----------------");
        writeln("x = ", x);
        writeln("y = ", y);
        writeln("objective = ", 5*x*x + 5*y*y + 4*x*y);
    }
    CPLEX(default) cannot extract expression: 1*y*y + 1*x*x == 1.
    #Decision Optimization


    ------------------------------
    Fatin Nur Amirah Mahamood
    ------------------------------


  • 2.  RE: Error: CPLEX(default) cannot extract expression

    Posted yesterday

    Since your decision variables are integer you could use CPOptimizer within CPLEX:

    using CP;
     
    dvar int x in -1..1;
    dvar int y in -1..1;
     
    minimize
        5*x*x + 5*y*y + 4*x*y;
     
    subject to {
       x*x + y*y == 1;
    }
     
    execute {
        writeln("Results:");
        writeln("-----------------");
        writeln("x = ", x);
        writeln("y = ", y);
        writeln("objective = ", 5*x*x + 5*y*y + 4*x*y);
      }    


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



  • 3.  RE: Error: CPLEX(default) cannot extract expression

    Posted 16 hours ago

    Hi. Thank you for your response. However, I'm sorry, my dvar should be in float. Tne expectes rsult is x=-1/sqrt 2, y=1/sqrt 2



    ------------------------------
    Fatin Nur Amirah Mahamood
    ------------------------------



  • 4.  RE: Error: CPLEX(default) cannot extract expression

    Posted 11 hours ago
    Edited by Fatin Nur Amirah Mahamood 11 hours ago

    Thank you for your response. However, I need to clarify that my decision variable (dvar) should be in float. The expected result is x=-1/sqrt(2) , y=1/sqrt(2). This result matches both the textbook example and my manual calculations, as well as results obtained using Python's scipy library (via the Lagrange method).

    From my understanding, "using cp;" does not allow for float dvar. Is there an alternative approach to solving this problem?

    Additionally, I came across this statement in the documentation:

    "When you call the barrier optimizer, your quadratic constraints will be checked for the necessary PSD property, and an error status 5002 will be returned if any of them violate it."

    I also verified that my constraint is not convex. Does this imply that my function cannot be solved using CPLEX?

    Thank you for your guidance.



    ------------------------------
    Fatin Nur Amirah Mahamood
    ------------------------------



  • 5.  RE: Error: CPLEX(default) cannot extract expression

    Posted 9 hours ago

    Hi,

    you could write

    using CP;
    
    int scale=10000;
     
    dvar int scalex in -scale..scale;
    dvar int scaley in -scale..scale;
    
    dexpr float x=scalex/scale;
    dexpr float y=scaley/scale;
     
    minimize
        5*x*x + 5*y*y + 4*x*y;
     
    subject to {
       x*x + y*y == 1;
    }
     
    execute {
        writeln("Results:");
        writeln("-----------------");
        writeln("x = ", x);
        writeln("y = ", y);
        writeln("objective = ", 5*x*x + 5*y*y + 4*x*y);
      }    

    to use decimal decision variables

    NB:

    Do not hesitate to vote for the wish to have CPLEX deal with non convex quadratic constraints

    https://ibm-data-and-ai.ideas.ibm.com/ideas/CPLEX-I-24



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



  • 6.  RE: Error: CPLEX(default) cannot extract expression

    Posted 7 hours ago

    My response was crafted with AI assistance, tailored to provide detailed and actionable guidance for your query.

    The error occurs because IBM CPLEX does not allow certain types of constraints, particularly quadratic equalities, in mixed-integer programming problems (dvar int). Quadratic equality constraints like x*x + y*y == 1 cannot be directly handled with integer decision variables.

    Piecewise Approximation: If the enumeration approach isn't feasible (e.g., larger ranges), approximate the circle using a combination of constraints or lookup tables.

    Use a Constraint Programming (CP) Engine

    The CP engine (using CP;) supports certain types of logical constraints better, such as enumerations, but it still won't handle the quadratic equality directly. Reformulate the problem to use CP if enumeration or constraints like "or" conditions are more natural.



    ------------------------------
    Saif Sabri
    ------------------------------



  • 7.  RE: Error: CPLEX(default) cannot extract expression

    Posted 3 hours ago

    Indeed, you can also use interpolation with piecewise linear as can be seen at 

    https://github.com/AlexFleischerParis/opltipsandtricks/blob/master/interpolatewithpiecewiselinear.mod



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