Last data update: 2014.03.03

R: Cooperative Game Theory
GameTheory-packageR Documentation

Cooperative Game Theory

Description

Implementation of a common set of punctual solutions for Cooperative Game Theory.

Details

Package: GameTheory
Type: Package
Version: 1.0
Date: 2015-02-04
License: GPL (>= 2)

Author(s)

Sebastian Cano-Berlanga <cano.berlanga@gmail.com>

References

Aumann, R.J. and Maschler, M., (1985) "Game Theoretic Analysis of a bankruptcy from the Talmud." Journal of Economic Theory 36, pp.195–213.

O'Neill B. (1982). "A problem of rights arbitration from the Talmud." Mathematical Social Sciences, 2(4), pp.345–371.

Shapley L, Shubik M (1954). "A Method for Evaluating the Distribution of Power in a Committee System." The American Political Science Review, 48(3), 787–792.

Shapley L (1953). A value for n-person games. In Tucker A, Kuhn H (Eds.), Contributions to the theory of games II (pp. 307–317). Princeton University Press: Princeton NJ.

Schmeidler D (1969). "The Nucleolus of a characteristic function game." SIAM Journal of Applied Mathematics, 17, 1163–1170.

Examples


### TRANSFERABLE UTILITY

## 3 PLAYER SHAPLEY VALUE

# Begin defining the game

COALITIONS <- c(46125,17437.5,5812.5,69187.5,53812.5,30750,90000)
LEMAIRE<-DefineGame(3,COALITIONS)
summary(LEMAIRE)

# End defining the game

NAMES <- c("Investor 1","Investor 2","Investor 3")
LEMAIRESHAPLEY <- ShapleyValue(LEMAIRE,NAMES)
summary(LEMAIRESHAPLEY)

# 3 PLAYER NUCLEOLUS OF A GAINS GAME 

LEMAIRENUCLEOLUS<-Nucleolus(LEMAIRE)
summary(LEMAIRENUCLEOLUS)


# 4 PLAYER SHAPLEY VALUE

COALITIONS <- c(26,27,55,57,53,81,83,82,84,110,108,110,110,110,110)
AIR<-DefineGame(4,COALITIONS)

NAMES <- c("Airline 1","Airline 2","Airline 3","Airline 4")
AIRSHAPLEY<-ShapleyValue(AIR,NAMES)
summary(AIRSHAPLEY)

# 4 PLAYER NUCLEOLUS OF A COST GAME 

AIRNUCLEOLUS<-Nucleolus(AIR,type="Cost")
summary(AIRNUCLEOLUS)

## SHAPLEY - SHUBIK POWER INDEX

# 2003 Elections
SEATS<-c(46,42,23,15,9)
PARTIES<-c("CiU","PSC","ERC","PP","ICV")
E2003<-ShapleyShubik(68,SEATS,PARTIES)
summary(E2003)

# 2006 Elections
SEATS<-c(48,37,21,14,12,3)
PARTIES<-c("CiU","PSC","ERC","PP","ICV","C's")
E2006<-ShapleyShubik(68,SEATS,PARTIES)
summary(E2006)

# 2012 Elections
SEATS<-c(50,20,21,19,13,9,3)
PARTIES<-c("CiU","PSC","ERC","PP","ICV","C's","CUP")
E2012<-ShapleyShubik(68,SEATS,PARTIES)
summary(E2012)

## CONFLICTING CLAIMS PROBLEM

## replication of Gallastegui et al. (2003), Table 7.

CLAIMS <- c(158,299,927,2196,4348,6256,13952)
COUNTRIES <- c("Germany","Netherlands","Belgium","Ireland","UK","Spain","France")
INARRA <- AllRules(13500,CLAIMS,COUNTRIES)
summary(INARRA)

plot(INARRA,5) ## Display allocations for UK
LorenzRules(INARRA) ## Inequality graph


Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(GameTheory)
Loading required package: lpSolveAPI
Loading required package: combinat

Attaching package: 'combinat'

