getAlternativesComparisons: Get comparisons of alternatives

Description Usage Arguments Value Examples

View source: R/libxmcda.R

Description

Extracts <alternativesComparisons> from an XML tree written according to the XMCDA standard and stores the performances of the concerned alternatives.

Usage

1
getAlternativesComparisons(tree, performanceTable, mcdaConcept = NULL)

Arguments

tree

Object containing the XMCDA XML tree.

performanceTable

A matrix containing the performance table to be considered, whose dimnames are the alternatives' IDs (rows) and the criteria's IDs (columns).

mcdaConcept

A string containing the specific mcdaConcept attribute which should be searched for.

Value

The function returns a list structured as follows:

The first elements contain the <alternativesComparisons> found in <tree> as matrices. These elements are named according to the mcdaConcept attribute if it can be found. Each line of each matrix corresponds to one constraint of the type "alternative a is preferred to alternative b with preference threshold delta". A line is structured as follows: the first n elements encode alternative a (via the values it takes in performanceTable), the next n elements encode alternative b, and the last element contains the preference threshold delta.

status

Either OK if all the <criteria> tags could be correctly read, or the description of the error.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
tree = newXMLDoc()

newXMLNode("xmcda:XMCDA", 
           namespace = c("xsi" = "http://www.w3.org/2001/XMLSchema-instance", 
           "xmcda" = "http://www.decision-deck.org/2009/XMCDA-2.1.0"), 
           parent=tree)

root<-getNodeSet(tree, "/xmcda:XMCDA")

aC<-newXMLNode("alternativesComparisons", parent=root[[1]] , namespace=c())

pairs<-newXMLNode("pairs", parent=aC, namespace=c())
pair<-newXMLNode("pair", parent=pairs, namespace=c())

initial<-newXMLNode("initial", parent=pair)
newXMLNode("alternativeID", "a01", parent=initial, namespace=c())

terminal<-newXMLNode("terminal", parent=pair, namespace=c())
newXMLNode("alternativeID", "a02", parent=terminal, namespace=c())

value<-newXMLNode("value", parent=pair, namespace=c())
newXMLNode("real", "0.5", parent=value, namespace=c())

alternativesIDs <- c("a01","a02")
criteriaIDs <- c("g1","g2")

performance.table<-matrix(nrow=length(alternativesIDs),
                          ncol=length(criteriaIDs),
                          dimnames = list(alternativesIDs,criteriaIDs))

for (i in 1:length(alternativesIDs)){
  for (j in 1:length(criteriaIDs)){
    performance.table[i,j] = runif(1)
  }
}

y<-getNodeSet(tree,"//alternativesComparisons")

x<-getAlternativesComparisons(y[[1]], performance.table)

RXMCDA documentation built on May 1, 2019, 10:23 p.m.