Skip to content

Commit

Permalink
- FIX: Adopted to changes of DiagrammeR
Browse files Browse the repository at this point in the history
- FIX: Analyze sometimes doesn't show all alternatives
  • Loading branch information
gluc committed Feb 2, 2016
1 parent 803a35c commit 1994988
Show file tree
Hide file tree
Showing 18 changed files with 78 additions and 34 deletions.
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: ahp
Type: Package
Title: Analytic Hierarchy Process
Version: 0.2.6
Date: 2016-01-15
Version: 0.2.7
Date: 2016-02-02
Author: Christoph Glur
Maintainer: Christoph Glur <[email protected]>
VignetteBuilder: knitr
Expand All @@ -27,3 +27,4 @@ URL: http://github.com/gluc/ahp
BugReports: http://github.com/gluc/ahp/issues
Depends:
R (>= 3.0)
RoxygenNote: 5.0.1
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by roxygen2 (4.1.1): do not edit by hand
# Generated by roxygen2: do not edit by hand

export(AhpMatrix)
export(Analyze)
Expand Down
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# All changes to ahp are documented here.

## Version 0.2.7
- FIX: Adopted to changes of DiagrammeR
- FIX: Analyze sometimes doesn't show all alternatives

## Version 0.2.6
- CHANGE: Rename col Consistency to Inconsistency
- CHANGE: Remove col Consistency if all values are NA
Expand Down
8 changes: 5 additions & 3 deletions R/analyze.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@ GetDataFrame <- function(ahpTree,

names(df)[1] <- " "

if (variable[1] == "priority") df <- df[ , -4]
if (all(is.na(df$Inconsistency))) df <- subset(df, select=-c(Inconsistency))
else df <- df[ , -5]
if (variable[1] == "priority") df$Weight <- NULL
else df$Priority <- NULL

if (all(is.na(df$Inconsistency))) df$Inconsistency <- NULL


return (df)

Expand Down
3 changes: 2 additions & 1 deletion R/table.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ AnalyzeTable <- function(ahpTree,
pruneFun = pruneFun)
df <- df[ , -1]

alternatives <- names(df)[-c(1:3, ncol(df))]
#alternatives <- names(df)[-c(1:3, ncol(df))]
alternatives <- GetAlternativesNames(ahpTree)
dfw <- df[ , alternatives, drop = FALSE]

dfw[is.na(dfw)] <- 1
Expand Down
3 changes: 1 addition & 2 deletions R/visualize.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ GetGraph <- function(ahpTree,

edges <- combine_edges(edges, edgesAlt, edgesAlts)

graph <- create_graph(nodes)
graph <- add_edges(graph, edges)
graph <- create_graph(nodes, edges)

return (graph)

Expand Down
2 changes: 1 addition & 1 deletion man/AhpMatrix.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions man/Analyze.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/Calculate.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/GetPairwiseFromFunction.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions man/Load.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/PrioritiesFromPairwiseMatrixEigenvalues.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/PrioritiesFromScoresDefault.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/RunGUI.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/Visualize.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions man/ahp.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 32 additions & 1 deletion tests/testthat/test-Analyze.R
Original file line number Diff line number Diff line change
@@ -1,30 +1,59 @@
context("ahp analyze")



test_that("Analyze Identity", {
ahpFile <- system.file("extdata", "car.ahp", package="ahp")
carAhp <- Load(ahpFile)
Calculate(carAhp, pairwiseFun = PrioritiesFromPairwiseMatrixGeometricMean)
df <- Analyze(carAhp)

expect_equal(ncol(df), 8)
expect_equal(names(df), c(" ", "Weight", "Odyssey", "Accord Sedan", "CR-V", "Element", "Accord Hybrid", "Pilot"))

})


test_that("Analyze Identity 2", {
ahpFile <- system.file("extdata", "car.ahp", package="ahp")
carAhp <- Load(ahpFile)
Calculate(carAhp)
df <- Analyze(carAhp, variable = "priority")

expect_equal(ncol(df), 9)
expect_equal(names(df), c(" ", "Priority", "Odyssey", "Accord Sedan", "CR-V", "Element", "Accord Hybrid", "Pilot", "Inconsistency"))

})



test_that("Analyze Prune", {
ahpFile <- system.file("extdata", "car.ahp", package="ahp")
carAhp <- Load(ahpFile)
Calculate(carAhp)
df <- Analyze(
carAhp,
sort = "orig",
pruneFun = function(x, decisionMaker) {
PruneLevels(x, decisionMaker, 1) &&
PruneByCutoff(x, decisionMaker, minWeight = 0.05)
}
)

expect_equal(nrow(df), 4)
expect_equal(names(df), c(" ", "Weight", "Accord Sedan", "Accord Hybrid", "Pilot", "CR-V", "Element", "Odyssey", "Inconsistency"))

})



test_that("Analyze Prune", {
test_that("Analyze Prune 2", {
ahpFile <- system.file("extdata", "car.ahp", package="ahp")
carAhp <- Load(ahpFile)
Calculate(carAhp)
df <- AnalyzeTable(
carAhp,
variable = "priority",
pruneFun = function(x, decisionMaker) {
PruneByCutoff(x, decisionMaker, minWeight = 0.6)
}
Expand All @@ -36,3 +65,5 @@ test_that("Analyze Prune", {





5 changes: 4 additions & 1 deletion tests/testthat/test-Visualize.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ test_that("Visualize", {
Calculate(carAhp)
graph <- GetGraph(carAhp)
expect_equal(class(graph), "dgr_graph")
expect_equal(dim(graph$nodes_df), c(18, 8))
expect_equal(dim(graph$nodes_df), c(18, 10))
expect_equal(names(graph$nodes_df), c("nodes", "type", "label", "tooltip", "style", "shape", "color", "fillcolor", "penwidth", "fontname"))
expect_equal(dim(graph$edges_df), c(24, 7))
expect_equal(names(graph$edges_df), c("from", "to", "arrowhead", "color", "penwidth", "rel", "dir"))

})

Expand Down

0 comments on commit 1994988

Please sign in to comment.