-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathobstacle.py
35 lines (26 loc) · 1.01 KB
/
obstacle.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
import numpy as np
class Obstacle:
def __init__(self, boundsx, boundsy, penalty=100):
self.boundsx = boundsx
self.boundsy = boundsy
self.penalty = 1
def __call__(self, x):
return (self.boundsx[0] <= x[0] <= self.boundsx[1]
and self.boundsy[0] <= x[1] <= self.boundsy[1]) * self.penalty
class Obstacle3D:
def __init__(self, boundsx, boundsy, boundsz, penalty=100):
self.boundsx = boundsx
self.boundsy = boundsy
self.boundsz = boundsz
self.penalty = 1
def __call__(self, x):
return (self.boundsx[0] <= x[0] <= self.boundsx[1]
and self.boundsy[0] <= x[1] <= self.boundsy[1]
and self.boundsz[0] <= x[2] <= self.boundsz[1]) * self.penalty
class ComplexObstacle(Obstacle):
def __init__(self, bounds):
self.obs = []
for boundsx, boundsy in bounds:
self.obs.append(Obstacle(boundsx, boundsy))
def __call__(self, x):
return np.max([o(x) for o in self.obs])