Deleting and Removing Modeling Objects

A special type of modification is that of deleting a modeling object by calling its end() method. Consider, for example, the deletion of a variable. What happens if the variable you delete has been used in constraints or the objective, or has been extracted to CPLEX? Concert Technology carefully removes the deleted variable from all other modeling objects and algorithms that may keep a reference to the variable in question. This applies to any modeling object to be removed. However, user-defined handles to the removed variable are not managed by Concert Technology. Instead it is up to the user to make sure that these handles are not used after the deletion of the modeling object. The only operation allowed then is the assignment operator.

Concert Technology also provides a way to remove a modeling object from all other modeling objects and algorithms exactly the same way as when deleting it, yet without deleting the modeling object. This is done by calling the method removeFromAll(). This may be helpful to temporarily remove a variable from your model while keeping the option to add it back later on.

It is important to understand the difference between the above and calling model.remove(obj) for an object obj. In this case, it does not necessarily mean that obj is removed from the problem CPLEX maintains. Whether or not this happens depends on the removed object being referenced by yet another extracted modeling object. Usually when a constraint is removed from the extracted model, the constraint is also removed from CPLEX as well, unless it was added to the model more than once.

Consider the case where a variable is removed from CPLEX after one of the delete or remove operations discussed above. If the cplex object contains a simplex basis, by default the status for that variable is removed from the basis as well. If the variable happens to be basic, the operation corrupts the basis. If this is not desired, CPLEX provides a delete mode that first pivots the variable out of the basis before removing it. The resulting basis is not guaranteed to be feasible or optimal, but it will still constitute a valid basis. To select this mode, call method:

cplex.setDeleteMode(IloCplex::FixBasis); 

Similarly, when removing a constraint with the FixBasis delete mode, CPLEX will pivot the corresponding slack or artificial variable into the basis before removing it, to assure maintaining a valid basis. In either case, if no valid basis was available in the first place, no pivot operation is performed. To set the delete mode back to its default setting, call:

cplex.setDeleteMode(IloCplex::LeaveBasis);

Previous Page: Modifying a Model  Return to Top Next Page: Changing Variable Type