2013-02-09 497 views
2

我正在使用優化函數「fmincon」,並且在某些情況下它不會收斂。我必須確定這些案件,並採取必要的行動,但所用的所有的方法失敗,在追趕的錯誤,讓我繼續得到錯誤:Matlab fmincon - 找不到可行的解決方案,但沒有發現錯誤

No feasible solution found. 

fmincon stopped because the size of the current search direction is less than 
twice the default value of the step size tolerance but constraints are not 
satisfied to within the selected value of the constraint tolerance. 

首先,我想選擇功能的exitflag:如果它會返回一個已知的錯誤(-1,1,0 ...),但每次出現錯誤時,退出的退出標誌都有一個正確的值。

[x,fval,exitflag] = fmincon(@(x) costFunction(x,INPUTS),x0,A,b,[],[],lb,ub,[],options); 
if exitflag == 0 
    do something; 
end 

然後我用「的try/catch」結構試過,而且在這種情況下,代碼繼續運行,並毫無遺漏了任何錯誤......

try %start try/catch 
    [x,fval,exitflag] = fmincon(@(x) costFunction(x,INPUTS),x0,A,b,[],[],lb,ub,[],options); 
catch err 
    disp(err.identifier); 
     ... actions 
end % end try/catch 

任何建議是善意的歡迎。

PS:使用的選項是:

options = optimset(oldopts,'Display','notify', 'Algorithm','active-set', 'MaxFunEvals', 10000); 
+0

你提供了一個滿足約束條件的'x0'嗎? – 2013-02-09 16:27:30

+0

我查過了,其實在某些情況下x0不滿足約束條件,我也會更新這個。 – 2013-02-09 21:28:01

回答

0
  1. 是什麼oldopts
  2. is less than twice the default value of the step size tolerance建議您需要更改步長或容差值。有幾種方法可以解決這個問題:猜測或顯示迭代顯示。

    optimset(oldopts,'Display','iter' ...% or 'iter-detailed' 
    
  3. 一旦你弄清楚你想改變什麼,你可以用它設置:

    optimset(options,'stepsize', 1e-2) % or optimset(options,'tolX', 1e-e)... 
    
  4. 停止尋找出口標誌拋出一個錯誤。該錯誤是一個收斂或迭代問題。

  5. 問問自己,如果該算法能能夠使用圖形化方法(如果可能)

  6. RTM收斂:http://www.mathworks.com/help/optim/ug/when-the-solver-fails.html

+0

好吧,這也是一個選擇,我會嘗試,但仍然應該抓住錯誤,不要像沒事一樣傳遞...... – 2013-02-09 21:26:22

0

根據the docs你應該尋找出exitFlag == -2,而不是0到檢查該場景:

ie

[x,fval,exitflag] = fmincon(@(x) costFunction(x,INPUTS),x0,A,b,[],[],lb,ub,[],options); 
if exitflag == -2 
    %// Handle non-convergence 
else 
    %// Converged 
end 
相關問題