Skip to content

Instantly share code, notes, and snippets.

@Mizux
Mizux / tsp_node_with_various_cost.py
Created February 5, 2024 09:56
TSP with node having various cost
#!/usr/bin/env python3
"""
Having a cost different if a node is visited last or along the route
"""
from ortools.constraint_solver import routing_enums_pb2
from ortools.constraint_solver import pywrapcp
def create_data_model():
@Mizux
Mizux / multi_knapsack_with_color_sat.py
Created December 5, 2023 22:10
multi knapsacks with color constraint
#!/usr/bin/env python3
"""Solve a multiple knapsack problem using the CP-SAT solver."""
from ortools.sat.python import cp_model
def main():
data = {}
data["weights"] = [48, 30, 42, 36, 36, 48, 42, 42, 36, 24, 30, 30, 42, 36, 36]
data["values"] = [10, 30, 25, 50, 35, 30, 15, 40, 30, 35, 45, 10, 20, 30, 25]
assert len(data["weights"]) == len(data["values"])
data["num_items"] = len(data["weights"])
@Mizux
Mizux / test.sh
Last active August 28, 2023 08:57
sysctl hw.optional on Apple M1
```sh
$ sysctl hw.optional
hw.optional.arm.FEAT_FlagM: 1
hw.optional.arm.FEAT_FlagM2: 1
hw.optional.arm.FEAT_FHM: 1
hw.optional.arm.FEAT_DotProd: 1
hw.optional.arm.FEAT_SHA3: 1
hw.optional.arm.FEAT_RDM: 1
hw.optional.arm.FEAT_LSE: 1
hw.optional.arm.FEAT_SHA256: 1
@Mizux
Mizux / filtering_sat.py
Last active May 23, 2023 22:18
filtering.py
#!/usr/bin/env python3
'''Simple test
'''
from ortools.sat.python import cp_model
import pandas as pd
# Define the dataframe with feature columns and the target column
data = {
'A': [1.59, 0.9, 2.82,2.44,2.61],
'B': [0.68,0.1,1.3,1.64,1.59],
@Mizux
Mizux / main.cpp
Last active October 13, 2022 22:19
c++ read/write to a file
#include <cstdio>
#include <iostream>
#include <filesystem>
#include <fstream>
namespace fs = std::filesystem;
int main()
{
const std::string filename = std::tmpnam(nullptr);
@Mizux
Mizux / vrp_vmax.py
Last active August 8, 2022 16:06
VRP with 2 Vehicles max for same physical locations
#!/usr/bin/env python3
"""Vehicles Routing Problem (VRP).
Some point are on the same physical location
No more than two vehicle to visit a physical location
"""
from ortools.constraint_solver import routing_enums_pb2
from ortools.constraint_solver import pywrapcp
@Mizux
Mizux / squirrel3.js
Created August 5, 2022 14:29 — forked from psema4/squirrel3.js
An implementation of the Squirrel3 Noise-based RNG
// Based on the GDC 2017 talk "Math for Game Programmers: Noise-Based RNG"
// https://www.youtube.com/watch?v=LWFzPP8ZbdU&ab_channel=GDC
const BIT_NOISE1 = 0xB5297A4D
const BIT_NOISE2 = 0x68E31DA4
const BIT_NOISE3 = 0x1B56C4E9
const PRIME1 = 198491317
const PRIME2 = 6542989
class Squirrel3 {
@Mizux
Mizux / hack-a-digital-card-game.markdown
Created July 25, 2022 13:53
Hack. A digital card game
@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'] = [
[