-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
65 lines (50 loc) · 1.63 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Copyright (c) 2023 Otto Link. Distributed under the terms of the GNU
# General Public License. The full license is in the file LICENSE,
# distributed with this software.
import matplotlib.pyplot as plt
import numpy as np
import tools.alpha_model as am
if __name__ == '__main__':
# load heightmap
z = am.load_img('data/hmap.png')[:, :, 0]
z = np.flipud(z).T
z = (z - z.min()) / z.ptp()
extent = [0, 1, 0, 1]
seed = 1
print(z.shape)
n_cities = 10
# smaller extent to avoid borders
xc, yc = am.random_grid_halton(n_cities,
seed=seed,
extent=[0.1, 0.9, 0.1, 0.9])
size = np.random.default_rng(seed + 1).random(n_cities)
size[-1] = 2 # one big city
xr, yr, zr, path_dict, edge_weight = am.generate_network_alpha_model(
xc,
yc,
size,
z,
n_dummy_nodes=6000,
alpha=0.7,
dz_weight=5,
extent=extent,
seed=seed)
# plot - heightmap
plt.figure()
plt.imshow(z.T, origin='lower', extent=extent, cmap='terrain')
plt.axis('off')
# plot - heightmap + road network
plt.figure()
img = am.load_img('data/hmap_c.png')
plt.imshow(np.rot90(img), extent=extent)
plt.scatter(xc, yc, 5 + size * 200, c='w', alpha=0.5)
ne = edge_weight.shape[0]
for p in range(ne):
for q in range(p + 1, ne):
if edge_weight[p, q]:
xe = [xr[p], xr[q]]
ye = [yr[p], yr[q]]
lw = 0.2 + 4 * edge_weight[p, q]
plt.plot(xe, ye, 'w-', lw=lw)
plt.axis('off')
plt.show()