最終更新 3 months ago

The example is from Scott et al., 2011. Generalized mccormick relaxations. Journal of Global Optimization, 51(4), pp.569-606.

修正履歴 d94a6f05e809f4472cc26cf5bff1ba47f84428d8

implicit_relaxation.jl Raw
1using McCormick, BenchmarkTools
2
3"""
4Direct relaxation of implicit function
5"""
6function direct_relax(f, x, p)
7 delta = Inf
8 while delta > 1e-8
9 x_prev = x
10 x = f(x, p)
11 delta = abs(x_prev.cv - x.cv) + abs(x_prev.cc - x.cc)
12 end
13
14 return x
15end
16
17"""
18Faster alternative
19"""
20function fast_direct_relax(f, x, p)
21 delta = Inf
22 while delta > 1e-8
23 x_prev = x
24 x_m = x.cv + .5 * (x.cc - x.cv)
25 x = f(x_m, p)
26 delta = abs(x_prev.cv - x.cv) + abs(x_prev.cc - x.cc)
27 end
28
29 return x
30end
31
32f(x, p) = (p - (p^3)/6 + (p^5)/120)*x^(-1/2) + 100
33
34p = MC{1,NS}(1.0, 1.0, Interval(0.5, 5.0))
35x = MC{1,NS}(1.0, 1.0)
36
37res = @btime direct_relax(f, x, p)
38println(res) # 342.860 μs (2414 allocations: 96.52 KiB) MC{1, NS}(99.8362536820914, 100.40188539116205, [97.9454, 103.135], [0.0], [0.0], true)
39
40res = @btime fast_direct_relax(f, x, p)
41println(res) # 2.972 μs (301 allocations: 4.75 KiB) MC{1, NS}(99.8675794497822, 100.37248484959062, [97.9679, 103.101], [0.0], [0.0], true)