Skip to content

Instantly share code, notes, and snippets.

View pabloazurduy's full-sized avatar

Pablo Azurduy pabloazurduy

View GitHub Profile
#!/bin/bash
# Get total system memory
TOTAL_MEM=$(sysctl -n hw.memsize)
# 1. ps: Get data
# 2. awk1: Calculate sums and output raw data with "|" delimiter (PCT|MB|NAME)
# 3. sort: Sort numerically by the first column (PCT)
# 4. awk2: Format the table and add headers
@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
Last active January 8, 2026 22:58
linear model snippet for medium post
# 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