Create a gist now

Instantly share code, notes, and snippets.

glpk model for cloud vs colo costs
#Colo Server costs
set ServerTypes;
set InstanceTypes;
param CoreDemand; #How many cores do we need for a workload
param OurMoney; #The maximum upper-bound of what we're willing to spend
param ColoCostPerU; #How much are we paying per U of colocation
param Months; # How many months do we know we need this hardware
## Owned Servers
param ServerCost{b in ServerTypes};
param ServerCores{b in ServerTypes};
param ServerRam{b in ServerTypes};
param ServerUs{b in ServerTypes};
## EC2 Instances
param InstanceCost{a in InstanceTypes};
param InstanceCores{b in InstanceTypes};
param InstanceRAM{b in InstanceTypes};
## Variables for how many of each we'll need
var ServerQuantity{q in ServerTypes}, integer, >= 0;
var InstanceQuantity{q in InstanceTypes}, integer, >= 0;
## Our objective: To minimize the number of servers subject to our Core demand
# minimize server_count: sum{i in ServerTypes} ServerQuantity[i];
minimize instance_count: sum{i in InstanceTypes} InstanceQuantity[i];
#Initial cost of servers + monthly colo fee must be less than the total budget
s.t. total_cost: sum{i in ServerTypes} (ServerQuantity[i] * ServerCost[i] + ServerQuantity[i] * ServerUs[i] * ColoCostPerU * Months) <= OurMoney;
#Initial server cost must be less than the total budget
# s.t. server_cost: sum{d in ServerTypes} ServerQuantity[d] * ServerCost[d] <= OurMoney;
# Every server must incur a colocation cost per month and it must be positive
s.t. server_hosting_cost: sum{d in ServerTypes} ServerQuantity[d] * ServerUs[d] * ColoCostPerU >= 0;
# The number of servers we have must been our core count requirement
s.t. server_cores_needed: sum{i in ServerTypes} ServerQuantity[i] * ServerCores[i] >= CoreDemand;
## EC2 Requirements
# The number of EC2 instances we have must meet our Core demand
s.t. instance_cores_needed: sum{i in InstanceTypes} InstanceCores[i] * InstanceQuantity[i] >= CoreDemand;
# Every EC2 instance must incur a monthly cost and it must be greater than zero
s.t. instance_cost_per_month: sum{i in InstanceTypes} InstanceQuantity[i] * InstanceCost[i] >= 0;
# The total we're willing to spend must be less than our total budget
s.t. max_budget_for_instances: sum{i in InstanceTypes} InstanceQuantity[i] * InstanceCost[i] * Months <= OurMoney;
display{i in ServerTypes}: ServerQuantity[i];
display{i in ServerTypes}: ServerQuantity[i] * ServerCost[i];
display{i in ServerTypes}: ServerQuantity[i] * ServerCost[i] + ServerQuantity[i] * ServerUs[i] * ColoCostPerU * Months;
display{i in InstanceTypes}: InstanceQuantity[i];
display{i in InstanceTypes}: InstanceQuantity[i] * InstanceCost[i] * Months;
set ServerTypes := DellPowerEdgeR515;
param ServerCost := DellPowerEdgeR515 1901;
param ServerCores := DellPowerEdgeR515 8;
param ServerRam := DellPowerEdgeR515 16;
param ServerUs := DellPowerEdgeR515 2;
set InstanceTypes := Small Large XLarge HCPULarge HCPUXLarge;
param InstanceCost := Small 72
Large 288
XLarge 576
HCPULarge 144
HCPUXLarge 576;
param InstanceCores := Small 1
Large 2
XLarge 4
HCPULarge 2
HCPUXLarge 8;
param InstanceRAM := Small 1700
Large 7500
XLarge 15000
HCPULarge 1700
HCPUXLarge 7000;
param CoreDemand := 432;
param OurMoney := 800000;
param ColoCostPerU := 50;
param Months := 12;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment