Skip to content

Instantly share code, notes, and snippets.

View phabee's full-sized avatar

Fabian Leuthold phabee

View GitHub Profile
#' get next best pilot stop using nearest neighbor
#'
#' @param tour
#' @param dima
#'
#' @return
#' @export
get_best_pilot_stop <- function(tour, dima) {
stops <- 1:nrow(dima)
potential_stops <- stops[-tour]
@phabee
phabee / diet.m
Last active November 4, 2020 11:03
MATLAB GUROBI Diet Example Script
function diet()
% Copyright 2020, Gurobi Optimization, LLC
%
% Solve the classic diet model
% Nutrition guidelines, based on
% USDA Dietary Guidelines for Americans, 2005
% http://www.health.gov/DietaryGuidelines/dga2005/
ncategories = 4;
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
int fibonacci(int n);
int main() {
clock_t begin, end;
float z;
int a;
<script type = "text/javascript">
function fibonacci(n)
{
if (n > 2)
return fibonacci(n-2) + fibonacci(n-1);
if (n == 2 || n == 1)
return 1;
return 0;
}
public class Fibonacci {
public static void main(String[] args) {
long start = System.nanoTime();
long a = fibonacci(30);
long end = System.nanoTime();
System.out.println("Result: a="+a+ ", calculation time was " + (end - start)/1e9+" s.");
}
def fibonacci(n):
if n >= 2:
return fibonacci(n - 2) + fibonacci(n - 1)
elif n == 2:
return 1
elif n == 1:
return 1
else:
return 0
tic
fibonacci(30)
toc
function [n] = fibonacci(x)
if (x == 1 || x==0)
n = x;
else
n = fibonacci(x-1) + fibonacci(x-2);
end
library(tictoc)
fibonacci <- function(n) {
if (n > 1) {
return (fibonacci(n-2) + fibonacci(n-1))
} else if (n == 1) {
return (1)
}
return(0)
}
@phabee
phabee / gurobi_model_translation.m
Created May 13, 2020 06:56
Call Gurobi from Matlab and transform inequalities to equalities introducing Slack-Variables
model.obj = [1,1,0,0,0,0]';
model.sense = ['=', '=', '=', '=', '>', '>', '>', '>']';
model.rhs = [200000, 100, 200, 0, 0, 0, 0, 0]';
model.lb = [0, 0, 0, 0, 0, 0]';
model.ub = [1e22, 1e22, 1e22, 1e22, 1e22, 1e22]';
model.vtype = ['C', 'C', 'C', 'C', 'C', 'C']'
model.A = sparse([800, 400, 1, 0, 0, 0; 1, 0, 0, -1, 0, 0; 0, 1, 0, 0, -1, 0; 2, -1, 0, 0, 0, 1; zeros(4,2), eye(4)]);
model.modelsense = 'max';
model.slack = [0, 0, 1, 1, 1, 1];
@phabee
phabee / r_perf_test_4.R
Last active July 18, 2018 09:24
Compare Column-Level vs. Row-Level Filtering in R
#' Generate random Tour
#'
#' Generates a random Tour with nrows number of stops with x/y coordinates and
#' a 4-digit random ZIP-code.
#'
#' @param nrows numeric, the number of stops
#'
#' @return data.frame, the tour
#' @export
generate_random_tour <- function(nrows) {