DexiModel-class {DEXiR} | R Documentation |
DexiModel
Description
DexiModel
is a RC class representing a DEXi model in R.
Details
Normally, DexiModel
objects are created by reading from a .dxi
file,
previously developed by the DEXi software. In principle, all fields of a DexiModel
should be considered read-only. DEXiR does not provide any explicit
functionality for creating and changing DEXi models in R. Of course, models can still be created
and modified in R, but without integrity and consistency guarantees.
Fields
name
character. Name of the model.
description
character. An optional textual description of the model.
linking
logical. Indicates whether or not the model uses linked attributes, which are used in DEXi to represent hierarchies of attributes (i.e., directed acyclic graphs) rather than trees.
root
DexiAttribute. The virtual root of all subtrees/hierarchies of attributes in the model.
attributes
list. A list of all DexiAttributes that constitute the model.
att_names
character. A list of all attribute names, as defined in the original DEXi model. Notice that these names may contain whitespace and other "strange" characters, and may not be unique.
att_ids
character. A list of unique attribute IDs generated by DEXiR from
att_names
usingmake.unique
. When using the DEXiR package, it is strongly advised to refer to attributes with their IDs rather than DEXi names.basic
list. A list of all basic (input) DexiAttributes in the model.
aggregate
list. A list of all aggregate (output) DexiAttributes in the model.
links
list. A list of all linked DexiAttributes in the model.
basic_ids
character. A vector of all basic attributes' unique names.
aggregate_ids
character. A vector of all aggregate attributes' unique names.
link_ids
character. A vector of all linked attributes' unique names.
alternatives
data.frame. A data frame representing decision alternatives contained in the
.dxi
file.
Methods
alternative(name = "NewAlternative", ...)
Create a data frame containing data of one decision alternative.
name
, character(1), represents the alternative's name. The arguments...
define the alternative's values to be put in the data frame. Please seeset_alternative
for the syntax of...
.as_character(alt, transpose = FALSE, structure = FALSE, round = NULL)
The argument
alt
is assumed to be a data frame containing data of one or more decision alternatives with values represented by numeric vectors.as_character(alt)
transforms the values ofalt
into a more human-readable form using character strings. Additionally,transpose = TRUE
transposes the data frame, so that rows correspod to attributes and columns to alternatives.structure = TRUE
additionally displays the tree structure of attributes; the latter works only withtranspose = TRUE
.round
denotes the number of decimal digits for printing numeric values.att_index(atts, use_id = TRUE)
Find the indices of attributes.
atts
is a character vector of attribute IDs (whenuse_id = TRUE
) or original DEXi attribute names (whenuse_id = FALSE
). Result: a numeric vector containing the set of indices. Example:Car$att_index(c("PRICE", "TECH.CHAR."))
att_stat()
Count the number of all attributes (including the virtual root), as well as the number of basic, aggregate and linked attributes in the model. Result: a list of the form list(all=..., basic=..., aggregate=..., link=...).
attrib(atts)
A general function for finding attributes in the model.
atts
is a vector or list ofDexiAttribute
s, attribute indices (integer) or attribute IDs (character). Result: a list of foundDexiAttribute
s (orNA
s if not found). Example:Car$attrib(list(5, "PRICE", "TECH.CHAR."))
compare_alternatives(...)
Calls
compare_alternatives(.self, ...)
to carry out Comparison of Alternatives. Please seecompare_alternatives
for the description of...
arguments.convert(...)
Calls
convert_alternatives(.self, ...)
to convert decision alternatives' data. Please seeconvert_alternatives
for the description of...
arguments.evaluate(...)
Calls
evaluate(.self, ...)
to evaluate decision alternatives. Please seeevaluate
for the description of...
arguments.first()
Return first non-virtual model attribute, i.e., first descendant of model$root.
initialize(name = "", description = "", root = NULL, linking = FALSE, ...)
Initialize a
DexiModel
object.link_attributes()
Carries out the linking of attributes. DEXi attributes that have the same names and value scales, and satisfy some other constraints to prevent making cycles in the model, are linked together so that they logically represent a single attribute. In this way, a tree of attributes is conceptually turned in a hierarchy (directed acyclic graph). If
linking = TRUE
,link_attributes
is called bysetup()
after reading the model.plus_minus(...)
Calls
plus_minus(.self, ...)
to carry out Plus-Minus Analysis. Please seeplus_minus
for the description of...
arguments.scale(atts)
Find attribute scales.
atts
is a vector ofDexiAttribute
s. Result: a vector of the correspondingDexiScale
s (orNA
s).selective_explanation(...)
Calls
selective_explanation(.self, ...)
to carry out Selective Explanation. Please seeselective_explanation
for the description of...
arguments.setup()
Called by
initialize()
as the last step that establishes consistent internal data structures by making unique attribute IDs, linking attributes (if required), making lists of attributes and their IDs, and creating a data frame of alternatives.verify()
Check the correctnes of a
DexiModel
object and its fields. Result:error()
orTRUE
.
See Also
evaluate
, set_alternative
, read_dexi()
Examples
# Get ".dxi" file name
CarDxi <- system.file("extdata", "Car.dxi", package = "DEXiR")
# Read DEXi model
Car <- read_dexi(CarDxi)
# Print fields of Car
Car
Car$verify()
Car$name
Car$description
Car$linking
att_names(Car$attributes)
Car$att_names
Car$att_ids
Car$basic_ids
Car$aggregate_ids
Car$att_stat()
Car$scale(Car$aggregate)
# Find some attributes in the model
Car$first()
Car$attributes[[3]]
Car$attrib("PRICE")
Car$att_index("PRICE")
# Display alternatives loaded from "Car.dxi"
Car$alternatives
Car$as_character(Car$alternatives)
Car$as_character(Car$alternatives, transpose = TRUE)
Car$as_character(Car$alternatives, transpose = TRUE, structure = TRUE)
# Define and evaluate a decision alternative (some car)
alt <- Car$alternative("MyCar",
BUY.PRICE="low", MAINT.PRICE=2, X.PERS=3, X.DOORS=3, LUGGAGE="medium", SAFETY=2)
Car$evaluate(alt)
Car$as_character(Car$evaluate(alt))
# Employ the set-based evaluation (notice how the value of SAFETY propagates upwards to TECH.CHAR.)
alt <- Car$alternative("MyCar",
BUY.PRICE="low", MAINT.PRICE=2, X.PERS=3, X.DOORS=3, LUGGAGE="medium", SAFETY=c(2,3))
Car$evaluate(alt)
Car$as_character(Car$evaluate(alt))
# Analysis of alternatives
Car$selective_explanation(1)
Car$selective_explanation(alt)
Car$plus_minus(alt)
Car$compare_alternatives(alt)
Car$compare_alternatives(1, 2)
Car$compare_alternatives(1, alt)