-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpoints_neighbers_find.py
59 lines (48 loc) · 1.52 KB
/
points_neighbers_find.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
import numpy as np
np.set_printoptions(linewidth=200, precision=5, suppress=True)
import pandas as pd;
pd.options.display.max_rows = 20;
pd.options.display.expand_frame_repr = False
import pylab as plt
import numpy.matlib
#import Utils as utl
def ismember(A,B):
return [np.sum(a == B) for a in A]
def points_neighbers_find(x,xE,xU,Bin,Ain):
[delta_general, index,x1] = mindis(x, np.concatenate((xE,xU ), axis=1) )
active_cons = []
b = Bin - np.dot(Ain,x)
for i in range(len(b)):
if b[i][0] < 1e-3:
active_cons.append(i+1)
active_cons = np.array(active_cons)
active_cons1 = []
b = Bin - np.dot(Ain,x1)
for i in range(len(b)):
if b[i][0] < 1e-3:
active_cons1.append(i+1)
active_cons1 = np.array(active_cons1)
if len(active_cons) == 0 or min(ismember(active_cons,active_cons1)) == 1:
newadd = 1
success = 1
if mindis(x,xU) == 0:
newadd = 0
else:
success = 0
newadd = 0
xU = np.concatenate((xU,x),axis=0)
return x, xE, xU, newadd, success
def mindis(x, xi):
# function [y,x1,index] = mindistance(x,xi)
# % calculates the minimum distance from all the existing points
# % xi all the previous points
# % x the new point
y = float('inf')
N = xi.shape[1]
for i in range(N):
y1 = np.linalg.norm(x[:, 0] - xi[:, i])
if y1 < y:
y = np.copy(y1)
x1 = np.copy(xi[:, i])
index = np.copy(i)
return y, index, x1