Skip to content

Commit 5a972e4

Browse files
committed
Add possibility to pass previous allocation: avoiding an initial iteration.
1 parent 16b3e3e commit 5a972e4

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

src/main/annealing.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Runs the simulated annealing method starting from network `I0`. Only sensible if
3232
- `model::Function`: For custom models => a function that taks an optimizer and an 'auxdata' structure as created by create_auxdata() as input and returns a fully parameterized JuMP model
3333
- `final_model::JuMPModel`: Alternatively: a readily parameterized JuMP model to be used (from `optimal_network()`)
3434
- `recover_allocation::Function`: The `recover_allocation()` function corresponding to either `model` or `final_model`
35+
- `allocation::Dict`: The result from `recover_allocation()` from a previous solution of the model: to skip an initial resolve without perturbations.
3536
3637
# Examples
3738
```julia
@@ -126,7 +127,15 @@ function annealing(param, graph, I0; kwargs...)
126127
weight_old = 0.5
127128
counter = 0
128129
I1 = I0
129-
results = nothing
130+
if (haskey(kwargs, :allocation) && !isempty(kwargs[:allocation]))
131+
results = kwargs[:allocation]
132+
counter += 1
133+
if options.display
134+
display(plot_graph(graph, I1))
135+
end
136+
else
137+
results = nothing
138+
end
130139

131140
# rng(0) # set the seed of random number generator for replicability
132141
acceptance_str = ["rejected", "accepted"]
@@ -326,7 +335,7 @@ function retrieve_options_annealing(graph; kwargs...)
326335
if haskey(options, sym_key)
327336
options[sym_key] = v
328337
else
329-
if !(sym_key in [:model, :final_model, :recover_allocation])
338+
if !(sym_key in [:model, :final_model, :recover_allocation, :allocation])
330339
error("Unknown parameter: $sym_key")
331340
end
332341
end

src/main/optimal_network.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ function optimal_network(param, graph; I0=nothing, Il=nothing, Iu=nothing, verbo
178178
# SIMULATED ANNEALING
179179

180180
if param.gamma > param.beta && param.annealing
181-
results = annealing(param, graph, I0, final_model = model, recover_allocation = recover_allocation)
181+
results = annealing(param, graph, I0, final_model = model, recover_allocation = recover_allocation, allocation = results)
182182
end
183183

184184
if return_model == 2

0 commit comments

Comments
 (0)