How Can I Reduce The Value Of Coefficients for a Decision Variable?
AnsweredHi, apologies for the vague title.
I'm currently modeling an MILP problem where I decide whether I pursue an action according to constraints, for the following periods. I'm using Python.
You can see the objective function's mathematical expression here.
I have eliminated several information regarding the model due to confidentiality.
My main aim here is to see which members of the list has the value of 1 for all three periods.
If ActionVar[1,1] == 1, that means that I pursue the action.
Additionally, if ActionVar[1,1] == 1, said variable must be 1 as well for the following periods. I can achieve this result with a logical constraint, no problem there. My main problem is that since I am solving this problem for 3 periods, the model is solving the "already decided" variables again for the next period as well, and this performance of the model really drags the solution run to last for more than 1 hour. When I write the model into .mps and .lp files, I get this display for the objective function:
3 C0 + 3 C1 + 3 C2 + 2 C3 + 2 C4 + 2 C5 + 1 C6 + 1 C7 + 1 C8
C0, C1, C2 represent ActionVar[1,1], ActionVar[1,2], ActionVar[1,3]
C3, C4, C5 represent ActionVar[2,1], ActionVar[2,2], ActionVar[2,3]
C6, C7, C8 represent ActionVar[3,1], ActionVar[3,2], ActionVar[3,3]
As you can see, the coefficients for the C0, C1 and C2 variables are 3, so the model is involving these variables to the solution again. Is there any way that I can reduce every coefficient to 1? I have tried variable slicing, but I think since I have defined the variable as a dict, it gave me an error. I wonder if there's any solution to my problem.
You can see a similar code below. Thanks in advance.
periods = [1,2,3]
decision = [1,2,3]
#Edit forgot to define the model here.
m = Model("Action")
#Defining decision variable
ActionVar = {}
for t in periods:
for i in decision:
ActionVar[t,i] = m.addVar(obj=0, vtype=GRB.BINARY)
#Objective Function
m.setObjective(quicksum([ActionVar[t,i] for t in periods for i in decision]))
m.modelSense = GRB.MINIMIZE
I'm not adding the constraints as I have to reveal as little as possible here. I believe this is an issue regarding the objective function. Thanks so much for your time!
-
You can adjust the objective coefficient of a linear variable via its Obj attribute, e.g.,
ActionVar[1,1].Obj = 1
Would this work?
1 -
I am currently running it. Do I have to change the Obj attribute in the defining decision variable part?
as in:
ActionVar = {}
for t in periods:
for i in decision:
ActionVar[t,i] = m.addVar(obj=1, vtype=GRB.BINARY)Funny thing, I no longer get the incremented coefficients in the display part. Unfortunately, it still takes too long for model to run.
Also, since my model uses parameters that are very large, I have cropped my main dataframe in order to tried to see the model clearly, I noticed something in the stats part.
When I run the model that is on a smaller scale, I get this result:
m.printStats()
Output:
Statistics for model:
Linear constraint matrix: 90 Constrs, 50 Vars, 280 NZs
Variable types: 0 Continuous,
50 Integer (50 Binary)
Matrix coefficient range: [ 1, 1 ]
Objective coefficient range: [ 1, 1 ]
Variable bound range: [ 1, 1 ]
RHS coefficient range: [ 1, 1 ]But when I run my model that is on a larger scale (actual model), I get this result when I run m.printStats():
Statistics for model:
Linear constraint matrix: 7706 Constrs, 3670 Vars, 148972 NZs
Variable types : 0 Continuous, 3670 Integer (3670 Binary)
Matrix coefficient range: [ 1, 3 ]
Objective coefficient range : [ 1, 1 ]
Variable bound range: [ 1, 1 ]
RHS coefficient range: [ 1, 1 ]I noticed that Matrix Coefficient Range is = [1,3] a different range compared to smaller scaled model. How can I interpret this? I really really only cropped my dataframe I'm extracting the data, so I doubt it's caused by my data size.
Thanks in advance!
1 -
Do I have to change the Obj attribute in the defining decision variable part?
No this might not work in your case, because you create the objective afterwards. To be sure that all objective coefficients are set to 1 after you created your objective, you have to set the objective attribute of each variable
#Objective Function
m.setObjective(quicksum([ActionVar[t,i] for t in periods for i in decision]))
m.modelSense = GRB.MINIMIZE
for t in periods:
for i in decision:
ActionVar[t,i].Obj = 1I noticed that Matrix Coefficient Range is = [1,3] a different range compared to smaller scaled model. How can I interpret this?
The matrix coefficient range means that there are coefficients between 1 and 3 in your linear coefficient matrix. You can use the write method to write an LP file and have a closer look at the model you built.
m.write("myLP.lp")
0 -
Hi, apologies for the late response. We have decided to use Lagrangian Relaxation to reduce the solving time, but not yet formed the updated obj function. This problem request can be closed. Thanks so much for your time and effort.
0
Please sign in to leave a comment.
Comments
4 comments