Skip to content

Instantly share code, notes, and snippets.

View Mizux's full-sized avatar

Mizux Mizux

View GitHub Profile
@Mizux
Mizux / cvrptw.py
Last active August 22, 2024 15:26
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,
@Mizux
Mizux / problem.py
Last active September 30, 2021 17:46
Constraint on Station TW for Subramanian
#!/usr/bin/env python3
from ortools.constraint_solver import routing_enums_pb2
from ortools.constraint_solver import pywrapcp
import math
import numpy as np
def create_data_model():
data = {}
fuel_capacity = 40000
@Mizux
Mizux / chain.py
Last active September 30, 2021 17:46
Multiple route chains
#!/usr/bin/env python3
"""
Test Multiple route chains constraint
We have several chain [A, B, C], [U, V, W], [X,Y] etc..
and a bunch of regular nodes [1,2,3,...]
constraints:
* Can't interleave chains e.g. "A -> B -> X -> C -> Y" is forbidden
* Can have regular node inside a chain e.g. "A -> 3 -> B -> 1 -> C" is OK
"""
@Mizux
Mizux / diff.md
Last active September 30, 2021 17:46
vrp_with_fuelanddroppedvisits
%diff --color -u vrp_with_fuelanddroppedvisits.py vrp_with_fuelanddroppedvisits_new.py
--- vrp_with_fuelanddroppedvisits.py	2021-01-21 21:21:06.223665222 +0100
+++ vrp_with_fuelanddroppedvisits_new.py	2021-01-21 21:06:52.350242086 +0100
@@ -1,11 +1,11 @@
-from __future__ import print_function
+#!/usr/bin/env python3
+
 from ortools.constraint_solver import routing_enums_pb2
 from ortools.constraint_solver import pywrapcp
@Mizux
Mizux / same_vehicle.py
Last active January 23, 2024 14:29
VRP with same vehicles constraints.
#!/usr/bin/env python3
"""Vehicles Routing Problem (VRP)."""
import sys
from ortools.constraint_solver import routing_enums_pb2, pywrapcp
# Model
dim_name = 'Dimension'
def duration_callback(from_index, to_index):
@Mizux
Mizux / tsp_refuel.py
Last active September 30, 2021 17:46
TSP with refuel stations
#!/usr/bin/env python3
from __future__ import print_function
from ortools.constraint_solver import routing_enums_pb2
from ortools.constraint_solver import pywrapcp
import math
import numpy as np
import matplotlib.pyplot as plt
def create_data_model():
@Mizux
Mizux / vrp_fuel.py
Last active September 30, 2021 17:46
VRP with refuel stations
#!/usr/bin/env python3
from __future__ import print_function
from ortools.constraint_solver import routing_enums_pb2
from ortools.constraint_solver import pywrapcp
import numpy as np
import math
def create_data_model():
"""Stores the data for the problem."""
data = {}
@Mizux
Mizux / vrptw_collect_deliveries.py
Last active March 17, 2025 16:22
VRPTW with collects and deliveries
#!/usr/bin/env python3
from ortools.constraint_solver import pywrapcp
from ortools.constraint_solver import routing_enums_pb2
def create_data_model(input_data=None):
"""Stores the data for the problem."""
data = {}
data['distance_matrix'] = [
[
@Mizux
Mizux / vrp_new_order.py
Last active December 17, 2023 16:03
VRP with a new order
#!/usr/bin/env python3
"""Capacited Vehicles Routing Problem (CVRP).
Here we simulate a vehicle already loaded with 4 orders and on its way to deliver them
When a new order (node 5 -> 6) arrives.
"""
from ortools.constraint_solver import routing_enums_pb2
from ortools.constraint_solver import pywrapcp
def print_solution(manager, routing, solution):