Last active
November 20, 2017 03:23
-
-
Save gluc/b03520be946a6d8dcff7b014ae2cfbc7 to your computer and use it in GitHub Desktop.
Manipulate ahp problem by code
This file contains hidden or 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(ahp) | |
library(data.tree) | |
vacation <- Load("vacation.ahp") | |
# look at the structure | |
vacation | |
# look at some preference dfs | |
vacation$preferences$Dad$pairwise$preferences | |
# manipulate preferences by code | |
newprefs <- structure(list(c1 = list("Costs", "Costs", "Fun"), c2 = list( | |
"Fun", "Spa", "Spa"), preference = c(7, 2, 3)), .Names = c("c1", | |
"c2", "preference"), row.names = c(NA, -3L), class = "data.frame") | |
vacation$preferences$Dad$pairwise$preferences <- newprefs | |
# reset voting powers by code (power to the children!): | |
vacation$`decision-makers` <- c(Dad = 0.1, Mom = 0.2, Kid = 0.7) | |
# ...except maybe for spa, that's still Mom's territory | |
vacation$Spa$`decision-makers` <- c(Dad = 0.2, Mom = 0.7, Kid = 0.1) | |
Calculate(vacation) | |
ahp::Analyze(vacation) |
This file contains hidden or 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
Version: 2.0 | |
Alternatives: &alternatives | |
Beach: | |
cost: 10000 | |
Mountains: | |
cost: 5000 | |
Goal: | |
name: Vacation | |
decision-makers: | |
#optional node, needed only if not all decision-makers have equal voting power | |
- Dad: 0.4 | |
- Mom: 2/5 | |
- Kid: 0.2 | |
preferences: | |
Dad: | |
pairwise: | |
- [Costs, Fun, 4] | |
- [Costs, Spa, 9] | |
- [Fun, Spa, 4] | |
Mom: | |
pairwise: | |
- [Costs, Fun, 1/4] | |
- [Costs, Spa, 1/9] | |
- [Fun, Spa, 1/5] | |
Kid: | |
pairwise: | |
- [Costs, Fun, 1/9] | |
- [Costs, Spa, 1] | |
- [Fun, Spa, 9] | |
children: | |
Costs: | |
preferences: | |
Dad: | |
pairwiseFunction: | |
function(a1, a2) min(9, max(1/9, a2$cost/a1$cost)) | |
Mom: | |
scoreFunction: | |
function(a) 1/a$cost | |
Kid: | |
priority: | |
- Beach: 1/2 | |
- Mountains: 0.5 | |
children: *alternatives | |
Fun: | |
preferences: | |
Dad: | |
pairwise: | |
- [Beach, Mountains, 1/6] | |
Mom: | |
pairwise: | |
- [Beach, Mountains, 2] | |
Kid: | |
# Often, entering pairwise preferences is lengthy, especially if you | |
# have multiple alternatives. Instead, you can enter scores, i.e. rate | |
# each alternative on a scale. The scale can be chosen freely. The | |
# priorities are derived as score / sum(scores) | |
score: | |
- Beach: 5 | |
- Mountains: 0 | |
children: *alternatives | |
Spa: | |
preferences: | |
Dad: | |
pairwise: | |
- [Beach, Mountains, 2] | |
Mom: | |
pairwise: | |
- [Beach, Mountains, 6] | |
Kid: | |
pairwise: | |
- [Beach, Mountains, 1/2] | |
children: *alternatives |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment