Skip to content

Commit

Permalink
Switched out in-repo examples for test scripts
Browse files Browse the repository at this point in the history
Example use now lives in the wiki at github.com/Foggalong/RobustOCS/wiki
  • Loading branch information
Foggalong committed Jul 18, 2024
1 parent 03bda30 commit fc766b6
Show file tree
Hide file tree
Showing 13 changed files with 2,255 additions and 312 deletions.
2 changes: 1 addition & 1 deletion examples/04/S04.txt
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
177 changes: 0 additions & 177 deletions examples/04/example.ipynb

This file was deleted.

52 changes: 52 additions & 0 deletions examples/04/test.py
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!")
11 changes: 0 additions & 11 deletions examples/1000/README.md

This file was deleted.

Loading

0 comments on commit fc766b6

Please sign in to comment.