1// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab 2// Copyright (C) 2008-2009 - INRIA - Michael Baudin 3// Copyright (C) 2011 - DIGITEO - Michael Baudin 4// 5// Copyright (C) 2012 - 2016 - Scilab Enterprises 6// 7// This file is hereby licensed under the terms of the GNU GPL v2.0, 8// pursuant to article 5.3.4 of the CeCILL v.2.1. 9// This file was originally licensed under the terms of the CeCILL v2.1, 10// and continues to be available under such terms. 11// For more information, see the COPYING file which you should have received 12// along with this program. 13// <-- CLI SHELL MODE --> 14// 15// optimtestcase -- 16// Non linear inequality constraints are positive. 17// 18// Arguments 19// x: the point where to compute the function 20// index : the stuff to compute 21// 22function [ f , c , index ] = optimtestcase ( x , index ) 23 f = [] 24 c = [] 25 if ( index == 2 | index == 6 ) then 26 f = x(1)^2 + x(2)^2 + 2.0 * x(3)^2 + x(4)^2 ... 27 - 5.0 * x(1) - 5.0 * x(2) - 21.0 * x(3) + 7.0 * x(4) 28 end 29 if ( index == 5 | index == 6 ) then 30 c1 = - x(1)^2 - x(2)^2 - x(3)^2 - x(4)^2 ... 31 - x(1) + x(2) - x(3) + x(4) + 8 32 c2 = - x(1)^2 - 2.0 * x(2)^2 - x(3)^2 - 2.0 * x(4)^2 ... 33 + x(1) + x(4) + 10.0 34 c3 = - 2.0 * x(1)^2 - x(2)^2 - x(3)^2 - 2.0 * x(1) ... 35 + x(2) + x(4) + 5.0 36 c = [c1 c2 c3] 37 end 38endfunction 39warning("off"); // WARNING_EMPTY_OPS 40// 41// Test search with various error cases 42// 43nm = neldermead_new (); 44nm = neldermead_configure(nm,"-numberofvariables",4); 45nm = neldermead_configure(nm,"-function",optimtestcase); 46nm = neldermead_configure(nm,"-x0",[0.0 0.0 0.0 0.0]'); 47nm = neldermead_configure(nm,"-maxiter",200); 48nm = neldermead_configure(nm,"-maxfunevals",1000); 49nm = neldermead_configure(nm,"-tolsimplexizerelative",1.e-4); 50nm = neldermead_configure(nm,"-simplex0method","axes"); 51nm = neldermead_configure(nm,"-method","box"); 52nm = neldermead_configure(nm,"-nbineqconst",3); 53nm = neldermead_configure(nm,"-simplex0length",20.0); 54// 55// Test with inconsistent bounds 56// 57nm = neldermead_configure(nm,"-boundsmin",[10.0 -10.0 -10.0 -10.0]); 58nm = neldermead_configure(nm,"-boundsmax",[-10.0 10.0 10.0 10.0]); 59instr = "nm = neldermead_search(nm)"; 60lclmsg = gettext("%s: The max bound %s for variable #%d is lower than the min bound %s.\n"); 61assert_checkerror ( instr , lclmsg , [] , "optimbase_checkbounds","-10",1,"10" ); 62// 63// Test with wrong number of min bounds 64// 65nm = neldermead_configure(nm,"-boundsmin",[10.0]); 66nm = neldermead_configure(nm,"-boundsmax",[-10.0 10.0 10.0 10.0]); 67cmd = "nm = neldermead_search(nm)"; 68lclmsg = gettext("%s: The number of variables %d does not match the number of min bounds: %d.\n"); 69assert_checkerror ( cmd , lclmsg , [] , "optimbase_checkbounds" , 4 , 1); 70// 71// Test with wrong number of max bounds 72// 73nm = neldermead_configure(nm,"-boundsmin",[10.0 -10.0 -10.0 -10.0]); 74nm = neldermead_configure(nm,"-boundsmax",[-10.0]); 75cmd = "nm = neldermead_search(nm)"; 76lclmsg = gettext("%s: The number of variables %d does not match the number of max bounds: %d.\n"); 77assert_checkerror ( cmd , lclmsg , [] , "optimbase_checkbounds" , 4 , 1); 78// 79// Test with Box algorithm and randomized bounds simplex and no bounds 80// 81nm = neldermead_configure(nm,"-boundsmin",[]); 82nm = neldermead_configure(nm,"-boundsmax",[]); 83nm = neldermead_configure(nm,"-simplex0method","randbounds"); 84cmd = "nm = neldermead_search(nm)"; 85assert_checkerror(cmd,"%s: Randomized bounds initial simplex is not available without bounds.",[],"neldermead_startup"); 86// 87// Clean-up 88// 89nm = neldermead_destroy(nm); 90// 91// Test search with verbose to log file 92// 93nm = neldermead_new (); 94nm = neldermead_configure(nm,"-numberofvariables",4); 95nm = neldermead_configure(nm,"-function",optimtestcase); 96nm = neldermead_configure(nm,"-x0",[0.0 0.0 0.0 0.0]'); 97nm = neldermead_configure(nm,"-maxiter",10); 98nm = neldermead_configure(nm,"-verbose",1); 99nm = neldermead_configure(nm,"-logfile" , fullfile(TMPDIR,"search.txt" )); 100nm = neldermead_configure(nm,"-verbosetermination",1); 101nm = neldermead_configure(nm,"-nbineqconst",3); 102nm = neldermead_configure(nm,"-method","box"); 103nm = neldermead_search(nm, "off"); 104nm = neldermead_destroy(nm); 105computed = deletefile(fullfile(TMPDIR,"search.txt")); 106assert_checkequal ( computed , %t ); 107