Skip to content

Commit 87535f7

Browse files
committed
Also include customization in get_model() function.
1 parent e8aa3c0 commit 87535f7

3 files changed

Lines changed: 23 additions & 48 deletions

File tree

src/main/annealing.jl

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -103,29 +103,6 @@ function annealing(param, graph, I0; kwargs...)
103103
else
104104
auxdata = create_auxdata(param, graph, edges, I0)
105105
model, recover_allocation = get_model(param, auxdata)
106-
107-
# --------------
108-
# CUSTOMIZATIONS
109-
110-
if haskey(param, :optimizer_attr)
111-
for (key, value) in param.optimizer_attr
112-
set_optimizer_attribute(model, String(key), value)
113-
end
114-
end
115-
116-
if haskey(param, :model_attr)
117-
for value in values(param.model_attr)
118-
if !(value isa Tuple)
119-
error("model_attr must be a dict of tuples.")
120-
end
121-
set_optimizer_attribute(model, value[1], value[2])
122-
end
123-
end
124-
# E.g.:
125-
# set_attribute(model,
126-
# MOI.AutomaticDifferentiationBackend(),
127-
# MathOptSymbolicAD.DefaultBackend(),
128-
# )
129106
end
130107

131108
if !options.verbose

src/main/helper.jl

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,29 @@ function get_model(param, auxdata)
234234
else
235235
error("Usupported model configuration with labor_mobility = $(param.mobility) and cross_good_congestion = $(param.cong)")
236236
end
237+
238+
# --------------
239+
# CUSTOMIZATIONS
240+
241+
if haskey(param, :optimizer_attr)
242+
for (key, value) in param.optimizer_attr
243+
set_optimizer_attribute(model, String(key), value)
244+
end
245+
end
246+
247+
if haskey(param, :model_attr)
248+
for value in values(param.model_attr)
249+
if !(value isa Tuple)
250+
error("model_attr must be a dict of tuples.")
251+
end
252+
set_optimizer_attribute(model, value[1], value[2])
253+
end
254+
end
255+
# E.g.:
256+
# set_attribute(model,
257+
# MOI.AutomaticDifferentiationBackend(),
258+
# MathOptSymbolicAD.DefaultBackend(),
259+
# )
237260
return model, recover_allocation
238261
end
239262

@@ -262,4 +285,3 @@ function rescale_network!(param, graph, I1, Il, Iu; max_iter = 100)
262285

263286
return I1
264287
end
265-

src/main/optimal_network.jl

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -67,36 +67,12 @@ function optimal_network(param, graph; I0=nothing, Il=nothing, Iu=nothing, verbo
6767
# INITIALIZATION
6868

6969
auxdata = create_auxdata(param, graph, edges, I0)
70-
7170
model, recover_allocation = get_model(param, auxdata)
7271

73-
# --------------
74-
# CUSTOMIZATIONS
75-
7672
if !verbose
7773
set_silent(model)
7874
end
7975

80-
if haskey(param, :optimizer_attr)
81-
for (key, value) in param.optimizer_attr
82-
set_optimizer_attribute(model, String(key), value)
83-
end
84-
end
85-
86-
if haskey(param, :model_attr)
87-
for value in values(param.model_attr)
88-
if !(value isa Tuple)
89-
error("model_attr must be a dict of tuples.")
90-
end
91-
set_optimizer_attribute(model, value[1], value[2])
92-
end
93-
end
94-
# E.g.:
95-
# set_attribute(model,
96-
# MOI.AutomaticDifferentiationBackend(),
97-
# MathOptSymbolicAD.DefaultBackend(),
98-
# )
99-
10076
if return_model == 1
10177
return model, recover_allocation
10278
end

0 commit comments

Comments
 (0)