dcp error
JreigeF opened this issue · comments
JreigeF commented
My error
DCPError: Problem does not follow DCP rules. Specifically:
The objective is not DCP. Its following subexpressions are not:
Promote(1.0, (5,)) / (var67 + -[0.13333333 0.25 0.13333333 0.05 0.16666667])
Don't know how to fix this error even though the obj is convex
** Code **
import cvxpy as cp
import numpy as np
Lambda = np.array([8/60, 15/60, 8/60, 3/60, 10/60]) # Arrival rates (lambda_i)
Lambda_tot = np.sum(Lambda) # Total arrival rate (lambda)
L = 1e10 # Job size in number of instructions
C = np.array([1e4, 1e4, 1e4, 1e4, 1e4]) # Server capacities (C_i) in MIPS
e = np.array([0.01,0.02,0.03,0.04,0.05]) # Cost of 1 MIPS in USD per month
n = len(C) # Number of queues
# Calculate minimum budget
c = L / 1e6 * e
B_min = np.sum(c * Lambda)
# Define the decision variables
u = cp.Variable(n) # Server capacities
# Define the objective function
obj = (1/Lambda_tot)*(cp.sum(Lambda *(1/(u-Lambda))))
# Define the constraints
constraints = [
u >= Lambda, # Stability conditions
cp.sum(e * u) <= B_min # Budget constraint
]
# Define the problem
problem = cp.Problem(cp.Minimize(obj), constraints)
# Solve the problem
problem.solve()
# Print the optimal solution
if problem.status == 'optimal':
optimal_capacities = u.value
minimum_budget = problem.value
print("Optimal Capacities:", optimal_capacities)
print("Minimum Budget Needed:", minimum_budget)
else:
print("Problem not solved to optimality.")
Steven Diamond commented
You need to use cvxpy.inv_pos