Ejemplo n.º 1
0
def test_shape_3():
    # A and b have incompatible shapes
    A = sp.array([[-1., 0],
                  [0, -1],
                  [1, 1]])

    b = sp.array([[0., 1]])

    xi = sp.array([0.25, 0.1])

    with pytest.raises(ValueError):
        artools.in_region(xi, A, b)
Ejemplo n.º 2
0
def test_shape_4():
    # xi has incompatible shape
    A = sp.array([[-1., 0],
                  [0, -1],
                  [1, 1]])

    b = sp.array([[0., 0, 1]])

    xi = sp.array([0.25, 0.1, 0.1])

    with pytest.raises(ValueError):
        artools.in_region(xi, A, b)
Ejemplo n.º 3
0
def test_unbounded_3():
    # check on an unbounded region
    A = sp.array([[-1., 0],
                  [0, -1]])

    b = sp.array([0., 0])

    xi = sp.array([0.5, 0])

    assert artools.in_region(xi, A, b)
Ejemplo n.º 4
0
def test_unbounded_2():
    # check out an unbounded region
    A = sp.array([[-1., 0],
                  [0, -1]])

    b = sp.array([0., 0])

    xi = sp.array([-0.5, -0.5])

    assert artools.in_region(xi, A, b) is False
Ejemplo n.º 5
0
def test_in_1():
    # simple 2-D triangle case
    A = sp.array([[-1., 0],
                  [0, -1],
                  [1, 1]])

    b = sp.array([0., 0, 1])

    xi = sp.array([0.1, 0.1])

    assert artools.in_region(xi, A, b)
Ejemplo n.º 6
0
def test_on_1():
    # on a 2-D hyperplane
    A = sp.array([[-1., 0],
                  [0, -1],
                  [1, 1]])

    b = sp.array([0., 0, 1])

    xi = sp.array([0.5, 0.5])

    assert artools.in_region(xi, A, b)
Ejemplo n.º 7
0
def test_out_2():
    # positive space
    A = sp.array([[-1., 0],
                  [0, -1],
                  [1, 1]])

    b = sp.array([0., 0, 1])

    xi = sp.array([2., 2])

    assert (artools.in_region(xi, A, b) is False)
Ejemplo n.º 8
0
def test_shape_2():
    # b is a 2-D row vector
    A = sp.array([[-1., 0],
                  [0, -1],
                  [1, 1]])

    b = sp.array([[0., 0, 1]])

    xi = sp.array([0.25, 0.1])

    assert artools.in_region(xi, A, b)
Ejemplo n.º 9
0
def test_on_2():
    # on an extreme point
    A = sp.array([[-1., 0],
                  [0, -1],
                  [1, 1]])

    b = sp.array([0., 0, 1])

    xi = sp.array([1., 0])

    assert artools.in_region(xi, A, b)
Ejemplo n.º 10
0
def test_out_3():
    # simple 3-D case
    A = sp.array([[-1., 0, 0],
                  [0, -1, 0],
                  [0, 0, -1],
                  [1, 1, 1]])

    b = sp.array([0., 0, 0, 1])

    xi = sp.array([0.7, 0.7, 0.7])

    assert (artools.in_region(xi, A, b) is False)
Ejemplo n.º 11
0
def test_in_3():
    # simple 3-D case
    A = sp.array([[-1., 0, 0],
                  [0, -1, 0],
                  [0, 0, -1],
                  [1, 1, 1]])

    b = sp.array([0., 0, 0, 1])

    xi = sp.array([0.25, 0.1, 0.25])

    assert artools.in_region(xi, A, b)
Ejemplo n.º 12
0
def test_tol_in_1():
    # slightly in the region at the origin
    A = sp.array([[-1., 0],
                  [0, -1],
                  [1, 1]])

    b = sp.array([0., 0, 1])

    tol = 1e-8
    xi = sp.array([0.0 + tol, 0.0 + tol])

    assert artools.in_region(xi, A, b, tol=tol)
Ejemplo n.º 13
0
def test_tol_on_1():
    # on an extreme point specifying tolerance
    A = sp.array([[-1., 0],
                  [0, -1],
                  [1, 1]])

    b = sp.array([0., 0, 1])

    xi = sp.array([1., 0])

    tol = 1e-2

    assert artools.in_region(xi, A, b, tol=tol)
Ejemplo n.º 14
0
def test_tol_out_1():
    # slightly out of the region at the origin, and not within the accepted
    # tolerance
    A = sp.array([[-1., 0],
                  [0, -1],
                  [1, 1]])

    b = sp.array([0., 0, 1])

    tol = 1e-10
    xi = sp.array([0.0 - 2*tol, 0.0 + tol])

    assert (artools.in_region(xi, A, b, tol=tol) is False)
Ejemplo n.º 15
0
def test_tol_in_2():
    # slightly out of the region at the origin, but still within the accepted
    # tolerance
    A = sp.array([[-1., 0],
                  [0, -1],
                  [1, 1]])

    b = sp.array([0., 0, 1])

    tol = 1e-8
    xi = sp.array([0.0 - tol, 0.0 - tol])

    assert artools.in_region(xi, A, b, tol=tol)
Ejemplo n.º 16
0
# this combination of stoich_mat and Cf produces an initial guess that is on
# the boubdary of the feasible region and not technically in the region.
stoich_mat = -sp.array([[-1, -1, 1.], [-1., 0, 1]]).T
Cf = sp.array([1., 1., 0.2])

# this combination works fine
#stoich_mat = -sp.array([[-1, -1, 1.], [-2., 0, 1]]).T
#Cf = sp.array([1., 1., 0.2])

A = -stoich_mat
b = Cf
c = scipy.linalg.lstsq(A, b)[0]

fig = artools.plot_hplanes(-stoich_mat, b, lims=(-2.0, 2.0))
ax = fig.gca()
ax.hold(True)

v = con2vert(A, b)
print v

print artools.in_region(c, A, b)



ax.plot(c[0], c[1], "bo")
ax.plot(v[0, 0], v[0, 1], "ro")
ax.plot(v[1, 0], v[1, 1], "ro")
ax.plot(v[2, 0], v[2, 1], "ro")

plt.show(fig)