示例#1
0
def test_matthias_zonotopes():
    'tests from_centered_zonotope constructor'

    # zonotopes from Figure 2 of "On Computing the Minkowski Difference of Zonotopes" by Matthias Althoff

    # Z_m (shifted due to lack of center in our constructor)
    m = lpset.from_centered_zonotope([[1, 0], [0, 1], [1, 1]])
    expected = [[-2, -2], [-2, 0], [0, 2], [2, 2], [2, 0], [0, -2]]
    assert_verts_equals(m.verts(), expected)

    # Z_{s,1}
    s1 = lpset.from_centered_zonotope([[0.5, -0.25], [0, 0.25]])
    expected = [[-0.5, 0], [-0.5, 0.5], [0.5, 0], [0.5, -0.5]]
    assert_verts_equals(s1.verts(), expected)

    # Z_{s,2}
    s2 = lpset.from_centered_zonotope([[0.5, -0.5], [0, 0.5]])

    #s2.plot()
    #plt.show()

    expected = [[-0.5, 0], [-0.5, 1.0], [0.5, 0], [0.5, -1.0]]
    assert_verts_equals(s2.verts(), expected)

    # Z_{s,3}
    s3 = lpset.from_centered_zonotope([[2.0, -0.5], [0, 0.5]])
    expected = [[-2.0, 0], [-2.0, 1.0], [2.0, 0], [2.0, -1.0]]
    assert_verts_equals(s3.verts(), expected)
示例#2
0
def test_mindiff_3d():
    'test minkowski difference in 3d'

    m = lpset.from_centered_zonotope([[1, 1, 1], [1, 0, 0], [0, 1, 0],
                                      [0, 0, 1]])
    s = lpset.from_centered_zonotope([[-1 / 3, 1 / 3, 1 / 3], [1 / 3, 0, 0],
                                      [0, 1 / 3, 0], [0, 0, 1 / 3]])

    p_in = m.find_point_in_diff(s)

    print(p_in)

    assert False
示例#3
0
def test_intersection():
    'test the lpset intersection'

    m = lpset.from_centered_zonotope([[1, 1, 1], [1, 0, 0], [0, 1, 0],
                                      [0, 0, 1]])
    s = lpset.from_centered_zonotope([[-1 / 3, 1 / 3, 1 / 3], [1 / 3, 0, 0],
                                      [0, 1 / 3, 0], [0, 0, 1 / 3]])

    inter = lpset.intersection(m, s)

    verts_s = s.verts3d()
    verts_inter = lpplot.get_verts3d(inter)

    assert_verts_equals(verts_s, verts_inter)
示例#4
0
def test_mindiff_2d():
    'test minkowski difference in 2d'

    # Z_m (shifted due to lack of center in our constructor)
    m = lpset.from_centered_zonotope([[1, 0], [0, 1], [1, 1]])

    # Z_{s,1}
    s1 = lpset.from_centered_zonotope([[0.5, -0.25], [0, 0.25]])

    p_in = m.find_point_in_diff(s1)

    print(p_in)

    assert False
示例#5
0
def test_minkowski_difference():
    'test minkowski difference'

    # tests from Figure 2 of "On Computing the Minkowski Difference of Zonotopes" by Matthias Althoff

    # Z_m (shifted due to lack of center in our constructor)
    z_m = lpset.from_centered_zonotope([[1, 0], [0, 1], [1, 1]])

    # Z_{s,1}
    z_s1 = lpset.from_centered_zonotope([[0.5, -0.25], [0, 0.25]])

    z_d1 = z_m.clone().minkowski_difference(z_s1)

    z_m.plot(':')
    z_s1.plot('-')
    z_d1.plot('--')

    plt.show()
示例#6
0
def test_complement_lps():
    'test getting the complement lps'

    m = lpset.from_centered_zonotope([[1, 1, 1], [1, 0, 0], [0, 1, 0],
                                      [0, 0, 1]])

    c = m.get_complement_lpsets()

    assert len(c) == 8
示例#7
0
def test_2d_zonotope():
    'simple zonotope test'

    m = lpset.from_centered_zonotope([[1, 1], [0, 1]])

    m.plot()
    plt.show()

    expected = [[-1, -2], [-1, 0], [1, 2], [1, 0]]
    assert_verts_equals(m.verts(), expected)
示例#8
0
def test_chull_hard():
    'test convex hull operation'

    m = lpset.from_centered_zonotope([[1, 0], [0, 1], [1, 1]])

    # Z_{s,1}
    s1 = lpset.from_centered_zonotope([[0.5, -0.25], [0, 0.25]])

    # Z_{s,2}
    s2 = lpset.from_centered_zonotope([[0.5, -0.5], [0, 0.5]])

    # s = s1
    s = s2

    #combined = lpset.minkowski_sum([m, s1])
    combined = lpset.minkowski_sum([m, s])

    lam = -0.1
    slack = 0.1
    c = lpset.from_forced_chull(m, combined, lam=lam, slack=slack)

    a_index = c.lpi.names.index('a')

    direction_vec = [0] * a_index + [1]
    c.lpi.set_minimize_direction(direction_vec, offset=0)
    val = c.lpi.minimize(columns=[a_index])[0]

    print(f"min_val of a: {val}")

    direction_vec = [0] * a_index + [-1]
    c.lpi.set_minimize_direction(direction_vec, offset=0)
    val = c.lpi.minimize(columns=[a_index])[0]

    print(f"max_val of a: {val}")

    m.plot('b:')
    s.plot('r:')
    combined.plot('k--')
    c.plot('g-')
    plt.show()

    assert False
示例#9
0
def test_minkowski_dif_twogen():
    'test the minkowski difference from a zonotope with two linearly dependent generators'

    z = lpset.from_centered_zonotope([[0, 1], [0, -1]])
    expected = [[-2, 0], [2, 0]]
    assert_verts_equals(z.verts(), expected)

    b = lpset.from_box([[-0.1, 0.1]])
    dif = z.clone().minkowski_difference(b)

    expected = [[-1.9, 0], [1.9, 0]]
    assert_verts_equals(dif.verts(), expected)
示例#10
0
def test_3d_zonotope_plot():
    'test verts3d on zonotope'

    # zonotope from Figure 6 of "On Computing the Minkowski Difference of Zonotopes" by Matthias Althoff

    m = lpset.from_centered_zonotope([[1, 1, 1], [1, 0, 0], [0, 1, 0],
                                      [0, 0, 1]])

    #s = lpset.from_zonotope([0, 0, 0], [[-1/3, 1/3, 1/3], [1/3, 0, 0], [0, 1/3, 0], [0, 0, 1/3]])

    verts = m.verts3d()
    assert len(verts) == 14

    # figure should work
    fig = plt.figure()
    ax = fig.add_subplot(111, projection="3d")
    m.plot3d(ax)

    plt.show()

    assert False