Skip to content

Commit d04c241

Browse files
authored
Merge pull request #33 from OptimalTransportNetworks/development
Development
2 parents c89b05c + 7f5ffd4 commit d04c241

File tree

6 files changed

+17
-15
lines changed

6 files changed

+17
-15
lines changed

examples/example01.jl

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,14 @@ using OptimalTransportNetworks
88
# Set parameters: try with labor mobility: true/false, convex: beta>=gamma,
99
# nonconvex: gamma>beta, cross good congestion: true/false
1010

11-
param = init_parameters(labor_mobility = true, K = 10, gamma = 1, beta = 1, verbose = true,
12-
N = 1, cross_good_congestion = false, nu = 1, duality = false)
13-
14-
# tol is the tolerance in distance b/w iterations for road capacity
15-
# kappa=I^gamma/delta_i, default is 1e-7 but we relax it a bit here
11+
param = init_parameters(labor_mobility = true, K = 10, gamma = 1, beta = 1, N = 1,
12+
cross_good_congestion = true)
1613

1714
# ------------
1815
# Init network
1916

20-
graph = create_graph(param, 11, 11, type = "map") # create a map network of 11x11 nodes located in [0,10]x[0,10]
17+
# create a map network of 11x11 nodes located in [0,10]x[0,10]
18+
graph = create_graph(param, 11, 11, type = "map")
2119
# note: by default, productivity and population are equalized everywhere
2220

2321
# Customize graph
@@ -33,7 +31,6 @@ graph[:Zjn][Ni, :] .= 1 # central node more productive
3331

3432

3533
# Plot the network with the optimal transportation plan
36-
3734
plot_graph(graph, results[:Ijk], node_sizes = results[:Cj])
3835

3936
# The size/shade of the nodes reflects the total consumption at each node

examples/example04.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Random
99
# Init and Solve network
1010

1111
param = init_parameters(K = 100, labor_mobility = false,
12-
N = 1, gamma = 1, beta = 1, duality = false)
12+
N = 1, gamma = 1, beta = 1, duality = true)
1313
w = 13; h = 13
1414
graph = create_graph(param, w, h, type = "map")
1515

src/main/annealing.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Runs the simulated annealing method starting from network `I0`. Only sensible if
3737
# Examples
3838
```julia
3939
# Nonconvex case, disabling automatic annealing
40-
param = init_parameters(K = 10, gamma = 2, annealing = false)
40+
param = init_parameters(K = 10, gamma = 2, annealing = false, duality = false)
4141
graph = create_graph(param)
4242
graph[:Zjn][61] = 10.0
4343
results = optimal_network(param, graph)

src/main/optimal_network.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Solve for the optimal network by solving the inner problem and the outer problem
2121
2222
# Examples
2323
```julia
24-
param = init_parameters(K = 10)
24+
param = init_parameters(K = 10, duality = false)
2525
graph = create_graph(param)
2626
graph[:Zjn][61] = 10.0
2727
results = optimal_network(param, graph)

src/main/plot_graph.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Plot a graph visualization with various styling options.
4949
5050
# Examples
5151
```julia
52-
param = init_parameters(K = 10)
52+
param = init_parameters(K = 10, duality = false)
5353
graph = create_graph(param)
5454
graph[:Zjn][51] = 10.0
5555
results = optimal_network(param, graph)

src/models/solve_allocation_by_duality_cgc.jl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,10 @@ function hessian_duality_cgc(
146146

147147
# Constant term: first part of Bprime
148148
cons = m1dbeta * n1dnum1 * numbetam1
149-
# Constant in T'
150-
cons2 = numbetam1 / (numbetam1+nu*beta)
149+
## Constant in T'
150+
# cons2 = numbetam1 / (numbetam1+nu*beta)
151+
# New: constant in T' -> More accurate!
152+
cons3 = m1dbeta * n1dnum1 * (numbetam1+nu*beta) / (1+beta)
151153

152154
# Precompute elements
153155
res = recover_allocation_duality_cgc(x, auxdata)
@@ -201,10 +203,13 @@ function hessian_duality_cgc(
201203
if jd == j
202204
KPprimeAB1 = m1dbeta * Pjn[j, nd]^(-sigma) * PCj[j]^(sigma-1)
203205
term += Qjkn[j, k, n] * (KPprimeAB1 - KPAprimeB1 + KPABprime1) # Derivative of Qjkn
204-
term += T * (((1+beta) * KPprimeAB1 + cons2 * KPABprime1) * G + Gprime) # T'G + TG'
206+
# term += T * (((1+beta) * KPprimeAB1 + cons2 * KPABprime1) * G + Gprime) # T'G + TG'
207+
term += T * ((1+beta) * KPprimeAB1 * G + Gprime) # T'G (first part) + TG'
208+
term += cons3 * Qjkn[j, k, nd] / PCj[j] * G # Second part of T'G
205209
elseif jd == k
206210
term += Qjkn[j, k, n] * (KPAprimeB1 - KPABprime1) # Derivative of Qjkn
207-
term -= T * cons2 * KPABprime1 * G # T'G: second part [B'(k) has opposite sign]
211+
# term -= T * cons2 * KPABprime1 * G # T'G: second part [B'(k) has opposite sign]
212+
term -= cons3 * Qjkn[j, k, nd] / PCj[j] * G # Second part of T'G
208213
end
209214
end
210215
if Qjkn[k, j, n] > 0 # Flows in the direction of j

0 commit comments

Comments
 (0)