Questions tagged [cvxpy]

CVXPY is a Python-embedded modeling language for convex optimization problems inspired by the MATLAB package CVX.

609 questions
1
vote
1 answer

Is there a way to write a constraint in cvxpy on an Array variabile N so that all values in the Array are either 0 or the same values?

Let's suppose we have X=variable(n, boolean=True) and an array B of length n containing repeated integers. I want to write a constraint so that the element by element multiplication of the solution of X by B is an Array containing as elements 0 or a…
1
vote
0 answers

CVXPY: Equality Norm Constraints

I am confused with my constraints. I have a matrix variable with size [8,2] and two norm constraints cp.norm(V[:,0])**2==5 and cp.norm(V[:,1])**2==5. But there is a error said that : DCPError: Problem does not follow DCP rules. Specifically: The…
1
vote
1 answer

How to use a parameter and its reciprocal in a CVXPY DPP?

In the following test program import cvxpy as cp def cp_log_ratio_norm(a, b): # Both `a * cp.inv_pos(b)` and `a / b` make this problem non-DPP return cp.maximum(a * b, b * cp.inv_pos(a)) var = cp.Variable(pos=True) param =…
Richard
  • 56,349
  • 34
  • 180
  • 251
1
vote
1 answer

DCP error for quadratic optimization problem

I am using cvxpy to solve quadratic optimization problem. The quadratic problem is part of another optimization routine which iteratively feeds the quadratic optimization problem P matrix and q vector. The issue is if my number of variables are less…
user1443613
  • 171
  • 2
  • 11
1
vote
0 answers

Error "failed building wheel for cvxpy" encountered when attempting to install CVXPY

I've encountered the error below while attempting to install the convex optimization library CVXPY. I previously encountered this (distinct) error, and was able to rectify it by updating my pip installation with python -m pip install --upgrade…
10GeV
  • 453
  • 2
  • 14
1
vote
1 answer

How can I perform a calculation on my CVXPY variable?

I have a convex programming problem in which I am constrained to several periods, each of these periods represents different times of a day in minutes. Assume we are constrained to 7 periods in the day, these periods consist [480, 360, 120, 180, 90,…
Aidan Donnelly
  • 369
  • 5
  • 19
1
vote
0 answers

How to reshape a CVXPY variable for constraint calculation?

I have an integer variable named running_times which is length N. Each index in this variable represents the running time required for each period over a 24 hour period. I need to perform a calculation against some data which has the shape (48,)…
1
vote
1 answer

Python - portfolio opimisation using CVXPY - DCP rules not followed

I have a problem related to portfolio opimisation, I am trying to maximise an objective which is: say I have column A, and solution weights, my objective is to minimise the sum of [(weights - column A)^ 2 / column A], in other words, it's a problem…
1
vote
1 answer

How do I make a ranged constraint in CVXPY?

I want to minimize the change between two vectors using CVXPY, but I get a DCPError: import cvxpy as cv proposed_vector = cv.Variable(100) prob = cv.Problem( cv.Minimize( # guess_vector is my initial starting vector of length 100 …
PyRsquared
  • 6,970
  • 11
  • 50
  • 86
1
vote
1 answer

Constraint of cvxpy: How to constrain only some elements of the variable to be nonzero?

I have a variable made of 961 elements. And I have a constraint like this: only 8 elements of the variable are nonzero, and the others are 0. I don't know how to express this constraint in cvxpy. I tried this: import cvxpy as cp K = cp.Variable(961,…
1
vote
0 answers

Modeling separable NON-CONVEX constrained optimization problem in CVXPY

I have an optimization problem that I'd like to solve in python. The objective function is NOT convex everywhere. I thought I'd use CVXPY, but any other package in python is welcome. Here is the problem: Minimize p(x_1) + p(x_2) + ... +…
1
vote
1 answer

Computing the Analytic Center of a Polytope in Python

I have a polytope described by a set of inequalities and equalities that are given as numpy arrays. These arrays will usually be quite large, as they describe the LP-relaxation of an MIPLIB problem. I want to compute the analytic center of this…
1
vote
0 answers

DCP analysis rules for the constraints in CVXPY

Why is cvxpy.square(x) >= 0 in the constraints not DCP (disciplined convex programming; explicit rules can be found here), whereas the expression cvxpy.square(x) as an objective is DCP? A more general question would be: what role does >= play in the…
1
vote
1 answer

Can't assign necessary entries to a CVXPY (2,2) Variable

I'm trying to implement this research paper. The paper is combining multiple metrics into a single joint formulation. The authors manipulate it into an optimization problem, with the condition of a semi-definite program. M, N are whole numbers. …
cupofcalculus
  • 51
  • 1
  • 8
1
vote
1 answer

How to populate a variable/expression in CVXPY

I am trying to translate cvx code to cvxpy. The major problem I am having is finding something similar to expressions. I used expressions to set values for an entire list of len(n). From my understanding the attributes in a variable in cvx cannot be…