-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptimization_Code_First_Try.py
More file actions
151 lines (113 loc) · 3.73 KB
/
Copy pathOptimization_Code_First_Try.py
File metadata and controls
151 lines (113 loc) · 3.73 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
from shapely.geometry import Point, LineString, Polygon
import matplotlib.pyplot as mpl
import geopy
import numpy as np
import math
class Plane:
def __init__(self, xlim, ylim):
self.fig, self.ax = mpl.subplots()
self.modules = []
self.elements = []
self.ax.set_xlim(xlim)
self.ax.set_ylim(ylim)
self.ax.set_facecolor('white')
self.ax.set_aspect('equal', adjustable='box')
def add_element(self, element):
if element.get_type() == 'Point':
self.modules.append(element)
elif element.get_type() == 'Polygon':
self.elements.append(element)
def plot_land(self):
for element in self.elements:
x, y = element.polygon.exterior.xy
self.ax.fill(x, y, fc='blue', label='Polygon', alpha=0.5, zorder = 0)
def plot_modules(self):
for module in self.modules:
x, y = module.point.xy
self.ax.plot(x, y, 'o', color ='red', markersize = 5, zorder = 3)
def show_graph(self):
mpl.show()
def expand_sound_waves(self):
for module in self.modules:
self.expand_sound_module(module)
def expand_sound_module(self, module):
min_radius = 0.1
current_radius = 1.7
current_color = 0.01
rate_of_change = (1.7-min_radius)/20
while current_radius>=min_radius:
circle = module.point.buffer(current_radius)
x, y = circle.exterior.xy
self.ax.plot(x, y, color = (0,current_color, 0), label = 'Circle', linewidth = 1, zorder = 1)
current_radius -= rate_of_change
current_color += 0.0495
"""def expand_sound_module(self, module):
#sound intensity = 1 / distance^2
min_radius = 2.5"""
class Land:
def __init__(self, exterior_coords, interior_coords=None):
self.polygon = Polygon(exterior_coords, interior_coords)
self.exterior_coords = exterior_coords
self.barriers = []
self.modules = []
self.number_of_modules = 0
def add_barrier(self, barrier):
self.barriers.append(barrier)
def get_type(self):
return 'Polygon'
# def calculate_fitness(self):
def add_module(self, sound_module):
self.modules.append(sound_module)
class Sound_Module:
def __init__(self, coord):
self.point = Point(coord)
self.coord = coord
self.x = coord[0]
self.y = coord[1]
def get_module_position(self):
return self.coord
def get_type(self):
return 'Point'
class Barrier:
def __init__(self, exterior_coords, interior_coords=None):
self.polygon = Polygon(exterior_coords, interior_coords)
self.exterior_coords = exterior_coords
def get_barrier_shape(self):
return self.exterior_coords
def get_type(self):
return 'Polygon'
xlim = (-10,20)
ylim = (-10,20)
plane = Plane(xlim,ylim)
exterior_coords = [[-5, -5], [-5, 15], [15, 15], [15, -5]]
coord = [5,5]
second_coord = [5,5.5]
third_coord = [6,6]
fourth_coord = [16,16]
module = Sound_Module(coord)
field = Land(exterior_coords)
second_module = Sound_Module(second_coord)
third_module = Sound_Module(third_coord)
fourth_module = Sound_Module(fourth_coord)
plane.add_element(module)
plane.add_element(field)
plane.add_element(second_module)
plane.add_element(third_module)
plane.add_element(fourth_module)
plane.plot_land()
plane.plot_modules()
plane.expand_sound_waves()
plane.show_graph()
'''
Plot land
Plot barriers
Plot modules
Check if modules are in the land
Visualize sound waves from modules
Assign sound intensity value to pixels
Check for overlapping sound waves and do something
Calculate fitness
Setup
-
Optimization (later)
'''