Warning of constraint limit exceed fixing
OngoingThe following information for my question is provided below:
I am trying to solve
here M=26=i
Btotal=5*1.5e6
Gain_final_V2V=giv2i-bs(of the pic)=
[2597.5727990651158, 3156.978351073531, 5305.489326799453, 3488.9747383001554, 3556.3703346242582, 4209.642834042834, 3216.2253501689943, 3616.6713767731144, 3721.2489122703337, 4815.242406071199, 7523.679665260634, 5148.824520601632, 4781.0405235624285, 4825.401541460312, 5293.640310589527, 7880.490491309103, 5144.549521524911, 4058.1748037853367, 4029.064234977265, 3670.7731966185406, 4933.650603653963, 4301.815468714573, 4629.004866144499, 7406.363983954186, 4736.348196770436, 4446.8020800583445]
and Gain_final_V2V=gjv2v-bs(of the pic)
=[3411.7021800330017, 4383.893622532522, 3143.920480566424, 3152.1430240894356, 2596.579324386922, 3044.244764660792, 3524.4518965433053, 2510.4417141729073, 2863.8285361945786, 5714.688173071876, 3152.3522620213735, 2668.9943712772624, 2173.361880068201, 3192.161712881365, 4462.116286156692, 1699.3377755789538, 2835.485261732316, 2012.5175075008174, 3480.850305355655, 3853.166079972098]
for O in range(26):
from gurobipy import Model, GRB
# Create a new model
m = Model()
# Define decision variables p[i, j] and pjv2v
p = {}
pjv2v = []
piv2i=[]
for j in range(20):
p[1, j+1] = m.addVar(lb=0, vtype=GRB.BINARY, name="p[1,{}]".format(j+1))
pjv2v.append(m.addVar(lb=-100, ub=23, name="pjv2v[{}]".format(j+1)))
for i in range(26):
piv2i.append(m.addVar(lb=-100, ub=23, name="pjv2v[{}]".format(i+1)))
# Update the model to include the variables
m.update()
# Define the constraint
con = sum(p[1, j+1] for j in range(20)) <= 3 ##eqn_2 of base ppr
# Add the constraint to the model
m.addConstr(con)
noise=[]
rho_n=-(174) #in dbm/hz
Btotal=5*1.5e6
noise=(Btotal*rho_n)/26
# Define the objective function
down = sum(p[1, j+1] * Gain_final_V2V[j] * pjv2v[j] for j in range(20))+noise
interference=sum(p[1, j+1] * Gain_final_V2V[j] * pjv2v[j] for j in range(20))
up=piv2i[O]*Gain_final_V2I[O]
eqn_11f=m.addConstrs(( piv2i[i] <=23 for i in range(26)), name='eqnf')
eqn_11g= m.addConstrs(( pjv2v[j] <=23 for j in range(20)), name='eqng')
auxiliary_variable=m.addVar(lb=-GRB.INFINITY, ub = -1, vtype=GRB.CONTINUOUS, name="Auxiliary_Variable")
m.addConstr(auxiliary_variable==down)
SINR=m.addVar(lb=-GRB.INFINITY,ub=GRB.INFINITY,vtype=GRB.CONTINUOUS, name="SINR")
abc=SINR*auxiliary_variable
m.addConstr(abc==up)
m.params.NumericFocus = 2
#m.setObjective(SINR,GRB.MINIMIZE)
w=m.addVar(lb=0,ub=GRB.INFINITY, vtype=GRB.CONTINUOUS, name="1+SINR")
m.addConstr(w==1+SINR)
z=m.addVar(lb=0,ub=GRB.INFINITY, vtype=GRB.CONTINUOUS, name="log(1+SINR)")
gc = m.addGenConstrLogA(w, z, 2)
m.setObjective(z,GRB.MAXIMIZE)
m.setParam("NonConvex",2)
m.optimize()
but here whenever I run the code the error that pops up is:
how to solve this
kindly help :)
-
also i am having another problem.
here N=20
M=26
and z=3
meaning the eqn:in this eqn the part of denumator sometimes should take 1 ,2 and 3 as summing p[i,j] like the previous pic
but in my following code it is always taking 3
how to fix this26 M should all together handle 20 N
but in my code it is handling 26*3 N
because it is always taking 3
but I want to do that it should take 1 ,2 or 3 sometimes as the sum of 1st snap and alltogether handle 20Ns
how i can fix this
kindly help
best regards
Sujana0 -
Hi Sujana,
In your code you use the `Model.addGenConstrLogA` function. The documentation for this function is here and describes four attributes which control the piecewise linearization that Gurobi performs: FuncPieces, FuncPieceError, FuncPiecesLength, and FuncPieceRatio. Your warning message is suggesting that you make adjustments to these attributes to try and reduce the size of the constraint violations in the solution found. Finding the right values to satisfactorily decrease the violations while achieving a satisfactory solve time may be a process of trial and error.
Respectfully, I do not understand your second question, but perhaps someone else in the community will. You may find inspiration in your colleague's related question.
Best of luck,
Riley0 -
thanks for respoding Riley
my ques is :here M=26
N=20
z=3
and
now my objective is to:
now in my code i am unable to include
this portion and even tho my code works it is always taking the p[1,j] values altho it should take p[i,j] after each iteration where i=26,j=20
and my following code is:Gain_final_V2V=giv2i-bs(of the pic)=
[2597.5727990651158, 3156.978351073531, 5305.489326799453, 3488.9747383001554, 3556.37Gain_final_V2V=gjv2v-bs(of the pic)
Gain_final_V2V=gjv2v-bs(of the pic)
=[3411.7021800330017, 4383.893622532522, 3143.920480566424, 3152.1430240894356, 2596.579324386922, 3044.244764660792, 3524.4518965433053, 2510.4417141729073, 2863.8285361945786, 5714.688173071876, 3152.3522620213735, 2668.9943712772624, 2173.361880068201, 3192.161712881365, 4462.116286156692, 1699.3377755789538, 2835.485261732316, 2012.5175075008174, 3480.850305355655, 3853.166079972098]03346242582, 4209.642834042834, 3216.2253501689943, 3616.6713767731144, 3721.2489122703337, 4815.242406071199, 7523.679665260634, 5148.824520601632, 4781.0405235624285, 4825.401541460312, 5293.640310589527, 7880.490491309103, 5144.549521524911, 4058.1748037853367, 4029.064234977265, 3670.7731966185406, 4933.650603653963, 4301.815468714573, 4629.004866144499, 7406.363983954186, 4736.348196770436, 4446.8020800583445]for O in range(26):
from gurobipy import Model, GRB
# Create a new model
m = Model()
# Define decision variables p[i, j] and pjv2v
p = {}
pjv2v = []
piv2i=[]
for j in range(20): #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
p[O+1, j+1] = m.addVar(lb=0, vtype=GRB.BINARY, name="p[1,{}]".format(j+1))
pjv2v.append(m.addVar(lb=-100, ub=23, name="pjv2v[{}]".format(j+1)))
for i in range(26):
piv2i.append(m.addVar(lb=-100, ub=23, name="pjv2v[{}]".format(i+1)))
# Update the model to include the variables
m.update()
# Define the constraint
con = sum(p[O+1, j+1] for j in range(20)) <= 3 ##eqn_2 of base ppr #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
print(con)
noise=[]
rho_n=-(174) #in dbm/hz
Btotal=5*1.5e6
noise=(Btotal*rho_n)/26
# Define the objective function
down = sum(p[O+1, j+1] * Gain_final_V2V[j] * pjv2v[j] for j in range(20))+noise #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
print(down)
up=piv2i[O]*Gain_final_V2I[O]
eqn_11f=m.addConstrs(( piv2i[i] <=23 for i in range(26)), name='eqnf')
eqn_11g= m.addConstrs(( pjv2v[j] <=23 for j in range(20)), name='eqng') #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
auxiliary_variable=m.addVar(lb=-GRB.INFINITY, ub = -1, vtype=GRB.CONTINUOUS, name="Auxiliary_Variable")
m.addConstr(auxiliary_variable==down)
SINR=m.addVar(lb=-GRB.INFINITY,ub=GRB.INFINITY,vtype=GRB.CONTINUOUS, name="SINR")
abc=SINR*auxiliary_variable
m.addConstr(abc==up)
m.params.NumericFocus = 2
#m.setObjective(SINR,GRB.MAXIMIZE)
w=m.addVar(lb=0,ub=GRB.INFINITY, vtype=GRB.CONTINUOUS, name="1+SINR")
m.addConstr(w==1+SINR)
LOG2_=m.addVar(lb=0,ub=GRB.INFINITY, vtype=GRB.CONTINUOUS, name="log2(1+SINR)")
gc = m.addGenConstrLogA(w, LOG2_, 2)
aaa=(5*1.5e9)/26
m.setObjective((aaa*LOG2_),GRB.MAXIMIZE)
m.setParam("NonConvex",2)
m.optimize()
now whenever i print con then it always gives parameter with p[1,*] means O is not changingkindly tell me how i can incorporate the eqn i am unable to and finally do the objective line
badly in need of your expertise on board
best regards,sujana
0 -
Hi Sujana,
Your model may be correct but you are not giving your variables unique names and so your "con" constraints (which are different) look the same when printing.
Replacename="p[1,{}]".format(j+1)
with
name="p[{},{}]".format(O+1,j+1)
to fix the issue.
- Riley
0 -
thank you riley but i am still unable to incorporate
inside the loop
and when i try that
constr = sum(p[i+1, 20] for i in range(26) if (i+1, 20) in p) <= 1
m.addConstr(constr)
print(constr)inside that for O in range(26):
it always provides:
how to fix this
i want p[1,20]+p[2,20]+p[3,20]................+p[26,20]<=1
also i am unsure of whether my code satistiesseeking your help in both the aspects
Best regards,
sujana0 -
Hi Sujana,
You are looping and increasing the value of O as you loop. You are creating a fresh dictionary p each time in the loop and add items whose first index is O+1. As such your dictionary will only contain variables whose first indice is identical. Are you aware that your code is creating 26 models? It is not clear to me whether you are intending this.
I am also unsure of whether your code satisfies the equation.
- Riley
0 -
thank you for your response riley
yes I m creating 26 models to get 26 values of (Btotal/M)log2(1+sinr) cause i am unable to sum up as my equation is statedhence afterwards getting 26 values I am manually summing up the best objective
if you know how i can sum up all of them at once please let me know
without using the loop how this can be done please let me knowprovided constraints are:
and infos of them is stated above comment
with regards,sujana
0 -
Hi Sujana,
I would check with your teacher if this is the best approach. Or perhaps Tanbir Mahatab Emon can help?
- Riley
0 -
hi riley,
you were right
now i could implement the problem by 1 model
where i have taken i=5,j=5
afterward i=5,j=10 and i=5,j=15
all of them shows the same result as below:
why is this happening?
even though i am changing j manually to record no matter what is j it is giving these 2 values only
my following code right now is:
Gain_final_V2I=[-1556.969928074958, 115088.91771640752, 177694.47911317323, 130573.06734283901, -2659.099484648859]when j=5:
Gain_final_V2V=[-10440.614079695104, 10.739604231320882, -16601.94581425221, -20400.772858467815, -24726.782460859096]
from gurobipy import Model, GRB
m = Model()
# Define decision variables p[i, j] and pjv2v
p = {}
pjv2v = []
piv2i=[]
for O in range(5):
for j in range(5):
p[O+1, j+1] = m.addVar(lb=0, vtype=GRB.BINARY, name="p[{},{}]".format(O+1,j+1))
for i in range(5):
piv2i.append(m.addVar(lb=0, ub=23, name="piv2i[{}]".format(i+1)))
for j in range(5):
pjv2v.append(m.addVar(lb=0, ub=23, name="pjv2v[{}]".format(j+1)))
m.update()
print(p)
print(piv2i)
print(pjv2v)
eqn_1=m.addConstrs(sum(p[i+1,j+1] for i in range(5))<=1 for j in range(5))
eqn_2=m.addConstrs(sum(p[i+1,j+1] for j in range(5))<=3 for i in range(5))
rho_n=-(174) #in dbm/hz
Btotal=5*1.5e6
noise=(Btotal*rho_n)/5
m.setObjective(sum(final),GRB.MAXIMIZE)
m.setParam("NonConvex",2)
m.optimize()when j=15:
Gain_final_V2V=[-20883.423226544437, -8525.550572680211, -14971.827485316973, -43467.82648846318, -21180.286507383677, -14245.638762119452, -43749.53738731502, -13490.670399685234, -10564.329882674141, -16388.62883316595, -9434.96993886823, -3342.047080598144, -11025.490544368218, -19638.213224785184, -18993.831432557614]from gurobipy import Model, GRB
m = Model()
# Define decision variables p[i, j] and pjv2v
p = {}
pjv2v = []
piv2i=[]
for O in range(5):
for j in range(15):
p[O+1, j+1] = m.addVar(lb=0, vtype=GRB.BINARY, name="p[{},{}]".format(O+1,j+1))
for i in range(5):
piv2i.append(m.addVar(lb=0, ub=23, name="piv2i[{}]".format(i+1)))
for j in range(15):
pjv2v.append(m.addVar(lb=0, ub=23, name="pjv2v[{}]".format(j+1)))
m.update()eqn_1=m.addConstrs(sum(p[i+1,j+1] for i in range(5))<=1 for j in range(15))
eqn_2=m.addConstrs(sum(p[i+1,j+1] for j in range(15))<=3 for i in range(5))rho_n=-(174) #in dbm/hz
Btotal=5*1.5e6
noise=(Btotal*rho_n)/5down = [0] * 5
up=[0]*5
auxiliary_variable=[0]*5
SINR=[0]*5
abc=[0]*5
w=[0]*5
LOG2_=[0]*5
gc=[0]*5
aaa=[0]*5
final=[0]*5
for k in range(5):
down[k]= sum(p[k+1,j+1]*pjv2v[j]*Gain_final_V2V[j] for j in range(15))+noise
up[k]=piv2i[k]*Gain_final_V2I[k]
auxiliary_variable[k]=m.addVar(lb=-GRB.INFINITY ,ub =-1, vtype=GRB.CONTINUOUS, name="Auxiliary_Variable")
m.addConstr(auxiliary_variable[k]==down[k])
SINR[k]=m.addVar(lb=0,ub=GRB.INFINITY,vtype=GRB.CONTINUOUS, name="SINR")
abc[k]=SINR[k]*auxiliary_variable[k]
m.addConstr(abc[k]==up[k])
m.params.NumericFocus = 2
w[k]=m.addVar(lb=1,ub=GRB.INFINITY, vtype=GRB.CONTINUOUS, name="1+SINR")
m.addConstr(w[k]==1+SINR[k])
LOG2_[k]=m.addVar(lb=-GRB.INFINITY,ub=GRB.INFINITY, vtype=GRB.CONTINUOUS, name="log2(1+SINR)")
gc[k] = m.addGenConstrLogA(w[k], LOG2_[k], 2)
aaa[k]=(5*1.5e6)/5
final[k]=aaa[k]*LOG2_[k]m.setObjective(sum(final),GRB.MAXIMIZE)
m.setParam("NonConvex",2)
m.optimize()
why no matter whatever j i am giving it is providing either 803 or 4.33
kindly help
where am i going wrong
best regards
sujana0
Please sign in to leave a comment.
Comments
9 comments