Skip to main content

Adding callback function with lazy constraints causes a worse solution than initial guess.

Answered

Comments

3 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff
    This post is more than two years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum, or try Gurobot, our chatbot interface offering instant, expert-level support.
  • Riley Clement
    • Gurobi Staff

    Hi Yuankai,

    I think it's important to remember that a lazy constraint should be globally valid, and always be valid - whether it is added or not.  Consequently it does not make sense to have both z == 1, and z == 0, as lazy constraints since they cannot both be valid.

    Since you are indicating that you expect (x,y) = (4,4) to be a good solution I will assume that you meant to write

    if x_val+y_val>=8:

    in your callback, instead of

    if x_val+y_val>8:

    In your particular example, once the solver arrives at a solution with x + y >= 8 - which it will very quickly - it will have z == 1 as a constraint.  This constraint then remains for the rest of the solve - every solution will have z equal to 1 and incur the penalty.

    It may be that imposing a lazy constraint, which removes a solution which incurs a collision, is the right approach to this problem, but just not in the way it is currently being done.  In your toy example, you can penalize solutions with x + y >= 8 using your idea of the binary z variable (with a large negative objective coefficient) by adding the following constraint:

    x + y <= 8 + Mz

    for some constant M, which is sufficiently large.  Then the only way x + y can be greater than 8 is if z is equal to 1 (and the penalty is imposed).  How well this translates to your actual problem, I am not sure.  I don't think a bi-level optimization is required here.

    Many years ago I wrote an undergrad project on scheduling gantry cranes with collision avoidance.  It looks like it may have many similarities with your fruit harvesting problem.  Here is a copy if you wish to have a look.

    - Riley

     

    0
  • Yuankai Zhu
    • Gurobi-versary
    • First Comment
    • First Question

    Thanks Riley,

    I will try to remodel my problem and see if it can fix the issue.

    Best,

    Yuankai

    0

Post is closed for comments.