Open adhl-0216 opened 2 months ago
from pulp import LpMinimize, LpProblem, LpVariable, lpSum
prob = LpProblem("Server_Fleet_Management", LpMinimize)
x_s1 = LpVariable('x_s1', lowBound=0, cat='Integer') x_s2 = LpVariable('x_s2', lowBound=0, cat='Integer') x_s3 = LpVariable('x_s3', lowBound=0, cat='Integer')
prob += 500 x_s1 + 600 x_s2 + 200 * x_s3
prob += 60 x_s1 >= 1000 # Timestep 1 demand for s1 prob += 75 x_s2 >= 2000 # Timestep 1 demand for s2 prob += 8 * x_s3 >= 150 # Timestep 1 demand for s3
prob.solve()
print("Status:", LpStatus[prob.status]) print("Number of s1 servers:", x_s1.varValue) print("Number of s2 servers:", x_s2.varValue) print("Number of s3 servers:", x_s3.varValue)
from pulp import LpMaximize, LpProblem, LpVariable, LpStatus
prob = LpProblem("Maximize_Revenue", LpMaximize)
x_s1 = LpVariable('x_s1', lowBound=0, cat='Integer') # CPU server type s1 x_s2 = LpVariable('x_s2', lowBound=0, cat='Integer') # CPU server type s2 x_s3 = LpVariable('x_s3', lowBound=0, cat='Integer') # GPU server type s3
cpu_slot_size = 2 gpu_slot_size = 4
s1_capacity = 60 # CPU server type s1 capacity s2_capacity = 75 # CPU server type s2 capacity s3_capacity = 8 # GPU server type s3 capacity
demand_s1 = 500000 # Demand for CPU server type s1 demand_s2 = 50000 # Demand for CPU server type s2 demand_s3 = 400 # Demand for GPU server type s3
data_center_capacity = 15300
cpu_revenue_per_unit = 15 gpu_revenue_per_unit = 1680
prob += (cpu_revenue_per_unit (s1_capacity x_s1 + s2_capacity x_s2) + gpu_revenue_per_unit (s3_capacity * x_s3)), "Total Revenue"
prob += s1_capacity x_s1 <= demand_s1, "Demand for s1" prob += s2_capacity x_s2 <= demand_s2, "Demand for s2" prob += s3_capacity * x_s3 <= demand_s3, "Demand for s3"
prob += cpu_slot_size (x_s1 + x_s2) + gpu_slot_size x_s3 <= data_center_capacity, "Slot Capacity"
prob.solve()
print("Status:", LpStatus[prob.status]) print("Number of s1 servers:", x_s1.varValue) print("Number of s2 servers:", x_s2.varValue) print("Number of s3 servers:", x_s3.varValue)
demand_met_s1 = s1_capacity x_s1.varValue if x_s1.varValue is not None else 0 demand_met_s2 = s2_capacity x_s2.varValue if x_s2.varValue is not None else 0 demand_met_s3 = s3_capacity * x_s3.varValue if x_s3.varValue is not None else 0
revenue_s1 = cpu_revenue_per_unit demand_met_s1 revenue_s2 = cpu_revenue_per_unit demand_met_s2 revenue_s3 = gpu_revenue_per_unit * demand_met_s3
print("Demand met by s1 servers:", demand_met_s1) print("Revenue generated by s1 servers: $", revenue_s1)
print("Demand met by s2 servers:", demand_met_s2) print("Revenue generated by s2 servers: $", revenue_s2)
print("Demand met by s3 servers:", demand_met_s3) print("Revenue generated by s3 servers: $", revenue_s3)
total_revenue = revenue_s1 + revenue_s2 + revenue_s3 print("Total revenue: $", total_revenue)
print("Slot used by s1 servers:", cpu_slot_size x_s1.varValue if x_s1.varValue is not None else "N/A") print("Slot used by s2 servers:", cpu_slot_size x_s2.varValue if x_s2.varValue is not None else "N/A") print("Slot used by s3 servers:", gpu_slot_size x_s3.varValue if x_s3.varValue is not None else "N/A") print("Total slots used:", (cpu_slot_size (x_s1.varValue if x_s1.varValue is not None else 0) + cpu_slot_size (x_s2.varValue if x_s2.varValue is not None else 0) + gpu_slot_size (x_s3.varValue if x_s3.varValue is not None else 0)))
` from pulp import LpMaximize, LpProblem, LpVariable, LpStatus
prob = LpProblem("Maximize_Profit", LpMaximize)
x_s1 = LpVariable('x_s1', lowBound=0, cat='Integer') # CPU server type s1 x_s2 = LpVariable('x_s2', lowBound=0, cat='Integer') # CPU server type s2 x_s3 = LpVariable('x_s3', lowBound=0, cat='Integer') # GPU server type s3
cpu_slot_size = 2 gpu_slot_size = 4
s1_capacity = 60 # CPU server type s1 capacity s2_capacity = 75 # CPU server type s2 capacity s3_capacity = 8 # GPU server type s3 capacity
demand_s1 = 446707 # Demand for CPU server type s1 demand_s2 = 54424 # Demand for CPU server type s2 demand_s3 = 408 # Demand for GPU server type s3
data_center_capacity = 15300
cpu_revenue_per_unit = 15 gpu_revenue_per_unit = 1680
s1_energy_consumption = 400 s2_energy_consumption = 400 s3_energy_consumption = 3000
s1_avg_maintenance_cost = 288 s2_avg_maintenance_cost = 308 s3_avg_maintenance_cost = 2310
energy_cost_rate = 0.35
revenue = (cpu_revenue_per_unit (s1_capacity x_s1 + s2_capacity x_s2) + gpu_revenue_per_unit (s3_capacity * x_s3))
s1_cost = (s1_energy_consumption energy_cost_rate + s1_avg_maintenance_cost) x_s1 s2_cost = (s2_energy_consumption energy_cost_rate + s2_avg_maintenance_cost) x_s2 s3_cost = (s3_energy_consumption energy_cost_rate + s3_avg_maintenance_cost) x_s3 total_cost = s1_cost + s2_cost + s3_cost
profit = revenue - total_cost prob += profit, "Total Profit"
prob += s1_capacity x_s1 <= demand_s1, "Demand for s1" prob += s2_capacity x_s2 <= demand_s2, "Demand for s2" prob += s3_capacity * x_s3 <= demand_s3, "Demand for s3"
prob += cpu_slot_size (x_s1 + x_s2) + gpu_slot_size \ x_s3 <= data_center_capacity, "Slot Capacity"
prob.solve()
demand_met_s1 = s1_capacity x_s1.varValue if x_s1.varValue is not None else 0 demand_met_s2 = s2_capacity x_s2.varValue if x_s2.varValue is not None else 0 demand_met_s3 = s3_capacity * x_s3.varValue if x_s3.varValue is not None else 0
revenue_s1 = cpu_revenue_per_unit demand_met_s1 revenue_s2 = cpu_revenue_per_unit demand_met_s2 revenue_s3 = gpu_revenue_per_unit * demand_met_s3
cost_s1 = (s1_energy_consumption energy_cost_rate + s1_avg_maintenance_cost) \ x_s1.varValue if x_s1.varValue is not None else 0 cost_s2 = (s2_energy_consumption energy_cost_rate + s2_avg_maintenance_cost) \ x_s2.varValue if x_s2.varValue is not None else 0 cost_s3 = (s3_energy_consumption energy_cost_rate + s3_avg_maintenance_cost) \ x_s3.varValue if x_s3.varValue is not None else 0
profit_s1 = revenue_s1 - cost_s1 profit_s2 = revenue_s2 - cost_s2 profit_s3 = revenue_s3 - cost_s3
print("="50) print("Optimization Status:", LpStatus[prob.status]) print("="50)
print(f"Server Type: s1 (CPU)") print(f" Number of Servers: {x_s1.varValue}") print(f" Demand Met: {demand_met_s1}") print(f" Revenue Generated: ${revenue_s1:,.2f}") print(f" Cost Incurred: ${cost_s1:,.2f}") print(f" Profit: ${profit_s1:,.2f}") print("-"*50)
print(f"Server Type: s2 (CPU)") print(f" Number of Servers: {x_s2.varValue}") print(f" Demand Met: {demand_met_s2}") print(f" Revenue Generated: ${revenue_s2:,.2f}") print(f" Cost Incurred: ${cost_s2:,.2f}") print(f" Profit: ${profit_s2:,.2f}") print("-"*50)
print(f"Server Type: s3 (GPU)") print(f" Number of Servers: {x_s3.varValue}") print(f" Demand Met: {demand_met_s3}") print(f" Revenue Generated: ${revenue_s3:,.2f}") print(f" Cost Incurred: ${cost_s3:,.2f}") print(f" Profit: ${profit_s3:,.2f}") print("-"*50)
total_revenue = revenue_s1 + revenue_s2 + revenue_s3 total_cost = cost_s1 + cost_s2 + cost_s3 total_profit = total_revenue - total_cost total_slots_used = (cpu_slot_size (x_s1.varValue if x_s1.varValue is not None else 0) + cpu_slot_size (x_s2.varValue if x_s2.varValue is not None else 0) + gpu_slot_size * (x_s3.varValue if x_s3.varValue is not None else 0))
print("="50) print("Overall Results") print(f" Total Revenue: ${total_revenue:,.2f}") print(f" Total Cost: ${total_cost:,.2f}") print(f" Total Profit: ${total_profit:,.2f}") print(f" Total Slots Used: {total_slots_used}/{data_center_capacity}") print("="50) `
A potential approach involves the following steps:
Initial Purchase: Start by buying servers to meet the initial demand, focusing on the server types that align with the latency sensitivity of each data center.
Dynamic Adjustment: As time progresses, continue to monitor the demand and adjust the server allocation: