示例#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())
示例#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())
示例#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)
示例#4
0
 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())
示例#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)
示例#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())
示例#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)
示例#8
0
 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())
示例#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())
示例#10
0
 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())
示例#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)
示例#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)
示例#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)
示例#14
0
 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)
示例#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)
示例#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)
示例#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)
示例#18
0
 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())
示例#19
0
 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)
示例#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)
示例#21
0
 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)
示例#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)
示例#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)
示例#24
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)
示例#25
0
文件: gomori.py 项目: kavaliou/MOiU
    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)
示例#26
0
文件: gomori.py 项目: kavaliou/MOiU
    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)
示例#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)
示例#28
0
 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())
示例#29
0
 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())
示例#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)
示例#31
0
文件: gomori.py 项目: kavaliou/MOiU
    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)
示例#32
0
 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)
示例#33
0
 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)
示例#34
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)
示例#35
0
 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)
示例#36
0
 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)
示例#37
0
 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)
示例#38
0
 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)
示例#39
0
 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)
示例#40
0
 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)
示例#41
0
文件: run_labs.py 项目: kavaliou/MOiU
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)
示例#42
0
文件: run_labs.py 项目: kavaliou/MOiU
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)
示例#43
0
文件: run_labs.py 项目: kavaliou/MOiU
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)
示例#44
0
 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)