使用 MultiStart
或 GlobalSearch
找到基于问题的多个局部解
在使用基于问题的方法的 MultiStart
或 GlobalSearch
函数的问题的解中,output
结构体包含一个名为 local
的字段,其中包含有关局部解的信息。例如,使用 rastriginsfcn
找到运行此示例时可用的两个变量的 MultiStart
函数的局部解。
x = optimvar("x",LowerBound=-50,UpperBound=50); y = optimvar("y",LowerBound=-50,UpperBound=50); fun = rastriginsfcn([x,y]); prob = optimproblem(Objective=fun); ms = MultiStart; x0.x = -30; x0.y = 20; rng default % For reproducibility [sol,fval,exitflag,output] = solve(prob,x0,ms,MinNumStartPoints=50);
Solving problem using MultiStart. MultiStart completed the runs from all start points. All 50 local solver runs converged with a positive local solver exitflag.
disp(sol)
x: 6.8842e-10 y: 1.0077e-09
disp(fval)
0
MultiStart
找到了多少个局部解?
multisols = output.local.sol; N = numel(multisols)
N = 46
绘制值。
plot3(multisols.x,multisols.y,multisols.Objective,'bo')
MultiStart
从 50 个初始点开始,但只找到 46 个解。MultiStart
报告所有运行都已收敛。因此,有些解有多个通向这些解的初始点。查找列出多个初始点的 x0
值。
myx0 = output.local.x0; sx = zeros(size(myx0)); for i = 1:length(sx) sx(i) = numel(myx0{i}); end mults = find(sx >= 2)
mults = 1×4
13 17 25 36
确定从 fmincon
中的两个初始点出发 mults(1)
是否最终到达同一个解。
pts = myx0(mults(1)); r = pts{1}.x; t01.x = r(1); s = pts{1}.y; t01.y = s(1); disp(t01)
x: -30 y: 20
opts = optimoptions("fmincon",Display="none"); sol1 = solve(prob,t01,Options=opts)
sol1 = struct with fields:
x: -1.9899
y: -2.9849
t02.x = r(2); t02.y = s(2); disp(t02)
x: 34.9129 y: -24.5718
sol2 = solve(prob,t02,Options=opts)
sol2 = struct with fields:
x: -1.9899
y: -2.9849
尽管起点 t01
和 t02
相距较远,但解 sol1
和 sol2
的显示精度相同。
另请参阅
MultiStart
| solve
| GlobalSearch