Writing multiple times in model.write() lp file in Gurobi without overwriting the previous content in C++

Viewed 42

I am solving a multi-scenario optimization model where I am running the same model multiple times. Here, I am changing the parameters of the objective function each time. I want to check if my model is being developed correctly or not. So, I am using model.write(). But it is overwriting the previous content. Basically, I want to do an "append" to the previous content in the file. A snippet of the code is given below:

GRBLinExpr Return_Objective = 0;
for (i = 0; i < Scenarios; i++)
{
    for (j = 0; j < Securities; j++)
    {
        Return_Objective += probabilty_matrix[k][i] * (return_matrix[i][j] * Weights[j]);
    }
}
//Here, k represents the number of scenarios.
model.setObjective(Return_Objective);
//Now writing the model to file
model.write("C:/Users/Bharati/Desktop/Lee/mip1_Markowitz.lp");

Any suggestions would be of great help to me.

1 Answers

The Model::write() method does not let you append to the file due to the requirements of the LP file format. What you should do is name each file separately for each step in your program, then compare or combine the files separately.

Related