# \donttest{
#### the Dakota example of Winston (2003, section 6.3, 6.6 and 6.8)
A <- matrix(c(
0, 0, 0, 1,
8, 6, 1, 0,
4, 2, 1.5, 0,
2, 1.5, 0.5, 0
), 4, 4, TRUE)
B <- matrix(c(
60, 30, 20, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0
), 4, 4, TRUE)
S0Exg <- {
S0Exg <- matrix(NA, 4, 4)
S0Exg[2:4, 4] <- c(48, 20, 8)
S0Exg
}
## Compute the equilibrium by the function CGE::sdm.
ge <- CGE::sdm(A = A, B = B, S0Exg = S0Exg)
ge$p / ge$p[1]
ge$z
## Compute the equilibrium by the function sdm2.
## The function policyMeanValue is used to accelerate convergence.
ge <- sdm2(
A = A, B = B, S0Exg = S0Exg,
policy = policyMeanValue,
names.commodity = c("dollar", "lumber", "lab1", "lab2"),
names.agent = c("desk producer", "table producer", "chair producer", "consumer"),
numeraire = "dollar"
)
ge$z
ge$p
#### an example at http://web.mit.edu/15.053/www/AMP-Chapter-04.pdf.
A <- matrix(c(
0, 0, 0, 1,
0.5, 2, 1, 0,
1, 2, 4, 0
), 3, 4, TRUE)
B <- matrix(c(
6, 14, 13, 0,
0, 0, 0, 0,
0, 0, 0, 0
), 3, 4, TRUE)
S0Exg <- {
S0Exg <- matrix(NA, 3, 4)
S0Exg[2:3, 4] <- c(24, 60)
S0Exg
}
ge <- CGE::sdm(
A = A, B = B, S0Exg = S0Exg
)
ge$z
ge$p / ge$p[1]
#### an example at https://web.stanford.edu/~ashishg/msande111/notes/chapter4.pdf.
A <- matrix(c(
0, 0, 1,
4.44, 0, 0,
0, 6.67, 0,
4, 2.86, 0,
3, 6, 0
), 5, 3, TRUE)
B <- matrix(c(
3, 2.5, 0,
0, 0, 0,
0, 0, 0,
0, 0, 0,
0, 0, 0
), 5, 3, TRUE)
S0Exg <- {
S0Exg <- matrix(NA, 5, 3)
S0Exg[2:5, 3] <- 100
S0Exg
}
ge <- CGE::sdm(
A = A, B = B, S0Exg = S0Exg
)
ge$z
ge$p / ge$p[1]
#### an example at https://utw11041.utweb.utexas.edu/ORMM/supplements/methods/lpmethod/S3_dual.pdf.
A <- matrix(c(
0, 0, 1,
0, 1, 0,
1, 3, 0,
1, 0, 0
), 4, 3, TRUE)
B <- matrix(c(
2, 3, 0,
1, 0, 0,
0, 0, 0,
0, 0, 0
), 4, 3, TRUE)
S0Exg <- {
S0Exg <- matrix(NA, 4, 3)
S0Exg[2:4, 3] <- c(5, 35, 20)
S0Exg
}
ge <- CGE::sdm(
A = A, B = B, S0Exg = S0Exg
)
ge$z
ge$p / ge$p[1]
#### the Giapetto example of Winston (2003, section 3.1)
A <- matrix(c(
0, 0, 1,
2, 1, 0,
1, 1, 0,
1, 0, 0
), 4, 3, TRUE)
B <- matrix(c(
27 - 10 - 14, 21 - 9 - 10, 0,
0, 0, 0,
0, 0, 0,
0, 0, 0
), 4, 3, TRUE)
S0Exg <- {
S0Exg <- matrix(NA, 4, 3)
S0Exg[2:4, 3] <- c(100, 80, 40)
S0Exg
}
ge <- sdm2(
A = A, B = B, S0Exg = S0Exg,
policy = policyMeanValue,
numeraire = 1
)
ge$z
ge$p
#### the Dorian example (a minimization problem) of Winston (2003, section 3.2)
A <- matrix(c(
0, 0, 1,
7, 2, 0,
2, 12, 0
), 3, 3, TRUE)
B <- matrix(c(
28, 24, 0,
0, 0, 0,
0, 0, 0
), 3, 3, TRUE)
S0Exg <- {
S0Exg <- matrix(NA, 3, 3)
S0Exg[2:3, 3] <- c(50, 100)
S0Exg
}
ge <- sdm2(
A = A, B = B, S0Exg = S0Exg,
policy = policyMeanValue,
numeraire = 1
)
ge$p
ge$z
#### the diet example (a minimization problem) of Winston (2003, section 3.4)
A <- matrix(c(
0, 0, 0, 0, 1,
400, 3, 2, 2, 0,
200, 2, 2, 4, 0,
150, 0, 4, 1, 0,
500, 0, 4, 5, 0
), 5, 5, TRUE)
B <- matrix(c(
500, 6, 10, 8, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0
), 5, 5, TRUE)
S0Exg <- {
S0Exg <- matrix(NA, 5, 5)
S0Exg[2:5, 5] <- c(50, 20, 30, 80)
S0Exg
}
ge <- sdm2(
A = A, B = B, S0Exg = S0Exg,
policy = policyMeanValue,
numeraire = 1
)
ge$p
ge$z
#### An example of Elizabeth Stapel (Linear Programming: Introduction. Purplemath.
## Available from https://www.purplemath.com/modules/linprog.htm):
## Find the maximal value of 3x + 4y subject to the following constraints:
## x + 2y <= 14, 3x - y >= 0, x - y <= 2, x >= 0, y >= 0
A <- matrix(c(
0, 0, 1,
1, 2, 0,
0, 1, 0,
1, 0, 0
), 4, 3, TRUE)
B <- matrix(c(
3, 4, 0,
0, 0, 0,
3, 0, 0,
0, 1, 0
), 4, 3, TRUE)
S0Exg <- {
S0Exg <- matrix(NA, 4, 3)
S0Exg[2:4, 3] <- c(14, 0, 2)
S0Exg
}
ge <- sdm2(
A = A, B = B, S0Exg = S0Exg,
policy = policyMeanValue,
priceAdjustmentVelocity = 0.03,
numeraire = 1
)
ge$z
ge$p
# }
Run the code above in your browser using DataLab