Skip to content

Instantly share code, notes, and snippets.

using Graphs
using PicoSAT
function optimal_coloring(g::SimpleGraph{T})::Graphs.Coloring{T} where {T <: Integer}
# FIXME which is faster: maximum clique or maximal clique?
max_clique = argmax(length, maximal_cliques(g))
#max_clique = independent_set(complement(g), DegreeIndependentSet())
#@show max_clique
for χ in length(max_clique):nv(g)
#println("Trying χ=$χ")
@dstahlke
dstahlke / primes_walk.jl
Created August 1, 2021 07:48
Walk as we count integers, turning right when it's prime.
using Primes
using StatsBase
using InteractiveViz
using GLMakie
function run(L, turns, zoom)
function xy_to_grid(x, y)
return round(Integer, L/2 + x*zoom), round(Integer, L/2 + y*zoom)
end
@dstahlke
dstahlke / bk393.cc
Created January 10, 2016 22:06
Linux driver for B&K Precision 393 multimeter
// Linux driver for B&K Precision 393 multimeter.
// g++ -Wall -Wextra -std=c++11 -o bk393 bk393.cc
// It currently points to /dev/ttyUSB0, but I'd recommend adding a udev rule to get a consistent device name:
// SUBSYSTEMS=="usb", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="A60198LN", MODE="0664", GROUP="mygroup", SYMLINK+="bk393"
#include <boost/utility.hpp>
#include <array>
#include <iomanip>
#include <cstdio>
@dstahlke
dstahlke / lovasz.py
Last active March 18, 2024 20:54
Python code to compute the Lovasz, Schrijver, and Szegedy numbers for graphs.
# Compute the Lovasz, Schrijver, and Szegedy numbers for graphs.
#
# A graph with 32 vertices takes under one second, so it's not the fastest.
# Probably the specialized code for Lovasz number from
# http://dollar.biz.uiowa.edu/~sburer/pmwiki/pmwiki.php%3Fn=Main.SDPLR%3Faction=logout.html
# would be much faster (I haven't tried it).
# Copyright (c) 2013 Daniel Stahlke (dan@stahlke.org)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
@dstahlke
dstahlke / parfor.py
Last active December 24, 2015 05:09
IPython extension for transparent use of joblib.Parallel.
# NOTE: this is just a proof of concept and breaks when, for example, you have
# parenthesis inside a quotation. I'm still trying to find the easiest way to
# handle this properly. Suggestions are welcome.
#
# An IPython extension for transparent use of joblib.
# To use, type something like this in IPython:
# [ x*2 parfor x in range(10) ]
# To use custom options, type this at the IPython prompt:
# _parfor = joblib.Parallel(n_jobs=-1, verbose=5)
#