The following object is masked from 'package:utils':

    combn

Loading required package: gtools
Loading required package: ineq
Loading required package: kappalab
Loading required package: lpSolve
Loading required package: quadprog
Loading required package: kernlab

Attaching package: 'kappalab'

The following object is masked from 'package:ineq':

    entropy

> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/GameTheory/GameTheory-package.Rd_%03d_medium.png", width=480, height=480)
> ### Name: GameTheory-package
> ### Title: Cooperative Game Theory
> ### Aliases: GameTheory-package GameTheory
> 
> ### ** Examples
> 
> 
> ### TRANSFERABLE UTILITY
> 
> ## 3 PLAYER SHAPLEY VALUE
> 
> # Begin defining the game
> 
> COALITIONS <- c(46125,17437.5,5812.5,69187.5,53812.5,30750,90000)
> LEMAIRE<-DefineGame(3,COALITIONS)
> summary(LEMAIRE)

Characteristic form of the game 

Number of agents: 3 

Coaliton Value(s) 

       v(i)
1   46125.0
2   17437.5
3    5812.5
12  69187.5
13  53812.5
23  30750.0
123 90000.0

> 
> # End defining the game
> 
> NAMES <- c("Investor 1","Investor 2","Investor 3")
> LEMAIRESHAPLEY <- ShapleyValue(LEMAIRE,NAMES)
> summary(LEMAIRESHAPLEY)

Shapley Value for the given game 

           Shapley Value
Investor 1         51750
Investor 2         25875
Investor 3         12375
> 
> # 3 PLAYER NUCLEOLUS OF A GAINS GAME 
> 
> LEMAIRENUCLEOLUS<-Nucleolus(LEMAIRE)
Model name: Nucleolus of a gains game 
            C1    C2    C3    C4             
Minimize     0     0     0    -1             
R1           0     0     0     1  >=        0
R2           1     0     0    -1  >=    46125
R3           0     1     0    -1  >=  17437.5
R4           1     1     0    -1  >=  69187.5
R5           0     0     1    -1  >=   5812.5
R6           1     0     1    -1  >=  53812.5
R7           0     1     1    -1  >=    30750
R8           1     1     1     0   =    90000
Kind       Std   Std   Std   Std             
Type      Real  Real  Real  Real             
Upper      Inf   Inf   Inf   Inf             
Lower        0     0     0     0             

Model name:  'Nucleolus of a gains game ' - run #1    
Objective:   Minimize(R0)
 
SUBMITTED
Model size:        8 constraints,       4 variables,           19 non-zeros.
Sets:                                   0 GUB,                  0 SOS.
 
Using DUAL simplex for phase 1 and PRIMAL simplex for phase 2.
The primal and dual simplex pricing strategy set to 'Devex'.
 
Found feasibility by dual simplex after             4 iter.
 
Optimal solution             -6562.5 after          5 iter.

Excellent numeric accuracy ||*|| = 0

 MEMO: lp_solve version 5.5.2.0 for 64 bit OS, with 64 bit LPSREAL variables.
      In the total iteration count 5, 0 (0.0%) were bound flips.
      There were 2 refactorizations, 0 triggered by time and 0 by density.
       ... on average 2.5 major pivots per refactorization.
      The largest [LUSOL v2.2.1.0] fact(B) had 18 NZ entries, 1.0x largest basis.
      The constraint matrix inf-norm is 1, with a dynamic range of 1.
      Time to load data was 0.002 seconds, presolve used 0.000 seconds,
       ... 0.000 seconds in simplex solver, in total 0.002 seconds.
Using DUAL simplex for phase 1 and PRIMAL simplex for phase 2.
The primal and dual simplex pricing strategy set to 'Devex'.
 
Found feasibility by dual simplex after             3 iter.
 
Optimal solution            -7031.25 after          4 iter.

