Exemple #1
0
 def test_7(self):
     a = np.array([1, 1, -2, 3, 2, -1, -1, 3], dtype=np.float).reshape(
         (2, 4))
     task = LinearProgrammingTask(a, np.array([1, 2]),
                                  np.array([1, 2, -1, 1]),
                                  np.array([0, 0, 1, 1], dtype=np.float))
     self.assertFalse(task.solve_with_simplex_method())
Exemple #2
0
 def test_8(self):
     a = np.array([-2, -1, 3, -7.5, 0, 0, 0, 2, 4, -2, 6, 0, 1, 5, -1, -4, 1, -1, 0, -1, 0, 3, 1, 1],
                  dtype=np.float).reshape((3, 8))
     task = LinearProgrammingTask(
         a, np.array([-23.5, -24, 2]), np.array([-6, 9, -5, 2, -6, 0, 1, 3]),
         np.array([0, 0, 0, 5, 4, 0, 0, 7], dtype=np.float)
     )
     self.assertFalse(task.solve_with_simplex_method())
Exemple #3
0
 def test_1(self):
     a = np.array([3, 1, 1, 0, 1, -2, 0, 1], dtype=np.float).reshape((2, 4))
     task = LinearProgrammingTask(a, np.array([1, 1]),
                                  np.array([1, 4, 1, -1]),
                                  np.array([0, 0, 1, 1], dtype=np.float))
     self.assertTrue(task.solve_with_simplex_method())
     np.testing.assert_array_almost_equal(task.result_x, [0, 1, 0, 3])
     self.assertEqual(float(task.get_target_function_value()), 1)
 def test_4(self):
     c = np.array([-4, 8, 8, -7, 0, 0], dtype=np.float64)
     b = np.array([-4, -6, 2], dtype=np.float64)
     A = np.array(
         [[1, 1, 1, 1, 0, 0], [-1, 1, 0, 0, 1, 0], [-1, -2, 0, 0, 0, 1]],
         dtype=np.float64)
     jb = [3, 4, 5]
     task = LinearProgrammingTask(A, b, c, j_basis=jb)
     self.assertFalse(task.solve_with_dual_simplex_method())
Exemple #5
0
 def test_1(self):
     a = np.array([3, 1, 1, 0, 1, -2, 0, 1], dtype=np.float).reshape((2, 4))
     task = LinearProgrammingTask(
         a, np.array([1, 1]),
         np.array([1, 4, 1, -1]), np.array([0, 0, 1, 1], dtype=np.float)
     )
     self.assertTrue(task.solve_with_simplex_method())
     np.testing.assert_array_almost_equal(task.result_x, [0, 1, 0, 3])
     self.assertEqual(float(task.get_target_function_value()), 1)
Exemple #6
0
 def test_7(self):
     a = np.array([1, 1, -2, 3, 2, -1, -1, 3],
                  dtype=np.float
                  ).reshape((2, 4))
     task = LinearProgrammingTask(
         a, np.array([1, 2]), np.array([1, 2, -1, 1]),
         np.array([0, 0, 1, 1], dtype=np.float)
     )
     self.assertFalse(task.solve_with_simplex_method())
Exemple #7
0
 def test_6(self):
     a = np.array([-2, 3, 1, 1, 0, 0, 1, 2, 2, 0, 1, 0, 2, -1, -3, 0, 0, 1],
                  dtype=np.float).reshape((3, 6))
     task = LinearProgrammingTask(
         a, np.array([36, 45, 30]), np.array([2, 4, 1, 0, 0, 0]),
         np.array([0, 0, 0, 36, 45, 30], dtype=np.float))
     self.assertTrue(task.solve_with_simplex_method())
     np.testing.assert_array_almost_equal(task.result_x,
                                          [21, 12, 0, 42, 0, 0])
     self.assertAlmostEqual(float(task.get_target_function_value()), 90)
 def test_task_5_from_method(self):
     c = np.array([1, 2, 1, -3, 3, 1, 0], dtype=np.float64)
     b = np.array([1, 4, 7], dtype=np.float64)
     A = np.array([[1, 7, 2, 0, 1, -1, 4], [0, 5, 6, 1, 0, -3, -2],
                   [3, 2, 2, 1, 1, 1, 5]],
                  dtype=np.float64)
     d_bottom = [-1, 1, -2, 0, 1, 2, 4]
     d_top = [3, 2, 2, 5, 3, 4, 5]
     task = LinearProgrammingTask(A, b, c, d_bottom=d_bottom, d_top=d_top)
     self.assertFalse(
         task.solve_with_dual_simplex_method_with_constraints())
