This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import gurobipy as gp | |
from gurobipy import GRB | |
## First Stage Constants | |
i = np.array([6,14,27]) | |
s = np.array([1,5,3]) | |
B = 1000 | |
S = 100 | |
## Second Stage Constants |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# SOLVING | |
m.optimize() | |
result = x.x | |
print(f"Our Server farm will cost ${np.round(m.ObjVal,2)}. We should buy {result[0]} CPUs, {result[1]} GPUs, and {result[2]} TPUs ") | |
# Our Server farm will cost $995.6. We should buy 51.0 CPUs, 5.0 GPUs, and 8.0 TPUs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# CONSTRAINTS | |
## Installation Budget | |
m.addConstr(i @ x <= B) | |
## Space | |
m.addConstr(s @ x <= S) | |
## Meet demand in each scenario | |
m.addConstrs(( | |
x + y[:,k] >= d_xi[:,k] for k in range(K) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# OBJECTIVE | |
m.setObjective(i @ x + gp.quicksum(c @ y[:,k] * p[k] for k in range(K))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
m = gp.Model("2SP") | |
m.ModelSense = GRB.MINIMIZE | |
m.setParam('OutputFlag', 0) # Telling gurobi to not be verbose | |
m.params.logtoconsole=0 | |
# VARIABLES | |
## First Stage Decision variable | |
x = m.addMVar((3,), vtype = GRB.INTEGER, name = "x") | |
## 2nd stage decision for each potential scenario | |
y = m.addMVar((3,K), vtype = GRB.INTEGER, name = "y") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import gurobipy as gp | |
from gurobipy import GRB | |
## First Stage Constants | |
i = np.array([6,14,27]) | |
s = np.array([1,5,3]) | |
B = 1000 | |
S = 100 | |
## Second Stage Constants |