Skip to content

Instantly share code, notes, and snippets.

View cocomoff's full-sized avatar
🏠
Working from home

Keisuke OTAKI cocomoff

🏠
Working from home
View GitHub Profile
@cocomoff
cocomoff / example_legendre.jl
Created August 15, 2019 23:47
Legendre変換のお勉強: (x, y)ではなく(p, w)で関数を表す
using Plots
# 適当な2次関数,導関数,接線の方程式
f(x; b=-3, d=2) = (b .+ x) .^2 .+ d
df(x; b=-3, d=2) = 2 .* (b .+ x)
fₜₐₙ(x, xₚ; b=-3, d=2) = df(xₚ) .* (x .- xₚ) .+ f(xₚ, b=b, d=d)
# 関数
x = 1:0.1:5;
@cocomoff
cocomoff / random_road_network.py
Created August 12, 2019 05:43
random_road_network.py
# -*- coding: utf-8 -*-
#
# build random road network
#
# 1. randomly sample location points
# 2. compute pair-wise shortest paths
# 3. keep pairs if its length < 1.5 x (ST)
import numpy as np
import networkx as nx
@cocomoff
cocomoff / dp_zdd.cpp
Created August 12, 2019 02:02
dp_zdd.cpp
#include <bits/stdc++.h>
#include "cuddObj.hh"
using namespace std;
const string red = "\033[0;31m";
const string green = "\033[0;32m";
const string reset = "\033[0m";
// Global manager
Cudd mgr;
@cocomoff
cocomoff / run.sh
Created July 17, 2019 04:30
dot-png generator
#!/bin/zsh
for l in `ls output/*.dot`;
do
fname=${l:r}.png;
dot -Tpng $l > $fname;
done;
@cocomoff
cocomoff / example_tdzdd.cpp
Created July 8, 2019 02:22
example_tdzdd.cpp
#include <fstream>
#include <iostream>
#include <tdzdd/DdSpec.hpp>
#include <tdzdd/DdStructure.hpp>
using namespace std;
const bool DEBUG_ENUM = false;
class Combination : public tdzdd::DdSpec<Combination, int, 2> {
@cocomoff
cocomoff / example_tdzdd_01knapsack.cpp
Created July 8, 2019 01:32
example_tdzdd_01knapsack.cpp
#include <fstream>
#include <iostream>
#include <tdzdd/DdSpec.hpp>
#include <tdzdd/DdStructure.hpp>
using namespace std;
class KnapsackZdd : public tdzdd::DdSpec<KnapsackZdd, int, 2> {
int const n;
int const *w;
@cocomoff
cocomoff / multidag_longest_path.py
Created July 4, 2019 01:24
multidag_longest_path.py
# -*- coding: utf-8 -*-
import networkx as nx
import networkx.algorithms as nxa
def longest_path_for_multidigraph(G, weight='weight', default_weight=1):
dist = {}
for v in nx.topological_sort(G):
us = []
for u, data in G.pred[v].items():
@cocomoff
cocomoff / example_bdd_constraint_var18.cpp
Created July 4, 2019 00:39
example_bdd_constraint_var18.cpp
#include <iostream>
#include <random>
#include <vector>
#include "cuddObj.hh"
using namespace std;
int main() {
Cudd mgr;
@cocomoff
cocomoff / example_bdd_constraint.cpp
Last active July 4, 2019 00:27
example_bdd_constraint.cpp
#include <iostream>
#include <random>
#include <vector>
#include "cuddObj.hh"
using namespace std;
int main() {
Cudd mgr;
@cocomoff
cocomoff / example_wt.cpp
Created July 3, 2019 14:07
wavelet tree of integer values
#include <bits/stdc++.h>
#include <sdsl/wavelet_trees.hpp>
using namespace std;
using namespace sdsl;
int main() {
wt_int<rrr_vector<63>> wt;
// auto iv = int_vector<>({0, 7, 2, 1, 4, 3, 6, 7, 2, 5, 0, 4, 7, 2, 6, 3});
auto iv = int_vector<>({0, 2, 1, 3, 2, 0, 2, 3});