Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initial Guess/Warm start in CVXPY: give a hint of the solution

In this bit of code:

import cvxpy as cvx

# Examples: linear programming
# Create two scalar optimization variables.
x = cvx.Variable()
y = cvx.Variable()

# Create 4 constraints.
constraints = [x >= 0,
               y >= 0,
               x + y >= 1,
              2*x + y >= 1]

# Form objective.
obj = cvx.Minimize(x+y)

# Form and solve problem.
prob = cvx.Problem(obj, constraints)
prob.solve(warm_start= True)  # Returns the optimal value.
print ("status:", prob.status)
print ("optimal value", prob.value)
print ("optimal var", x.value, y.value)

I'm looking for a way to choose the warm start value myself (for example: x = 1/2 and y = 1/2), not the previous solver result.

Is there any way to give the solver this input? And if not, is there a non-commercial alternative to cvxpy?

like image 381
Riley Avatar asked Sep 13 '18 13:09

Riley


People also ask

What is the default solver for Cvxpy?

By default CVXPY calls the solver most specialized to the problem type. For example, ECOS is called for SOCPs. SCS can handle all problems (except mixed-integer programs). If the problem is a QP, CVXPY will use OSQP.

What is the difference between Cvxpy and Cvxopt?

In cvxopt you have to write your problem in a more standard way for the type of solver you want to use, whereas cvxpy is supposed to adapt your problem based on the structure you use for your problem (they are supposed to select the type of cvxopt solver depending on your problem and pass the variables in an standard ...


2 Answers

You can manually assign the values using x.value = 1/2, and then passing the warm_start=True parameter in the available solvers. Keep in mind not all solvers allow this, one that does is for example SCS.

More info available on: https://www.cvxpy.org/tutorial/advanced/index.html

like image 123
Cerebrock Avatar answered Oct 10 '22 05:10

Cerebrock


To the 2021 readers: today is impossible (in cvxpy) to give a hand to the solver with an initial guess. Warm start right now only works when you solve the same problem with different parameter values, initializing with the previous solution (see https://github.com/cvxpy/cvxpy/issues/1355).

like image 45
PIII Avatar answered Oct 10 '22 05:10

PIII