Skip to content

Commit 272c89b

Browse files
authored
Merge pull request #14 from SebKrantz/parameterized_graph
Parameterized graph
2 parents 2301fea + d30f213 commit 272c89b

File tree

5 files changed

+12
-16
lines changed

5 files changed

+12
-16
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ import MathOptInterface as MOI
4242
import MathOptSymbolicAD
4343

4444
param[:model_attr] = Dict(:backend => (MOI.AutomaticDifferentiationBackend(),
45-
MathOptSymbolicAD.DefaultBackend()))
45+
MathOptSymbolicAD.DefaultBackend()))
4646
# Or: MathOptSymbolicAD.ThreadedBackend()
4747
```
4848

4949
* It is recommended to use Coin-HSL linear solvers for [Ipopt](https://github.com/jump-dev/Ipopt.jl) to speed up computations. In my opinion the simplest way to use them is to get a (free for academics) license and download the binaries [here](https://licences.stfc.ac.uk/product/coin-hsl), extract them somewhere, and then set the `hsllib` (place here the path to where you extracted `libhsl.dylib`, it may also be called `libcoinhsl.dylib`, in which case you may have to rename it to `libhsl.dylib`) and `linear_solver` options as follows:
5050

5151
```julia
5252
param[:optimizer_attr] = Dict(:hsllib => "/usr/local/lib/libhsl.dylib", # Adjust path
53-
:linear_solver => "ma57") # Use ma57, ma86 or ma97
53+
:linear_solver => "ma57") # Use ma57, ma86 or ma97
5454
```
5555

5656
The [Ipopt.jl README](https://github.com/jump-dev/Ipopt.jl?tab=readme-ov-file#linear-solvers) suggests to use the larger LibHSL package for which there exists a Julia module and proceed similarly. In addition, users may try an [optimized BLAS](https://github.com/jump-dev/Ipopt.jl?tab=readme-ov-file#blas-and-lapack) and see if it yields significant performance gains (and let me know if it does).

docs/src/api.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,3 @@ OptimalTransportNetworks.represent_edges
4141
OptimalTransportNetworks.create_auxdata
4242
OptimalTransportNetworks.get_model
4343
```
44-
45-
<!-- ```@autodocs
46-
Modules = [OptimalTransportNetworks]
47-
Public = false
48-
Private = true
49-
Order = [:function]
50-
``` -->

docs/src/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ import MathOptInterface as MOI
3737
import MathOptSymbolicAD
3838

3939
param[:model_attr] = Dict(:backend => (MOI.AutomaticDifferentiationBackend(),
40-
MathOptSymbolicAD.DefaultBackend()))
40+
MathOptSymbolicAD.DefaultBackend()))
4141
# Or: MathOptSymbolicAD.ThreadedBackend()
4242
```
4343

4444
* It is recommended to use Coin-HSL linear solvers for [Ipopt](https://github.com/jump-dev/Ipopt.jl) to speed up computations. In my opinion the simplest way to use them is to get a (free for academics) license and download the binaries [here](https://licences.stfc.ac.uk/product/coin-hsl), extract them somewhere, and then set the `hsllib` (place here the path to where you extracted `libhsl.dylib`, it may also be called `libcoinhsl.dylib`, in which case you may have to rename it to `libhsl.dylib`) and `linear_solver` options as follows:
4545

4646
```julia
4747
param[:optimizer_attr] = Dict(:hsllib => "/usr/local/lib/libhsl.dylib", # Adjust path
48-
:linear_solver => "ma57") # Use ma57, ma86 or ma97
48+
:linear_solver => "ma57") # Use ma57, ma86 or ma97
4949
```
5050

5151
The [Ipopt.jl README](https://github.com/jump-dev/Ipopt.jl?tab=readme-ov-file#linear-solvers) suggests to use the larger LibHSL package for which there exists a Julia module and proceed similarly. In addition, users may try an [optimized BLAS](https://github.com/jump-dev/Ipopt.jl?tab=readme-ov-file#blas-and-lapack) and see if it yields significant performance gains (and let me know if it does).

examples/paper_example04.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ using Random
33
using Plots
44

55
# Initialize parameters
6-
param = init_parameters(K = 100, rho = 0, labor_mobility = false)
6+
param = init_parameters(K = 100, sigma = 2, rho = 0, labor_mobility = false)
77
width, height = 13, 13
88

99
# Create graph
@@ -17,7 +17,7 @@ Ni = find_node(g0, ceil(width/2), ceil(height/2)) # center
1717
g0[:Zjn][Ni] = 1 # more productive node
1818
g0[:Lj][Ni] = 1 # more productive node
1919

20-
Random.seed!(10) # use 5, 8, 10 or 11
20+
Random.seed!(11) # use 5, 8, 10 or 11
2121
nb_cities = 20 # draw a number of random cities in space
2222
for i in 1:nb_cities-1
2323
newdraw = false
@@ -113,11 +113,13 @@ plots = Vector{Any}(undef, length(simulation))
113113
i = 0
114114
for s in simulation
115115
i += 1
116+
sizes = 2 .* results[Symbol(s)][:cj] .* (g0[:Lj] .> 1e-6) / maximum(results[Symbol(s)][:cj])
117+
shades = results[Symbol(s)][:cj] .* (g0[:Lj] .> 1e-6) / maximum(results[Symbol(s)][:cj])
116118
plots[i] = plot_graph(g0, results[Symbol(s)][:Ijk],
117119
geography = geographies[Symbol(s)], obstacles = obstacles[i] == "on",
118120
mesh = true, mesh_transparency = 0.2,
119-
node_sizes = results[Symbol(s)][:cj],
120-
node_shades = g0[:Zjn], node_color = :seismic,
121+
node_sizes = sizes, node_shades = shades,
122+
node_color = :seismic,
121123
edge_min_thickness = 1, edge_max_thickness = 4)
122124
title!(plots[i], "Geography $(s)")
123125
end

src/OptimalTransportNetworks.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ Fajgelbaum, P. D., & Schaal, E. (2020). Optimal transport networks in spatial eq
2222
2323
The library is based on the JuMP modeling framework for mathematical optimization in Julia, and roughly follows the
2424
MATLAB OptimalTransportNetworkToolbox (v1.0.4b) provided by the authors. Compared to MATLAB, the Julia library presents
25-
a simplified interface and only exports key functions, while retaining full flexibility.
25+
a simplified interface. Notably, the `graph` object contains both the graph structure and all data parameterizing
26+
the network, whereas the `param` object only contains (non-spatial) model parameters.
2627
2728
# Exported Functions
2829

0 commit comments

Comments
 (0)