Exemple #9
0
 def test_8(self):
     a = np.array([
         -2, -1, 3, -7.5, 0, 0, 0, 2, 4, -2, 6, 0, 1, 5, -1, -4, 1, -1, 0,
         -1, 0, 3, 1, 1
     ],
                  dtype=np.float).reshape((3, 8))
     task = LinearProgrammingTask(
         a, np.array([-23.5, -24, 2]), np.array([-6, 9, -5, 2, -6, 0, 1,
                                                 3]),
         np.array([0, 0, 0, 5, 4, 0, 0, 7], dtype=np.float))
     self.assertFalse(task.solve_with_simplex_method())
 def test_task_7_from_method(self):
     c = np.array([0, -1, 1, 0, 4, 3], dtype=np.float64)
     b = np.array([2, 2, 5], dtype=np.float64)
     A = np.array(
         [[2, 1, 0, 3, -1, -1], [0, 1, -2, 1, 0, 3], [3, 0, 1, 1, 1, 1]],
         dtype=np.float64)
     d_bottom = [2, 0, -1, -3, 2, 1]
     d_top = [7, 3, 2, 3, 4, 5]
     task = LinearProgrammingTask(A, b, c, d_bottom=d_bottom, d_top=d_top)
     self.assertFalse(
         task.solve_with_dual_simplex_method_with_constraints())
Exemple #11
0
 def test_4(self):
     a = np.array([0, -1, 1, 7.5, 0, 0, 0, 2, 0, 2, 1, 0, -1, 3, -1.5, 0, 1, -1, 1, -1, 0, 3, 1, 1],
                  dtype=np.float
                  ).reshape((3, 8))
     task = LinearProgrammingTask(
         a, np.array([6, 1.5, 10]), np.array([-6, -9, -5, 2, -6, 0, 1, 3]),
         np.array([4, 0, 6, 0, 4.5, 0, 0, 0], dtype=np.float)
     )
     self.assertTrue(task.solve_with_simplex_method())
     np.testing.assert_array_almost_equal(task.result_x, [0, 0, 0, 0, 0, 1.6, 2.2, 3])
     self.assertAlmostEqual(float(task.get_target_function_value()), 11.2)
Exemple #12
0
 def test_5(self):
     a = np.array([-2, -1, 1, -7, 0, 0, 0, 2, 4, 2, -1, 0, 1, 5, -1, -5, 1, 11, 0, 1, 0, 3, 1, 1],
                  dtype=np.float
                  ).reshape((3, 8))
     task = LinearProgrammingTask(
         a, np.array([14, -31, 7]), np.array([6, -9, 5, -2, 6, 0, -1, 3]),
         np.array([4, 0, 6, 0, 4, 0, 0, 0], dtype=np.float)
     )
     self.assertTrue(task.solve_with_simplex_method())
     np.testing.assert_array_almost_equal(task.result_x, [0, 0, 26, 4, 40, 0, 0, 0])
     self.assertAlmostEqual(float(task.get_target_function_value()), 362.0)
Exemple #13
0
 def test_6(self):
     a = np.array([-2, 3, 1, 1, 0, 0, 1, 2, 2, 0, 1, 0, 2, -1, -3, 0, 0, 1],
                  dtype=np.float
                  ).reshape((3, 6))
     task = LinearProgrammingTask(
         a, np.array([36, 45, 30]), np.array([2, 4, 1, 0, 0, 0]),
         np.array([0, 0, 0, 36, 45, 30], dtype=np.float)
     )
     self.assertTrue(task.solve_with_simplex_method())
     np.testing.assert_array_almost_equal(task.result_x, [21, 12, 0, 42, 0, 0])
     self.assertAlmostEqual(float(task.get_target_function_value()), 90)
 def test_task_1_from_method(self):
     c = np.array([7, -2, 6, 0, 5, 2], dtype=np.float64)
     b = np.array([-7, 22, 30], dtype=np.float64)
     A = np.array(
         [[1, -5, 3, 1, 0, 0], [4, -1, 1, 0, 1, 0], [2, 4, 2, 0, 0, 1]],
         dtype=np.float64)
     d_bottom = [2, 1, 0, 0, 1, 1]
     d_top = [6, 6, 5, 2, 4, 6]
     task = LinearProgrammingTask(A, b, c, d_bottom=d_bottom, d_top=d_top)
     self.assertTrue(task.solve_with_dual_simplex_method_with_constraints())
     np.testing.assert_array_almost_equal(task.result_x, [5, 3, 1, 0, 4, 6])
     self.assertEqual(float(task.get_target_function_value()), 67)
