Skip to content

Commit

Permalink
Make recom and flip chains an iterable a la GerryChain Python
Browse files Browse the repository at this point in the history
Although this is a breaking change, this brings GerryChain Julia
more in line with GerryChain Python and allows the user to save
and export state more easily. This API is different from the one
proposed in #94 in that it returns a Partition object and the
scores.
  • Loading branch information
InnovativeInventor committed Jul 26, 2021
1 parent 6893a4f commit 7883b42
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
ProgressBars = "49802e3a-d2f1-5c88-81d8-b72133a6f568"
PyPlot = "d330b81b-6aea-500a-939a-2ce795aea3ee"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
ResumableFunctions = "c5292f4c-5179-55e1-98c5-05642aab7184"
Shapefile = "8e980c4a-a4fe-5da2-b3a7-4b4b0353a2f4"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Expand Down
1 change: 1 addition & 0 deletions src/GerryChain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Shapefile
import LibGEOS
import LibSpatialIndex
using Logging
using ResumableFunctions

export AbstractGraph,
BaseGraph,
Expand Down
4 changes: 3 additions & 1 deletion src/flip.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ every score at each step of the chain.
infinite loops if the acceptance function is never
satisfied!
"""
function flip_chain(
function flip_chain end # this is a workaround
@resumable function flip_chain(
graph::BaseGraph,
partition::Partition,
pop_constraint::PopulationConstraint,
Expand Down Expand Up @@ -186,6 +187,7 @@ function flip_chain(
end
end
score_vals = score_partition_from_proposal(graph, partition, proposal, scores)
@yield partition, score_vals
push!(chain_scores.step_values, score_vals)
step_completed = true
end
Expand Down
4 changes: 3 additions & 1 deletion src/recom.jl
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ step of the chain.
infinite loops if the acceptance function is never
satisfied!
"""
function recom_chain(
function recom_chain end # this is a workaround
@resumable function recom_chain(
graph::BaseGraph,
partition::Partition,
pop_constraint::PopulationConstraint,
Expand Down Expand Up @@ -322,6 +323,7 @@ function recom_chain(
end
end
score_vals = score_partition_from_proposal(graph, partition, proposal, scores)
@yield partition, score_vals
push!(chain_scores.step_values, score_vals)
step_completed = true
end
Expand Down

0 comments on commit 7883b42

Please sign in to comment.