Skip to content

Instantly share code, notes, and snippets.

View pabloazurduy's full-sized avatar

Pablo Azurduy pabloazurduy

View GitHub Profile
@pabloazurduy
pabloazurduy / snippet _qp_model.py
Created April 26, 2020 18:17
a snippet that shows the implementation of the qp appx
from helpers.mip import get_quadratic_appx
# get a new variable that represents u^2 = qa_u
qa_u = {}
for i in stores:
for t in days:
qa_u[(i,t)] = get_quadratic_appx(model = mdl,
var = u[(i,t)],
id_name = 'qpu_{}_{}'.format(i,t),
min_interval = 0, # lower value where we estimate that u will be moving
@pabloazurduy
pabloazurduy / mip.py
Created April 26, 2020 18:13
quadratic_appx helper
import numpy as np
import mip
def get_quadratic_appx(model ,
var,
id_name = None,
min_interval = 0,
max_interval = 100,
num_linspace = 100,
M = 1e7 ):
@pabloazurduy
pabloazurduy / model.py
Created April 25, 2020 20:17
linear model snippet
# the LP model
import mip
mdl = mip.Model(sense=mip.MINIMIZE, solver_name=mip.CBC)
# sets
days = list(range(len(demand[1])))
stores = list(demand_parameters.keys())
# variables