Congressional Redistricting

Congressional Redistricting preview image

1 collaborator

Light_dependent_reaction_background Luke Elissiry (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by the author
Model was written in NetLogo 5.3.1 • Viewed 108 times • Downloaded 6 times • Run 0 times
Download the 'Congressional Redistricting' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

patches-own [population district state]

to gen
  ca
  import-pcolors "city"
  let p 0
  ask patches [
    set population 100 * (10 - pcolor)
    if min [pcolor] of neighbors > pcolor [
      set p p + 1
      set district p
      set state "edge"
    ]
  ]
  ask patches with [state = "edge"] [
    set pcolor yellow
  ]
end 

to create
  ca
  import-pcolors "city"
  let p 0
  ask patches [
    set population 100 * (10 - pcolor)
    if min [pcolor] of neighbors > pcolor [
      set p p + 1
      set district p
      set state "edge"
    ]
  ]
  while [any? patches with [state = 0]] [
    wait .1
    ask patches with [state = "edge"] [
      if any? neighbors4 with [state = 0] [
        ask one-of neighbors4 with [state = 0] [
          set district [district] of myself
          set state "edge"
        ]
      ]
      determine-state
    ]
  ]
  ask patches [
    determine-state
  ]
  while [(any? patches with [state = "edge" and (sum ([population] of patches with [district = [district] of myself]) < 9.5 / 10 * sum ([population] of patches) / p)]) or
    (any? patches with [state = "edge" and (sum ([population] of patches with [district = [district] of myself]) > 10.5 / 10 * sum ([population] of patches) / p)])] [
    wait .1
    ask patches with [state = "edge" and (sum ([population] of patches with [district = [district] of myself]) < 9.5 / 10 * sum ([population] of patches) / p)] [
      ask neighbors4 with [state = "edge" and district != [district] of myself] [
        set district [district] of myself
        ask neighbors [determine-state]
      ]
      determine-state
    ]
    ask patches with [state = "edge" and (sum ([population] of patches with [district = [district] of myself]) > 10.5 / 10 * sum ([population] of patches) / p)] [
      set district [district] of one-of neighbors4
      ask neighbors [determine-state]
      determine-state
    ]
    ask patches with [state = "edge"] [
      if not any? neighbors4 with [district != [district] of myself] [
        set district [district] of one-of neighbors4
        determine-state
      ]
    ]
  ]
  ask patches with [state = "edge"] [
    if not any? neighbors4 with [district != [district] of myself] [
      set district [district] of one-of neighbors4
      determine-state
    ]
  ]
  ask patches [
    set pcolor district * 20 - 1 - population / 120
  ]
  let x 1
  let total 0
  while [x < p] [
    let pop sum ([population] of patches with [district = x])
    set total total + pop
    output-print (word "D" x " - " pop)
    set x x + 1
  ]
  output-print total
end 

to determine-state
  if-else any? neighbors4 with [district != [district] of myself]
  [
    set state "edge"
    set pcolor yellow
  ]
  [
    set state "done"
    set pcolor 9 - population / 120
  ]
end 

There is only one version of this model, created almost 2 years ago by Luke Elissiry.

Attached files

File Type Description Last updated
city background Map used for districting. almost 2 years ago, by Luke Elissiry Download
Congressional Redistricting.png preview Preview for 'Congressional Redistricting' almost 2 years ago, by Luke Elissiry Download

This model does not have any ancestors.

This model does not have any descendants.