import os, sys, random, time import pygame from pygame import gfxdraw import numpy as np sys.path.append(os.path.abspath('.')) from src.state import State from src import districts, mutation, metrics from src.connectivity import can_lose from src.constraints import fix_pop_equality from src.draw import draw_districts # state = State.fromFile('data/t500-c3.json') state = State.makeRandom(400, seed=1) for _ in range(1): state, _ = state.contract(seed=0) # met = metrics.compactness_convex_hull met = metrics.polsby_popper mutate = False n_districts = 5 districts = districts.make_random(state, n_districts) # districts = np.random.randint(0, n_districts, (state.n_tiles,), dtype='i') tolerance = 0.5 draw_kwargs = { "draw_bounding_hulls": False, "draw_bounding_circles": False, "draw_district_edges": True, "draw_vertices": False, "draw_neigbors_lines": False }
from src.state import State from src.optimization import upscale def upscale(districts, mapping): upscaled = np.zeros((districts.shape[0], mapping.shape[0]), dtype='i') for i in range(districts.shape[0]): for j in range(mapping.shape[0]): upscaled[i, j] = districts[i, mapping[j]] return upscaled pygame.init() # seed = 1337 seed = 1 if len(sys.argv) == 1: states = [ State.makeRandom(1000, seed=seed) ] else: states = [ State.fromFile(sys.argv[1]) ] if len(sys.argv) == 1: ### Subdivide voronoi grid map. ### n_districts = 10 n_divisions = 2 mappings = [ None ] screen = pygame.display.set_mode(( 2000, 500 )) screen.fill(( 255, 255, 255 )) for _ in range(n_divisions): state, mapping = states[-1].contract(seed=seed) states.append(state)