1 | #!/usr/bin/env python |
---|
2 | # |
---|
3 | # Problem definition: |
---|
4 | # A-R Hedar and M Fukushima, "Derivative-Free Filter Simulated Annealing |
---|
5 | # Method for Constrained Continuous Global Optimization", Journal of |
---|
6 | # Global Optimization, 35(4), 521-549 (2006). |
---|
7 | # |
---|
8 | # Original Matlab code written by A. Hedar (Nov. 23, 2005) |
---|
9 | # http://www-optima.amp.i.kyoto-u.ac.jp/member/student/hedar/Hedar_files/go.htm |
---|
10 | # and ported to Python by Mike McKerns (December 2014) |
---|
11 | # |
---|
12 | # Author: Mike McKerns (mmckerns @caltech and @uqfoundation) |
---|
13 | # Copyright (c) 1997-2016 California Institute of Technology. |
---|
14 | # License: 3-clause BSD. The full license text is available at: |
---|
15 | # - http://mmckerns.github.io/project/mystic/browser/mystic/LICENSE |
---|
16 | |
---|
17 | def objective(x): |
---|
18 | x0,x1,x2,x3,x4 = x #XXX: allow x != 5? |
---|
19 | return 5.3578547*x2**2 + 0.8356891*x0*x4 + 37.293239*x0 - 40792.141 |
---|
20 | |
---|
21 | bounds = [(78,102),(33,45)] + [(27,45)]*3 |
---|
22 | # with penalty='penalty' applied, solution is: |
---|
23 | xs = [78.0, 33.0, 29.9955776, 45.0, 36.7749999] |
---|
24 | ys = -30665.488305434 |
---|
25 | |
---|
26 | def u(x): |
---|
27 | x0,x1,x2,x3,x4 = x |
---|
28 | return 85.334407 + 0.0056858*x1*x4 + 0.0006262*x0*x3 - 0.0022053*x2*x4 |
---|
29 | |
---|
30 | def v(x): |
---|
31 | x0,x1,x2,x3,x4 = x |
---|
32 | return 80.51249 + 0.0071317*x1*x4 + 0.0029955*x0*x1 + 0.0021813*x2*x2 |
---|
33 | |
---|
34 | def w(x): |
---|
35 | x0,x1,x2,x3,x4 = x |
---|
36 | return 9.300961 + 0.0047026*x2*x4 + 0.0012547*x0*x2 + 0.0019085*x2*x3 |
---|
37 | |
---|
38 | |
---|
39 | from mystic.penalty import quadratic_inequality |
---|
40 | |
---|
41 | def penalty1(x): # <= 0.0 |
---|
42 | return u(x) - 92.0 |
---|
43 | |
---|
44 | def penalty2(x): # <= 0.0 |
---|
45 | return -u(x) |
---|
46 | |
---|
47 | def penalty3(x): # <= 0.0 |
---|
48 | return v(x) - 110.0 |
---|
49 | |
---|
50 | def penalty4(x): # <= 0.0 |
---|
51 | return -v(x) + 90.0 |
---|
52 | |
---|
53 | def penalty5(x): # <= 0.0 |
---|
54 | return w(x) - 25.0 |
---|
55 | |
---|
56 | def penalty6(x): # <= 0.0 |
---|
57 | return -w(x) + 20.0 |
---|
58 | |
---|
59 | @quadratic_inequality(penalty1, k=1e10) |
---|
60 | @quadratic_inequality(penalty2, k=1e10) |
---|
61 | @quadratic_inequality(penalty3, k=1e10) |
---|
62 | @quadratic_inequality(penalty4, k=1e10) |
---|
63 | @quadratic_inequality(penalty5, k=1e10) |
---|
64 | @quadratic_inequality(penalty6, k=1e10) |
---|
65 | def penalty(x): |
---|
66 | return 0.0 |
---|
67 | |
---|
68 | from mystic.constraints import as_constraint |
---|
69 | |
---|
70 | solver = as_constraint(penalty) |
---|
71 | |
---|
72 | |
---|
73 | |
---|
74 | if __name__ == '__main__': |
---|
75 | |
---|
76 | from mystic.solvers import diffev2 |
---|
77 | from mystic.math import almostEqual |
---|
78 | |
---|
79 | result = diffev2(objective, x0=bounds, bounds=bounds, penalty=penalty, npop=40, gtol=500, disp=False, full_output=True) |
---|
80 | |
---|
81 | assert almostEqual(result[0], xs, tol=1e-2) |
---|
82 | assert almostEqual(result[1], ys, rel=1e-2) |
---|
83 | |
---|
84 | |
---|
85 | |
---|
86 | # EOF |
---|