Constraints do not follow DCP rules in CVXPY

2024/11/15 6:23:51

I want to solve this problem using CVXPY but I don't know why I get the following error message:

DCPError: Problem does not follow DCP rules.

I guess my constraints are not DCP. Is there any way to model this in DCP?

n_k = [10000, 20000]request_rate = [15, 10]p_k_1 = np.random.rand(n_k[0])p_k_2 = np.random.rand(n_k[1])#params
p_k_param_1 = cvx.Parameter(1, n_k[0], sign="positive")
p_k_param_1 = np.array(p_k_1)
p_k_param_2 = cvx.Parameter(1, n_k[1], sign="positive")
p_k_param_2 = np.array(p_k_2)request_rate_param = cvx.Parameter(2, sign="positive")
request_rate_param = np.array(request_rate)#varibales
c_k = cvx.Variable(2)
T_k = cvx.Variable(2)constraints = [ cvx.sum_entries(c_k) <= 10000,c_k >= 0,c_k[0]==cvx.sum_entries(1-cvx.exp(-request_rate_param[0]*T_k[0]*p_k_param_1)),c_k[1]==cvx.sum_entries(1-cvx.exp((-request_rate_param[1]*T_k[1])*p_k_param_2))]h_k_1 = request_rate_param[0] * cvx.sum_entries((p_k_param_1 * (1-cvx.exp(-request_rate_param[0]*T_k[0]*p_k_param_1))))
h_k_2 = request_rate_param[1]* cvx.sum_entries(p_k_param_2 * (1-cvx.exp(-request_rate_param[1]*T_k[1]*p_k_param_2)))obj = cvx.Maximize(cvx.log(h_k_1) + cvx.log(h_k_2))
prob = cvx.Problem(obj, constraints)
prob.solve(verbose=True)
Answer

Your utility function:

cvx.log(h_k_1) + cvx.log(h_k_2)

is not convex.

These rules might be able to tell you what you can sub in your solution.

https://en.xdnf.cn/q/72310.html

Related Q&A

is this betweenness calculation correct?

I try to calculate betweenness for all nodes for the path from 2 to 6 in this simple graph.G=nx.Graph() edge=[(1,5),(2,5),(3,5),(4,5),(4,6),(5,7),(7,6)] G.add_edges_from(edge) btw=nx.betweenness_centra…

Why does PIL thumbnail not resizing correctly?

I am trying to create and save a thumbnail image when saving the original user image in the userProfile model in my project, below is my code:def save(self, *args, **kwargs):super(UserProfile, self).sa…

Put the legend of pandas bar plot with secondary y axis in front of bars

I have a pandas DataFrame with a secondary y axis and I need a bar plot with the legend in front of the bars. Currently, one set of bars is in front of the legend. If possible, I would also like to pla…

Printing floats with a specific number of zeros

I know how to control the number of decimals, but how do I control the number of zeros specifically?For example:104.06250000 -> 104.0625 119.00000 -> 119.0 72.000000 -> 72.0

How do I make a matplotlib scatter plot square?

In gnuplot I can do this to get a square plot:set size squareWhat is the equivalent in matplotlib? I have tried this:import matplotlib matplotlib.use(Agg) import matplotlib.pyplot as plt plt.rcParams[…

Efficiently determining if a business is open or not based on store hours

Given a time (eg. currently 4:24pm on Tuesday), Id like to be able to select all businesses that are currently open out of a set of businesses. I have the open and close times for every business for ev…

parsing .xsd in python

I need to parse a file .xsd in Python as i would parse an XML. I am using libxml2. I have to parse an xsd that look as follow: <xs:complexType name="ClassType"> <xs:sequence><x…

How to get the params from a saved XGBoost model

Im trying to train a XGBoost model using the params below: xgb_params = {objective: binary:logistic,eval_metric: auc,lambda: 0.8,alpha: 0.4,max_depth: 10,max_delta_step: 1,verbose: True }Since my input…

Reverse Label Encoding giving error

I label encoded my categorical data into numerical data using label encoderdata[Resi] = LabelEncoder().fit_transform(data[Resi])But I when I try to find how they are mapped internally usinglist(LabelEn…

how to check if a value exists in a dataframe

hi I am trying to get the column name of a dataframe which contains a specific word,eg: i have a dataframe,NA good employee Not available best employer not required well mana…