Skip to main content

How to test the performance of an optimal solution on different scenarios?



  • Silke Horn
    Gurobi Staff Gurobi Staff

    I'm not sure I fully understand what you want to do.

    If you simply want to evaluate a different objective function at the current solution, you can define a new expression and then use the getValue method to compute the value of this expression in the current solution. (The link goes to the method for linear expressions, but there are similar methods for quadratic or matrix expressions.)

    If that is not what you want, please give us some more details about exactly what you want to change and what you want to fix.

  • Runqing Zhao
    First Question

    Hi Silke,

    Sorry for my unclear description. I don't need to change the objective function. I just want to calculate the objective value when only the demand in my model is changed.


    Let me try to describe my problem again:

    My original model has:

    basic setting: a fixed traffic demand (passengers/minute),  the cost to buy a car for tranpsort department

    objective function: minimize (passengers' delay + the total cost to buy cars)

    decision variables: dispatch pattern and fleet size

    constrains: maximum fleet size......

    Step 1: I will get an optimal solution through Gurobi's optimization, including how the cars are dispatched and how many cars will be bought under this scenario.

    Step 2: After I solve this model, I want to change the traffic demand to be stochastic, and apply the optimal solution in step 1 (dispatch pattern and fleet size), to calculate the new objective value when demand is changed. Only the traffic demand is changed in this step, the objective value and all other parts of the model are the same.

    I have finished the step 1 and I don't know how to achieve step 2.

     Thank you very much!  Please let me know if my description is still unclear.

  • Silke Horn
    Gurobi Staff Gurobi Staff

    Thanks for adding more details.

    You can modify your model, then simply call optimize again. Gurobi will then use the known solution the warm-start the second optimization.

    With the scenario feature that came with Gurobi 9, you can also define both model versions in one model and then have Gurobi solve them in one go.


Please sign in to leave a comment.