Exemple #15
0
 def test_3(self):
     a = np.array(
         [0, 1, 4, 1, 0, -8, 1, 5, 0, -1, 0, -1, 0, 0, 0, 0, 0, 2, -1, 0, -1, 3, -1, 0, 1, 1, 1, 1, 0, 3, 1, 1],
         dtype=np.float
     ).reshape((4, 8))
     task = LinearProgrammingTask(
         a, np.array([36, -11, 10, 20]), np.array([-5, 2, 3, -4, -6, 0, 1, -5]),
         np.array([4, 5, 0, 6, 0, 0, 0, 5], dtype=np.float)
     )
     self.assertTrue(task.solve_with_simplex_method())
     np.testing.assert_array_almost_equal(task.result_x, [0, 9.5, 5.33333333, 1.5, 0, 0, 3.66666667, 0])
     self.assertAlmostEqual(float(task.get_target_function_value()), 32.6666666667)
Exemple #16
0
 def test_2(self):
     a = np.array(
         [0, 1, 4, 1, 0, -3, 1, 0, 1, -1, 0, 1, 0, 0, 0, 0, 0, 7, -1, 0, -1, 3, -1, 0, 1, 1, 1, 1, 0, 3, -1, 1],
         dtype=np.float
     ).reshape((4, 8))
     task = LinearProgrammingTask(
         a, np.array([6, 10, -2, 15]), np.array([-5, -2, 3, -4, -6, 0, -1, -5]),
         np.array([10, 0, 1.5, 0, 0.5, 0, 0, 3.5], dtype=np.float)
     )
     self.assertTrue(task.solve_with_simplex_method())
     np.testing.assert_array_almost_equal(task.result_x, [10, 0, 2.2, 0, 2.6, 0.93333333, 0, 0])
     self.assertEqual(float(task.get_target_function_value()), -59)
Exemple #17
0
 def test_task_1_from_example(self):
     c = np.array([7, -2, 6, 0, 5, 2], dtype=np.float64)
     b = np.array([-8, 22, 30], dtype=np.float64)
     A = np.array(
         [[1, -5, 3, 1, 0, 0], [4, -1, 1, 0, 1, 0], [2, 4, 2, 0, 0, 1]],
         dtype=np.float64)
     d_bottom = [2, 1, 0, 0, 1, 1]
     d_top = [6, 6, 5, 2, 4, 6]
     task = LinearProgrammingTask(A, b, c, d_bottom=d_bottom, d_top=d_top)
     self.assertTrue(task.solve_integral_linear_task())
     np.testing.assert_array_almost_equal(task.result_x, [6, 3, 0, 1, 1, 6],
                                          4)
     self.assertAlmostEqual(float(task.get_target_function_value()), 53, 4)
 def test_4(self):
     c = np.array([-4, 8, 8, -7, 0, 0], dtype=np.float64)
     b = np.array([-4, -6, 2], dtype=np.float64)
     A = np.array([
         [1, 1, 1, 1, 0, 0],
         [-1, 1, 0, 0, 1, 0],
         [-1, -2, 0, 0, 0, 1]
     ], dtype=np.float64)
     jb = [3, 4, 5]
     task = LinearProgrammingTask(
         A, b, c, j_basis=jb
     )
     self.assertFalse(task.solve_with_dual_simplex_method())
 def test_task_6_from_method(self):
     c = np.array([0, 1, 2, 1, -3, 4, 7], dtype=np.float64)
     b = np.array([1.5, 9, 2], dtype=np.float64)
     A = np.array([[2, -1, 1, 0, 0, -1, 3], [0, 4, -1, 2, 3, -2, 2],
                   [3, 1, 0, 1, 0, 1, 4]],
                  dtype=np.float64)
     d_bottom = [0, 0, -3, 0, -1, 1, 0]
     d_top = [3, 3, 4, 7, 5, 3, 2]
     task = LinearProgrammingTask(A, b, c, d_bottom=d_bottom, d_top=d_top)
     self.assertTrue(task.solve_with_dual_simplex_method_with_constraints())
     np.testing.assert_array_almost_equal(task.result_x,
                                          [0, 1, 3.5, 0, 3.5, 1, 0], 4)
     self.assertAlmostEqual(float(task.get_target_function_value()), 1.5, 4)
