Skip to content

Instantly share code, notes, and snippets.

@jtrussell
Created June 20, 2019 17:56
Show Gist options
  • Save jtrussell/fbf67717e919763a4b9d2bc3708b1dbe to your computer and use it in GitHub Desktop.
Save jtrussell/fbf67717e919763a4b9d2bc3708b1dbe to your computer and use it in GitHub Desktop.
Pseudo-ish code for service area fitness
def get_fitness(individual):
# Award a baseline score based on total volume
percent_volume = get_percent_volume(individual)
score = min(percent_volume, 0.75) * max_volume_score
if percent_volume >= 0.75:
# Award additional points for contiguity if we've met
# the volume threshold.
num_contiguous_blocks = get_num_contiguous_blocks(individual)
contiguous_bonus = get_contiguous_bonus(num_contiguous_blocks)
score = score + contiguous_bonus
if num_contiguous_blocks is 1:
# Once we achieve contiguity, start whittling away
# unnecessary ZIP Codes.
num_codes_in_area = get_num_codes_in_area(individual)
fewest_codes_bonus = get_fewest_codes_bonus(num_codes_in_area)
score = score + fewest_codes_bonus
return score
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment