Skip to content

Commit 846ae68

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent e486852 commit 846ae68

File tree

1 file changed

+47
-47
lines changed

1 file changed

+47
-47
lines changed

linear_programming/interior_point_method.py

+47-47
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,23 @@ def __init__(
3636

3737
def _is_valid_input(self) -> bool:
3838
"""
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
5656
"""
5757
return (
5858
self.constraint_matrix.shape[0] == self.constraint_bounds.shape[0]
@@ -61,23 +61,23 @@ def _is_valid_input(self) -> bool:
6161

6262
def _convert_to_standard_form(self) -> tuple[np.ndarray, np.ndarray]:
6363
"""
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.])
8181
"""
8282
(m, n) = self.constraint_matrix.shape
8383
slack = np.eye(m)
@@ -87,19 +87,19 @@ def _convert_to_standard_form(self) -> tuple[np.ndarray, np.ndarray]:
8787

8888
def solve(self) -> tuple[np.ndarray, float]:
8989
"""
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
103103
"""
104104
a, c = self._convert_to_standard_form()
105105
m, n = a.shape

0 commit comments

Comments
 (0)