anchor_y = [0, 5, 0, -5, 0]
target_x = np.random.uniform(-5, 5,
                             size=(NumberOfTargetNode))  #随机生成50个数,范围在-5到5
target_y = np.random.uniform(-5, 5, size=(NumberOfTargetNode))
target_absl_array_x = []
target_absl_array_y = []
c**t = 0
#根据实际坐标生成模拟的距离阵
P = [[0, 50, 100, 50, 25, 1], [50, 0, 50, 100, 25, 1], [100, 50, 0, 50, 25, 1],
     [50, 100, 50, 0, 25, 1], [25, 25, 25, 25, 0, 1], [1, 1, 1, 1, 1, 0]]

for i in range(NumberOfTargetNode):
    print i
    D2 = []
    for j in range(NumberOfAnchorNode):
        d = getDist([target_x[i], target_y[i]], [anchor_x[j], anchor_y[j]])
        d = addGaussNoise(d, 0, 0.5)
        D2.append(d * d)
    for k in range(NumberOfAnchorNode):
        P[k][NumberOfAnchorNode] = D2[k]
    for k in range(NumberOfAnchorNode):
        P[NumberOfAnchorNode][k] = D2[k]

    Loc, x, y = mds_fun(P, NumberOfTotalNode)
    target_realtive_x = x[5]
    target_realtive_y = y[5]
    parm, diff = fin_pso(anchor_x, anchor_y, x[0:5], y[0:5])

    print "最小Difference值:", diff
    if (diff > 50):
        c**t += 1
Пример #2
0
    parm, diff = fin_pso(anchor_x, anchor_y, d2, target_realtive_x,
                         target_realtive_y)
    return parm, diff


np.set_printoptions(suppress=True)  #禁止科学计数法显示结果
anchor_x = [-5, 0, 5, 0, 0]
anchor_y = [0, 5, 0, -5, 0]

target_x = 2.0
target_y = 2.0
NumberOfAnchorNode = 5
NumberOfTotalNode = NumberOfAnchorNode + 1
d2 = []  #目标节点到锚节点的距离平方
for j in range(NumberOfAnchorNode):
    d = getDist([target_x, target_y], [anchor_x[j], anchor_y[j]])
    d2.append(d * d)

#根据实际坐标生成模拟的距离阵
P = [[0, 50, 100, 50, 25, 1], [50, 0, 50, 100, 25, 1], [100, 50, 0, 50, 25, 1],
     [50, 100, 50, 0, 25, 1], [25, 25, 25, 25, 0, 1], [1, 1, 1, 1, 1, 0]]

for k in range(NumberOfAnchorNode):
    P[k][NumberOfAnchorNode] = d2[k]
for k in range(NumberOfAnchorNode):
    P[NumberOfAnchorNode][k] = d2[k]

parm, diff = getLocAfterPSO(P, d2)
print "最小Difference值:"
print diff