1// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab 2// Copyright (C) 2011 - DIGITEO - Michael Baudin 3// 4// Copyright (C) 2012 - 2016 - Scilab Enterprises 5// 6// This file is hereby licensed under the terms of the GNU GPL v2.0, 7// pursuant to article 5.3.4 of the CeCILL v.2.1. 8// This file was originally licensed under the terms of the CeCILL v2.1, 9// and continues to be available under such terms. 10// For more information, see the COPYING file which you should have received 11// along with this program. 12// <-- CLI SHELL MODE --> 13// <-- ENGLISH IMPOSED --> 14// <-- NO CHECK REF --> 15// This test is designed to produce a warning: 16// this warning is localized. 17// This is why we do not check the ref. 18// Checking the ref file under Linux fails, because 19// <-- ENGLISH IMPOSED --> has no effect there. 20// See : http://bugzilla.scilab.org/show_bug.cgi?id=9284 21function [ y , index ] = rosenbrock ( x , index ) 22 y = 100*(x(2)-x(1)^2)^2 + (1-x(1))^2; 23endfunction 24// 25// Check backward compatibility: 26// check obsolete options "-myterminateflag" and "-myterminate". 27// 28function [ this , terminate , status ] = mystoppingrule2 ( this , simplex ) 29 ssize = optimsimplex_size ( simplex , "sigmaplus" ); 30 if ( ssize < 1.e-2 ) then 31 terminate = %t; 32 status = "mysize"; 33 else 34 terminate = %f 35 end 36endfunction 37// 38// Test with my own termination criteria 39// 40nm = neldermead_new (); 41nm = neldermead_configure(nm,"-numberofvariables",2); 42nm = neldermead_configure(nm,"-function",rosenbrock); 43nm = neldermead_configure(nm,"-x0",[1.1 1.1]'); 44nm = neldermead_configure(nm,"-maxiter",%inf); 45nm = neldermead_configure(nm,"-maxfunevals",%inf); 46nm = neldermead_configure(nm,"-method","variable"); 47// Disable default terminations 48nm = neldermead_configure(nm,"-tolxmethod",%f); 49nm = neldermead_configure(nm,"-tolsimplexizemethod",%f); 50nm = neldermead_configure(nm,"-myterminateflag",%t); 51WARNING: Option -myterminateflag is obsolete. 52WARNING: Please use -outputcommand instead. 53WARNING: This feature will be permanently removed in Scilab 5.4.1 54nm = neldermead_configure(nm,"-myterminate",mystoppingrule2); 55WARNING: Option -myterminate is obsolete. 56WARNING: Please use -outputcommand instead. 57WARNING: This feature will be permanently removed in Scilab 5.4.1 58// 59// Check cget 60value = neldermead_cget(nm,"-myterminateflag"); 61assert_checktrue ( value ); 62// 63value = neldermead_cget(nm,"-myterminate"); 64assert_checkequal ( typeof(value) , "function" ); 65// 66nm = neldermead_search(nm); 67// Check optimum point 68xopt = neldermead_get(nm,"-xopt"); 69assert_checkalmostequal ( xopt , [1.0 1.0]', 1e-2 ); 70// Check optimum point value 71fopt = neldermead_get(nm,"-fopt"); 72assert_checkalmostequal ( fopt , 0.0 , [] , 1e-4 ); 73// Check status 74status = neldermead_get(nm,"-status"); 75assert_checkequal ( status , "mysize" ); 76nm = neldermead_destroy(nm); 77