# Data from https://en.wikipedia.org/wiki/List_of_cities_in_Australia_by_population
lgas = [
[‘City of Brisbane’ 1272999]
[‘City of Gold Coast’ 635191]
[‘Moreton Bay Region’ 479639]
[‘City of Blacktown’ 382831]
[‘City of Canterbury-Bankstown’ 380406]
[‘City of Casey’ 364600]
[‘Central Coast Council’ 345809]
[‘City of Logan’ 341985]
[‘Sunshine Coast Region’ 336482]
[‘City of Wyndham’ 283294]
[‘Northern Beaches Council’ 274041]
[‘City of Greater Geelong’ 264866]
[‘City of Parramatta’ 260296]
[‘City of Sydney’ 248736]
[‘Cumberland Council’ 242674]
[‘City of Hume’ 241188]
[‘City of Whittlesea’ 236539]
[‘Sutherland Shire’ 232369]
[‘City of Liverpool’ 231296]
[‘City of Ipswich’ 229845]
[‘City of Stirling’ 223743]
[‘City of Wollongong’ 219798]
[‘City of Penrith’ 216282]
[‘City of Wanneroo’ 212768]
[‘City of Fairfield’ 210825]
[‘City of Brimbank’ 208247]
[‘City of Lake Macquarie’ 207775]
[‘City of Monash’ 204936]
[‘Inner West Council’ 201880]
[‘City of Townsville’ 196800]
[‘City of Moreland’ 188762]
[‘The Hills Shire’ 183791]
[‘City of Melbourne’ 183756]
[‘City of Boroondara’ 183023]
[‘Bayside Council’ 181472]
[‘City of Whitehorse’ 180735]
[‘City of Onkaparinga’ 174575]
[‘City of Campbelltown’ 174078]
[‘City of Melton’ 172500]
[‘Toowoomba Region’ 170356]
[‘Shire of Mornington Peninsula’ 168862]
[‘Cairns Region’ 168449]
[‘City of Greater Dandenong’ 168362]
[‘City of Newcastle’ 167363]
[‘City of Kingston’ 167293]
[‘City of Darebin’ 166430]
[‘City of Knox’ 165147]
[‘City of Joondalup’ 160718]
[‘Redland City’ 160331]
[‘Georges River Council’ 160272]
]
L = range(len(lgas))
# seats = 100
population = sum(lgas[i][1] for i in L)
_cities = {}
def cities(i s):
if i == len(lgas)-1:
return (abs(s – target[i]) s)
else:
if (i s) not in _cities:
_cities[i s] = min((max(abs(a-target[i]) cities(i+1 s-a)[0]) a s-a)
for a in range(s+1))
return _cities[i s]
import matplotlib
import matplotlib.pyplot as plt
xs = range(1 150)
ys = []
for seats in xs:
target = [lgas[i][1]*seats/population for i in L]
_cities = {}
v = cities(0 seats)
ys.append(v[0])
plt.plot(xs ys)
plt.show()