Exemple #20
0
 def test_task_3_from_example(self):
     c = np.array([-3, 2, 0, -2, -5, 2], dtype=np.float64)
     b = np.array([-3, 3, 13], dtype=np.float64)
     A = np.array(
         [[1, 0, 1, 0, 0, 1], [1, 2, -1, 1, 1, 2], [-2, 4, 1, 0, 1, 0]],
         dtype=np.float64)
     d_bottom = [-2, -1, -2, 0, 1, -4]
     d_top = [2, 3, 1, 5, 4, -1]
     task = LinearProgrammingTask(A, b, c, d_bottom=d_bottom, d_top=d_top)
     self.assertTrue(task.solve_integral_linear_task())
     np.testing.assert_array_almost_equal(task.result_x,
                                          [-2, 2, 0, 2, 1, -1], 4)
     self.assertAlmostEqual(float(task.get_target_function_value()), -1, 4)
 def test_5(self):
     c = np.array([3, 2, 0, 3, -2, -4], dtype=np.float64)
     b = np.array([2, 5, 0], dtype=np.float64)
     A = np.array(
         [[2, 1, -1, 0, 0, 1], [1, 0, 1, 1, 0, 0], [0, 1, 0, 0, 1, 0]],
         dtype=np.float64)
     d_bottom = [0, -1, 2, 1, -1, 0]
     d_top = [2, 4, 4, 3, 3, 5]
     task = LinearProgrammingTask(A, b, c, d_bottom=d_bottom, d_top=d_top)
     self.assertTrue(task.solve_with_dual_simplex_method_with_constraints())
     np.testing.assert_array_almost_equal(task.result_x,
                                          [1.5, 1, 2, 1.5, -1, 0])
     self.assertEqual(float(task.get_target_function_value()), 13)
Exemple #22
0
 def test_4(self):
     a = np.array([
         0, -1, 1, 7.5, 0, 0, 0, 2, 0, 2, 1, 0, -1, 3, -1.5, 0, 1, -1, 1,
         -1, 0, 3, 1, 1
     ],
                  dtype=np.float).reshape((3, 8))
     task = LinearProgrammingTask(
         a, np.array([6, 1.5, 10]), np.array([-6, -9, -5, 2, -6, 0, 1, 3]),
         np.array([4, 0, 6, 0, 4.5, 0, 0, 0], dtype=np.float))
     self.assertTrue(task.solve_with_simplex_method())
     np.testing.assert_array_almost_equal(task.result_x,
                                          [0, 0, 0, 0, 0, 1.6, 2.2, 3])
     self.assertAlmostEqual(float(task.get_target_function_value()), 11.2)
Exemple #23
0
 def test_5(self):
     a = np.array([
         -2, -1, 1, -7, 0, 0, 0, 2, 4, 2, -1, 0, 1, 5, -1, -5, 1, 11, 0, 1,
         0, 3, 1, 1
     ],
                  dtype=np.float).reshape((3, 8))
     task = LinearProgrammingTask(
         a, np.array([14, -31, 7]), np.array([6, -9, 5, -2, 6, 0, -1, 3]),
         np.array([4, 0, 6, 0, 4, 0, 0, 0], dtype=np.float))
     self.assertTrue(task.solve_with_simplex_method())
     np.testing.assert_array_almost_equal(task.result_x,
                                          [0, 0, 26, 4, 40, 0, 0, 0])
     self.assertAlmostEqual(float(task.get_target_function_value()), 362.0)
 def test_task_3_from_method(self):
     c = np.array([2, 1, -2, -1, 4, -5, 5, 5], dtype=np.float64)
     b = np.array([40, 107, 61], dtype=np.float64)
     A = np.array([[1, 0, 0, 12, 1, -3, 4, -1], [0, 1, 0, 11, 12, 3, 5, 3],
                   [0, 0, 1, 1, 0, 22, -2, 1]],
                  dtype=np.float64)
     d_bottom = [0, 0, 0, 0, 0, 0, 0, 0]
     d_top = [3, 5, 5, 3, 4, 5, 6, 3]
     task = LinearProgrammingTask(A, b, c, d_bottom=d_bottom, d_top=d_top)
     self.assertTrue(task.solve_with_dual_simplex_method_with_constraints())
     np.testing.assert_array_almost_equal(
         task.result_x, [3, 5, 0, 1.8779, 2.7545, 3.0965, 6, 3], 4)
     self.assertAlmostEqual(float(task.get_target_function_value()),
                            49.6577, 4)
