Skip to contents

Given a pure string representation of a power relation, create a PowerRelation object.

Usage

newPowerRelationFromString(
  string,
  elementNames = "[0-9a-zA-Z]",
  asWhat = identity
)

Arguments

string

String representation of a power relation. Special characters such as \(\succ\) and \(\sim\) are replaced with their ASCII equivalents > and ~ respectively.

elementNames

Regular expression to match single characters in string input that should be interpreted as a name of an element. If character does not match, it is simply ignored.

asWhat

Elements are interpreted as string characters by default. base::as.numeric or base::as.integer can be passed to convert those string characters into numeric values.

Value

PowerRelation object containing vector of elements or players $elements, an ordered list of coalitions $rankingCoalitions and an ordered vector of comparators $rankingComparators

as well as an ordered list of equivalence classes $equivalenceClasses for convenience

Details

Elements in this power relation are assumed to be one character long. E.g., the coalitions "{1,2,3}" and 123 are equivalent, given that the elementNames parameter tells the function to only interpret the characters 1, 2 and 3 as valid element names.

See also

Other newPowerRelation functions: newPowerRelation()

Examples

# Elements: 1 2 3
# 123 > 12 > 23 > 1 > (13 ~ 2)
newPowerRelationFromString("123 > 12 > 23 > 1 > 13 ~ 2", asWhat = as.numeric)
#> Elements: 1 2 3
#> 123 > 12 > 23 > 1 > (13 ~ 2)

# commas, braces and spaces are ignored by default
# notice that since an empty set is not a valid name of an element,
# it is simply ignored. Since there are no valid elements at the
# end, it is interpreted as an empty set.
newPowerRelationFromString("{1,2,3} > {1,3} > {1,2 } ~ \u2205", asWhat = as.numeric)
#> Elements: 1 2 3
#> 123 > 13 > (12 ~ {})

# use unvoncentional names
pr <- newPowerRelationFromString(".,; > .;~.,~,; > .~,~;", elementNames = "[.,;]")
stopifnot(pr$elements == sort(c(".", ",", ";")))