diff --git a/bitten/test_b2.py b/bitten/test_b2.py new file mode 100644 index 0000000..d95af1d --- /dev/null +++ b/bitten/test_b2.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 +from bitten import * +import numpy as np + +constraints, tol = ( + lambda *p: 2.0 * p[0] + 2.0 * p[1] + p[9] + p[10] - 10.0, + lambda *p: 2.0 * p[0] + 2.0 * p[2] + p[9] + p[11] - 10.0, + lambda *p: 2.0 * p[1] + 2.0 * p[2] + p[10] + p[11] - 10.0, + lambda *p: -8.0 * p[0] + p[9], + lambda *p: -8.0 * p[1] + p[10], + lambda *p: -8.0 * p[2] + p[11], + lambda *p: -2.0 * p[3] - p[4] + p[9], + lambda *p: -2.0 * p[5] - p[6] + p[10], + lambda *p: -2.0 * p[7] - p[8] + p[11], +), 1e-15 + + +@bite(Minimize(), Constrain(*constraints, tol=tol), _debug=True) +def fun( + p0=Bound(0.0, 1.0), + p1=Bound(0.0, 1.0), + p2=Bound(0.0, 1.0), + p3=Bound(0.0, 1.0), + p4=Bound(0.0, 1.0), + p5=Bound(0.0, 1.0), + p6=Bound(0.0, 1.0), + p7=Bound(0.0, 1.0), + p8=Bound(0.0, 1.0), + p9=Bound(0.0, 100.0), + pA=Bound(0.0, 100.0), + pB=Bound(0.0, 100.0), + pC=Bound(0.0, 1.0), +): + p = (p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, pA, pB, pC) + s1, s2, s3 = 0.0, 0.0, 0.0 + for i in range(4): + s1 += p[i] + s2 += np.square(p[i]) + for i in range(4, 13): + s3 += p[i] + return 5.0 * s1 - 5.0 * s2 - s3 + + +print("solution:", fun()) +for k, v in fun.__optimized__.items(): + print(f"{k:>4}: {v:.8f}") diff --git a/bitten/test_e.py b/bitten/test_e.py new file mode 100644 index 0000000..a381718 --- /dev/null +++ b/bitten/test_e.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python3 +from bitten import * + +@bite(Minimize(0), budget=1_000, _debug=True) +def nothing(x): + return 420.69 + +print("OPTIMIZED:", nothing.__optimized__, "RESULT:", nothing.__result__, sep="\n") + +@bite(Minimize(1, 2), budget=1_000, _debug=True) +def nothing(a, b): + return a + b + +print("OPTIMIZED:", nothing.__optimized__, "RESULT:", nothing.__result__, sep="\n")