import pandas as pd
import numpy as np
def prepare_data():
origins = ['GARY', 'CLEV', 'PITT']
destinations = ['FRA', 'DET', 'LAN', 'WIN', 'STL', 'FRE', 'LAF']
products = ['bands', 'coils', 'plate']
limit = 625
supply_df = pd.DataFrame(
np.array(
[
[400, 700, 800],
[800, 1600, 1800],
[200, 300, 300],
]
),
columns=origins,
index=products,
).T
demand_df = pd.DataFrame(
np.array(
[
[300, 300, 100, 75, 650, 225, 250],
[500, 750, 400, 250, 950, 850, 500],
[100, 100, 0, 50, 200, 100, 250],
]
),
columns=destinations,
index=products,
).T
fixedcosts_df = pd.DataFrame(
np.array(
[
[3000, 1200, 1200, 1200, 2500, 3500, 2500],
[2000, 1000, 1500, 1200, 2500, 3000, 2200],
[2000, 1200, 1500, 1500, 2500, 3500, 2200],
]
),
columns=destinations,
index=origins,
)
v_costs = {
('bands','GARY'): [30, 10, 8, 10, 11, 71, 6],
('bands','CLEV'): [22, 7, 10, 7, 21, 82, 13],
('bands','PITT'): [19, 11, 12, 10, 25, 83, 15],
('coils','GARY'): [39, 14, 11, 14, 16, 82, 8],
('coils','CLEV'): [27, 9, 12, 9, 26, 95, 17],
('coils','PITT'): [24, 14, 17, 13, 28, 99, 20],
('plate','GARY'): [41, 15, 12, 16, 17, 86, 8],
('plate','CLEV'): [29, 9, 13, 9, 28, 99, 18],
('plate','PITT'): [26, 14, 17, 13, 31, 104, 20]
}
v_costs_dict = {(orig, destinations[i], prod):v for (prod, orig) in v_costs.keys() for i,v in enumerate(v_costs[prod,orig])}
return origins, destinations, products, supply_df, demand_df, limit, fixedcosts_df, v_costs_dict
# read model
ampl.read('supply_chain.mod')
# get data
origins, destinations, products, supply, demand, limit, fixedcosts, variablecosts = prepare_data()
# load data into ampl
ampl.set['ORIG'] = origins
ampl.set['DEST'] = destinations
ampl.set['PROD'] = products
ampl.param['supply'] = supply
ampl.param['demand'] = demand
ampl.param['limit'] = limit
ampl.param['fcost'] = fixedcosts
ampl.param['vcost'] = variablecosts
# solve with highs
ampl.solve(solver='highs')
ampl.option['display_eps'] = 1e-6;
ampl.display('Use, Trans')