Skip to content

Instantly share code, notes, and snippets.

@270ajay
270ajay / 0VRPTWBigM.py
Last active July 26, 2018 07:20
Optimizing Vehicle Routing Problem with Time Windows using Mixed Integer Programming (BigM formulation). Uses PuLP library in python.
import csv
import pulp #This contains LP Modeling and solver
import time #This is used to see how much time for solving
#######################################################################
#######################################################################
@270ajay
270ajay / 0VRPTWColGen.py
Created July 26, 2018 07:17
Using Column Generation for Optimizing Vehicle Routing Problem with Time Windows. The Objective here is only to minimize the number of vehicles used. Uses PuLP library in python.
import csv
import pulp #This contains LP Modeling and solver
import time #This is used to see how much time for solving
#######################################################################
#######################################################################
@270ajay
270ajay / VRPTWLNS.py
Created July 26, 2018 07:20
Uses Large Neighborhood Search for optimizing Vehicle Routing Problem with Time Windows. This algorithm can easily be improved.
import csv
import pulp #This contains LP Modeling and solver
import time #This is used to see how much time for solving
import random
#######################################################################
#######################################################################
@270ajay
270ajay / 0SuitcasePacking.py
Last active July 26, 2018 09:47
Optimizing the packing of Suit Cases/Luggage using Mixed Integer Programming. Objective is to maximize the cost of items that can fit in the suitcases without exceeding weight restrictions.
import csv
import pulp #This contains LP Modeling and solver
#------------------------------------------------------------------------------------------------------
#GETTING & PREPARING DATA
#------------------------------------------------------------------------------------------------------
with open('InputItems.csv') as csvfile:
data = list(csv.reader(csvfile))
@270ajay
270ajay / 0ProjectPlanning.py
Created July 26, 2018 09:44
Optimizing the Project Planning Problem using Mixed Integer Programming where the objective is to minimize the number of Teams assigned to Projects/Customers in a Quarter. -- Every project should be assigned to a team. -- No project must be assigned to more than 1 team. -- 1 week is required if a team wants to start a new project.
import csv
import pulp #This contains LP Modeling and solver
import time #This is used to see how much time for solving
print()
print("Solving the problem... Please wait")
print()
@270ajay
270ajay / 0CuttingStockColGen.py
Last active July 27, 2018 13:46
Optimizing the Cutting Stock problem using Column Generation. The data used is taken from CPLEX's example.
import pulp #This contains LP Modeling and solver
import time #This is used to see how much time it takes for solving
#######################################################################
#######################################################################
SizeOfStrips = [25, 40, 50, 55, 70] #size of strips that can be cut from rolls
@270ajay
270ajay / 0CP_VRPTW.py
Last active August 26, 2018 14:30
Optimizing Vehicle Routing Problem with Time Windows using Constraint Programming & Metaheuristics. Uses Google OR tools. -- Finds very good solution for large problem in seconds. Check https://developers.google.com/optimization/reference/constraint_solver/routing/RoutingModel/, https://developers.google.com/optimization/reference/constraint_sol…
"""Capacitated Vehicle Routing Problem with Time Windows (CVRPTW).
"""
import csv
import math
from ortools.constraint_solver import pywrapcp
from ortools.constraint_solver import routing_enums_pb2
"""Check https://developers.google.com/optimization/reference/constraint_solver/routing/RoutingModel/,
https://developers.google.com/optimization/reference/constraint_solver/routing/RoutingDimension/,
@270ajay
270ajay / 0MonteCarloSimulationNewsvendor.py
Last active August 14, 2018 06:29
Uses Monte Carlo Simulation to maximize profit. -- Newspaper demand per day is normally distributed. Can be done easily on excel.
import numpy as np
import math
'''Using MonteCarlo Simulation to maximize profit.
A Newspaper boy can buy 100, 120, 140, or 160 newspapers/day/month.
He will only be able to buy same number of newspapers for the whole month.
For example, if he buys 100 newspapers/day/month, then he will not be able to
buy 120, 140, or 160 newspapers in any day in that month.
@270ajay
270ajay / stressTest.py
Created February 18, 2020 12:18
Stress test
import time
import random
'''Course: https://www.coursera.org/learn/algorithmic-toolbox#about'''
def maxPairwiseProductSlow(numberList):
'''prints max product between any two numbers in the numberList
slow approach'''
@270ajay
270ajay / slowVsFastAlgorithms.py
Created February 18, 2020 12:19
Slow and fast algorithms
'''Course: https://www.coursera.org/learn/algorithmic-toolbox#about'''
def getFibonacciNumberForNSlow(number):
'''very slow algorithms to get fibonacci number.
Uses recursion (calls same function inside)'''
assert number >= 0, "number should be greater than or equal to 0"
if number <= 1: