Decision Optimization

 View Only
Expand all | Collapse all

Designating an IloCplex as MIP before adding any variables or constraints

  • 1.  Designating an IloCplex as MIP before adding any variables or constraints

    Posted Mon September 14, 2020 04:07 AM
    Hi,
    I am creating a LP/MIP using a custom class MyCplex, which extends IloCplex. In this class I might add some constraints involving boolean Variables, depending on the chosen settings. If I do, I would like to initialize these variables with a value. I understand that this can be done by adding a warm start to the model and changing the warm start as shown in the following snippet.


    Since I am adding this constraint multiple times I don't want to add a warm start everytime I call the function which adds the constraint. I tried two solutions. First I tried to add the warm start outside of the function at the very start directly after creating the LP/MIP. This leads to the following error:

    Second, I tried checking if the program already has an associated warm start, with the following line:

    This leads to another error:


    I found a way to check if an IloCplex is a MIP, but now way of designating it as one. I could after the creation of the entire model iterate through all variables and then set the initial values, however this would require a lot of restructuring as I have no saved reference to these variables after adding them to the model.

    I thought about adding a dummy boolean variable right at the start, in order to turn the model into an MIP which would (hopefully) allow me to add a MIP start, but this feels like a workaround, which I would like to avoid.

    Is there a way of adding the MIP start beforehand without the suggested solutions?


    ------------------------------
    Lia Gardner
    ------------------------------

    #DecisionOptimization


  • 2.  RE: Designating an IloCplex as MIP before adding any variables or constraints

    Posted Mon September 14, 2020 04:50 AM
    From what you write it seems that it may be sufficient to use function getNMIPStarts() which will check the number of MIP starts in the model without raising an exception.

    Unfortunately, there is no way to explicitly mark a model as MIP, so your best option is to add a dummy variable or something else that implicity converts the model to a MIP, like SOS constraints etc.

    As an alternative, you could add to your class an instance variables that holds the MIP start to be added (or a list of MIP starts to be added). Then instead of adding the MIP start directly, you just register it with this variable. Additionally, you overwrite the solve() method and in the overridden method you first add any pending MIP starts (from the instance variable) and then call the super class's solve() method.

    ------------------------------
    Daniel Junglas
    ------------------------------