예제 #1
0
    def test_solve_max1_A(self):
        A, b, c = self.init_problem_arrays1()
        S = Simplex(A, b, c, debug=False, which='max')

        Asolved = np.array([[-1., -5. / 3., -1. / 3.], [0., -1. / 3., 1. / 3.],
                            [1., 7. / 3., -1. / 3.]])
        self.assertTrue(np.allclose(Asolved, S.T.A))
예제 #2
0
    def test_solve_min3_y(self):
        A, b, c = self.init_problem_arrays3()
        S = Simplex(A, b, c, debug=False, which='min')

        y_solved = [1., 0., 0.]
        self.assertTrue(np.allclose(y_solved, S.T.y))
예제 #3
0
    def test_solve_min3_x(self):
        A, b, c = self.init_problem_arrays3()
        S = Simplex(A, b, c, debug=False, which='min')

        x_solved = [7., 0., 0., 3.]
        self.assertTrue(np.allclose(x_solved, S.T.x))
예제 #4
0
    def test_solve_min3_t_mask(self):
        A, b, c = self.init_problem_arrays3()
        S = Simplex(A, b, c, debug=False, which='min')

        t_mask = [0, 0, 1]
        self.assertTrue(np.alltrue(S.T.t.mask == t_mask))
예제 #5
0
    def test_solve_min3_t_indices(self):
        A, b, c = self.init_problem_arrays3()
        S = Simplex(A, b, c, debug=False, which='min')

        t_indices = [3, 0, 2]
        self.assertTrue(np.alltrue(S.T.t.data == t_indices))
예제 #6
0
    def test_solve_max1_c(self):
        A, b, c = self.init_problem_arrays1()
        S = Simplex(A, b, c, debug=False, which='max')

        csolved = np.array([-1., -2. / 3., -1. / 3.])
        self.assertTrue(np.allclose(csolved, S.T.c))
예제 #7
0
    def test_min_solution_when_requesting_max(self):
        A, b, c = self.init_unbounded_max_arrays1()
        S = Simplex(A, b, c, debug=False, which='max')

        self.assertIsNone(S.min_solution)
예제 #8
0
    def test_max_solution_when_requesting_min(self):
        A, b, c = self.init_unbounded_max_arrays1()
        S = Simplex(A, b, c, debug=False, which='min')

        solution = inf
        self.assertAlmostEqual(solution, S.max_solution)
예제 #9
0
    def test_solve_max2_solution(self):
        A, b, c = self.init_problem_arrays2()
        S = Simplex(A, b, c, debug=False, which='max')

        solution = 11. / 3.
        self.assertAlmostEqual(solution, S.max_solution)
예제 #10
0
    def test_solve_max2_y(self):
        A, b, c = self.init_problem_arrays2()
        S = Simplex(A, b, c, debug=False, which='max')

        ysolved = [0., 2. / 3., 1.]
        self.assertTrue(np.allclose(ysolved, S.T.y))
예제 #11
0
    def test_solve_max2_t_indices(self):
        A, b, c = self.init_problem_arrays2()
        S = Simplex(A, b, c, debug=False, which='max')

        t_indices = np.array([0, 2, 1])
        self.assertTrue(np.alltrue(np.array(S.T.t) == t_indices))
예제 #12
0
    def test_solve_max2_b(self):
        A, b, c = self.init_problem_arrays2()
        S = Simplex(A, b, c, debug=False, which='max')

        bsolved = np.array([4. / 3., 2. / 3., 1. / 3.])
        self.assertTrue(np.allclose(bsolved, S.T.b))
예제 #13
0
    def test_solve_max1_x(self):
        A, b, c = self.init_problem_arrays1()
        S = Simplex(A, b, c, debug=False, which='max')

        xsolved = [0., 1. / 3., 2. / 3.]
        self.assertTrue(np.allclose(xsolved, S.T.x))
예제 #14
0
    def test_solve_max1_r_mask(self):
        A, b, c = self.init_problem_arrays1()
        S = Simplex(A, b, c, debug=False, which='max')

        r_mask = [0, 1, 0]
        self.assertTrue(np.alltrue(S.T.r.mask == r_mask))
예제 #15
0
    def test_solve_max1_r_indices(self):
        A, b, c = self.init_problem_arrays1()
        S = Simplex(A, b, c, debug=False, which='max')

        r_indices = np.array([2, 0, 1])
        self.assertTrue(np.alltrue(np.array(S.T.r) == r_indices))
예제 #16
0
    def test_solve_min3_solution_w_list_input(self):
        A, b, c = self.init_problem_lists3()
        S = Simplex(A, b, c, debug=False, which='min')

        solution = 4.
        self.assertAlmostEqual(solution, S.min_solution)
예제 #17
0
    def test_max_infeasible(self):
        A, b, c = self.init_infeasible_max_arrays1()
        S = Simplex(A, b, c, debug=False, which='max')

        self.assertIsNone(S.max_solution)
예제 #18
0
    def test_solve_min3_b(self):
        A, b, c = self.init_problem_arrays3()
        S = Simplex(A, b, c, debug=False, which='min')

        b_solved = np.array([3., 7., 12.])
        self.assertTrue(np.allclose(b_solved, S.T.b))
예제 #19
0
    def test_min_infeasible(self):
        A, b, c = self.init_unbounded_max_arrays1()
        S = Simplex(A, b, c, debug=False, which='min')

        self.assertIsNone(S.min_solution)
예제 #20
0
    def test_solve_min3_c(self):
        A, b, c = self.init_problem_arrays3()
        S = Simplex(A, b, c, debug=False, which='min')

        c_solved = np.array([0., -1., -1., -1.])
        self.assertTrue(np.allclose(c_solved, S.T.c))
예제 #21
0
    def test_min_unbounded_feasible(self):
        A, b, c = self.init_infeasible_max_arrays1()
        S = Simplex(A, b, c, debug=False, which='min')

        solution = -inf
        self.assertAlmostEqual(solution, S.min_solution)
예제 #22
0
    def test_solve_min3_r_indices(self):
        A, b, c = self.init_problem_arrays3()
        S = Simplex(A, b, c, debug=False, which='min')

        r_indices = [1, 1, 2, 0]
        self.assertTrue(np.alltrue(S.T.r.data == r_indices))