{{ message }}

Instantly share code, notes, and snippets.

👶
I may be slow to respond.

# Dirk Schumacher dirkschumacher

👶
I may be slow to respond.
Last active Feb 8, 2022
View user2022_tutorial_draft.md

# Draft: Applied Mixed Integer Linear Programming for Beginners

## Format preferences

• virtual, morning hours Nashville, Tennessee time, as I am based in Berlin, 2 - 3 hours

• English

## The title of the tutorial

• Applied Mixed Integer Linear Programming for Beginners

## The broad topic it covers

• Discrete optimization, operations research
Created Oct 30, 2021
View bytecode.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 # let's construct some byte code # x <- 42 # y <- x + 42 bcode <- .Internal(mkCode( c( 12L, # this is an identifier which byte-code version you use (I think) # each line is an operator, the first item is the operator, followed by operands (aka. arguments) 16L, 0L, # Operator "LDCONST" (load constant) from the index 1 in the constant pool # now value 1 is on the stack 22L, 1L, # Operator "SETVAR" (set variable) assign the last value on the stack to the name at index 2
Last active Oct 20, 2021
View rosenbrock.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 # License GPL 2 library(armacmp) # from the R docs of optim fr <- function(x) { ## Rosenbrock Banana function x1 <- x[1] x2 <- x[2] return(100 * (x2 - x1 * x1)^2 + (1 - x1)^2) } grr <- function(x = type_colvec()) { ## Gradient of 'fr'
Last active Jan 30, 2021
View if_bytecode.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 # Let's build this expression by hand # val <- 0 # if (this) { # val <- 1 # } constant_pool <- list( NULL, as.symbol("val"), # we need a symbol val as.symbol("this"), # we also need a symbol this, 0, 1 # next we need the two values 0 and 1
Created Dec 14, 2020
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 input <- readLines("path/to/input") input <- as.integer(input) library(ompr) library(ompr.roi) library(ROI.plugin.glpk) library(tidyverse) n <- length(input) MIPModel() %>% # a variable for each input number
Created Oct 24, 2020
View optim_torch.md
```library(torch)
optim_torch <- function(params, fn, method, iterations = 1000, ...) {
optimizer <- do.call(paste0("optim_", method), list(params, ...))
for (i in seq_len(iterations)) {
obj_val <- fn(params)
if (i %% 100 == 0) message(as.numeric(obj_val))
obj_val\$backward()
optimizer\$step()```
Last active Sep 29, 2020
View dependencies.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 # investigate your project or package dependencies # using the {tidyverse}, {renv} and {tools}. # since this code is wrapped in {reprex}, the below library calls # will be identified as dependent packages although only {tidyverse}, {renv} # and {tools} are actually used. library(tidyverse, warn.conflicts = FALSE) # ironically the most deps :) # add some more dependencies as an example suppressPackageStartupMessages(library(caret, warn.conflicts = FALSE)) suppressPackageStartupMessages(library(tidymodels, warn.conflicts = FALSE))
Last active Jun 12, 2020
View role_based_access_logician.md

# Role based access control as a logic program

```# remotes::install_github("dirkschumacher/logician")
# a role based access control
library(logician)
role_database <- logician_database(
role(user),```
Last active Jun 8, 2020
View tower_of_hanoi.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 library(logician) # Towers of Hanoi # https://en.wikipedia.org/wiki/Tower_of_Hanoi # Original Prolog Implementation: # https://www.cs.toronto.edu/~sheila/384/w11/simple-prolog-examples.html database <- logician_database( # no `is` operator yet, so we have to define all valid numbers num(1),num(2),num(3),num(4),num(5), num(6),num(7),num(8),num(9),
Created May 16, 2020
View test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 from l0bnb import fit_path from l0bnb import gen_synthetic X, y, b = gen_synthetic(n=10, p=10, supp_size=10) sols = fit_path(X, y, lambda_2 = 0.01, max_nonzeros = 1) print(sols)