- Join over
**1.5M+ people** - Join over
**100K+ communities** - Free
**without limits** - Create
**your own community**

I wrote the following code to try to solve the above problem:

```
import numpy as np
from cvxpy import *
# Number of robots
nr = 10
# Number of time steps
T = 10
# time sample [sec]
dt = 0.2
# Foorprint (radius) [meters]
R = 1.5
# robots' initial conditions
X0 = []
for i in range(nr):
x0 = np.random.randn(3,1)
X0.append(x0)
# Robots' goals
G = []
for i in range(nr):
g = np.random.randn(3,1)
G.append(g)
# variables list of robots states, one for each robot
Xlist = []
# variables list of robots contorls, one for each robot
Vlist = []
# Max velocity [m/s]
vmax = 1.0
# Create states/controls variables
for i in range(nr):
Xlist.append(Variable(3, T+1))
Vlist.append(Variable(3,T))
# define objecives
cost = 0
for i in range(nr):
cost += sum_squares(Xlist[i][:,T] - G[i])
obj = Minimize(cost)
constr = []
# define constraints
for ri in range(nr):
constr.append(Xlist[ri][:,0] == X0[ri])
for t in range(T):
constr.append(Xlist[ri][:,t+1] == Xlist[ri][:,t] + dt*Vlist[ri][:,t])
constr.append(norm(Vlist[ri][:,t], 'inf') <= vmax)
if ri < (nr-1):
for rj in range(ri+1, nr):
constr.append( sum_squares(Xlist[ri][:,t+1] - Xlist[rj][:,t+1]) > 2*R )
prob = Problem(obj, constr)
prob.solve()
```

However, it gives the following error

`cvxpy.error.DCPError: Problem does not follow DCP rules.`

What does this mean?

I've installed MOSEK 8.1 to run with CVXPY yet when I run cvxpy with it, I get this attribute error. Does this mean CVXPY can't run with MOSEK 8.1 yet?

How can i fix this error

@miggy2129 your issue seems similar to a Git issue described here: cvxgrp/cvxpy#497. Please post your information there so we can consolidate the information (and keep you updated on a solution).

In principle, cvxpy 1.0 has been tested with mosek 7 and mosek 8. It has also been tested with pre-releases of mosek 9.

@Cerebrock In order to call SuperSCS from CVXPy you need to use this version of CVXPy: https://github.com/nishi951/cvxpy. You also need to install the Python interface of SuperSCS (see https://kul-forbes.github.io/scs/page_installation.html)

@Cerebrock You mean differences between this version of CVXPy and the official version? Mark Nishimura's version was forked a while ago and I think it has not been updated since. I believe at some point, SuperSCS will be properly integrated with CVX(Py). By the way, how did you come across SuperSCS?

Hey guys, I'm having an issue with cvxpy/scs, I have a docker container which installs all the dependencies and then I try to run the example from the cvxpy github page with GPU=True and SCS and it returns "Status: Unbounded" but with GPU=False it works ok. Also the scs-python GPU test returns "Status: Unbounded". What could be the error?

Dockerfile: https://gist.github.com/ruloweb/5378aa16b1e75f56c5b0a84386d8859b

Example: https://gist.github.com/ruloweb/d1c2653a29321cde43158076d1890cf9

OS: Ubuntu 16.04 on Azure, image NVIDIA GPU Cloud image, NVIDIA Tesla P100

nvidia-smi displays GPU usage.

Hey guys, I am new to CVXPY and went through the documentation. I wrote couple maximization functions recently but am currently stuck on a way to design a constraint....I have my code and problem on Stackoverflow but not many people are able to answer it ..... https://stackoverflow.com/questions/54336137/how-to-define-variables-constrains-to-pandas-dataframe-when-using-cvxpy-for-opt/54356289#54356289

Would be awesome if u guys can just check it out and let me know where I am making a mistake

Hi all, I have a small question about dmcp. I believe the function f(x,y) = x^2 * y is DMCP, since if we fix either x or y, then the function is convex. However, when I pose this as a cvxpy optimization problem and run is_dmcp, it returns false. Anyone know what could be happening?

