46 lines
1.2 KiB
Python
46 lines
1.2 KiB
Python
#!/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}")
|