-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switched out in-repo examples for test scripts
Example use now lives in the wiki at github.com/Foggalong/RobustOCS/wiki
- Loading branch information
Showing
13 changed files
with
2,255 additions
and
312 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
1 1 0.11111111111111 | ||
2 2 0.11111111111111 | ||
3 3 4.0 | ||
4 4 4.0 | ||
4 4 4.0 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import numpy as np | ||
import robustocs as rocs | ||
|
||
# SETUP | ||
# ----- | ||
|
||
# load in the problem variables | ||
sigma, mubar, omega, n = rocs.load_problem( | ||
"A04.txt", | ||
"EBV04.txt", | ||
"S04.txt", | ||
issparse=True | ||
) | ||
sires = range(0, n, 2) | ||
dams = range(1, n, 2) | ||
lam = 0.5 | ||
kap = 1 | ||
|
||
# true solution to the standard and robust problems | ||
true_std = np.array([0, 0, 0.5, 0.5]) | ||
true_rob = np.array([0.382, 0.382, 0.118, 0.118]) | ||
|
||
# tolerance for comparisons; NOTE this test uses a much stricter tolerance | ||
# for the non-robust problem since both solvers should compute it exactly. | ||
tol_std = 1e-7 | ||
tol_rob = 1e-3 | ||
|
||
|
||
# TESTS | ||
# ----- | ||
|
||
w, obj = rocs.highs_standard_genetics(sigma, mubar, sires, dams, lam, n) | ||
assert ((w - true_std) < tol_std).all(), "QP in HiGHS was incorrect" | ||
|
||
w, obj = rocs.gurobi_standard_genetics(sigma, mubar, sires, dams, lam, n) | ||
assert ((w - true_std) < tol_std).all(), "QP in Gurobi was incorrect" | ||
|
||
w, z, obj = rocs.gurobi_robust_genetics( | ||
sigma, mubar, omega, sires, dams, lam, kap, n) | ||
assert ((w - true_rob) < tol_rob).all(), "conic in Gurobi was incorrect" | ||
|
||
w, z, obj = rocs.gurobi_robust_genetics_sqp( | ||
sigma, mubar, omega, sires, dams, lam, kap, n) | ||
assert ((w - true_rob) < tol_rob).all(), "SQP in Gurobi was incorrect" | ||
|
||
w, z, obj = rocs.highs_robust_genetics_sqp( | ||
sigma, mubar, omega, sires, dams, lam, kap, n) | ||
assert ((w - true_rob) < tol_rob).all(), "conic in HiGHS was incorrect" | ||
|
||
print("Success!") |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.