Skip to content

Instantly share code, notes, and snippets.

View samirsaci's full-sized avatar

Samir Saci samirsaci

View GitHub Profile
@samirsaci
samirsaci / simpleplot.py
Created March 31, 2021 21:28
Simple Plot
ax = df_par.plot(x='%SKU', y='%CumSum', figsize = (20,7.5))
plt.xlabel('Percentage of SKU (%)',fontsize=15)
plt.ylabel('Percentage of Boxes Ordered (%)',fontsize=15)
plt.title('Pareto Analysis using Cumulative Sum of Boxes Prepared (%) = f(%SKU)', fontsize = 15)
plt.show()
@samirsaci
samirsaci / plot_marker.py
Created March 31, 2021 21:44
Plot marker
# > 80% Volume
df_par80 = df_par[df_par['%CumSum'] > 80].copy()
perc_sku80 = df_par80['%SKU'].min()
perc_sum80 = df_par80['%CumSum'].min()
# 20% SKU
df_sku20 = df_par[df_par['%SKU'] > 20].copy()
perc_sku20 = df_sku20['%SKU'].min()
perc_sum20 = df_sku20['%CumSum'].min()
@samirsaci
samirsaci / 1-2017.csv
Created March 31, 2021 22:45
picking_orders.csv
We can't make this file beautiful and searchable because it's too large.
DATE FORMAT ORDER_NUMBER SKU PCS
01/01/2017 835220 290731 1.0
01/01/2017 835220 373272 1.0
01/01/2017 835214 362101 1.0
01/01/2017 835215 215515 1.0
01/01/2017 835215 287995 1.0
01/01/2017 835215 310751 1.0
01/01/2017 835215 331543 1.0
01/01/2017 835212 159789 1.0
01/01/2017 835209 309851 1.0
@samirsaci
samirsaci / pulp_prep.py
Last active April 5, 2021 20:59
Prep data pulp
import pandas as pd
from pulp import * # pip install pulp
import matplotlib.pyplot as plt
from itertools import chain, repeat
def ncycles(iterable, n):
"Returns the sequence elements n times"
return chain.from_iterable(repeat(tuple(iterable), n))
# Staff needs per Day
# Initialize Model
model = LpProblem("Minimize Staffing", LpMinimize)
# Create Variables
start_jours = ['Shift: ' + i for i in jours]
x = LpVariable.dicts('shift_', n_days, lowBound=0, cat='Integer')
# Define Objective
model += lpSum([x[i] for i in n_days])
@samirsaci
samirsaci / model_analysis.py
Created April 5, 2021 21:18
Pulp Analysis
# Solve Model
model.solve()
# The status of the solution is printed to the screen
print("Status:", LpStatus[model.status])
# How many workers per day ?
dct_work = {}
for v in model.variables():
dct_work[int(v.name[-1])] = int(v.varValue)
Monday Tuesday Wednesday Thursday Friday Saturday Sunday
Shift: Monday 14 14 14 14 14 0 0
Shift: Tuesday 0 14 14 14 14 14 0
Shift: Wednesday 0 0 8 8 8 8 8
Shift: Thursday 0 0 0 0 0 0 0
Shift: Friday 13 13 0 0 13 13 13
Shift: Saturday 0 0 0 0 0 0 0
Shift: Sunday 4 4 4 4 0 0 4
Days Staff Demand Staff Supply Extra_Ressources
Monday 31 31 0
Tuesday 45 45 0
Wednesday 40 40 0
Thursday 40 40 0
Friday 48 49 1
Saturday 30 35 5
Sunday 25 25 0
@samirsaci
samirsaci / initi_variables.py
Created April 15, 2021 12:30
Init Variables
# Count Machines
machines_count = 1 + max(task[0] for job in jobs_data for task in job)
print("{:,} machines".format(machines_count))
all_machines = range(machines_count)
# Computes horizon dynamically as the sum of all durations.
horizon = sum(task[1] for job in jobs_data for task in job)
print("Total Time using Naive Solution: {} min".format(horizon))
# Named tuple to store information about created variables
@samirsaci
samirsaci / constraints.py
Created April 15, 2021 12:55
Add constraints
# Add Constraints: No Overlapping of tasks for the same machine
# Create and add disjunctive constraints.
for machine in all_machines:
model.AddNoOverlap(machine_to_intervals[machine])
# Precedences inside a job: End Time of Step n is before starting time of Step n+1
for job_id, job in enumerate(jobs_data):
for task_id in range(len(job) - 1):
model.Add(all_tasks[job_id, task_id +
1].start >= all_tasks[job_id, task_id].end)