(self)
| 70 | self.assertNumpyEqual(b, e.b, msg="Expected vector obtained by stacking") |
| 71 | |
| 72 | def test_simple_solve(self): |
| 73 | problem = placo.Problem() |
| 74 | |
| 75 | # A problem where the sum of all the 16 variables should be equal to 1 |
| 76 | x = problem.add_variable(16) |
| 77 | problem.add_constraint(x.expr().sum() == np.array([1.0])) |
| 78 | problem.solve() |
| 79 | self.assertNumpyEqual( |
| 80 | x.value, |
| 81 | 1 / 16.0, |
| 82 | msg="16 values which sum equals 1 should be minimized to 1/16", |
| 83 | ) |
| 84 | |
| 85 | # We add an inequality so that the 0th value should be greater than 2 |
| 86 | problem.add_constraint(x.expr(0, 1) >= np.array([2.0])) |
| 87 | problem.add_constraint(x.expr(0, 1) <= np.array([10.0])) |
| 88 | problem.solve() |
| 89 | self.assertGreaterEqual(x.value[0], 2.0 - 1e-6, msg=f"The value should be >= 2") |
| 90 | self.assertNumpyEqual( |
| 91 | x.value[1:], -1 / 15.0, msg=f"The remaining values should be -1/15." |
| 92 | ) |
| 93 | |
| 94 | def test_expression_constraint(self): |
| 95 | problem = placo.Problem() |
nothing calls this directly
no test coverage detected