Skip to content

Instantly share code, notes, and snippets.

@Mizux
Mizux / vrp_items_to_delivery.py
Last active May 4, 2022 09:36
vrp_items_to_delivery.py
#!/usr/bin/env python3
# [START program]
"""Vehicles Routing Problem (VRP) for delivering items from any suppliers.
Description:
Need to deliver some item X and Y at end nodes (at least 11 X and 13 Y).
Several locations provide them and even few provide both.
* fleet
* vehicles: 2
* x capacity: 15
* y capacity: 15
@Mizux
Mizux / vrp_fairness.py
Created March 24, 2022 08:23
vrp fairness
#!/usr/bin/env python3
from ortools.constraint_solver import routing_enums_pb2
from ortools.constraint_solver import pywrapcp
def create_data_model():
"""Stores the data for the problem."""
data = {}
data['distance_matrix'] = [
[
@Mizux
Mizux / team_sat.py
Last active March 19, 2022 20:50
Tournament
#!/usr/bin/env python3
"""Example of a simple team scheduling problem."""
from ortools.sat.python import cp_model
def main(n):
# Data.
num_teams = 2 * n
num_rounds = n
num_games = n
all_teams = range(num_teams)
@Mizux
Mizux / clean_workflow.sh
Created October 28, 2021 15:34
Script use to clean disabled workflows
#!/usr/bin/env bash
# First, disable the workflow you want to delete (via Github console) before executing this script.
# This script need gh cli and jq
# ref: https://github.com/cli/cli
# ref: https://github.com/stedolan/jq
set -euo pipefail
command -v gh
command -v jq
@Mizux
Mizux / cvrptw_pd.py
Last active September 30, 2021 17:44
Sample for Westlife1002
#!/usr/bin/env python3
"""Capacitated Vehicle Routing Problem"""
from six.moves import xrange
from ortools.constraint_solver import pywrapcp
from ortools.constraint_solver import routing_enums_pb2
import networkx as nx
import matplotlib.pyplot as plt
import random
import math
import pandas as pd
@Mizux
Mizux / vrp_with_weighted_travel_time.py
Created June 25, 2021 03:30
VRP with weighted travel time
from ortools.constraint_solver import routing_enums_pb2
from ortools.constraint_solver import pywrapcp
# Create Data Model
def create_data_model():
"""Stores the data for the problem."""
data = {}
data['time_matrix'] = [
[0,77,157,140,258,233,289,175,202,479,209,275,641,299,108,83,151,198,246,0,125,319,321,607,408,336,274,502,268,227,461,393,505,445,373,835,725,325,82,27,180,186,388,193,29,29,29,575,23,163,117,672,79],
[77,0,234,217,221,189,272,144,280,556,286,248,718,376,175,53,154,265,209,77,203,283,277,684,485,413,351,579,345,304,538,376,582,522,440,912,802,402,159,104,257,142,465,270,106,106,106,652,100,126,184,749,82],
@Mizux
Mizux / vrp_passengers_goods.py
Last active September 30, 2021 17:46
Passengers and Goods VRP for hihae...
#!/usr/bin/env python3
#### dial-a-ride problem with time window and maximum riding time
from ortools.constraint_solver import routing_enums_pb2
from ortools.constraint_solver import pywrapcp
#import pandas as pd
import math
# Create Data Model
@Mizux
Mizux / psing.py
Created June 8, 2021 17:21
psing
#!/usr/bin/env python3
from ortools.constraint_solver import routing_enums_pb2
from ortools.constraint_solver import pywrapcp
time_mat = [
[
0, 998, 940, 336, 4003, 2039, 1786, 791, 651, 1027, 470, 1143, 761,
1390, 118, 3525
],
[
@Mizux
Mizux / vrp_plot.py
Last active September 30, 2021 17:46
VRP with display using matplotlib
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""vrp_plot.py
Simple Vehicle Routing Problem with display using plotlib
In the *Vehicle Routing Problem (VRP)*, the goal is to find optimal routes for multiple vehicles visiting a set of locations. (When there's only one vehicle, it reduces to the Traveling Salesman Problem.)
This example of a VRP in which the goal is to minimize the longest single route.
Imagine a company that needs to visit its customers in a city made up of identical rectangular blocks.
@Mizux
Mizux / cvrptw-open-start-times.py
Created May 18, 2021 16:52
Time vs Duration sample for svili
#!/usr/bin/env python3
#import pandas as pd
from ortools.constraint_solver import pywrapcp
def cvrptw(
distance_mtx,
duration_mtx,
capacities,
demands,
loading_times,