CVXPY is a Python-embedded modeling language for convex optimization problems inspired by the MATLAB package CVX.
Questions tagged [cvxpy]
609 questions
5
votes
1 answer
Solving Assignment Problem with conditional minimum group sizes using CVXPY
I'm using cvxpy within python to solve a particular type of assignment problem. I'd like to assign M people to N groups in a way that minimizes cost, with the following constraints on groups:
Groups cannot have more than J members
If a group is…

profj
- 311
- 3
- 10
5
votes
1 answer
CVXPY Import Error - 'sum_entries' is not defined
I just install the latest version of cvxpy using pip install and am working my way through the examples provided at http://nbviewer.jupyter.org/github/cvxgrp/cvx_short_course/blob/master/applications/portfolio_optimization.ipynb
The code does not…

The User
- 55
- 3
- 11
5
votes
0 answers
CVXPY: suppress output for GLPK
I am using cvxpy and since the update to 1.0.6 I get unwanted output when calling GLPK.
import cvxpy as cvx
x = cvx.Variable(2)
p = cvx.Problem(cvx.Minimize(x[0]), [x[0] + x[1] == 1, x[0] - x[1] >= 1])
p.solve(solver = cvx.GLPK)
In IPython3 this…

Hennich
- 682
- 3
- 18
5
votes
1 answer
CVXPY: how to efficiently solve a series of similar problems
I have a large problem defined in CVXPY modelling language. I want to solve series of this problems - still the same format but with different parameters (constants).
I found out that after calling problem.solve() internal problem generating takes…

dave-cz
- 413
- 4
- 22
5
votes
3 answers
How to create an inequality constraint on the inner product of two columns in CVXPY?
Suppose my constraint is the product of the first column and third column of the matrix variable is greater than one. How can I implement in CVXPY? Example:
w = Variable(4,3)
In Matlab, my constraint would be:
w(:,1)'*w(:,3)>1
How can I implement…

Creator
- 139
- 1
- 3
- 15
5
votes
1 answer
How to write several constraint in cvxpy?
I want to add many constraint in a optimization problem under cvxpy. In matlab I can do so by adding a line subject to and then use for loop to generate the constraints. How can I do the same work in cvxpy, as there is no 'subject to' concepts in…

Creator
- 139
- 1
- 3
- 15
5
votes
1 answer
Check constraints are ok in cvxpy with actual values
When solving optimisation problems in cvxpy, is there a nice way to check that the constraints are valid by substituing in actual values for the optimisation variables?
I have a complicated optimisation problem (100+ constraints), but I know what…

mjeppesen
- 1,040
- 1
- 10
- 14
4
votes
2 answers
Problem solving a minimization problem in cvxpy
I have a linear optimization problem, which can be expressed in a cost function code like this:
value_to_minimize = 0.0;
for i in range(0, len(v_1)):
value_to_minimize += np.abs(v_1[i] - (v_2[i] * c1 + v_3[i] * c2 + v_4[i] * c3));
The task of…

MerklT
- 803
- 7
- 18
4
votes
1 answer
Least square approximation of a polynomial with a constraint on the derivative in Python
I'm trying to fit a polynomial of the third degree through a number of points. This could be a very simple problem when not constraining the derivative. I found some promising solutions using CVXPY to combine least squares with constraints but so…

takje
- 2,630
- 28
- 47
4
votes
1 answer
How to solve the 8 queens problem with CVXPY?
I am really new to CVXPY. I am trying to solve the 8 queens problem, i.e., the problem of placing 8 chess queens on an 8 x 8 chessboard so that no two queens threaten each other. As I understand it, the constrainsts should be:
sum of each row…

Binyamin Even
- 3,318
- 1
- 18
- 45
4
votes
0 answers
How to solve a facility location allocation (IP) problem in CVXPY
I am learning to solve optimization problems using CVXPY, so I started with the following simple facility location allocation problem.
The Code in CVXPY is given as:
Fi = np.array([1,1,1]) # Fixed cost of each facility
Ci = np.array([15, 10,…

Muhammad Asif Khan
- 319
- 4
- 11
4
votes
0 answers
Violated constraint in CVXPY
I have a problem that can sometimes be infeasible. The desired behaviour is relax the constraint that was violated and continue, but alert the user that a constraint was violated.
I noticed that CVXPY 1.0 has a new violation() method that looks to…

swmfg
- 1,279
- 1
- 10
- 18
4
votes
1 answer
How to take the square root of quad_form output in CVXPY?
I am trying to solve a problem that involves \sqrt{w^t \Sigma w} in the objective function. To compute w^t \Sigma w, I use the quad_form function. How do I take its square root?
When in the code I try to write
risk = sqrt(quad_form(w, E))
I am…

Volodymyr Kruglov
- 469
- 3
- 14
3
votes
0 answers
CVXPY takes compilation time for days for MNIST data
Trying to simulate SOCP optimization problem using multiple class SVM for MNIST data. Could see that with solver set to ECOS, cvxpy compilation takes days to complete it.
CVXPY
…

Sree
- 61
- 2
3
votes
0 answers
How do I create a conditional asymmetric objective function for regression?
I'm trying to use a conditional asymmetric loss function with a regression model and am having issues. I want to penalize wrong way results but the direction flips depending on the sign of the variable.
import numpy as np
def…

MK23
- 31
- 2