forked from MxHbm/Management-Science
-
Notifications
You must be signed in to change notification settings - Fork 0
/
variables.py
130 lines (107 loc) · 7 KB
/
variables.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#### Script for creating instances of different types of variables in the model ####
from parameters import Parameters
import gurobipy as gp
from gurobipy import GRB
class DecisionVariablesModel1:
''' Overall class for decision variables of the model'''
def __init__(self, model: gp.Model, data: Parameters):
self.first_stage = self.FirstStage(model, data)
self.second_stage = self.SecondStage(model, data)
self.binary = self.Binary(model, data)
self.integer = self.Integer(model, data)
class FirstStage:
''' Continuous decision variables of the first stage of the model '''
def __init__(self, model: gp.Model, data: Parameters):
self.EXI = model.addVar(vtype=GRB.CONTINUOUS, name="EXI")
self.ENB = model.addVar(name="ENB") # for debugging
self.TCOST = model.addVar(name="TCOST") # for debugging
self.SN = model.addVar(lb=0, name="SN")
self.RM = model.addVars(data.T, lb=0, name="RMt")
self.IF = model.addVars(data.F, data.T, lb=0, ub = 500, name="IFf_t")
self.FP = model.addVars(data.F, data.T, lb=0, name="FPf_t")
self.V = model.addVars(data.F, data.L, data.T, lb=0, name="Vi_l_t")
self.DV = model.addVars(data.F, data.L, data.T, lb=0, name="DVf_l_t")
self.A = model.addVars(data.MP, data.T, lb=0, name="Am_t")
self.MO = model.addVars(data.MP, data.T, lb=0, name="MOm_t")
self.IWIP = model.addVars(data.MP, data.T, lb=0, name="IWIPm_t")
self.Q = model.addVars(data.MP, data.T, lb=0, name="Qm_t")
self.Z1 = model.addVars(data.MP, data.T, name="Z1m_t")
self.Z2 = model.addVars(data.MP, data.T, name="Z2m_t")
self.Aux = model.addVars(data.MP, data.T, lb=0, name="Auxm_t")
### Variabels needed for the detailed planning model
# self.ED = model.addVars(data.P, data.T, lb=0, name="EDp_t")
# self.PD = model.addVars(data.P, data.T, lb=0, name="PDp_t")
# self.PS = model.addVars(data.P, data.L ,data.T, lb=0, name="PSp_l_t")
# self.IFD = model.addVars(data.P, data.T, lb=0, name="IFDp_t")
# self.VD = model.addVars(data.FT, data.L, data.T, lb=0, name="VDi_l_t")
class SecondStage:
''' Continuous decision variables of the second stage of the model '''
def __init__(self, model: gp.Model, data: Parameters):
self.SA = model.addVars(data.S, data.F, data.L, data.T, lb=0, name="SAs_f_l_t")
self.SO = model.addVars(data.S, data.F, data.L, data.T, lb=0, name="SOs_f_l_t")
self.OS = model.addVars(data.S, data.F, data.L, data.T, lb=0, name="OSs_f_l_t")
self.RC = model.addVars(data.S, lb=0, name="RCs_s")
self.RS = model.addVars(data.S, data.T, lb=0, name="RSs_t")
self.RO = model.addVars(data.S, data.T, lb=0, name="ROs_t")
self.RI = model.addVars(data.S, data.T, lb=0, name="RIs_t")
self.ID = model.addVars(data.S, data.F, data.L, data.T, lb=0, name="IDs_f_l_t")
### Variabels needed for the detailed planning model
# self.RETURN = model.addVar(vtype=GRB.CONTINUOUS, lb = 0, name="RETURN")
# self.COST = model.addVar(vtype=GRB.CONTINUOUS, lb = 0, name="COST")
# self.IDD = model.addVars(data.S, data.P, data.L, data.T, lb=0, name="IDDs_p_l_t")
# self.SOD = model.addVars(data.S, data.P, data.L, data.T, lb=0, name="SODs_p_l_t")
# self.OSD = model.addVars(data.S, data.P, data.L, data.T, lb=0, name="OSDs_p_l_t")
class Binary:
''' Binary decision variables of the model '''
def __init__(self, model: gp.Model, data: Parameters):
self.R1 = model.addVars(data.MP, data.T, vtype=GRB.BINARY, name="R1m_t")
self.R2 = model.addVars(data.MP, data.T, vtype=GRB.BINARY, name="R2m_t")
self.Y = model.addVars(data.MP, data.T, vtype=GRB.BINARY, name="Ym_t")
class Integer:
''' Integer decision variables of the model '''
def __init__(self, model: gp.Model, data: Parameters):
self.TR = model.addVars(data.FT, data.L, data.T, vtype=GRB.INTEGER, lb=0,ub=30, name="TRi_l_t") ### New IMPLEMENTED UPPER BOUND !!!
self.E = model.addVars(data.F, data.T, vtype=GRB.INTEGER, lb=0, name="Ef_t")
self.Z = model.addVars(data.MP, data.T, vtype=GRB.INTEGER, lb=0, name="Zm_t")
### Variabels needed for the detailed planning model
# self.TRD = model.addVars(data.FT, data.L, data.T, vtype=GRB.INTEGER, lb=0, name="TRDi_l_t")
for m in data.MP:
for t in data.T:
self.Z[(m, t)].ub = data.zmax[m]
class DecisionVariablesModel2:
''' Overall class for decision variables of the model'''
def __init__(self, model: gp.Model, data: Parameters):
self.first_stage = self.FirstStage(model, data)
self.second_stage = self.SecondStage(model, data)
self.binary = self.Binary(model, data)
self.integer = self.Integer(model, data)
class FirstStage:
''' Continuous decision variables of the first stage of the model '''
def __init__(self, model: gp.Model, data: Parameters):
### Variabels needed for the detailed planning model
self.ED = model.addVars(data.P, data.T, lb=0, name="EDp_t")
self.PD = model.addVars(data.P, data.T, lb=0, name="PDp_t")
self.PS = model.addVars(data.P, data.L ,data.T, lb=0, name="PSp_l_t")
self.IFD = model.addVars(data.P, data.T, lb=0, name="IFDp_t")
self.VD = model.addVars(data.FT, data.L, data.T, lb=0, name="VDi_l_t")
class SecondStage:
''' Continuous decision variables of the second stage of the model '''
def __init__(self, model: gp.Model, data: Parameters):
### Variabels needed for the detailed planning model
self.RETURN = model.addVar(vtype=GRB.CONTINUOUS, lb = 0, name="RETURN")
self.COST = model.addVar(vtype=GRB.CONTINUOUS, lb = 0, name="COST")
self.IDD = model.addVars(data.S, data.P, data.L, data.T, lb=0, name="IDDs_p_l_t")
self.SOD = model.addVars(data.S, data.P, data.L, data.T, lb=0, name="SODs_p_l_t")
self.OSD = model.addVars(data.S, data.P, data.L, data.T, lb=0, name="OSDs_p_l_t")
class Binary:
''' Binary decision variables of the model '''
def __init__(self, model: gp.Model, data: Parameters):
#self.R1 = model.addVars(data.MP, data.T, vtype=GRB.BINARY, name="R1m_t")
#self.R2 = model.addVars(data.MP, data.T, vtype=GRB.BINARY, name="R2m_t")
#self.Y = model.addVars(data.MP, data.T, vtype=GRB.BINARY, name="Ym_t")
pass
class Integer:
''' Integer decision variables of the model '''
def __init__(self, model: gp.Model, data: Parameters):
### Variabels needed for the detailed planning model
self.TRD = model.addVars(data.FT, data.L, data.T, vtype=GRB.INTEGER, lb=0, name="TRDi_l_t")