TraleeTinkerers / Huawei-Hack-Phase1

MIT License
0 stars 0 forks source link

Research #2

Open adhl-0216 opened 2 months ago

Henry-0810 commented 2 months ago

A potential approach involves the following steps:

  1. 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.

  2. Dynamic Adjustment: As time progresses, continue to monitor the demand and adjust the server allocation:

    • If demand increases significantly, buy more servers.
    • If a data center becomes over-utilized, consider moving servers to balance the load.
    • If servers are nearing the end of their lifespan, replace them.
adhl-0216 commented 2 months ago

from pulp import LpMinimize, LpProblem, LpVariable, lpSum

Create the MILP problem

prob = LpProblem("Server_Fleet_Management", LpMinimize)

Define decision variables

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')

Objective function

prob += 500 x_s1 + 600 x_s2 + 200 * x_s3

Constraints

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

Add additional constraints for timesteps 2 and 3 similarly

Solve the problem

prob.solve()

Print the results

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)

adhl-0216 commented 2 months ago

from pulp import LpMaximize, LpProblem, LpVariable, LpStatus

Create the MILP problem

prob = LpProblem("Maximize_Revenue", LpMaximize)

Define decision variables

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

Slot sizes

cpu_slot_size = 2 gpu_slot_size = 4

Server capacities

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 to meet

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 slot capacity

data_center_capacity = 15300

Revenue per unit of demand met

cpu_revenue_per_unit = 15 gpu_revenue_per_unit = 1680

Objective function: Maximize total revenue

prob += (cpu_revenue_per_unit (s1_capacity x_s1 + s2_capacity x_s2) + gpu_revenue_per_unit (s3_capacity * x_s3)), "Total Revenue"

Demand constraints

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"

Slot capacity constraint

prob += cpu_slot_size (x_s1 + x_s2) + gpu_slot_size x_s3 <= data_center_capacity, "Slot Capacity"

Solve the problem

prob.solve()

Print the results

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)

Calculate the demand met by each server type

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

Calculate the revenue generated by each server type

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 and revenue generated by each server type

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)

Print total revenue

total_revenue = revenue_s1 + revenue_s2 + revenue_s3 print("Total revenue: $", total_revenue)

Additional debug information

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)))

adhl-0216 commented 2 months ago

` from pulp import LpMaximize, LpProblem, LpVariable, LpStatus

Create the MILP problem

prob = LpProblem("Maximize_Profit", LpMaximize)

Define decision variables

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

Slot sizes

cpu_slot_size = 2 gpu_slot_size = 4

Server capacities (units of demand they can meet)

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 to meet

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 slot capacity

data_center_capacity = 15300

Revenue per unit of demand met

cpu_revenue_per_unit = 15 gpu_revenue_per_unit = 1680

Costs: Energy consumption and maintenance for each server type

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

energy_cost_rate = 0.35

Objective function: Maximize profit (revenue - cost)

Revenue

revenue = (cpu_revenue_per_unit (s1_capacity x_s1 + s2_capacity x_s2) + gpu_revenue_per_unit (s3_capacity * x_s3))

Costs

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

Objective: Maximize profit

profit = revenue - total_cost prob += profit, "Total Profit"

Demand constraints

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"

Slot capacity constraint

prob += cpu_slot_size (x_s1 + x_s2) + gpu_slot_size \ x_s3 <= data_center_capacity, "Slot Capacity"

Solve the problem

prob.solve()

Calculate the demand met by each server type

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

Calculate the revenue generated by each server type

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

Calculate the costs for each server type

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

Calculate profit for each server type

profit_s1 = revenue_s1 - cost_s1 profit_s2 = revenue_s2 - cost_s2 profit_s3 = revenue_s3 - cost_s3

Print prettified results

print("="50) print("Optimization Status:", LpStatus[prob.status]) print("="50)

Results for s1 servers

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)

Results for s2 servers

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)

Results for s3 servers

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 results

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) `