Excellent numeric accuracy ||*|| = 0

 MEMO: lp_solve version 5.5.2.0 for 64 bit OS, with 64 bit LPSREAL variables.
      In the total iteration count 4, 0 (0.0%) were bound flips.
      There were 3 refactorizations, 0 triggered by time and 0 by density.
       ... on average 1.3 major pivots per refactorization.
      The largest [LUSOL v2.2.1.0] fact(B) had 17 NZ entries, 1.0x largest basis.
      The constraint matrix inf-norm is 1, with a dynamic range of 1.
      Time to load data was 0.002 seconds, presolve used 0.000 seconds,
       ... 0.000 seconds in simplex solver, in total 0.002 seconds.
Using DUAL simplex for phase 1 and PRIMAL simplex for phase 2.
The primal and dual simplex pricing strategy set to 'Devex'.
 
Found feasibility by dual simplex after             3 iter.
 
Optimal solution            -7031.25 after          4 iter.

Excellent numeric accuracy ||*|| = 0

 MEMO: lp_solve version 5.5.2.0 for 64 bit OS, with 64 bit LPSREAL variables.
      In the total iteration count 4, 0 (0.0%) were bound flips.
      There were 3 refactorizations, 0 triggered by time and 0 by density.
       ... on average 1.3 major pivots per refactorization.
      The largest [LUSOL v2.2.1.0] fact(B) had 16 NZ entries, 1.0x largest basis.
      The constraint matrix inf-norm is 1, with a dynamic range of 1.
      Time to load data was 0.002 seconds, presolve used 0.000 seconds,
       ... 0.000 seconds in simplex solver, in total 0.002 seconds.
> summary(LEMAIRENUCLEOLUS)

Nucleolus of a Gains Game for the given coalitions 

     v(S)     x(S)       Ei
1 46125.0 52687.50 -6562.50
2 17437.5 24468.75 -7031.25
3  5812.5 12843.75 -7031.25
> 
> 
> # 4 PLAYER SHAPLEY VALUE
> 
> COALITIONS <- c(26,27,55,57,53,81,83,82,84,110,108,110,110,110,110)
> AIR<-DefineGame(4,COALITIONS)
> 
> NAMES <- c("Airline 1","Airline 2","Airline 3","Airline 4")
> AIRSHAPLEY<-ShapleyValue(AIR,NAMES)
> summary(AIRSHAPLEY)

Shapley Value for the given game 

          Shapley Value
Airline 1      17.33333
Airline 2      18.00000
Airline 3      36.33333
Airline 4      38.33333
> 
> # 4 PLAYER NUCLEOLUS OF A COST GAME 
> 
> AIRNUCLEOLUS<-Nucleolus(AIR,type="Cost")
Model name: 
            C1    C2    C3    C4    C5    C6    
Minimize     0     0     0     0     1    -1    
Kind       Std   Std   Std   Std   Std   Std    
Type      Real  Real  Real  Real  Real  Real    
Upper      Inf   Inf   Inf   Inf   Inf   Inf    
Lower        0     0     0     0     0     0    
Model name: Nucleolus of a cost game 
            C1    C2    C3    C4    C5    C6         
Maximize     0     0     0     0     1    -1         
R1           0     0     0     0     0     1  >=    0
R2           1     0     0     0     1    -1  <=   26
R3           0     1     0     0     1    -1  <=   27
R4           1     1     0     0     1    -1  <=   53
R5           0     0     1     0     1    -1  <=   55
R6           1     0     1     0     1    -1  <=   81
R7           0     1     1     0     1    -1  <=   82
R8           1     1     1     0     1    -1  <=  108
R9           0     0     0     1     1    -1  <=   57
R10          1     0     0     1     1    -1  <=   83
R11          0     1     0     1     1    -1  <=   84
R12          1     1     0     1     1    -1  <=  110
R13          0     0     1     1     1    -1  <=  110
R14          1     0     1     1     1    -1  <=  110
R15          0     1     1     1     1    -1  <=  110
R16          1     1     1     1     0     0   =  110
Kind       Std   Std   Std   Std   Std   Std         
Type      Real  Real  Real  Real  Real  Real         
Upper      Inf   Inf   Inf   Inf   Inf   Inf         
Lower        0     0     0     0     0     0         

