Esempio n. 1
0
    def test_3(self):
        # 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):
            inRegion(xi, A, b)
Esempio n. 2
0
    def test_4(self):
        # 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):
            inRegion(xi, A, b)
Esempio n. 3
0
    def test_1(self):
        # check in an unbounded region
        A = sp.array([[-1., 0], [0, -1]])

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

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

        assert inRegion(xi, A, b)
Esempio n. 4
0
    def test_1(self):
        # 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 inRegion(xi, A, b)
Esempio n. 5
0
    def test_1(self):
        # 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 inRegion(xi, A, b)
Esempio n. 6
0
    def test_2(self):
        # 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 inRegion(xi, A, b)
Esempio n. 7
0
    def test_2(self):
        # positive space
        A = sp.array([[-1., 0], [0, -1], [1, 1]])

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

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

        assert (inRegion(xi, A, b) is False)
Esempio n. 8
0
    def test_3(self):
        # 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 (inRegion(xi, A, b) is False)
Esempio n. 9
0
    def test_3(self):
        # 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 inRegion(xi, A, b)
Esempio n. 10
0
    def test_1(self):
        # negative space
        A = sp.array([[-1., 0], [0, -1], [1, 1]])

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

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

        assert (inRegion(xi, A, b) is False)
Esempio n. 11
0
    def test_2(self):
        # 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 inRegion(xi, A, b)
Esempio n. 12
0
    def test_2(self):
        # 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 inRegion(xi, A, b) is False
Esempio n. 13
0
    def test_1(self):
        # b is a 2-D column vector
        A = sp.array([[-1., 0], [0, -1], [1, 1]])

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

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

        assert inRegion(xi, A, b)
Esempio n. 14
0
    def test_1(self):
        # 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 inRegion(xi, A, b, tol=tol)
Esempio n. 15
0
    def test_1(self):
        # 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 inRegion(xi, A, b, tol=tol)
Esempio n. 16
0
    def test_1(self):
        # 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 (inRegion(xi, A, b, tol=tol) is False)
Esempio n. 17
0
    def test_2(self):
        # 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 inRegion(xi, A, b, tol=tol)
Esempio n. 18
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.plotHplanes(-stoich_mat, b, lims=(-2.0, 2.0))
ax = fig.gca()
ax.hold(True)

v = con2vert(A, b)
print v

print artools.inRegion(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)