This seems inefficient. You are right that there is no single method (function) to remove all constraints from a model. You are correct to iterate over all the constraints and remove them. However, you should wait to call GRBModel::update() until after the loop is finished. Thanks to the lazy updates, this will be far more efficient than calling GRBModel::update() in each iteration.
Other ideas that may be better, depending on your application:
1) Start fresh with a new GRBModel object.
2) If you simply need to add one new constraint (on the objective), you will be more efficient to add that through a model modification.
> Well, the result is a GRBException, which must come from the line
>
> mymodel.addConstr(lex, GRB_LESS_EQUAL,
>
> (mymodel.get(GRB_DoubleAttr_ObjVal) * 1.001) ); .
>
> So, why does this occur, how do I help it, and how can I - efficiently
> - remove all constraints from my model and set other ones afterwards?
One should always catch the exception to determine the exact error. I can't reproduce the situation based on this code fragment, but my guess is that the ObjVal attribute is no longer available after you've made the model modifications.
> By the way, is it possible that the documentation is incomplete? When
> I enter "mymodel.r" in my programming environment, I get offered some
> completions, like "reset" and "remove", but also "relax", and there is
> no member function relax() listed for GRBModel in the Reference
> Manual.
This is an undocumented feature. In most cases, the undocumented features are not officially supported. In this case, you should relax a model by modifying the VarType attributes.
This seems inefficient. You are right that there is no single method (function) to remove all constraints from a model. You are correct to iterate over all the constraints and remove them. However, you should wait to call GRBModel::update() until after the loop is finished. Thanks to the lazy updates, this will be far more efficient than calling GRBModel::update() in each iteration.
while ( mymodel.get(GRB_IntAttr_NumConstrs) > 0 )
--
---
You received this message because you are subscribed to the Google Groups "Gurobi Optimization" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gurobi+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
model.remove(model.getConstrs())