Model name:  'Nucleolus of a cost game ' - run #1    
Objective:   Maximize(R0)
 
SUBMITTED
Model size:       16 constraints,       6 variables,           61 non-zeros.
Sets:                                   0 GUB,                  0 SOS.
 
Using PRIMAL simplex for phase 1 and DUAL simplex for phase 2.
The primal and dual simplex pricing strategy set to 'Devex'.
 
Found feasibility by primal simplex after           5 iter.
 
Optimal solution                  13 after          7 iter.

Excellent numeric accuracy ||*|| = 0

 MEMO: lp_solve version 5.5.2.0 for 64 bit OS, with 64 bit LPSREAL variables.
      In the total iteration count 7, 0 (0.0%) were bound flips.
      There were 2 refactorizations, 0 triggered by time and 0 by density.
       ... on average 3.5 major pivots per refactorization.
      The largest [LUSOL v2.2.1.0] fact(B) had 59 NZ entries, 1.0x largest basis.
      The constraint matrix inf-norm is 1, with a dynamic range of 1.
      Time to load data was 0.001 seconds, presolve used 0.000 seconds,
       ... 0.001 seconds in simplex solver, in total 0.002 seconds.
[1] 13 14 42 41 13  0
Using PRIMAL simplex for phase 1 and DUAL simplex for phase 2.
The primal and dual simplex pricing strategy set to 'Devex'.
 
Found feasibility by primal simplex after           5 iter.
 
Optimal solution                13.5 after          8 iter.

Excellent numeric accuracy ||*|| = 0

 MEMO: lp_solve version 5.5.2.0 for 64 bit OS, with 64 bit LPSREAL variables.
      In the total iteration count 8, 0 (0.0%) were bound flips.
      There were 3 refactorizations, 0 triggered by time and 0 by density.
       ... on average 2.7 major pivots per refactorization.
      The largest [LUSOL v2.2.1.0] fact(B) had 56 NZ entries, 1.0x largest basis.
      The constraint matrix inf-norm is 1, with a dynamic range of 1.
      Time to load data was 0.002 seconds, presolve used 0.000 seconds,
       ... 0.000 seconds in simplex solver, in total 0.002 seconds.
[1] 13.0 13.5 41.5 42.0 13.5  0.0
Using PRIMAL simplex for phase 1 and DUAL simplex for phase 2.
The primal and dual simplex pricing strategy set to 'Devex'.
 
Found feasibility by primal simplex after           4 iter.
 
Optimal solution               14.25 after          6 iter.

Excellent numeric accuracy ||*|| = 0

 MEMO: lp_solve version 5.5.2.0 for 64 bit OS, with 64 bit LPSREAL variables.
      In the total iteration count 6, 0 (0.0%) were bound flips.
      There were 3 refactorizations, 0 triggered by time and 0 by density.
       ... on average 2.0 major pivots per refactorization.
      The largest [LUSOL v2.2.1.0] fact(B) had 43 NZ entries, 1.0x largest basis.
      The constraint matrix inf-norm is 1, with a dynamic range of 1.
      Time to load data was 0.002 seconds, presolve used 0.000 seconds,
       ... 0.000 seconds in simplex solver, in total 0.002 seconds.
[1] 13.00 13.50 40.75 42.75 14.25  0.00
Using PRIMAL simplex for phase 1 and DUAL simplex for phase 2.
The primal and dual simplex pricing strategy set to 'Devex'.
 
Found feasibility by primal simplex after           4 iter.
 
Optimal solution               14.25 after          6 iter.

Excellent numeric accuracy ||*|| = 0

 MEMO: lp_solve version 5.5.2.0 for 64 bit OS, with 64 bit LPSREAL variables.
      In the total iteration count 6, 0 (0.0%) were bound flips.
      There were 3 refactorizations, 0 triggered by time and 0 by density.
       ... on average 2.0 major pivots per refactorization.
      The largest [LUSOL v2.2.1.0] fact(B) had 42 NZ entries, 1.0x largest basis.
      The constraint matrix inf-norm is 1, with a dynamic range of 1.
      Time to load data was 0.002 seconds, presolve used 0.000 seconds,
       ... 0.000 seconds in simplex solver, in total 0.002 seconds.
