1+ # The primal case, no mobility, no cross-good congestion, and an Armington (1969) world where each location produces only one good
2+
3+ function model_fixed_armington (optimizer, auxdata)
4+
5+ # Extract parameters
6+ param = auxdata. param
7+ graph = auxdata. graph
8+ kappa_ex_init = auxdata. kappa_ex
9+ A = auxdata. edges. A
10+ Apos = auxdata. edges. Apos
11+ Aneg = auxdata. edges. Aneg
12+ psigma = (param. sigma - 1 ) / param. sigma
13+ Lj = param. Lj
14+ # Production: Fixed because just one good is produced by each location
15+ Yj = dropdims (sum (param. Zjn, dims = 2 ) .* Lj .^ param. a, dims = 2 )
16+
17+ # Model
18+ model = Model (optimizer)
19+ set_string_names_on_creation (model, false )
20+
21+ # Variables
22+ @variable (model, Cjn[1 : graph. J, 1 : param. N] >= 1e-8 , container= Array, start = 1e-6 )
23+ @variable (model, Qin[1 : graph. ndeg, 1 : param. N], container= Array, start = 0.0 )
24+
25+ # Parameters: to be updated between solves
26+ @variable (model, kappa_ex[i = 1 : graph. ndeg] in Parameter (i), container= Array)
27+ set_parameter_value .(kappa_ex, kappa_ex_init)
28+
29+ # Defining Utility Funcion: from Cjn + parameters (by operator overloading)
30+ @expression (model, Cj, sum (Cjn .^ psigma, dims= 2 ) .^ (1 / psigma))
31+ @expression (model, cj, ifelse .(Lj .== 0 , 0.0 , Cj ./ Lj))
32+ @expression (model, uj, ((cj / param. alpha) .^ param. alpha .* (param. hj / (1 - param. alpha)) .^ (1 - param. alpha)) .^ (1 - param. rho) / (1 - param. rho))
33+ @expression (model, U, sum (param. omegaj .* Lj .* uj))
34+ @objective (model, Max, U)
35+
36+ # Balanced flow constraints
37+ @constraint (model, Pjn[j in 1 : param. J, n in 1 : param. N],
38+ Cjn[j, n] + sum (A[j, i] * Qin[i, n] for i in 1 : graph. ndeg) -
39+ Yj[j] + sum (
40+ ifelse (Qin[i, n] > 0 , Apos[j, i], Aneg[j, i]) *
41+ abs (Qin[i, n])^ (1 + param. beta) / kappa_ex[i]
42+ for i in 1 : graph. ndeg
43+ ) <= 0
44+ )
45+ return model
46+ end
47+
48+ function recover_allocation_fixed_armington (model, auxdata)
49+ param = auxdata. param
50+ graph = auxdata. graph
51+ model_dict = model. obj_dict
52+ results = Dict ()
53+ # Production: Fixed because just one good is produced by each location
54+ Yj = dropdims (sum (param. Zjn, dims = 2 ) .* param. Lj .^ param. a, dims = 2 )
55+ WY = param. Zjn .> 0
56+
57+ results[:welfare ] = value (model_dict[:U ])
58+ results[:Yjn ] = WY .* Yj
59+ results[:Yj ] = Yj
60+ results[:Cjn ] = value .(model_dict[:Cjn ])
61+ results[:Cj ] = dropdims (value .(model_dict[:Cj ]), dims = 2 )
62+ results[:Ljn ] = WY .* param. Lj
63+ results[:Lj ] = param. Lj
64+ results[:cj ] = dropdims (value .(model_dict[:cj ]), dims = 2 )
65+ results[:hj ] = ifelse .(results[:Lj ] .== 0 , 0.0 , param. Hj ./ results[:Lj ])
66+ results[:uj ] = dropdims (value .(model_dict[:uj ]), dims = 2 )
67+ # Prices
68+ results[:Pjn ] = shadow_price .(model_dict[:Pjn ])
69+ results[:PCj ] = dropdims (sum (results[:Pjn ] .^ (1 - param. sigma), dims= 2 ), dims = 2 ) .^ (1 / (1 - param. sigma))
70+ # Network flows
71+ results[:Qin ] = value .(model_dict[:Qin ])
72+ results[:Qjkn ] = gen_network_flows (results[:Qin ], graph, param. N)
73+ return results
74+ end
0 commit comments