Exemple #25
0
    def test_third(self):
        c = np.array([2, -5, 0, 0, 0], dtype=np.float64)
        b = np.array([-1, 10, 3], dtype=np.float64)
        A = np.array([
            [-2, -1, 1, 0, 0],
            [3, 1, 0, 1, 0],
            [-1, 1, 0, 0, 1],
        ],
                     dtype=np.float64)
        task = LinearProgrammingTask(A, b, c, j_basis=[0, 2, 4])

        self.assertTrue(task.solve_with_method_gomori())
        np.testing.assert_array_almost_equal(task.result_x, [3, 0, 5, 1, 6], 4)
        self.assertAlmostEqual(float(task.get_target_function_value()), 6, 4)
Exemple #26
0
    def test_second(self):
        c = np.array([1, -1, 0, 0, 0], dtype=np.float64)
        b = np.array([4, 3, 7], dtype=np.float64)
        A = np.array([
            [5, 3, 1, 0, 0],
            [-1, 2, 0, 1, 0],
            [1, -2, 0, 0, 1],
        ],
                     dtype=np.float64)
        task = LinearProgrammingTask(A, b, c, j_basis=[0, 3, 4])

        self.assertTrue(task.solve_with_method_gomori())
        np.testing.assert_array_almost_equal(task.result_x, [0, 0, 4, 3, 7], 4)
        self.assertAlmostEqual(float(task.get_target_function_value()), 0, 4)
Exemple #27
0
 def test_2(self):
     a = np.array([
         0, 1, 4, 1, 0, -3, 1, 0, 1, -1, 0, 1, 0, 0, 0, 0, 0, 7, -1, 0, -1,
         3, -1, 0, 1, 1, 1, 1, 0, 3, -1, 1
     ],
                  dtype=np.float).reshape((4, 8))
     task = LinearProgrammingTask(
         a, np.array([6, 10, -2, 15]),
         np.array([-5, -2, 3, -4, -6, 0, -1, -5]),
         np.array([10, 0, 1.5, 0, 0.5, 0, 0, 3.5], dtype=np.float))
     self.assertTrue(task.solve_with_simplex_method())
     np.testing.assert_array_almost_equal(
         task.result_x, [10, 0, 2.2, 0, 2.6, 0.93333333, 0, 0])
     self.assertEqual(float(task.get_target_function_value()), -59)
 def test_task_5_from_method(self):
     c = np.array([1, 2, 1, -3, 3, 1, 0], dtype=np.float64)
     b = np.array([1, 4, 7], dtype=np.float64)
     A = np.array([
         [1, 7, 2, 0, 1, -1, 4],
         [0, 5, 6, 1, 0, -3, -2],
         [3, 2, 2, 1, 1, 1, 5]
     ], dtype=np.float64)
     d_bottom = [-1, 1, -2, 0, 1, 2, 4]
     d_top = [3, 2, 2, 5, 3, 4, 5]
     task = LinearProgrammingTask(
         A, b, c,
         d_bottom=d_bottom, d_top=d_top
     )
     self.assertFalse(task.solve_with_dual_simplex_method_with_constraints())
 def test_task_7_from_method(self):
     c = np.array([0, -1, 1, 0, 4, 3], dtype=np.float64)
     b = np.array([2, 2, 5], dtype=np.float64)
     A = np.array([
         [2, 1, 0, 3, -1, -1],
         [0, 1, -2, 1, 0, 3],
         [3, 0, 1, 1, 1, 1]
     ], dtype=np.float64)
     d_bottom = [2, 0, -1, -3, 2, 1]
     d_top = [7, 3, 2, 3, 4, 5]
     task = LinearProgrammingTask(
         A, b, c,
         d_bottom=d_bottom, d_top=d_top
     )
     self.assertFalse(task.solve_with_dual_simplex_method_with_constraints())
Exemple #30
0
 def test_3(self):
     a = np.array([
         0, 1, 4, 1, 0, -8, 1, 5, 0, -1, 0, -1, 0, 0, 0, 0, 0, 2, -1, 0, -1,
         3, -1, 0, 1, 1, 1, 1, 0, 3, 1, 1
     ],
                  dtype=np.float).reshape((4, 8))
     task = LinearProgrammingTask(
         a, np.array([36, -11, 10, 20]),
         np.array([-5, 2, 3, -4, -6, 0, 1, -5]),
         np.array([4, 5, 0, 6, 0, 0, 0, 5], dtype=np.float))
     self.assertTrue(task.solve_with_simplex_method())
     np.testing.assert_array_almost_equal(
         task.result_x, [0, 9.5, 5.33333333, 1.5, 0, 0, 3.66666667, 0])
     self.assertAlmostEqual(float(task.get_target_function_value()),
                            32.6666666667)