[1] 13.00 13.50 40.75 42.75 14.25  0.00
> summary(AIRNUCLEOLUS)

Nucleolus of a Cost Game for the given coalitions 

  v(S)  x(S)    Ei
1   26 13.00 13.00
2   27 13.50 13.50
3   55 40.75 14.25
4   57 42.75 14.25
> 
> ## SHAPLEY - SHUBIK POWER INDEX
> 
> # 2003 Elections
> SEATS<-c(46,42,23,15,9)
> PARTIES<-c("CiU","PSC","ERC","PP","ICV")
> E2003<-ShapleyShubik(68,SEATS,PARTIES)
> summary(E2003)

Distribution of the agents 

CiU PSC ERC  PP ICV 
 46  42  23  15   9 

Minimum amount of votes to pass a vote:  68 

Shapley-Shubik Power Index 

       CiU        PSC        ERC         PP        ICV 
0.40000000 0.23333333 0.23333333 0.06666667 0.06666667 
> 
> # 2006 Elections
> SEATS<-c(48,37,21,14,12,3)
> PARTIES<-c("CiU","PSC","ERC","PP","ICV","C's")
> E2006<-ShapleyShubik(68,SEATS,PARTIES)
> summary(E2006)

Distribution of the agents 

CiU PSC ERC  PP ICV C's 
 48  37  21  14  12   3 

Minimum amount of votes to pass a vote:  68 

Shapley-Shubik Power Index 

       CiU        PSC        ERC         PP        ICV        C's 
0.40000000 0.23333333 0.23333333 0.06666667 0.06666667 0.00000000 
> 
> # 2012 Elections
> SEATS<-c(50,20,21,19,13,9,3)
> PARTIES<-c("CiU","PSC","ERC","PP","ICV","C's","CUP")
> E2012<-ShapleyShubik(68,SEATS,PARTIES)
> summary(E2012)

Distribution of the agents 

CiU PSC ERC  PP ICV C's CUP 
 50  20  21  19  13   9   3 

Minimum amount of votes to pass a vote:  68 

Shapley-Shubik Power Index 

       CiU        PSC        ERC         PP        ICV        C's        CUP 
0.53333333 0.13333333 0.13333333 0.13333333 0.03333333 0.03333333 0.00000000 
> 
> ## CONFLICTING CLAIMS PROBLEM
> 
> ## replication of Gallastegui et al. (2003), Table 7.
> 
> CLAIMS <- c(158,299,927,2196,4348,6256,13952)
> COUNTRIES <- c("Germany","Netherlands","Belgium","Ireland","UK","Spain","France")
> INARRA <- AllRules(13500,CLAIMS,COUNTRIES)
> summary(INARRA)

Claims of the Agents 

    Germany Netherlands     Belgium     Ireland          UK       Spain 
        158         299         927        2196        4348        6256 
     France 
      13952 

Assignments according to the following rules 

            Proportional     CEA      CEL Talmud      RA
Germany            75.81  158.00     0.00   79.0   73.73
Netherlands       143.46  299.00     0.00  149.5  139.53
Belgium           444.79  927.00     0.00  463.5  436.92
Ireland          1053.67 2196.00     0.00 1098.0 1071.42
UK               2086.22 3306.67   662.67 2174.0 2147.42
Spain            3001.71 3306.67  2570.67 3128.0 3101.42
France           6694.34 3306.67 10266.67 6408.0 6529.57

Inequality Analysis among rules (Gini Index) 

Proportional          CEA          CEL       Talmud           RA 
        0.58         0.38         0.77         0.56         0.57 
> 
> plot(INARRA,5) ## Display allocations for UK
> LorenzRules(INARRA) ## Inequality graph
> 
> 
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>