@@ -36,23 +36,23 @@ def __init__(
36
36
37
37
def _is_valid_input (self ) -> bool :
38
38
"""
39
- Validate the input for the linear programming problem.
40
-
41
- Returns:
42
- bool: True if input is valid, False otherwise.
43
-
44
- >>> objective_coefficients = np.array([1, 2])
45
- >>> constraint_matrix = np.array([[1, 1], [1, -1]])
46
- >>> constraint_bounds = np.array([2, 0])
47
- >>> ipm = InteriorPointMethod(objective_coefficients, constraint_matrix,
48
- constraint_bounds)
49
- >>> ipm._is_valid_input()
50
- True
51
- >>> constraint_bounds = np.array([2, 0, 1])
52
- >>> ipm = InteriorPointMethod(objective_coefficients, constraint_matrix,
53
- constraint_bounds)
54
- >>> ipm._is_valid_input()
55
- False
39
+ Validate the input for the linear programming problem.
40
+
41
+ Returns:
42
+ bool: True if input is valid, False otherwise.
43
+
44
+ >>> objective_coefficients = np.array([1, 2])
45
+ >>> constraint_matrix = np.array([[1, 1], [1, -1]])
46
+ >>> constraint_bounds = np.array([2, 0])
47
+ >>> ipm = InteriorPointMethod(objective_coefficients, constraint_matrix,
48
+ constraint_bounds)
49
+ >>> ipm._is_valid_input()
50
+ True
51
+ >>> constraint_bounds = np.array([2, 0, 1])
52
+ >>> ipm = InteriorPointMethod(objective_coefficients, constraint_matrix,
53
+ constraint_bounds)
54
+ >>> ipm._is_valid_input()
55
+ False
56
56
"""
57
57
return (
58
58
self .constraint_matrix .shape [0 ] == self .constraint_bounds .shape [0 ]
@@ -61,23 +61,23 @@ def _is_valid_input(self) -> bool:
61
61
62
62
def _convert_to_standard_form (self ) -> tuple [np .ndarray , np .ndarray ]:
63
63
"""
64
- Convert constraints to standard form by adding slack variables.
65
-
66
- Returns:
67
- tuple: A tuple of the standard form constraint matrix and objective
68
- coefficients.
69
-
70
- >>> objective_coefficients = np.array([1, 2])
71
- >>> constraint_matrix = np.array([[1, 1], [1, -1]])
72
- >>> constraint_bounds = np.array([2, 0])
73
- >>> ipm = InteriorPointMethod(objective_coefficients, constraint_matrix,
74
- constraint_bounds)
75
- >>> a_standard, c_standard = ipm._convert_to_standard_form()
76
- >>> a_standard
77
- array([[ 1., 1., 1., 0.],
78
- [ 1., -1., 0., 1.]])
79
- >>> c_standard
80
- array([1., 2., 0., 0.])
64
+ Convert constraints to standard form by adding slack variables.
65
+
66
+ Returns:
67
+ tuple: A tuple of the standard form constraint matrix and objective
68
+ coefficients.
69
+
70
+ >>> objective_coefficients = np.array([1, 2])
71
+ >>> constraint_matrix = np.array([[1, 1], [1, -1]])
72
+ >>> constraint_bounds = np.array([2, 0])
73
+ >>> ipm = InteriorPointMethod(objective_coefficients, constraint_matrix,
74
+ constraint_bounds)
75
+ >>> a_standard, c_standard = ipm._convert_to_standard_form()
76
+ >>> a_standard
77
+ array([[ 1., 1., 1., 0.],
78
+ [ 1., -1., 0., 1.]])
79
+ >>> c_standard
80
+ array([1., 2., 0., 0.])
81
81
"""
82
82
(m , n ) = self .constraint_matrix .shape
83
83
slack = np .eye (m )
@@ -87,19 +87,19 @@ def _convert_to_standard_form(self) -> tuple[np.ndarray, np.ndarray]:
87
87
88
88
def solve (self ) -> tuple [np .ndarray , float ]:
89
89
"""
90
- Solve problem with Primal-Dual Interior-Point Method.
91
-
92
- Returns:
93
- tuple: A tuple with optimal solution and the optimal value.
94
-
95
- >>> objective_coefficients = np.array([1, 2])
96
- >>> constraint_matrix = np.array([[1, 1], [1, -1]])
97
- >>> constraint_bounds = np.array([2, 0])
98
- >>> ipm = InteriorPointMethod(objective_coefficients, constraint_matrix,
99
- constraint_bounds)
100
- >>> solution, value = ipm.solve()
101
- >>> np.isclose(value, np.dot(objective_coefficients, solution))
102
- True
90
+ Solve problem with Primal-Dual Interior-Point Method.
91
+
92
+ Returns:
93
+ tuple: A tuple with optimal solution and the optimal value.
94
+
95
+ >>> objective_coefficients = np.array([1, 2])
96
+ >>> constraint_matrix = np.array([[1, 1], [1, -1]])
97
+ >>> constraint_bounds = np.array([2, 0])
98
+ >>> ipm = InteriorPointMethod(objective_coefficients, constraint_matrix,
99
+ constraint_bounds)
100
+ >>> solution, value = ipm.solve()
101
+ >>> np.isclose(value, np.dot(objective_coefficients, solution))
102
+ True
103
103
"""
104
104
a , c = self ._convert_to_standard_form ()
105
105
m , n = a .shape
0 commit comments