Exemple #31
0
    def test_MAIN_TASK(self):
        c = np.array([7, -2, 6, 0, 5, 2], dtype=np.float64)
        b = np.array([-8, 22, 30], dtype=np.float64)
        A = np.array([
            [1, -5, 3, 1, 0, 0],
            [4, -1, 1, 0, 1, 0],
            [2, 4, 2, 0, 0, 1],
        ],
                     dtype=np.float64)
        task = LinearProgrammingTask(A, b, c, j_basis=[3, 4, 5])

        self.assertTrue(task.solve_with_method_gomori())
        np.testing.assert_array_almost_equal(task.result_x,
                                             [0, 2, 0, 2, 24, 22], 4)
        self.assertAlmostEqual(float(task.get_target_function_value()), 160, 4)
 def test_task_2_from_method(self):
     c = np.array([3, 0.5, 4, 4, 1, 5], dtype=np.float64)
     b = np.array([15, 0, 13], dtype=np.float64)
     A = np.array(
         [[1, 0, 2, 2, -3, 3], [0, 1, 0, -1, 0, 1], [1, 0, 1, 3, 2, 1]],
         dtype=np.float64)
     d_bottom = [0, 0, 0, 0, 0, 0]
     d_top = [3, 5, 4, 3, 3, 4]
     task = LinearProgrammingTask(A, b, c, d_bottom=d_bottom, d_top=d_top)
     self.assertTrue(task.solve_with_dual_simplex_method_with_constraints())
     np.testing.assert_array_almost_equal(task.result_x,
                                          [3, 0, 4, 1.1818, 0.6364, 1.1818],
                                          4)
     self.assertAlmostEqual(float(task.get_target_function_value()),
                            36.2727, 4)
 def test_task_2_from_method(self):
     c = np.array([3, 0.5, 4, 4, 1, 5], dtype=np.float64)
     b = np.array([15, 0, 13], dtype=np.float64)
     A = np.array([[1, 0, 2, 2, -3, 3],
                   [0, 1, 0, -1, 0, 1],
                   [1, 0, 1, 3, 2, 1]], dtype=np.float64)
     d_bottom = [0, 0, 0, 0, 0, 0]
     d_top = [3, 5, 4, 3, 3, 4]
     task = LinearProgrammingTask(
         A, b, c,
         d_bottom=d_bottom, d_top=d_top
     )
     self.assertTrue(task.solve_with_dual_simplex_method_with_constraints())
     np.testing.assert_array_almost_equal(task.result_x, [3, 0, 4, 1.1818, 0.6364, 1.1818], 4)
     self.assertAlmostEqual(float(task.get_target_function_value()), 36.2727, 4)
 def test_task_3_from_method(self):
     c = np.array([2, 1, -2, -1, 4, -5, 5, 5], dtype=np.float64)
     b = np.array([40, 107, 61], dtype=np.float64)
     A = np.array([[1, 0, 0, 12, 1, -3, 4, -1],
                   [0, 1, 0, 11, 12, 3, 5, 3],
                   [0, 0, 1, 1, 0, 22, -2, 1]], dtype=np.float64)
     d_bottom = [0, 0, 0, 0, 0, 0, 0, 0]
     d_top = [3, 5, 5, 3, 4, 5, 6, 3]
     task = LinearProgrammingTask(
         A, b, c,
         d_bottom=d_bottom, d_top=d_top
     )
     self.assertTrue(task.solve_with_dual_simplex_method_with_constraints())
     np.testing.assert_array_almost_equal(task.result_x,
                                          [3, 5, 0, 1.8779, 2.7545, 3.0965, 6, 3], 4)
     self.assertAlmostEqual(float(task.get_target_function_value()), 49.6577, 4)
 def test_task_6_from_method(self):
     c = np.array([0, 1, 2, 1, -3, 4, 7], dtype=np.float64)
     b = np.array([1.5, 9, 2], dtype=np.float64)
     A = np.array([[2, -1, 1, 0, 0, -1, 3],
                   [0, 4, -1, 2, 3, -2, 2],
                   [3, 1, 0, 1, 0, 1, 4]], dtype=np.float64)
     d_bottom = [0, 0, -3, 0, -1, 1, 0]
     d_top = [3, 3, 4, 7, 5, 3, 2]
     task = LinearProgrammingTask(
         A, b, c,
         d_bottom=d_bottom, d_top=d_top
     )
     self.assertTrue(task.solve_with_dual_simplex_method_with_constraints())
     np.testing.assert_array_almost_equal(
         task.result_x,
         [0, 1, 3.5, 0, 3.5, 1, 0], 4)
     self.assertAlmostEqual(float(task.get_target_function_value()), 1.5, 4)
 def test_3(self):
     c = np.array([-4, 8, -18, -7, 0, 0, 0], dtype=np.float64)
     b = np.array([0, 5, -2], dtype=np.float64)
     A = np.array([
         [0, 0, -2, 1, 1, 0, 0],
         [2, 0, -1, 2, 0, 1, 0],
         [-2, 2, -2, -2, 0, 0, 1]
     ], dtype=np.float64)
     jb = [4, 5, 6]
     task = LinearProgrammingTask(
         A, b, c, j_basis=jb
     )
     self.assertTrue(task.solve_with_dual_simplex_method())
     self.assertAlmostEqual(task.get_target_function_value(task='simple'),
                            task.get_target_function_value(task='dual'))
     np.testing.assert_array_almost_equal(task.result_y, [0, 0, 2])
     self.assertEqual(float(task.get_target_function_value()), -4)
 def test_5(self):
     c = np.array([3, 2, 0, 3, -2, -4], dtype=np.float64)
     b = np.array([2, 5, 0], dtype=np.float64)
     A = np.array([
         [2, 1, -1, 0, 0, 1],
         [1, 0, 1, 1, 0, 0],
         [0, 1, 0, 0, 1, 0]
     ], dtype=np.float64)
     d_bottom = [0, -1, 2, 1, -1, 0]
     d_top = [2, 4, 4, 3, 3, 5]
     task = LinearProgrammingTask(
         A, b, c,
         d_bottom=d_bottom, d_top=d_top
     )
     self.assertTrue(task.solve_with_dual_simplex_method_with_constraints())
     np.testing.assert_array_almost_equal(task.result_x, [1.5, 1, 2, 1.5, -1, 0])
     self.assertEqual(float(task.get_target_function_value()), 13)
 def test_task_1_from_method(self):
     c = np.array([7, -2, 6, 0, 5, 2], dtype=np.float64)
     b = np.array([-7, 22, 30], dtype=np.float64)
     A = np.array([
         [1, -5, 3, 1, 0, 0],
         [4, -1, 1, 0, 1, 0],
         [2, 4, 2, 0, 0, 1]
     ], dtype=np.float64)
     d_bottom = [2, 1, 0, 0, 1, 1]
     d_top = [6, 6, 5, 2, 4, 6]
     task = LinearProgrammingTask(
         A, b, c,
         d_bottom=d_bottom, d_top=d_top
     )
     self.assertTrue(task.solve_with_dual_simplex_method_with_constraints())
     np.testing.assert_array_almost_equal(task.result_x, [5, 3, 1, 0, 4, 6])
     self.assertEqual(float(task.get_target_function_value()), 67)
 def test_task_4_from_method(self):
     c = np.array([-1, 5, -2, 4, 3, 1, 2, 8, 3], dtype=np.float64)
     b = np.array([3, 9, 9, 5, 9], dtype=np.float64)
     A = np.array(
         [[1, -3, 2, 0, 1, -1, 4, -1, 0], [1, -1, 6, 1, 0, -2, 2, 2, 0],
          [2, 2, -1, 1, 0, -3, 8, -1, 1], [4, 1, 0, 0, 1, -1, 0, -1, 1],
          [1, 1, 1, 1, 1, 1, 1, 1, 1]],
         dtype=np.float64)
     d_bottom = [0, 0, 0, 0, 0, 0, 0, 0, 0]
     d_top = [5, 5, 5, 5, 5, 5, 5, 5, 5]
     task = LinearProgrammingTask(A, b, c, d_bottom=d_bottom, d_top=d_top)
     self.assertTrue(task.solve_with_dual_simplex_method_with_constraints())
     np.testing.assert_array_almost_equal(
         task.result_x,
         [1.1579, 0.6942, 0, 0, 2.8797, 0, 1.0627, 3.2055, 0], 4)
     self.assertAlmostEqual(float(task.get_target_function_value()),
                            38.7218, 4)
 def test_task_4_from_method(self):
     c = np.array([-1, 5, -2, 4, 3, 1, 2, 8, 3], dtype=np.float64)
     b = np.array([3, 9, 9, 5, 9], dtype=np.float64)
     A = np.array([[1, -3, 2, 0, 1, -1, 4, -1, 0],
                   [1, -1, 6, 1, 0, -2, 2, 2, 0],
                   [2, 2, -1, 1, 0, -3, 8, -1, 1],
                   [4, 1, 0, 0, 1, -1, 0, -1, 1],
                   [1, 1, 1, 1, 1, 1, 1, 1, 1]], dtype=np.float64)
     d_bottom = [0, 0, 0, 0, 0, 0, 0, 0, 0]
     d_top = [5, 5, 5, 5, 5, 5, 5, 5, 5]
     task = LinearProgrammingTask(
         A, b, c,
         d_bottom=d_bottom, d_top=d_top
     )
     self.assertTrue(task.solve_with_dual_simplex_method_with_constraints())
     np.testing.assert_array_almost_equal(
         task.result_x,
         [1.1579, 0.6942, 0, 0, 2.8797, 0, 1.0627, 3.2055, 0], 4)
     self.assertAlmostEqual(float(task.get_target_function_value()), 38.7218, 4)