Here's the code, if helpful.

`z = cp.Variable()`

`w = cp.Variable()`

`cost = (z**2)*w`

`prob = cp.Problem(cp.Minimize(cost), [z >= 0, w >= 0])`

`print("problem is DMCP: {}".format(dmcp.is_dmcp(prob))) # false?`

Hi, all

I got stucked in applying the following form:(CVXPY)

x = cp.Variable(data_length)

obj = cp.Minimize((-mu_hat @ x)**2*cp.quad_form(x, covar))

constraints = [sum(x) == 1, x <= [bounds[i][1] for i in range(len(bounds))], x >= [bounds[i][0] for i in range(len(bounds))]]

prob = cp.Problem(obj, constraints)

prob.solve()

This creates "Problem does not follow DCP rules." But mathematically the objective function is convex. Also when I applied this by CVXOPT, it was fine.

Would you help me out to deal with this problem?

Hi all,

I am trying to write an optimization problem where I require using a cp.Parameter(integer=true) array as indices to populate another parameter:

rho_cvxpy = cp.Parameter((1,T), integer=True)

mass_cvxpy = cp.Parameter((1,n_modes))

massT_cvxpy = cp.Parameter((1,T))

massT_cvxpy == mass_cvxpy[rho_cvxpy]

This is obviously throwing an error that rho_cvxpy can't be used for indexing. Is there another way I can do this? Any help would be really appreciated! Thanks!

I am trying to write an optimization problem where I require using a cp.Parameter(integer=true) array as indices to populate another parameter:

rho_cvxpy = cp.Parameter((1,T), integer=True)

mass_cvxpy = cp.Parameter((1,n_modes))

massT_cvxpy = cp.Parameter((1,T))

massT_cvxpy == mass_cvxpy[rho_cvxpy]

This is obviously throwing an error that rho_cvxpy can't be used for indexing. Is there another way I can do this? Any help would be really appreciated! Thanks!

But usually, if you want to take exactly one element of a set, you might do something like

`c * x`

where `x`

is a boolean vector
(and

`c`

is a fixed vector) while adding `cp.sum(x)==1`

Hey @angeris thank you for your reply! That's a very cool suggestion for getting a single element of a set but I might not be able to use it for my case because 'indices' (given below) is not a boolean vector.

I am actually trying to recreate an operation which is very similar to the 'gather' command in TensorFlow:

tf.gather(params, indices)

where, in my case, in cvxpy 'params' and 'indices' are both cp.parameters.

Thank you so much for your help, I really appreciate it!

this is my script def optimize_average_latency(number_of_edge, migration_threat, latency_threat, beta):

F = cp.Variable(pos=True, name="F")

G = cp.Variable(pos=True, name="G")

y = cp.Variable(shape=(number_of_edge, number_of_edge), boolean =True)

F = cp.Variable(pos=True, name="F")

G = cp.Variable(pos=True, name="G")

y = cp.Variable(shape=(number_of_edge, number_of_edge), boolean =True)

```
objective = cp.Maximize(cp.log(migration_threat - F) + cp.log(latency_threat - G))
constraints = []
# Constraint: each base station connect to only one edge_server
for j in range(number_of_edge):
constraint_2 = 0
for i in range(number_of_edge):
constraint_2 = constraint_2 + y[i,j]
constraints += [constraint_2 - 1 == 0]
# Constraint: at least one edge have service
constraint_3 = 0
for i in range(number_of_edge):
for j in range(number_of_edge):
constraint_3 = constraint_3 + y[i,j]
constraints += [constraint_3 >= number_of_edge]
# Constraint: one edge serve for max n base_station
for i in range(number_of_edge):
constraint_4 = 0
for j in range(number_of_edge):
constraint_4 = constraint_4 + y[i,j]
constraints += [constraint_4 <= 4]
# Constraint: migration cost lower than optimal value
constraint_5 = sum(sum(y[i,j]*d[i,0]*beta for i in range(number_of_edge)) for j in range(number_of_edge))
constraints += [F >= constraint_5]
#Constraint: latency cost lower than optimal value
constraint_6 = sum(y[i,j]*d[i,j]*u[j] for j in range(number_of_edge) for i in range(number_of_edge))
constraints += [G >= constraint_6]
constraints += [F <= migration_threat]
constraints += [G <= latency_threat]
prob = cp.Problem(objective, constraints)
print("Optimal value", prob.solve(feastol=1e-24))
print("Optimal var")
print(y.value)
print(F.value)
print(G.value)
print(prob.status)
```

