メインコンテンツへスキップ

Removing lazy constraints

回答済み

コメント

8件のコメント

  • Maliheh Aramon
    • Gurobi Staff

    Hi Marco, 

    In Gurobi, the lazy constraints added via setting the Lazy attribute or generated during a callback function should be linear. Do you mean that you add non-linear lazy constraints? 

    I assume that you have a mip that you would like to solve several times with different lazy constraints generated during callbacks. You can build the model and save it to a file. In every run, you can then read the model without any lazy constraints from the file and call the model.optimize(cb) on a new model object with no lazy constraints. 

    Best regards,

    Maliheh

     

    0
  • Jose Walteros
    • Conversationalist
    • Gurobi-versary
    • First Question

    Hi Maliheh, 

    I think both Marco and I asked a similar question in the forum, although mine asks for a few more things (see here). I understand your idea of duplicating the model (by writing it to an lp file and then loading it back into a new model). However, this seems to be only a “workaround” that may work for testing and prototyping, but not for more complex code. A big issue here is the overhead of writing a potentially large model into a file within a callback. While I am not sure what Marco's specific needs are, I guess our general question is whether there is a way to interact with the lazy cuts added inside a callback. At the very least, if it is possible to remove them from the pool without having to “rebuild” the model from scratch. 

    -J. 

     

    0
  • Marco Correia
    • Conversationalist
    • Curious
    • Gurobi-versary

    Right. I suppose the mipsolver has a bunch of information not captured just by saving the current model to a file (like current search tree, heuristic scores, etc). So ideally, I would like for a way to just remove the lazy constraints that I added, similarly to what I can do with regular constraints.

    To clarify: My lazy constraints are linear, but the problem is a MIP (there are non-lazy constraints between integer variables). I want to remove the ones I added lazily, which preserves the feasibility of the found solution, and then continue (potentially adding more lazy constraints during the next iteration).

    0
  • Jose Walteros
    • Conversationalist
    • Gurobi-versary
    • First Question

    Marco, 

    Try calling model.update() in between runs. I am not 100% sure, but after some experimentation, this seems to reset the lazy pool. Could you please let me know if this works for you?

    -Jose

    0
  • Maliheh Aramon
    • Gurobi Staff

    Please see the last response to this post. To discard all lazy constraints, you can call model.reset() or make a modification to the model, for example, by adding a dummy variable. However, you cannot access lazy constraints by name, similar to regular constraints and remove a specific set.

    0
  • Marco Correia
    • Conversationalist
    • Curious
    • Gurobi-versary

    Thank you both!

    Doesn't model.reset() basically throws away everything, like starting from scratch? It says this in the docs:

    > Reset the model to an unsolved state, discarding any previously computed solution information.

    The point is to keep the last solution, and search information, and iterate from it.

    Regarding model.update(), does it work if I just call model.update(), or do I need to do some random change somewhere? If the latter, can I set some coefficient to some value and then back to the original value?

    0
  • Maliheh Aramon
    • Gurobi Staff

    For the model.update() to discard the lazy constraints, you would need to modify the model. You can consider adding a dummy variable, for example, and then call the update method. I also tested your suggestion of changing some coefficients and then setting them back to the original value, and it worked fine, meaning that the lazy constraints were discarded and the previous solution was used as a start solution.

    0
  • Marco Correia
    • Conversationalist
    • Curious
    • Gurobi-versary

    Perfect, thank you!

    0

サインインしてコメントを残してください。