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
14// <-- CLI SHELL MODE -->
15// <-- ENGLISH IMPOSED -->
16
17
18
19// Checks that the shape of x is always the same,
20// i.e. a column vector.
21function [ f , index ] = optimtestcase ( x , index )
22  if ( size ( x ) <> [4 1] ) then
23    error ( "Wrong shape for x !" )
24  end
25  f = x.' * x
26endfunction
27
28
29//
30// Test search with variable algorithm
31//
32nm = neldermead_new ();
33nm = neldermead_configure(nm,"-numberofvariables",4);
34nm = neldermead_configure(nm,"-function",optimtestcase);
35nm = neldermead_configure(nm,"-x0",[1 2 3 4]');
36nm = neldermead_configure(nm,"-maxiter",10);
37nm = neldermead_configure(nm,"-method","variable");
38nm = neldermead_search(nm, "off");
39nm = neldermead_destroy(nm);
40
41//
42// Test search with fixed algorithm
43//
44nm = neldermead_new ();
45nm = neldermead_configure(nm,"-numberofvariables",4);
46nm = neldermead_configure(nm,"-function",optimtestcase);
47nm = neldermead_configure(nm,"-x0",[1 2 3 4]');
48nm = neldermead_configure(nm,"-maxiter",10);
49nm = neldermead_configure(nm,"-method","fixed");
50nm = neldermead_search(nm, "off");
51nm = neldermead_destroy(nm);
52
53//
54// Test with non linear constraints
55//
56function [ f , c , index ] = optimtestcase2 ( x , index )
57  f = []
58  c = []
59  disp(x)
60  if ( size ( x ) <> [4 1] ) then
61    error ( "Wrong shape for x !" )
62  end
63  if ( ( index == 2 ) | ( index == 6 ) ) then
64      f = x.' * x
65  end
66  if ( ( index == 5 ) | ( index == 6 ) ) then
67    c1 = - x(1)^2 - x(2)^2 - x(3)^2 - x(4)^2 ...
68              - x(1) + x(2) - x(3) + x(4) + 8
69    c2 = - x(1)^2 - 2.0 * x(2)^2 - x(3)^2 - 2.0 * x(4)^2 ...
70              + x(1) + x(4) + 10.0
71    c3 = - 2.0 * x(1)^2 - x(2)^2 - x(3)^2 - 2.0 * x(1) ...
72              + x(2) + x(4) + 5.0
73    c = [c1 c2 c3]
74  end
75endfunction
76nm = neldermead_new ();
77nm = neldermead_configure(nm,"-numberofvariables",4);
78nm = neldermead_configure(nm,"-function",optimtestcase2);
79nm = neldermead_configure(nm,"-x0",[0 0 0 0]');
80nm = neldermead_configure(nm,"-maxiter",10);
81nm = neldermead_configure(nm,"-method","box");
82nm = neldermead_configure(nm,"-nbineqconst",3);
83nm = neldermead_search(nm, "off");
84nm = neldermead_destroy(nm);
85
86