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// <-- ENGLISH IMPOSED --> 15// Checks that the shape of x is always the same, 16// i.e. a column vector. 17function [ f , index ] = optimtestcase ( x , index ) 18 if ( size ( x ) <> [4 1] ) then 19 error ( "Wrong shape for x !" ) 20 end 21 f = x.' * x 22endfunction 23// 24// Test search with variable algorithm 25// 26nm = neldermead_new (); 27nm = neldermead_configure(nm,"-numberofvariables",4); 28nm = neldermead_configure(nm,"-function",optimtestcase); 29nm = neldermead_configure(nm,"-x0",[1 2 3 4]'); 30nm = neldermead_configure(nm,"-maxiter",10); 31nm = neldermead_configure(nm,"-method","variable"); 32nm = neldermead_search(nm, "off"); 33nm = neldermead_destroy(nm); 34// 35// Test search with fixed algorithm 36// 37nm = neldermead_new (); 38nm = neldermead_configure(nm,"-numberofvariables",4); 39nm = neldermead_configure(nm,"-function",optimtestcase); 40nm = neldermead_configure(nm,"-x0",[1 2 3 4]'); 41nm = neldermead_configure(nm,"-maxiter",10); 42nm = neldermead_configure(nm,"-method","fixed"); 43nm = neldermead_search(nm, "off"); 44nm = neldermead_destroy(nm); 45// 46// Test with non linear constraints 47// 48function [ f , c , index ] = optimtestcase2 ( x , index ) 49 f = [] 50 c = [] 51 disp(x) 52 if ( size ( x ) <> [4 1] ) then 53 error ( "Wrong shape for x !" ) 54 end 55 if ( ( index == 2 ) | ( index == 6 ) ) then 56 f = x.' * x 57 end 58 if ( ( index == 5 ) | ( index == 6 ) ) then 59 c1 = - x(1)^2 - x(2)^2 - x(3)^2 - x(4)^2 ... 60 - x(1) + x(2) - x(3) + x(4) + 8 61 c2 = - x(1)^2 - 2.0 * x(2)^2 - x(3)^2 - 2.0 * x(4)^2 ... 62 + x(1) + x(4) + 10.0 63 c3 = - 2.0 * x(1)^2 - x(2)^2 - x(3)^2 - 2.0 * x(1) ... 64 + x(2) + x(4) + 5.0 65 c = [c1 c2 c3] 66 end 67endfunction 68nm = neldermead_new (); 69nm = neldermead_configure(nm,"-numberofvariables",4); 70nm = neldermead_configure(nm,"-function",optimtestcase2); 71nm = neldermead_configure(nm,"-x0",[0 0 0 0]'); 72nm = neldermead_configure(nm,"-maxiter",10); 73nm = neldermead_configure(nm,"-method","box"); 74nm = neldermead_configure(nm,"-nbineqconst",3); 75nm = neldermead_search(nm, "off"); 76 0. 77 0. 78 0. 79 0. 80 0. 81 0. 82 0. 83 0. 84 0. 85 0. 86 0. 87 0. 88 0. 89 0. 90 0. 91 0. 92 0. 93 0. 94 0. 95 0. 96 1. 97 0. 98 0. 99 0. 100 0. 101 1. 102 0. 103 0. 104 0. 105 0. 106 1. 107 0. 108 0. 109 0. 110 0. 111 1. 112 0. 113 0. 114 0. 115 0. 116 1. 117 0. 118 0. 119 0. 120 0. 121 1. 122 0. 123 0. 124 0. 125 0. 126 1. 127 0. 128 0. 129 0. 130 0. 131 1. 132 0.575 133 0.575 134 0.575 135 -1.3 136 0.575 137 0.575 138 0.575 139 -1.3 140 0.4125 141 0.4125 142 0.4125 143 -0.65 144 0.8121875 145 0.8121875 146 -1.0628125 147 -0.37375 148 0.8121875 149 0.8121875 150 -1.0628125 151 -0.37375 152 0.5826562 153 0.5826562 154 -0.4798437 155 -0.268125 156 1.1472148 157 -0.7277852 158 -0.0387227 159 -0.5279219 160 0.823002 161 -0.239498 162 -0.0277793 163 -0.3787266 164 0.823002 165 -0.239498 166 -0.0277793 167 -0.3787266 168 -0.254559 169 0.4345035 170 -0.0546958 171 -0.7456896 172 -0.254559 173 0.4345035 174 -0.0546958 175 -0.7456896 176 -0.1934109 177 -0.4081375 178 0.8135612 179 -0.6717268 180 -0.1934109 181 -0.4081375 182 0.8135612 183 -0.6717268 184 0.0259124 185 -0.1281306 186 0.4480337 187 -0.5576654 188 -0.1944957 189 -0.497797 190 -0.3260538 191 -0.1221969 192 -0.1944957 193 -0.497797 194 -0.3260538 195 -0.1221969 196 -1.3132094 197 0.2012786 198 0.0748015 199 -0.3273479 200 -1.3132094 201 0.2012786 202 0.0748015 203 -0.3273479 204 -0.7094975 205 0.0767113 206 0.0458113 207 -0.3418679 208 -0.1739697 209 -0.8806538 210 0.1675844 211 0.3819016 212 -0.1739697 213 -0.8806538 214 0.1675844 215 0.3819016 216 -0.196745 217 -0.508979 218 0.1047661 219 0.0632345 220 0.712283 221 -0.7522959 222 0.0708243 223 0.0898673 224 0.712283 225 -0.7522959 226 0.0708243 227 0.0898673 228 0.3104755 229 -0.5180113 230 0.0637554 231 -0.0321448 232nm = neldermead_destroy(nm); 233