jump-dev / PiecewiseLinearOpt.jl

Solve optimization problems containing piecewise linear functions
Other
53 stars 21 forks source link

warmstart p.w.l. variable #21

Open stumarcus314 opened 6 years ago

stumarcus314 commented 6 years ago

Is it possible to warmstart a p.w.l. variable from a previous, related p.w.l. variable? When I use the code excerpt below to try this and set the solver to CBC, I get the error below. In the code below, the number of segments used in the p.w.l. variable log_x increases with each iteration.

WARNING: Ignoring partial starting solution. Cbc requires a feasible value to be specified for all variables.

Construct the piecewise linear approximation of log(x), log(y), and log(z).

num_seg = Array{UInt8}(3)
dx = Array{Array{Float64}}(3)
@variable(m,log_x[1:3]) # piecewise linear approximation of log(x)
@variable(m,log(lower_volume)<=log_volume<=log(upper_volume))
for iter=3:5

  ns = 2^iter
  num_seg[1] = ns # Number of segments used to approximate log x.
  num_seg[2] = ns # Number of segments used to approximate log y.
  num_seg[3] = ns # Number of segments used to approximate log z.

  for d=1:3
    dx[d] = linspace(getlowerbound(x[d]),getupperbound(x[d]),num_seg[d]+1)
    log_x[d] = piecewiselinear(m,x[d],dx[d],log,method=method)
  end
  #@constraint(m,log_volume == sum(log_x))
  #@objective(m,Min,log_volume)
  @objective(m,Min,sum(log_x))
  @time status = solve(m)

  sol_volume = prod(getvalue(x))
  println("solution volume: ",lower_volume," <= ",sol_volume," <= ",upper_volume)
  println("minimum volume: ",min_volume,". volume gap: ",sol_volume-min_volume,".")
  println("solution [x,y,z]: ",lower_x," <= ",getvalue(x)," <= ",upper_x)
  println("optimal [x,y,z]: ",opt_x)
end
joehuchette commented 6 years ago

As the warning suggests, Cbc requires you to warmstart each variable. All the formulations in this package add additional variables, so you would need to warmstart those values that are hidden from you at the moment.

This would be a reasonable thing to implement in the future, but it's not a simple addition. It's also unclear how much warmstarting would improve your solution time, but you could experiment with a solver such as Gurobi that accepts partial warmstart solutions.