This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Display the result if Optimal solution is found | |
| if status == cp_model.OPTIMAL: | |
| # Create one list of assigned tasks per machine. | |
| assigned_jobs = collections.defaultdict(list) | |
| for job_id, job in enumerate(jobs_data): | |
| for task_id, task in enumerate(job): | |
| machine = task[0] | |
| assigned_jobs[machine].append( | |
| assigned_task_type(start=solver.Value( | |
| all_tasks[job_id, task_id].start), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import collections | |
| # Import Python wrapper for or-tools CP-SAT solver. | |
| from ortools.sat.python import cp_model | |
| # Create the model. | |
| model = cp_model.CpModel() | |
| # Machine id | |
| dict_machine = {0:'Machine 1', 1:'Machine 2', 2:'Machine 3'} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| import numpy as np | |
| # Import Dataframe | |
| df = pd.read_csv('sales_data.csv', sep=";") | |
| print("{:,} transactions in your raw data".format(len(df))) | |
| # Format Date | |
| print("Start Processing ...") | |
| df['date'] = pd.to_datetime(df['date']) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| import numpy as np | |
| from rectpack import newPacker | |
| import rectpack.packer as packer | |
| import matplotlib.pyplot as plt | |
| # Initialize Model Parameters | |
| #-- Pallet Dimensions: 80 x 120 cm | |
| bx = 5 # Buffer x |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Function Solver | |
| def solver(n_812, n_1012, bins): | |
| # Pallets to load | |
| rectangles = [pal_812 for i in range(n_812)] + [pal_1012 for i in range(n_1012)] | |
| # Build the Packer | |
| pack = newPacker() | |
| # Add the rectangles to packing queue | |
| for r in rectangles: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def plot_solution(all_rects, pal_812, pal_1012): | |
| # Plot | |
| plt.figure(figsize=(10,10)) | |
| # Loop all rect | |
| for rect in all_rects: | |
| b, x, y, w, h, rid = rect | |
| x1, x2, x3, x4, x5 = x, x+w, x+w, x, x | |
| y1, y2, y3, y4, y5 = y, y, y+h, y+h,y | |
| # Pallet type |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| # Dictionnary of filenames | |
| list_files = ['DC-JAN-2017.xlsx', 'DC-FEB-2017.xlsx', 'DC-MAR-2017.xlsx','DC-APR-2017.xlsx', 'DC-MAY-2017.xlsx', 'DC-JUN-2017.xlsx', | |
| 'DC-JUL-2017.xlsx', 'DC-AUG-2017.xlsx', 'DC-SEP-2017.xlsx','DC-OCT-2017.xlsx', 'DC-NOV-2017.xlsx', 'DC-DEC-2017.xlsx'] | |
| zip_loop = zip(list_files, [i[3:6] for i in list_files]) | |
| # Final report DataFrame | |
| df_report = pd.DataFrame() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Function to open and clean | |
| def clean(file_raw, month): | |
| # Open the file and start from line 5 | |
| df_raw = pd.read_excel(file_raw, header = 5) | |
| df_raw.head() | |
| # Remove First Lines | |
| df_clean = df_raw.copy() | |
| df_clean = df_clean.iloc[4:] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def process_month(df_clean, month): | |
| # Type | |
| df_clean['Type'] = df_clean[['Renting', 'Investment']].apply( | |
| lambda t: 'Rent.' if t['Renting']=='X' else 'Invest.' if t['Investment']=='X' else 'Purch.', axis = 1) | |
| # Quantity | |
| dict_qty = dict(zip(['Rent.', 'Purch.', 'Invest.'], ['Rental Units', 'Purchasing Units', 'Invests. Units'])) | |
| df_clean['Qty'] = df_clean.apply(lambda t: t[dict_qty[t['Type']]], axis = 1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from pulp import * | |
| # Optimize your Bakery Model | |
| # Parameters | |
| items = ["A", "B", "C", "D", "E", "F"] | |
| profit = {"A":6, "B":4.4, "C":7.5, "D":0.9, "E":1.2, "F":2.2} | |
| baker = {"A":50, "B":0, "C":45, "D":35, "E":25, "F":0} | |
| oven = {"A":45, "B":0, "C":90, "D":20, "E":45, "F":0} | |
| display = {"A":4, "B":1.5, "C":3, "D":1, "E":1, "F":1} |