CVXPY claim that result is optimal but

Optimal value -0.0

Optimal var

[[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]

[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]

[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]

[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]

[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]

[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]

[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]

[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]

[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]

[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]]

0.0

0.0

optimal

Optimal var

[[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]

[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]

[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]

[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]

[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]

[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]

[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]

[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]

[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]

[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]]

0.0

0.0

optimal

all zero and it also violates my constraint ( constraint_3)

Can anyone help me to find what happen ?

@vutuong This is surprising, since I have

```
number_of_edge = 10
beta = 1
d = np.random.randn(number_of_edge, number_of_edge)
u = np.random.randn(number_of_edge)
migration_threat = 1
latency_threat = 2
F = cp.Variable(pos=True, name="F")
G = cp.Variable(pos=True, name="G")
y = cp.Variable(shape=(number_of_edge, number_of_edge), boolean=True)
objective = cp.Maximize(cp.log(migration_threat - F) + cp.log(latency_threat - G))
constraints = []
# Constraint: each base station connect to only one edge_server
for j in range(number_of_edge):
constraint_2 = 0
for i in range(number_of_edge):
constraint_2 = constraint_2 + y[i,j]
constraints += [constraint_2 - 1 == 0]
# Constraint: at least one edge have service
constraint_3 = 0
for i in range(number_of_edge):
for j in range(number_of_edge):
constraint_3 = constraint_3 + y[i,j]
constraints += [constraint_3 >= number_of_edge]
# Constraint: one edge serve for max n base_station
for i in range(number_of_edge):
constraint_4 = 0
for j in range(number_of_edge):
constraint_4 = constraint_4 + y[i,j]
constraints += [constraint_4 <= 4]
# Constraint: migration cost lower than optimal value
constraint_5 = sum(sum(y[i,j]*d[i,0]*beta for i in range(number_of_edge)) for j in range(number_of_edge))
constraints += [F >= constraint_5]
#Constraint: latency cost lower than optimal value
constraint_6 = sum(y[i,j]*d[i,j]*u[j] for j in range(number_of_edge) for i in range(number_of_edge))
constraints += [G >= constraint_6]
constraints += [F <= migration_threat]
constraints += [G <= latency_threat]
prob = cp.Problem(objective, constraints)
print("Optimal value", prob.solve())
print("Optimal var")
print(y.value)
print(F.value)
print(G.value)
print(prob.status)
```

which returns

```
Optimal value 0.6931471511429453
Optimal var
[[0. 0. 0. 0. 0. 0. 1. 0. 0. 1.]
[0. 0. 0. 0. 1. 0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0. 0. 0. 1. 0. 0.]
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[0. 0. 0. 1. 0. 1. 0. 0. 0. 0.]
[1. 1. 1. 0. 0. 0. 0. 0. 1. 0.]]
2.470714188795853e-09
1.3950814059526806e-08
optimal
```

This appears to be correct (feasible). What are your values for `beta`

, `number_of_edge`

, etc? Additionally, can you print out what `prob.solve(verbose=True)`

gives?

Do you think that i have problem with CVXPY installation? or what solver should i need to install to run this code ? @angeris Thanks.

I follow this guide https://www.cvxpy.org/install/index.html . Got the same result in Window and Linux 16.04

root@host3:/home/host3# python nash_bargaining.py

('Optimal value', None)

Optimal var

None

None

None

infeasible_inaccurate

('Optimal value', None)

Optimal var

None

None

None

infeasible_inaccurate

var y = cp.Variable(shape=(len1, len2), boolean =True)

CVXPY report that "Constraints are not DCP"

With Gurobi lib, there are no problem when i add this kind of constraint. so, Is there any way to add this kind of constraint ?