Exemple #41
0
def test_task_for_third():
    c = np.array([7, -2, 6, 0, 5, 2], dtype=np.float64)
    b = np.array([-8, 22, 30], dtype=np.float64)
    A = np.array([
        [1, -5, 3, 1, 0, 0],
        [4, -1, 1, 0, 1, 0],
        [2, 4, 2, 0, 0, 1],
    ], dtype=np.float64)
    task = LinearProgrammingTask(
        A, b, c, j_basis=[3, 4, 5]
    )

    has_answer = task.solve_with_method_gomori()

    print
    print 'Has answer: %s' % has_answer
    if has_answer:
        print 'x: %s' % map(lambda x: round(x, 3), task.result_x)
        print 'Target function: %s' % round(task.get_target_function_value(), 3)
Exemple #42
0
def test_task_for_second():
    c = np.array([-2, 1, -2, -1, 8, -5, 3, 5, 1, 2], dtype=np.float64)
    b = np.array([27, 6, 18], dtype=np.float64)
    A = np.array([
        [1, 0, 0, 1, 1, -3, 4, -1, 3, 3],
        [0, 1, 0, -2, 1, 1, 7, 3, 4, 5],
        [0, 0, 1, 1, 0 ,2, -1, 1, -4, 7]
    ], dtype=np.float64)
    d_bottom = [0] * 10
    d_top = [8, 7, 6, 7, 8, 5, 6, 7, 8, 5]
    task = LinearProgrammingTask(
        A, b, c,
        d_bottom=d_bottom, d_top=d_top
    )

    has_answer = task.solve_integral_linear_task(True)

    print
    print 'Has answer: %s' % has_answer
    if has_answer:
        print 'x: %s' % map(lambda x: round(x, 3), task.result_x)
        print 'Target function: %s' % round(task.get_target_function_value(), 3)
