Skip to content

Instantly share code, notes, and snippets.

Avatar

Fabian Leuthold phabee

View GitHub Profile
@phabee
phabee / GrowingTour.java
Created Jul 18, 2018
Compare Growing Object Performance R vs. Java
View GrowingTour.java
package ch.ims.tests;
import java.util.List;
import ch.ims.core.TourGenerator;
import ch.ims.model.TourStop;
public class GrowingTour {
public static void runTest(int nLoop, int initSize) {
@phabee
phabee / r_perf_test_3.R
Created Jul 18, 2018
Memory Allocation performance Test in R using statically initialized data.frames vs. dynamically growing data.frames
View r_perf_test_3.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_dynamic <- function(nrows) {
@phabee
phabee / r_perf_test_4.R
Last active Jul 18, 2018
Compare Column-Level vs. Row-Level Filtering in R
View r_perf_test_4.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) {
@phabee
phabee / gurobi_model_translation.m
Created May 13, 2020
Call Gurobi from Matlab and transform inequalities to equalities introducing Slack-Variables
View gurobi_model_translation.m
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];
View fibonacci.R
library(tictoc)
fibonacci <- function(n) {
if (n > 1) {
return (fibonacci(n-2) + fibonacci(n-1))
} else if (n == 1) {
return (1)
}
return(0)
}
View fibonacci_experiments.m
tic
fibonacci(30)
toc
function [n] = fibonacci(x)
if (x == 1 || x==0)
n = x;
else
n = fibonacci(x-1) + fibonacci(x-2);
end
View fibonacci_experiments.py
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
View Fibonacci.java
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.");
}
View fibonacci.html
<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;
}
View fibonacci.c
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
int fibonacci(int n);
int main() {
clock_t begin, end;
float z;
int a;