-
Notifications
You must be signed in to change notification settings - Fork 103
Add docs and example tests to barrier #449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 11 commits
1cf9cbb
04aa7bc
74409aa
381f7bf
abcd486
23a2046
da63ef2
a4d1f2b
82cbb2a
84acac3
54f4d4f
ceb8658
2be9dbe
7c52303
cf398c5
0b73872
692afab
ef11801
640f132
368e6ca
05a7798
fb31450
f143904
d715f3a
5b66f3d
67cbfc2
f72ff01
e92295a
8a60946
cec6a7f
0d1a2ae
eb140d1
08cbac2
e2449a9
a6b5e3e
f13d140
98cc2ac
0b97621
373a59b
ffca33f
cd979cf
eb67876
6c4b021
6bede5b
66a6b7a
93b0243
93d013a
668ded7
f50b7b1
5d56842
b6a7ad5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,10 +34,20 @@ | |
| sense, | ||
| ) | ||
| from cuopt.linear_programming.solver.solver_parameters import ( | ||
| CUOPT_AUGMENTED, | ||
| CUOPT_CUDSS_DETERMINISTIC, | ||
| CUOPT_DUALIZE, | ||
| CUOPT_ELIMINATE_DENSE_COLUMNS, | ||
| CUOPT_FOLDING, | ||
| CUOPT_INFEASIBILITY_DETECTION, | ||
| CUOPT_METHOD, | ||
| CUOPT_ORDERING, | ||
| CUOPT_PDLP_SOLVER_MODE, | ||
| ) | ||
| from cuopt.linear_programming.solver_settings import PDLPSolverMode | ||
| from cuopt.linear_programming.solver_settings import ( | ||
| PDLPSolverMode, | ||
| SolverMethod, | ||
| ) | ||
|
|
||
| RAPIDS_DATASET_ROOT_DIR = os.getenv("RAPIDS_DATASET_ROOT_DIR") | ||
| if RAPIDS_DATASET_ROOT_DIR is None: | ||
|
|
@@ -449,3 +459,98 @@ def test_problem_update(): | |
| prob.updateObjective(constant=5, sense=MINIMIZE) | ||
| prob.solve() | ||
| assert prob.ObjValue == pytest.approx(5) | ||
|
|
||
|
|
||
| def test_barrier_solver(): | ||
| """ | ||
| Test the barrier solver with different configurations. | ||
|
|
||
| Problem: | ||
| maximize 5*xs + 20*xl | ||
| subject to 1*xs + 3*xl <= 200 | ||
| 3*xs + 2*xl <= 160 | ||
| xs, xl >= 0 | ||
|
|
||
| Expected Solution: | ||
| Optimal objective: 1333.33 | ||
| xs = 0, xl = 66.67 (corner solution where constraint 1 is binding) | ||
| """ | ||
| prob = Problem("Barrier Test") | ||
|
|
||
| # Add variables | ||
| xs = prob.addVariable(lb=0, vtype=VType.CONTINUOUS, name="xs") | ||
| xl = prob.addVariable(lb=0, vtype=VType.CONTINUOUS, name="xl") | ||
|
|
||
| # Add constraints | ||
| prob.addConstraint(xs + 3 * xl <= 200, name="constraint1") | ||
| prob.addConstraint(3 * xs + 2 * xl <= 160, name="constraint2") | ||
|
|
||
| # Set objective: maximize 5*xs + 20 * xl | ||
| prob.setObjective(5 * xs + 20 * xl, sense=MAXIMIZE) | ||
|
|
||
| # Test 1: Default barrier settings | ||
| settings = SolverSettings() | ||
| settings.set_parameter(CUOPT_METHOD, SolverMethod.Barrier) | ||
| settings.set_parameter("time_limit", 10) | ||
|
|
||
| prob.solve(settings) | ||
|
|
||
| assert prob.solved | ||
| assert prob.Status.name == "Optimal" | ||
| assert prob.ObjValue == pytest.approx(1333.33, rel=0.01) | ||
| assert xs.Value == pytest.approx(0.0, abs=1e-4) | ||
| assert xl.Value == pytest.approx(66.67, rel=0.01) | ||
|
|
||
| # Test 2: Barrier with forced settings | ||
| settings_forced = SolverSettings() | ||
| settings_forced.set_parameter(CUOPT_METHOD, SolverMethod.Barrier) | ||
| settings_forced.set_parameter(CUOPT_FOLDING, 1) # Force folding | ||
|
||
| settings_forced.set_parameter(CUOPT_DUALIZE, 1) # Force dualize | ||
| settings_forced.set_parameter(CUOPT_ORDERING, 1) # AMD ordering | ||
| settings_forced.set_parameter(CUOPT_AUGMENTED, 1) # Augmented system | ||
| settings_forced.set_parameter(CUOPT_ELIMINATE_DENSE_COLUMNS, True) | ||
|
||
| settings_forced.set_parameter(CUOPT_CUDSS_DETERMINISTIC, True) | ||
| settings_forced.set_parameter("time_limit", 10) | ||
|
|
||
| prob.solve(settings_forced) | ||
|
|
||
| assert prob.solved | ||
| assert prob.Status.name == "Optimal" | ||
| assert prob.ObjValue == pytest.approx(1333.33, rel=0.01) | ||
|
|
||
| # Test 3: Barrier with features disabled | ||
| settings_disabled = SolverSettings() | ||
| settings_disabled.set_parameter(CUOPT_METHOD, SolverMethod.Barrier) | ||
| settings_disabled.set_parameter(CUOPT_FOLDING, 0) # No folding | ||
| settings_disabled.set_parameter(CUOPT_DUALIZE, 0) # No dualization | ||
| settings_disabled.set_parameter(CUOPT_ORDERING, 0) # cuDSS default | ||
| settings_disabled.set_parameter(CUOPT_AUGMENTED, 0) # ADAT system | ||
| settings_disabled.set_parameter(CUOPT_ELIMINATE_DENSE_COLUMNS, False) | ||
| settings_disabled.set_parameter(CUOPT_CUDSS_DETERMINISTIC, False) | ||
| settings_disabled.set_parameter("time_limit", 10) | ||
|
|
||
| prob.solve(settings_disabled) | ||
|
|
||
| assert prob.solved | ||
| assert prob.Status.name == "Optimal" | ||
| assert prob.ObjValue == pytest.approx(1333.33, rel=0.01) | ||
|
|
||
| # Test 4: Barrier with automatic settings (default -1 values) | ||
| settings_auto = SolverSettings() | ||
| settings_auto.set_parameter(CUOPT_METHOD, SolverMethod.Barrier) | ||
| settings_auto.set_parameter(CUOPT_FOLDING, -1) # Automatic | ||
| settings_auto.set_parameter(CUOPT_DUALIZE, -1) # Automatic | ||
| settings_auto.set_parameter(CUOPT_ORDERING, -1) # Automatic | ||
| settings_auto.set_parameter(CUOPT_AUGMENTED, -1) # Automatic | ||
| settings_auto.set_parameter("time_limit", 10) | ||
|
|
||
| prob.solve(settings_auto) | ||
|
|
||
| assert prob.solved | ||
| assert prob.Status.name == "Optimal" | ||
| assert prob.ObjValue == pytest.approx(1333.33, rel=0.01) | ||
|
|
||
| # Verify constraint slacks are non-negative | ||
| for c in prob.getConstraints(): | ||
| # For <= constraints with optimal solution, slack should be >= 0 | ||
| assert c.Slack >= -1e-6 # Allow small numerical tolerance | ||
Uh oh!
There was an error while loading. Please reload this page.