New constraint for example Mining
Hello! After I learned the example called mining, I find out when using this constraint
which means if mine m is closed in year t , and it cannot be opened again in the future.
It seems all mines should be opened from the beginning or it will not be opened forever
for a example, one mine is opened in year 1 and closed in year 5
and the avaliable of this mine will look like [1,1,1,1,1,0,0,0,0,0]
But what if the mine is opened in the middle, for a example one mine is opened in year 3 and closed in year 6
and the avaliable of this mine will look like [0,0,1,1,1,1,0,0,0,0]
I tried this
m = gp.Model('Mining')
Years = [1,2,3,4,5,6,7,8,9,10]
Mines = [1,2,3]
Open = m.addVars(Mines,vtype=GRB.INTEGER,lb=1,ub = 10,name="Open") #when the mine is opened
Close = m.addVars(Mines,vtype=GRB.INTEGER,lb=1,ub = 10,name="Close") #when the mine is closed
Available = m.addVars(Mines, Years,vtype=GRB.BINARY, name="Available")
m.addConstrs(Open[M] <= Close[M] for M in Mines) # close is later than open
# force Available=1 when Open<=y<=Close
for M in Mines:
for y in Years:
if y <= Open[M]:
Available[M,y] = 0
if y>= Open[M]:
Available[M,y] = 1
if y >= Close[M]:
Available[M,y] = 0
I know it is not correct, can somebody teach me how to code the proper one in python?
Thanks !
0
-
Official comment
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?.
Post is closed for comments.
Comments
1 comment