Skip to content

Instantly share code, notes, and snippets.

View gluc's full-sized avatar

Christoph Glur gluc

View GitHub Profile
title: monorepo
@gluc
gluc / script.R
Last active November 20, 2017 03:23
Manipulate ahp problem by code
library(ahp)
library(data.tree)
vacation <- Load("vacation.ahp")
# look at the structure
vacation
# look at some preference dfs
@gluc
gluc / port_risk.yaml
Last active May 18, 2017 02:24 — forked from mayt1992/R code
port_risk.ahp for R
Version: 2.0
Alternatives: &alternatives
Port 1:
shortname: p1
Port 2:
shortname: p2
Goal:
name: Port Risk
description: >
Evaluate Port Risk in the perspective of the Belt and Road Initiative.
library(data.tree)
data(acme)
acme$Set(len = runif(acme$totalCount))
# see ?as.data.frame.Node for more details
ToDataFrameTree(acme,
parent = function(node) node$parent$name,
child = "name",
len.parent = function(node) node$parent$len,
len.child = "len",
Version: 2.0
#####################################
# Alternatives Section
#
Alternatives: &alternatives
# Here, we list all the alternatives, together with their attributes.
# We can use these attributes later in the file when defining
# preferenceFunctions. The attributes can be quantitative or
Fun:
preferences:
Dad:
pairwise
- [Cargo Capacity, Passenger Capacity, 1/5]
Mom:
pairwise
- [Cargo Capacity, Passenger Capacity, 1/5]
Kid:
pairwise
@gluc
gluc / DiagrammeR new version
Created December 18, 2016 10:53
DiagrammeR
graph <- structure(list(graph_info = structure(list(graph_id = "i4wrALpq",
graph_name = "graph_i4wrALpq", graph_time = structure(1482058166.83195, class = c("POSIXct",
"POSIXt")), graph_tz = NA_character_, write_backups = FALSE), .Names = c("graph_id",
"graph_name", "graph_time", "graph_tz", "write_backups"), row.names = c(NA,
-1L), class = "data.frame"), nodes_df = structure(list(
@gluc
gluc / DiagrammeR.R
Created December 17, 2016 16:03
Newest version of DiagrammeR
nodes <- structure(list(id = 1:11, style = c("", "", "", "", "", "", "",
"", "", "", ""), shape = c("", "", "egg", "egg", "", "egg", "egg",
"", "egg", "egg", "egg"), fillcolor = c("", "Thistle", "", "",
"", "", "", "LightBlue", "LightBlue", "LightBlue", "LightBlue"
), fontname = c("", "", "", "", "", "", "", "", "", "", ""),
tooltip = c("- name: Acme Inc.", "This is the accounting department",
"- cost: 1e+06\n- p: 0.5", "- cost: 5e+05\n- p: 0.75", "- name: Research",
"- cost: 2e+06\n- p: 0.25", "- cost: 750000\n- p: 0.9", "- name: IT",
"- cost: 4e+05\n- p: 0.2", "- cost: 250000\n- p: 0.05", "- cost: 50000\n- p: 1"
), fontcolor = c("", "Firebrick", "", "", "", "", "", "",
@gluc
gluc / dohts.R
Last active August 26, 2016 23:03
library(data.tree)
library(xts)
f <- read.csv("https://gist.githubusercontent.com/gluc/3969bcfb2ddce61d8bdec2f52c133674/raw/16b577a6842492153db8e95ede0062a6187e60ab/hts-data.csv", stringsAsFactors = FALSE)
# construct tree
# ==============
# you may chose a different hierarchy order
dfs <- data.frame(pathString = paste("rt", df$u_loc, df$u_code, df$c_code, df$citizenship, df$grade, sep = "/"), stringsAsFactors = FALSE)
library(data.tree)
yaml <- "
campus:
south:
label: campussouth
north:
label: campusnorth
"