Gurobi warm start heuristics

1,002 views
Skip to first unread message

Cord Kaldemeyer

unread,
Feb 12, 2015, 5:30:04 AM2/12/15
to
I have read that gurobi can use warm starts by setting the option "warmstart=True" and created a simple heuristic to test if it improves the calculation time of my model. But even after some changes on the heuristic, I haven't yet not noticed a significant improvement of the calculation time. This made me skeptical and now I am not sure if I have implemented the warm start option the right way..

This is a short example of my implementation:

from pyomo.environ import *
from pyomo.opt import SolverFactory
import random

# Create model
mdl
= ConcreteModel()

# Timesteps
timesteps_max
= 24
timesteps
= range(0, timesteps_max)

# Set for timesteps
mdl
.T = Set(ordered=True, initialize=timesteps)

# Parameters
mdl
.Parameter1 = Param(mdl.T, initialize=dict(zip(timesteps,
                                                 
[random.randrange(0, 50, 1)
                                                 
for _ in
                                                  range
(timesteps_max)]))
mdl
.Parameter2 = Param(mdl.T, initialize=dict(zip(timesteps,
                                                 
[random.randrange(0, 50, 1)
                                                 
for _ in
                                                  range
(timesteps_max)]))

# Variables
mdl
.Variable1 = Var(mdl.T, within=NonNegativeReals)
mdl
.Variable2 = Var(mdl.T, within=NonNegativeReals)
mdl
.Variable3 = Var(mdl.T, within=NonNegativeReals)

...

# Example constraint
def example_constr_rule(mdl, t):
   
return (mdl.Variable1[t] >= 0)
mdl
.example_constr = Constraint(mdl.T, rule=example_constr_rule)

...

# Create instance
instance
= mdl.create()

# Choose solver
opt
= SolverFactory("gurobi")

# Warmstart heuristics
for i in timesteps:
   
# Initial value for Variable1
    instance
.Variable1[i] = 5

   
# Values for Param2
   
if (instance.Parameter1[i] > instance.Parameter2[i]):
        instance
.Variable2[i] = 5
   
else:
        instance
.Variable2[i] = 2

   
# Is it also possible to compare values of instance variables?
   
if (instance.Variable1[i-1] > instance.Variable2[i-1]):
        instance
.Variable3[i] = 5
   
else:
        instance
.Variable3[i] = 2

# Solve model
results
= opt.solve(instance, tee=True, warmstart=True)


Is this the right way to implement warm starts? Any hints are welcome!

Thanks in advance
Cord

Watson, Jean-Paul

unread,
Feb 12, 2015, 1:01:44 PM2/12/15
to pyomo...@googlegroups.com
This looks like the correct way to implement warm-starts. That said, the bulletproof way to check this is to look at the output of CPLEX/Gurobi, and see if there is an explicit indication that it found and accepted a valid initial solution. Both of those solvers are clear in terms of indicating if there is a warm-start, and if it wasn’t accepted, why it wasn’t accepted. 

As to whether warm-starts actually cut solve times, “it depends”. By supplying initial solutions, you may actually end up disabling some primal heuristics at the root node, and the latter may end up providing a better solution than your warm-start. It also depends on where the time is being spent in the solve. If a significant amount of time is expended proving optimality of a good solution (as is often the case), then you won’t see a noticeable change in run time by supplying a warm start.

jpw


mdl
.Variable3=Var(mdl.T, within=NonNegativeReals)


...

# Example constraint
def example_constr_rule(mdl, t):
   
return(mdl.Variable1[t]>=0)

mdl
.example_constr =Constraint(mdl.T, rule=example_constr_rule)


...

# Create instance
instance
= mdl.create()

# Choose solver

opt
=SolverFactory("gurobi")


# Warmstart heuristics
for i in timesteps:
   
# Initial value for Variable1
    instance
.Variable1[i]=5


   
# Values for positive tertiary reserve capacity and provision
   
if(instance.Parameter1[i]> instance.Parameter2[i]):

        instance
.Variable2[i]=5
   
else:
        instance
.Variable2[i]=2

   
# Is it also possible to compare values of instance variables?

   
if(instance.Variable1[i-1]> instance.Variable2[i-1]):

        instance
.Variable3[i]=5
   
else:
        instance
.Variable3[i]=2

# Solve model
results
= opt.solve(instance, tee=True, warmstart=True)


Is this the right way to implement warm starts? Any hints are welcome!

Thanks in advance
Cord

--
You received this message because you are subscribed to the Google Groups "Pyomo Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Cord Kaldemeyer

unread,
Feb 13, 2015, 5:24:18 AM2/13/15
to pyomo...@googlegroups.com
I have now found the line in the Gurobi output: "Read MIP start from file /tmp/tmpEhAxRv.gurobi.mst". So indeed everything seems to work well.

Your explanation concerning the solve times made the whole thing clearer to me. Thanks!!
Reply all
Reply to author
Forward
0 new messages