Exemple #43
0
def test_task_for_first():
    c = np.array([-1, 5, -2, 4, 3, 1, 2, 8, 3], dtype=np.float64)
    b = np.array([3, 9, 9, 5, 9], dtype=np.float64)
    A = np.array([
        [1, -3, 2, 0, 1, -1, 4, -1, 0],
        [1, -1, 6, 1, 0, -2, 2, 2, 0],
        [2, 2, -1, 1, 0, -3, 8, -1, 1],
        [4, 1, 0, 0, 1, -1, 0, -1, 1],
        [1, 1, 1, 1, 1, 1, 1, 1, 1]
    ], dtype=np.float64)
    d_bottom = [0] * 9
    d_top = [5] * 9
    task = LinearProgrammingTask(
        A, b, c,
        d_bottom=d_bottom, d_top=d_top
    )

    has_answer = task.solve_with_dual_simplex_method_with_constraints()

    print
    print 'Has answer: %s' % has_answer
    if has_answer:
        print 'x: %s' % map(lambda x: round(x, 3), task.result_x)
        print 'Target function: %s' % round(task.get_target_function_value(), 3)
 def test_1(self):
     c = np.array([0, -6, 6, 0, 0, 0, 0], dtype=np.float64)
     b = np.array([-1, 0, 4, 1], dtype=np.float64)
     A = np.array([[1, -2, 1, 1, 0, 0, 0], [-1, 2, -2, 0, 1, 0, 0],
                   [2, 2, 1, 0, 0, 1, 0], [0, -2, 2, 0, 0, 0, 1]],
                  dtype=np.float64)
     jb = [3, 4, 5, 6]
     task = LinearProgrammingTask(A, b, c, j_basis=jb)
     self.assertTrue(task.solve_with_dual_simplex_method())
     self.assertAlmostEqual(task.get_target_function_value(task='simple'),
                            task.get_target_function_value(task='dual'))
     np.testing.assert_array_almost_equal(task.result_y, [0, -3, 0, 0])
     self.assertEqual(float(task.get_target_function_value()), 0)