Skip to content

Instantly share code, notes, and snippets.

I may be slow to respond.

Dirk Schumacher dirkschumacher

I may be slow to respond.
View GitHub Profile
View gist:c0c1d78c721aa4fe2adc
= The news reads us data in Neo4J
Data by:
== Intro
Interesting data created by
I converted the data from the links.json file and converted it into two simple csv files.
LOAD CSV FROM "" AS csvline
dirkschumacher / gist:39b47a50f39e52deacf6
Last active Aug 29, 2015
Donations to German parties
View gist:39b47a50f39e52deacf6
= Donations to German parties
data from here:
== Sample Data Set
WITH data SKIP 0 LIMIT 375
MERGE (p:Party { name: data.partei_name, acronym: data.partei_acronym})
dirkschumacher / bvg.R
Last active Jul 29, 2016
Query BVG billing data from gmail with R
View bvg.R
# Use this code if you use the official BVG Berlin app
# I only tested it with credit card billing
# The BVG sends you an email for every purchase you make.
# The following code tries to find all those mails and analyzes them.

Keybase proof

I hereby claim:

  • I am dirkschumacher on github.
  • I am dirks ( on keybase.
  • I have a public key ASDroBuw_-Dy6s_YoGdf-7cyfLipgEXNflEyoE27_cc14Ao

To claim this, I am signing this object:

dirkschumacher / 20170509_bug_roi.R
Created May 9, 2017
Bounds on binary variables seem to be ignored in ROI (ROI_0.2-1)
View 20170509_bug_roi.R
# Bug report
# It seems variable bounds are ignored when using binary variables "B".
# It works as expected if variables of type "I" are used
# max: x1 + x2 + x3 + x4
# s.t. x1 + x2 + x3 + x4 <= 4
View ompr-benchmark.R
# based on the formulation from here
# devtools::install_github("dirkschumacher/ompr@milp")
max_colors <- 10
n <- 100
# variables n * max_colors

This vignettes discribes the modelling techniques available in ompr to make your life easier when developing a mixed integer programming model.

A MILP Model

You can think of a MIP Model as a big constraint maxtrix and a set of vectors. But you can also think of it as a set of decision variables, an objective function and a number of constraints as equations/inequalities. ompr implements the latter approach.

View 4-color-berlin.R
# based on a article from here
# CC by
# license here
map_data <- rgdal::readOGR("", "OGRGeoJSON")
# this gives as an adjancy list
View benchmark-tsp.R
# There are essential two prominent ways to model a TSP as a MILP. One is to formulate the full model using the Miller–Tucker–Zemlin (MTZ) formulation and the other option is to use the so-called sub-tour elimination constraints .[1](
# The first formulation is fairly compact (quadratic many constraints and variables) but is not suitable anymore when n gets larger. The second formulation has exponential many constraints at most, but can solve larger TSPs due to the better LP relaxation. The idea of the latter approach is add constraints to the model *during* the solution process as soon as a solution was found that contains a sub-tour. For solution strategies like this solvers usually offer callbacks that let's you modify the model during the the branch-and-cut process - this is however not currently supported by `ompr`.
# Therefor we will use the MTZ formulation and solve a fairly small TSP.
View lm_tf.R
# Linear regression with tensorflow and R
# Y = X * beta + epsilon
# =>
# beta = (X'X)^-1X'y
# first we build the computational graph
X <- tf$placeholder(tf$float64, name = "X")