Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving assignments #49

Closed
bsuwal opened this issue Aug 6, 2020 · 3 comments · Fixed by #121
Closed

Saving assignments #49

bsuwal opened this issue Aug 6, 2020 · 3 comments · Fixed by #121
Labels
enhancement New feature or request

Comments

@bsuwal
Copy link
Contributor

bsuwal commented Aug 6, 2020

A Score to get assignments

@sunnymatt sunnymatt added the enhancement New feature or request label Aug 7, 2020
@wesg52
Copy link

wesg52 commented Mar 20, 2021

Bump. In the python version I use

    districts = []
    plans = []
    for ix, partition in enumerate(chain):
        try:
            swap1, swap2 = list(partition.flows.keys())
            part1 = min(swap1, swap2)
            part2 = max(swap1, swap2)
            new_plan = plans[-1][:]
            new_plan[int(part1)] = len(districts)
            new_plan[int(part2)] = len(districts) + 1
            plans.append(new_plan)
            districts.append(list(partition.assignment.parts[part1]))
            districts.append(list(partition.assignment.parts[part2]))
        except: # First step in the chain
            districts = [list(part) for _, part in sorted(partition.assignment.parts.items())]
            plans.append(list(range(len(districts))))

@bsuwal
Copy link
Contributor Author

bsuwal commented Mar 23, 2021

hi @wesg52 , thanks for the bump! We will work on this asap. Feel free to let me know if you have any feedback on GerryChain meanwhile! (at [email protected])

@InnovativeInventor
Copy link
Member

@wesg52 #121 should close this issue as the partition and score will be returned at each step when callilng the iterable version of recom_chain or flip_chain. E.g. this is what I'm doing right now (with the PR's changes applied):

using GerryChain

SHAPEFILE_PATH = "./PA_VTDs.json"
POPULATION_COL = "TOTPOP"
ASSIGNMENT_COL = "CD_2011"

# Initialize graph and partition
graph = BaseGraph(SHAPEFILE_PATH, POPULATION_COL)
partition = Partition(graph, ASSIGNMENT_COL)

# Define parameters of chain (number of steps and population constraint)
pop_constraint = PopulationConstraint(graph, partition, 0.02)
num_steps = 10000

# Run the chain
for (partition, _) in recom_chain_iter(graph, partition, pop_constraint, num_steps, [DistrictAggregate("presd", "PRES12D"),], progress_bar=false)
    for (i, district in enumerate(partition.assignments)
        println(district) # the district that node i is assigned to
    end
end
flush(stdout)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants