| Title: | Tools for Calculating Allocations in Game Theory using Exact and Approximated Methods |
|---|---|
| Description: | The main objective of cooperative Transferable-Utility games (TU-games) is to allocate a good among the agents involved. The package implements major solution concepts including the Shapley value, Banzhaf value, and egalitarian rules, alongside their extensions for structured games: the Owen value and Banzhaf-Owen value for games with a priori unions, and the Myerson value for communication games on networks. To address the inherent exponential computational complexity of exact evaluation, the package offers both exact algorithms and linear approximation methods based on sampling, enabling the analysis of large-scale games. Additionally, it supports core set-based solutions, allowing computation of the vertices and the centroid of the core. |
| Authors: | Maria D. Guillen [cre, aut] (ORCID: <https://orcid.org/0000-0002-2445-5654>), Juan Carlos Gonçalves [aut] (ORCID: <https://orcid.org/0000-0002-0867-0004>) |
| Maintainer: | Maria D. Guillen <[email protected]> |
| License: | AGPL (>= 3) |
| Version: | 1.1.1 |
| Built: | 2026-05-10 08:40:33 UTC |
| Source: | https://github.com/mariaguilleng/tuvalues |
Calculate the Banzhaf value
banzhaf( characteristic_func, n_players = 0, method = "exact", n_rep = 10000, replace = FALSE, echo = TRUE )banzhaf( characteristic_func, n_players = 0, method = "exact", n_rep = 10000, replace = FALSE, echo = TRUE )
characteristic_func |
The valued function defined on the subsets of the number of players. |
n_players |
Only used if |
method |
Method used to calculate the Banzhaf value. Valid methods are:
|
n_rep |
Only used if |
replace |
Should sampling be with replacement? |
echo |
Only used if |
The Banzhaf value for each player
n <- 8 v <- function(coalition) { if (length(coalition) > n/2) { return(1) } else { return(0) } } banzhaf(v, method = "exact", n_players = n) banzhaf(v, method = "appro", n_rep = 2000, n_players = n, replace = TRUE) v<-c(0,0,0,1,2,1,3) banzhaf(v, method = "exact") banzhaf(v, method = "appro", n_rep = 2000, replace = TRUE)n <- 8 v <- function(coalition) { if (length(coalition) > n/2) { return(1) } else { return(0) } } banzhaf(v, method = "exact", n_players = n) banzhaf(v, method = "appro", n_rep = 2000, n_players = n, replace = TRUE) v<-c(0,0,0,1,2,1,3) banzhaf(v, method = "exact") banzhaf(v, method = "appro", n_rep = 2000, replace = TRUE)
Calculate the approximated Banzhaf Index based on sampling
banzhaf_appro(characteristic_func, n_players, n_rep, replace, echo)banzhaf_appro(characteristic_func, n_players, n_rep, replace, echo)
characteristic_func |
The valued function defined on the subsets of the number of players |
n_players |
The number of players |
n_rep |
The number of iterations to perform in the approximated calculation |
replace |
Should sampling be with replacement? |
echo |
Show progress of the calculation. |
The Shapley value for each player
Calculate the approximated Banzhaf Index
banzhaf_exact(characteristic_func, n_players)banzhaf_exact(characteristic_func, n_players)
characteristic_func |
The valued function defined on the subsets of the number of players |
n_players |
The number of players in the game. |
The Banzhaf Index for each player
Calculate the Banzhaf-Owen value
banzhaf_owen( characteristic_func, union, n_players = 0, method = "exact", n_rep = 10000, replace = TRUE, echo = TRUE )banzhaf_owen( characteristic_func, union, n_players = 0, method = "exact", n_rep = 10000, replace = TRUE, echo = TRUE )
characteristic_func |
The valued function defined on the subsets of the number of players |
union |
List of vectors indicating the a priori unions between the players |
n_players |
Only used if |
method |
Method used to calculate the Owen value. Valid methods are:
|
n_rep |
Only used if |
replace |
Should sampling be with replacement? |
echo |
Only used if |
The Banzhaf-Owen value for each player
Saavedra-Nieves, A., & Fiestras-Janeiro, M. G. (2021). Sampling methods to estimate the Banzhaf–Owen value. Annals of Operations Research, 301(1), 199-223.
characteristic_func <- c(0,0,0,0,30,30,40,40,50,50,60,70,80,90,100) union <- list(c(1,3),c(2),c(4)) banzhaf_owen(characteristic_func, union) banzhaf_owen(characteristic_func, union, method = "appro", n_rep = 4000)characteristic_func <- c(0,0,0,0,30,30,40,40,50,50,60,70,80,90,100) union <- list(c(1,3),c(2),c(4)) banzhaf_owen(characteristic_func, union) banzhaf_owen(characteristic_func, union, method = "appro", n_rep = 4000)
Calculate the approximated Banzhaf-Owen value using the algorithm proposed by Saavedra-Nieves & Fiestras-Janeiro (2021).
banzhaf_owen_appro(characteristic_func, union, n_players, n_rep, replace, echo)banzhaf_owen_appro(characteristic_func, union, n_players, n_rep, replace, echo)
characteristic_func |
The valued function defined on the subsets of the number of players |
union |
List of vectors indicating the a priori unions between the players |
n_players |
The number of players |
n_rep |
Only used if |
replace |
Should sampling be with replacement? |
echo |
Show progress of the calculation. |
The Banzhaf-Owen Index for each player
Saavedra-Nieves, A., & Fiestras-Janeiro, M. G. (2021). Sampling methods to estimate the Banzhaf–Owen value. Annals of Operations Research, 301(1), 199-223.
Calculate the approximated Banzhaf-Owen value
banzhaf_owen_exact(characteristic_func, union, n_players)banzhaf_owen_exact(characteristic_func, union, n_players)
characteristic_func |
The valued function defined on the subsets of the number of players |
union |
List of vectors indicating the a priori unions between the players |
n_players |
The number of players in the game. |
The Banzhaf Index for each player
Calculate the centroid of core of the game if it exits.
centroid( characteristic_func, n_players = 0, method = "exact", n_rep = 1000, echo = TRUE )centroid( characteristic_func, n_players = 0, method = "exact", n_rep = 1000, echo = TRUE )
characteristic_func |
The valued function defined on the subsets of the number of players. |
n_players |
Only used if |
method |
Method used to calculate the core. Valid methods are:
|
n_rep |
Only used if |
echo |
Only used if |
The centroid of the core if it exists.
Camacho, J., Gonçalves-Dosantos, J. C., & Sánchez-Soriano, J. (2025). A Linear Programming Approach to Estimate the Core in Cooperative Games. arXiv preprint arXiv:2510.01766.
v <- c(2,3,5,5,7,8,10) centroid(v, method = "exact") centroid(v, method = "appro", n_rep = 100) n <- 3 v <- function(coalition) { size <- length(coalition) if (size <= 1) { return(0) } else if (size == 2) { return(10) } else if (size == 3) { return(24) } else { return(0) } } centroid(v, n, method = "exact") centroid(v, n, method = "appro", n_rep = 200)v <- c(2,3,5,5,7,8,10) centroid(v, method = "exact") centroid(v, method = "appro", n_rep = 100) n <- 3 v <- function(coalition) { size <- length(coalition) if (size <= 1) { return(0) } else if (size == 2) { return(10) } else if (size == 3) { return(24) } else { return(0) } } centroid(v, n, method = "exact") centroid(v, n, method = "appro", n_rep = 200)
Create all the possible coalitions given the number of players
coalitions(n_players)coalitions(n_players)
n_players |
Number of players |
A list containing a data.frame of the binary representation
of the coalitions and a vector of the classical representation (as
sets) of the coalitions
Calculate the vertices of the core of the game following Camacho et al. (2025)
core_appro(characteristic_func, n_players = 0, n_rep = 1000, echo = TRUE)core_appro(characteristic_func, n_players = 0, n_rep = 1000, echo = TRUE)
characteristic_func |
The valued function defined on the subsets of the number of players. |
n_players |
Only used if |
n_rep |
The number of iterations to perform in the algorithm. |
echo |
Show progress of the calculation. |
The vertices of the estimated core
Camacho, J., Gonçalves-Dosantos, J. C., & Sánchez-Soriano, J. (2025). A Linear Programming Approach to Estimate the Core in Cooperative Games. arXiv preprint arXiv:2510.01766.
Calculate the vertices of core of the game.
core_exact(characteristic_func, n_players = 0)core_exact(characteristic_func, n_players = 0)
characteristic_func |
The valued function defined on the subsets of the number of players. |
n_players |
Only used if |
The vertices of the core
Calculate the vertices of core of the game if it exits.
coreVertex( characteristic_func, n_players = 0, method = "exact", n_rep = 1000, echo = TRUE )coreVertex( characteristic_func, n_players = 0, method = "exact", n_rep = 1000, echo = TRUE )
characteristic_func |
The valued function defined on the subsets of the number of players. |
n_players |
Only used if |
method |
Method used to calculate the core. Valid methods are:
|
n_rep |
Only used if |
echo |
Only used if |
The vertices of the core if it exists.
Camacho, J., Gonçalves-Dosantos, J. C., & Sánchez-Soriano, J. (2025). A Linear Programming Approach to Estimate the Core in Cooperative Games. arXiv preprint arXiv:2510.01766.
v <- c(2,3,5,5,7,8,10) coreVertex(v, method = "exact") coreVertex(v, method = "appro", n_rep = 100) n <- 3 v <- function(coalition) { size <- length(coalition) if (size <= 1) { return(0) } else if (size == 2) { return(10) } else if (size == 3) { return(24) } else { return(0) } } coreVertex(v, n, method = "exact") coreVertex(v, n, method = "appro", n_rep = 200)v <- c(2,3,5,5,7,8,10) coreVertex(v, method = "exact") coreVertex(v, method = "appro", n_rep = 100) n <- 3 v <- function(coalition) { size <- length(coalition) if (size <= 1) { return(0) } else if (size == 2) { return(10) } else if (size == 3) { return(24) } else { return(0) } } coreVertex(v, n, method = "exact") coreVertex(v, n, method = "appro", n_rep = 200)
Calculate the egalitarian value
egalitarian(characteristic_func, n_players = 0)egalitarian(characteristic_func, n_players = 0)
characteristic_func |
The valued function defined on the subsets of the number of players |
n_players |
Only used if |
The egalitarian value for each player
n <- 10 v <- function(coalition) { if (length(coalition) > n/2) { return(1) } else { return(0) } } egalitarian(v,n) v <- c(1,1,2,1,2,2,2) egalitarian(v)n <- 10 v <- function(coalition) { if (length(coalition) > n/2) { return(1) } else { return(0) } } egalitarian(v,n) v <- c(1,1,2,1,2,2,2) egalitarian(v)
Calculate the egalitarian value in games with a priori unions
egalitarian_unions(characteristic_func, union, n_players = 0)egalitarian_unions(characteristic_func, union, n_players = 0)
characteristic_func |
The valued function defined on the subsets of the number of players |
union |
List of vectors indicating the a priori unions between the players. |
n_players |
Only used if |
The egalitarian value for each player
n <- 10 v <- function(coalition) { if (length(coalition) > n/2) { return(1) } else { return(0) } } union <- list(1:4,5:n) egalitarian_unions(v,union,n) v <- c(1,1,2,1,2,2,2) union <- list(c(1,2),c(3)) egalitarian_unions(v, union)n <- 10 v <- function(coalition) { if (length(coalition) > n/2) { return(1) } else { return(0) } } union <- list(1:4,5:n) egalitarian_unions(v,union,n) v <- c(1,1,2,1,2,2,2) union <- list(c(1,2),c(3)) egalitarian_unions(v, union)
Calculate the equal surplus division value
equal_surplus_division(characteristic_func, n_players = 0)equal_surplus_division(characteristic_func, n_players = 0)
characteristic_func |
The valued function defined on the subsets of the number of players |
n_players |
Only used if |
The equal surplus division value for each player
n <- 10 v <- function(coalition) { if (length(coalition) > n/2) { return(1) } else { return(0) } } equal_surplus_division(v,n) v <- c(1,1,2,1,2,2,2) equal_surplus_division(v)n <- 10 v <- function(coalition) { if (length(coalition) > n/2) { return(1) } else { return(0) } } equal_surplus_division(v,n) v <- c(1,1,2,1,2,2,2) equal_surplus_division(v)
Calculate the equal surplus division value in games with a priori unions
equal_surplus_division_unions( characteristic_func, union, n_players = 0, type = 1 )equal_surplus_division_unions( characteristic_func, union, n_players = 0, type = 1 )
characteristic_func |
The valued function defined on the subsets of the number of players |
union |
List of vectors indicating the a priori unions between the players. |
n_players |
Only used if |
type |
Number indicating the type of equal surplus division value to compute following Alonso-Meijide et al. (2020). Values 1, 2 and 3 are implemented. |
The equal surplus division value for each player
Alonso-Meijide, J. M., Costa, J., García-Jurado, I., & Gonçalves-Dosantos, J. C. (2020). On egalitarian values for cooperative games with a priori unions. Top, 28(3), 672-688.
n <- 3 v <- function(coalition) { size <- length(coalition) if (size <= 1) { return(0) } else if (size == 2) { return(10) } else if (size == 3) { return(24) } else { return(0) } } union <- list(1:4,5:n) equal_surplus_division_unions(v,union,n,type = 1) v <- c(1,1,2,1,2,2,2) union <- list(c(1,2),c(3)) equal_surplus_division_unions(v, union, type = 2)n <- 3 v <- function(coalition) { size <- length(coalition) if (size <= 1) { return(0) } else if (size == 2) { return(10) } else if (size == 3) { return(24) } else { return(0) } } union <- list(1:4,5:n) equal_surplus_division_unions(v,union,n,type = 1) v <- c(1,1,2,1,2,2,2) union <- list(c(1,2),c(3)) equal_surplus_division_unions(v, union, type = 2)
Calculate the Myerson value in a communication game.
myerson( characteristic_func, graph_edges, n_players = 0, method = "exact", n_rep = 10000, echo = TRUE )myerson( characteristic_func, graph_edges, n_players = 0, method = "exact", n_rep = 10000, echo = TRUE )
characteristic_func |
The valued function defined on the subsets of the number of players. It can be provided as a vector or as a function. |
graph_edges |
Edges of the communication graph of the game. It must be
a |
n_players |
Only used if |
method |
Method used to calculate the Myerson value. Valid methods are:
|
n_rep |
Only used if |
echo |
Only used if |
The Myerson value for each player.
characteristic_func <- c( 1, 2, 0, 3, 3, 1, 4, 2, 5, 3, 3, 6, 4, 5, 15 ) graph_edges <- list(c(1, 2), c(2, 4)) myerson(characteristic_func, graph_edges, method = "exact") myerson(characteristic_func, graph_edges, method = "appro", n_rep = 1000) v <- function(S) { if (length(S) == 2) { return(1) } return(0) } n <- 3 graph_edges <- list(c(1, 2)) myerson(v, graph_edges, n_players = n, method = "exact") myerson(v, graph_edges, n_players = n, method = "appro", n_rep = 2000)characteristic_func <- c( 1, 2, 0, 3, 3, 1, 4, 2, 5, 3, 3, 6, 4, 5, 15 ) graph_edges <- list(c(1, 2), c(2, 4)) myerson(characteristic_func, graph_edges, method = "exact") myerson(characteristic_func, graph_edges, method = "appro", n_rep = 1000) v <- function(S) { if (length(S) == 2) { return(1) } return(0) } n <- 3 graph_edges <- list(c(1, 2)) myerson(v, graph_edges, n_players = n, method = "exact") myerson(v, graph_edges, n_players = n, method = "appro", n_rep = 2000)
Calculate the Myerson value in a communication game with a priori unions.
myerson_unions( characteristic_func, n_players = 0, unions, graph_edges, method = "exact", n_rep = 10000, echo = TRUE )myerson_unions( characteristic_func, n_players = 0, unions, graph_edges, method = "exact", n_rep = 10000, echo = TRUE )
characteristic_func |
The valued function defined on the subsets of the number of players. It can be provided as a vector or as a function. |
n_players |
Only used if |
unions |
List of vectors indicating the a priori unions between the players. |
graph_edges |
Edges of the communication graph of the game. It must be
a |
method |
Method used to calculate the Myerson value. Valid methods are:
|
n_rep |
Only used if |
echo |
Only used if |
The Myerson value for each player.
v <- c( 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1 ) graph_edges <- list(c(2,3),c(3,1),c(1,4)) unions <- list(c(2,3),c(1),c(4)) myerson_unions(v, unions = unions, graph_edges = graph_edges, method = "exact") myerson_unions(v, unions = unions, graph_edges = graph_edges, method = "appro", n_rep = 2000)v <- c( 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1 ) graph_edges <- list(c(2,3),c(3,1),c(1,4)) unions <- list(c(2,3),c(1),c(4)) myerson_unions(v, unions = unions, graph_edges = graph_edges, method = "exact") myerson_unions(v, unions = unions, graph_edges = graph_edges, method = "appro", n_rep = 2000)
Calculate the Owen value
owen( characteristic_func, union, n_players = 0, method = "exact", n_rep = 10000, echo = TRUE )owen( characteristic_func, union, n_players = 0, method = "exact", n_rep = 10000, echo = TRUE )
characteristic_func |
The valued function defined on the subsets of the number of players. |
union |
List of vectors indicating the a priori unions between the players. |
n_players |
The number of players in the game. |
method |
Method used to calculate the Owen value. Valid methods are:
|
n_rep |
Only used if |
echo |
Only used if |
The Owen value for each player.
Saavedra-Nieves, A., García-Jurado, I., & Fiestras-Janeiro, M. G. (2018). Estimation of the Owen value based on sampling. In The mathematics of the uncertain: A tribute to Pedro Gil (pp. 347-356). Cham: Springer International Publishing.
n <- 10 v <- function(coalition) { if (length(coalition) > n/2) { return(1) } else { return(0) } } u <- lapply(1:(n/2), function(i) c(2*i - 1, 2*i)) owen(v, union = u, method = "appro", n_rep = 4000, n_players = n) characteristic_func <- c(1,1,2,1,2,2,2) union <- list(c(1,2),c(3)) owen(characteristic_func, union) owen(characteristic_func, union, method = "appro", n_rep = 4000)n <- 10 v <- function(coalition) { if (length(coalition) > n/2) { return(1) } else { return(0) } } u <- lapply(1:(n/2), function(i) c(2*i - 1, 2*i)) owen(v, union = u, method = "appro", n_rep = 4000, n_players = n) characteristic_func <- c(1,1,2,1,2,2,2) union <- list(c(1,2),c(3)) owen(characteristic_func, union) owen(characteristic_func, union, method = "appro", n_rep = 4000)
Calculate the approximated Owen value based on sampling using the algorithm proposed by Saavedra-Nieves et al. (2018).
owen_appro(characteristic_func, union, n_players, n_rep, echo)owen_appro(characteristic_func, union, n_players, n_rep, echo)
characteristic_func |
The valued function defined on the subsets of the number of players |
union |
List of vectors indicating the a priori unions between the players |
n_players |
The number of players |
n_rep |
The number of iterations to perform in the approximated calculation |
echo |
Show progress of the calculation. |
The Owen value for each player
Saavedra-Nieves, A., García-Jurado, I., & Fiestras-Janeiro, M. G. (2018). Estimation of the Owen value based on sampling. In The mathematics of the uncertain: A tribute to Pedro Gil (pp. 347-356). Cham: Springer International Publishing.
Calculate the exact Owen
owen_exact(characteristic_func, union, n_players = NULL)owen_exact(characteristic_func, union, n_players = NULL)
characteristic_func |
The valued function defined on the subsets of the number of players |
union |
List of vectors indicating the a priori unions between the players |
n_players |
The number of players |
The Owen value for each player
Given a permutation 0 of players and a player i, calculate the set of predecessors of the player i in the order 0
predecessor(permutation, player, include_player = FALSE)predecessor(permutation, player, include_player = FALSE)
permutation |
A permutation of the players |
player |
Number of the player i |
include_player |
Whether the player i is included as predecessor of itself or not |
The set of predecessors of the player i in the order 0
Calculate the Shapley value
shapley( characteristic_func, n_players = 0, method = "exact", n_rep = 10000, echo = TRUE )shapley( characteristic_func, n_players = 0, method = "exact", n_rep = 10000, echo = TRUE )
characteristic_func |
The valued function defined on the subsets of the number of players. |
n_players |
Only used if |
method |
Method used to alculate the Shapley value. Valid methods are:
|
n_rep |
Only used if |
echo |
Only used if |
The Shapley value for each player.
Castro, J., Gómez, D., & Tejada, J. (2009). Polynomial calculation of the Shapley value based on sampling. Computers & operations research, 36(5), 1726-1730.
n <- 10 v <- function(coalition) { if (length(coalition) > n/2) { return(1) } else { return(0) } } shapley(v, method = "appro", n_rep = 4000, n_players = n) n <- 3 v <- c(1,1,2,1,2,2,2) shapley(v, method = "exact") shapley(v, method = "appro", n_rep = 4000)n <- 10 v <- function(coalition) { if (length(coalition) > n/2) { return(1) } else { return(0) } } shapley(v, method = "appro", n_rep = 4000, n_players = n) n <- 3 v <- c(1,1,2,1,2,2,2) shapley(v, method = "exact") shapley(v, method = "appro", n_rep = 4000)
Calculate the approximated Shapley value based on sampling using the algorithm proposed by Castro et al. (2009).
shapley_appro(characteristic_func, n_players, n_rep, echo)shapley_appro(characteristic_func, n_players, n_rep, echo)
characteristic_func |
The valued function defined on the subsets of the number of players |
n_players |
The number of players |
n_rep |
The number of iterations to perform in the approximated calculation |
echo |
Show progress of the calculation. |
The Shapley value for each player
Castro, J., Gómez, D., & Tejada, J. (2009). Polynomial calculation of the Shapley value based on sampling. Computers & operations research, 36(5), 1726-1730.
Calculate the exact Shapley value
shapley_exact(characteristic_func, n_players)shapley_exact(characteristic_func, n_players)
characteristic_func |
The valued function defined on the subsets of the number of players |
n_players |
The number of players |
The Shapley value for each player