-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAirportGame.R
More file actions
105 lines (94 loc) · 2.51 KB
/
AirportGame.R
File metadata and controls
105 lines (94 loc) · 2.51 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
library(CoopGame)
#' @name airportGameValue
#' @title Compute cost value of a coalition for an airport game.
#' @description \strong{Coalition cost value for an airport game:} \cr
#' For further information see \link{airportGame}
#' @aliases airportGameValue
#' @export airportGameValue
#' @template authhor/EW
#' @template param/S
#' @template param/k
#' @return Cost value for a coalition \code{S}.
#' @examples
#' source("AirportGames.R")
#' airportGameValue(S=c(1, 2, 3), k=c(10, 20, 30))
#'
airportGameValue<-function(S, k) {
paramCheckResult = getEmptyParamCheckResult()
stopOnInvalidCoalitionS(paramCheckResult, S)
stopOnInvalidNumberOfPlayers(paramCheckResult, n=length(k))
logicAirportGameValue(S, k)
}
logicAirportGameValue=function(S, k) {
result = 0
i<-1
end<-max(S)
while(i<=end) {
result = result + k[i]
i<-i+1
}
return (result)
}
#' @name airportGameVector
#' @title Compute game vector for an aiport game.
#' @description \strong{Game vector for an aiport game:} \cr
#' For further information see \link{airportGame}
#' @aliases airportGameVector
#' @export airportGameVector
#' @template author/EW
#' @template param/n
#' @template param/k
#' @return Game vector where each element represents the cost for each coalition possible (except empty coalition).
#' @examples
#' source("AirportGames.R")
#' airportGameVector(n=3,k=c(10, 20, 30))
#'
airportGameVector<-function(n, k) {
bitMatrix = createBitMatrix(n)[,1:n];
A<-c()
i<-1
end<-((2^n)-1)
while(i<=end) {
currCoal<-which(bitMatrix[i,]&1)
A[i] = airportGameValue(S=currCoal, k=k)
i<-i+1
}
return (A)
}
#' @title Construct an airport game
#' @description \strong{Create a list containing
#' all information about a specified airport game:} \cr
#' Each value of the cost vector \code{c} specifies the total cost of the
#' respective coalition. \cr
#' @template author/EW
#' @name airportGame
#' @template param/n
#' @template param/k
#' @return A list with three elements
#' representing the airport game (n, k, Cost vector c)
#' @export
#' @section Related Functions:
#' \link{airportGameValue}, \link{airportGameVector}
#' @examples
#' source("AirportGames.R")
#' airportGame(n=3, k=c(10, 20, 30))
#'
#' \donttest{
#' source("AirportGames.R")
#' airportGame(n=3, k=c(10, 20, 30))
#' #Output:
#' #$n
#' #[1] 3
#'
#' $k
#' #[1] 10 20 30
#'
#' #$c
#' #[1] 10 30 60 30 60 60 60
#' }
#'
airportGame<-function(n, k) {
c = airportGameVector(n=n, k=k)
retAirportGame = list(n=n, k=k, c=c)
return (retAirportGame)
}