Skip to content

Instantly share code, notes, and snippets.

@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,
@Mizux
Mizux / cvrptw.py
Last active October 26, 2023 07:07
CVRPTW for uni_r
#!/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['time_matrix'] = [
[0, 6, 9, 8, 7, 3, 6, 2, 3, 2],
[6, 0, 8, 3, 2, 6, 8, 4, 8, 8],
@Mizux
Mizux / vrp_break_travel.py
Last active June 16, 2023 09:00
VRP with breaks only depending on Travel time.
#!/usr/bin/env python3
# Copyright 2010-2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,