Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to convert Optimal ad problem to DPP #124

Open
w601sxs opened this issue Feb 17, 2022 · 1 comment
Open

Trying to convert Optimal ad problem to DPP #124

w601sxs opened this issue Feb 17, 2022 · 1 comment

Comments

@w601sxs
Copy link

w601sxs commented Feb 17, 2022

When I try the following example and check for dpp True:

# Generate data for optimal advertising problem.
import numpy as np
np.random.seed(1)
m = 5
n = 24
SCALE = 10000
B = np.random.lognormal(mean=8, size=(m,1)) + 10000
B = 1000*np.round(B/1000)

P_ad = np.random.uniform(size=(m,1))
P_time = np.random.uniform(size=(1,n))
P = P_ad.dot(P_time)

T = np.sin(np.linspace(-2*np.pi/2,2*np.pi  -2*np.pi/2,n))*SCALE
T += -np.min(T) + SCALE
c = np.random.uniform(size=(m,))
c *= 0.6*T.sum()/c.sum()
c = 1000*np.round(c/1000)
R = np.array([np.random.lognormal(c.min()/c[i]) for i in range(m)])

import cvxpy as cp

D = cp.Variable((m,n))
Si = [cp.minimum(R[i]*P[i,:]@D[i,:].T, B[i]) for i in range(m)]
prob = cp.Problem(cp.Maximize(cp.sum(Si)),
               [D >= 0,
                D.T @ np.ones(m) <= T,
                D @ np.ones(n) >= c])
prob.is_dpp()

Prints True

... But when I convert it to use parameters and variables like this:

# Problem scale
m = 5
n = 24
SCALE = 10000

B = cp.Parameter((m,1))

P = cp.Parameter((m,n))

T = cp.Parameter((n,))

c = cp.Parameter((m,))
R = cp.Parameter((m,))
D = cp.Variable((m,n))

Si = [cp.minimum(R[i]*P[i,:]@D[i,:].T, B[i]) for i in range(m)]

objective = cp.Maximize(cp.sum(Si))

constraints = [D >= 0,
               D.T @ np.ones(m) <= T, 
               D @ np.ones(n) >= c]

problem = cp.Problem(objective, constraints)

problem.is_dpp()

Prints False, so I can't build a layer with it.

@xkhainguyen
Copy link

In the first example, there are no cp parameters at all. Only one variable and everything else is constant.
In the second example, you defined some cp parameters, your objective is definitely not DPP. Try to check the documents and use slack variables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants