Skip to content

Instantly share code, notes, and snippets.

View phabee's full-sized avatar

Fabian Leuthold phabee

View GitHub Profile
@phabee
phabee / GrowingTour.java
Created July 18, 2018 06:12
Compare Growing Object Performance R vs. 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 July 18, 2018 07:26
Memory Allocation performance Test in R using statically initialized data.frames vs. dynamically growing data.frames
#' 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 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) {
@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];
library(tictoc)
fibonacci <- function(n) {
if (n > 1) {
return (fibonacci(n-2) + fibonacci(n-1))
} else if (n == 1) {
return (1)
}
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
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
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.");
}
<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;
}
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
int fibonacci(int n);
int main() {
clock_t begin, end;
float z;
int a;