CVXPY is a Python-embedded modeling language for convex optimization problems inspired by the MATLAB package CVX.
Questions tagged [cvxpy]
609 questions
3
votes
1 answer
Multiplying two variables in CVXPY
I'm in need of an LP where you can multiply two non-constants. Here is the following code that I am trying to perform:
import cvxpy as cvx
a = cvx.Variable()
b = cvx.Variable()
c = cvx.Variable()
obj = cvx.Maximize(((0.4270437386 * a) +…

Alex McLean
- 2,524
- 5
- 30
- 53
3
votes
1 answer
Building diagonal block matrix with some blocks as variable CVXPY
I want to generate a (diagonal) block matrix (preferably sparse) in CVXPY.
Some blocks can be eye(m) or anything but I have a block which is:
from cvxopt import *
import cvxpy as cvx
import numpy as np
import scipy
W = cvx.Variable(m,1)
W_diag =…

hoot
- 65
- 9
3
votes
1 answer
ArithmeticError causing "Rank(A) < p or Rank([G; A]) < n" error in cvxpy
I'm trying to use cvxpy (and hence cvxopt) to model optimal power flow in a relatively simple network with 28 nodes and 37 lines, but getting a "Rank(A) < p or Rank([G; A]) < n" error.
(Using the same code, I can find the optimal solution for a much…

mjeppesen
- 1,040
- 1
- 10
- 14
2
votes
1 answer
How to solve integer optimization problem with Python?
I have a system of linear equations Ax=b, A - matrix (m x n), x - (n x 1), b - (m x 1). The matrix A is almost all 0 and contains only ~ n*m^(1/2) non-zero elements. m and n can be quite large, such as n=28680, m=22500 or n=28680, m=62500. It is…

Alex
- 23
- 4
2
votes
2 answers
Two matrix multiplication operations in CVXPY gives UNKNOWN curvature and makes the problem not DCP
I want to solve the following optimization problem using cvxpy:
Maximize(y @ A @ x)
where A is a (n,m)-size matrix of positive valued elements;
x is boolean vector of is length m;
y is boolean vector is length n.
The constraints are:
sum(x)==1 and…

CodeWanderer
- 73
- 5
2
votes
0 answers
Python - solving for risk budget portfolio using cvxpy
I'm looking to write a set of code that allows me to set risk budget constraints to individual positions in a portfolio, i.e. each position to contribute a set amount of risk to the portfolio, and I'm looking to do it specifically in CVXPY as I have…

Dazz W
- 113
- 8
2
votes
0 answers
cvxpy DPP Doesn't Work For Complex Parameter
I need to solve a large number of small convex optimisation problems with the same constraints, so I am trying to use cvxpy's DPP feature to cache/speedup compilation. It doesn't seem to work for my problem containing a single complex matrix…

Calvin Liu
- 21
- 3
2
votes
1 answer
Python CVXPY matrix variable with fixed elements
I'm trying to use CVXPY to minimize an objective function with a quadratic term A.T @ P @ A with constant matrix P and variable matrix A, both of size n x n. This problem is not convex, but I want only A[0][0] as the variable while every other…

pythonml
- 23
- 2
2
votes
1 answer
Look-up based objective function in Cvxpy
I'd like to define an objective function based on a lookup table. As an example, we have an integer programming problem (binary) where we can pick one or more actions from a set of actions. Our cvxpy.Variable is:
element_vars = [1, 0, 0, 1] …

Sad Vaseb
- 299
- 3
- 10
2
votes
1 answer
cvxpy print constraint equation post optimization
I probably have a very easy question, but I couldn't find an answer online.
I have an optimization problem with many constraints. Hence, when the solution is infeasible, I loop through each of the constraints to explore what could have gone wrong.…

Angelo
- 1,594
- 5
- 17
- 50
2
votes
0 answers
Errors in computing the Euclidian distance between point and convex polytope using cvxpy
I am trying to find the euclidian distance between a d-dimensional polytope defined as A x <= b and a point, called point in the code below, that I am certain is outside of the polytope. This is a convex quadratic minimization problem. I would like…

Patrickens
- 321
- 3
- 14
2
votes
0 answers
CVXPY: quasiconvex fractional programming problem with variance term
I have a portfolio optimization problem where my objective function is the mean divided by the standard deviation.
The variance is the difference of two random variables so is computed as Var(X) + Var(Y) - 2 * Cov(X, Y). The variance term is…

eadains
- 63
- 2
2
votes
1 answer
Integer Programming for NNC
I'm trying to implement Integer Programming for Nearest Neighbor Classifier in python using cvxpy.
Short intro
Given a dataset of n points with a color (red or blue) we would like to choose the minimal number of candidate points, s.t for each point…

Timor
- 499
- 4
- 11
2
votes
0 answers
cvxpy - How to obtain the variable value after each iteration?
I am using cvxpy to solve a second order cone program. I have used the boilerplate code as mentioned in the cvxpy website - cvxpy SOCP webpage. I do not know how to obtain the variable value after each iteration...
Code from the link:
# Import…

Anirudh Ramesh
- 23
- 3
2
votes
3 answers
How to properly install qpsolvers for Python on Windows?
I am trying to install qpsolvers using pip.
The installation goes without errors, and the module imports properly afterwards.
However, qpsolvers has no available solvers for it to use :
import qpsolvers
print(qpsolvers.available_solvers)
returns…

user18496484
- 23
- 4