1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2008-2009 - INRIA - Michael Baudin
3 // Copyright (C) 2009-2011 - DIGITEO - Michael Baudin
5 // This file must be used under the terms of the CeCILL.
6 // This source file is licensed as described in the file COPYING, which
7 // you should have received as part of this distribution. The terms
8 // are also available at
9 // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
12 // optimbase_configure --
13 // Configure the current object with the given value for the given key.
15 function this = optimbase_configure (this,key,value)
16 UN=number_properties("tiny")
19 errmsg = msprintf(gettext("%s: Wrong number of input argument: %d expected.\n"), "optimbase_configure", 3);
24 optimbase_typereal ( value , "value" , 3 );
25 optimbase_checkscalar ( "optimbase_configure" , value , "value" , 3 )
26 optimbase_checkgreq ( "optimbase_configure" , value , "value" , 3 , 0 )
28 case "-verbosetermination" then
29 optimbase_typereal ( value , "value" , 3 );
30 optimbase_checkscalar ( "optimbase_configure" , value , "value" , 3 )
31 optimbase_checkgreq ( "optimbase_configure" , value , "value" , 3 , 0 )
32 this.verbosetermination = value;
34 optimbase_typestring ( value , "value" , 3 );
35 optimbase_checkscalar ( "optimbase_configure" , value , "value" , 3 )
36 if ( this.logstartup ) then
37 this = optimbase_logshutdown ( this )
40 this = optimbase_logstartup ( this );
42 optimbase_typereal ( value , "value" , 3 );
45 if n==1 then // Allowing row vectors by transposing them into column vectors
47 temp = m; // Switch the sizes in case we want to reuse them later in this function
51 errmsg = msprintf(gettext("%s: The x0 vector is expected to be a column matrix, but current shape is %d x %d"),"optimbase_configure",n,m);
56 this.numberofvariables = n; // Setting x0 also sets the size of the system
57 case "-maxfunevals" then
58 optimbase_typereal ( value , "value" , 3 );
59 optimbase_checkscalar ( "optimbase_configure" , value , "value" , 3 )
60 optimbase_checkgreq ( "optimbase_configure" , value , "value" , 3 , 1 )
61 this.maxfunevals = value;
63 optimbase_typereal ( value , "value" , 3 );
64 optimbase_checkscalar ( "optimbase_configure" , value , "value" , 3 )
65 optimbase_checkgreq ( "optimbase_configure" , value , "value" , 3 , 1 )
67 case "-tolfunabsolute" then
68 optimbase_typereal ( value , "value" , 3 );
69 optimbase_checkscalar ( "optimbase_configure" , value , "value" , 3 )
70 optimbase_checkgreq ( "optimbase_configure" , value , "value" , 3 , 0 )
71 this.tolfunabsolute = value;
72 case "-tolfunrelative" then
73 optimbase_typereal ( value , "value" , 3 );
74 optimbase_checkscalar ( "optimbase_configure" , value , "value" , 3 )
75 optimbase_checkgreq ( "optimbase_configure" , value , "value" , 3 , 0 )
76 this.tolfunrelative = value;
77 case "-tolxabsolute" then
78 optimbase_typereal ( value , "value" , 3 );
79 optimbase_checkscalar ( "optimbase_configure" , value , "value" , 3 )
80 optimbase_checkgreq ( "optimbase_configure" , value , "value" , 3 , 0 )
81 this.tolxabsolute = value;
82 case "-tolxrelative" then
83 optimbase_typereal ( value , "value" , 3 );
84 optimbase_checkscalar ( "optimbase_configure" , value , "value" , 3 )
85 optimbase_checkgreq ( "optimbase_configure" , value , "value" , 3 , 0 )
86 this.tolxrelative = value;
87 case "-tolxmethod" then
88 optimbase_typeboolean ( value , "value" , 3 );
89 optimbase_checkscalar ( "optimbase_configure" , value , "value" , 3 )
90 this.tolxmethod = value;
91 case "-tolfunmethod" then
92 optimbase_typeboolean ( value , "value" , 3 );
93 optimbase_checkscalar ( "optimbase_configure" , value , "value" , 3 )
94 this.tolfunmethod = value;
96 optimbase_typecallable ( value , "value" , 3)
98 case "-outputcommand" then
99 optimbase_typecallable ( value , "value" , 3)
100 this.outputcommand = value;
101 case "-numberofvariables" then
102 optimbase_typereal ( value , "value" , 3 );
103 optimbase_checkscalar ( "optimbase_configure" , value , "value" , 3 )
104 optimbase_checkgreq ( "optimbase_configure" , value , "value" , 3 , 1 )
105 this.numberofvariables = value;
106 case "-storehistory" then
107 optimbase_typeboolean ( value , "value" , 3 );
108 optimbase_checkscalar ( "optimbase_configure" , value , "value" , 3 )
109 this.storehistory = value;
110 case "-boundsmin" then
111 optimbase_typereal ( value , "value" , 3 );
112 this.boundsmin = value;
113 case "-boundsmax" then
114 optimbase_typereal ( value , "value" , 3 );
115 this.boundsmax = value;
116 case "-nbineqconst" then
117 optimbase_typereal ( value , "value" , 3 );
118 optimbase_checkscalar ( "optimbase_configure" , value , "value" , 3 )
119 optimbase_checkgreq ( "optimbase_configure" , value , "value" , 3 , 0 )
120 this.nbineqconst = value;
121 case "-withderivatives" then
122 optimbase_typeboolean ( value , "value" , 3 );
123 optimbase_checkscalar ( "optimbase_configure" , value , "value" , 3 )
124 this.withderivatives = value;
129 errmsg = msprintf(gettext("%s: Unknown key %s"),"optimbase_configure",key)
133 // Generates an error if the given variable is not of type real
134 function optimbase_typereal ( var , varname , ivar )
135 if ( type ( var ) <> 1 ) then
136 errmsg = msprintf(gettext("%s: Expected real variable for variable %s at input #%d, but got %s instead."),"optimbase_typereal", varname , ivar , typeof(var) );
140 // Generates an error if the given variable is not of type string
141 function optimbase_typestring ( var , varname , ivar )
142 if ( type ( var ) <> 10 ) then
143 errmsg = msprintf(gettext("%s: Expected string variable for variable %s at input #%d, but got %s instead."),"optimbase_typestring", varname , ivar , typeof(var) );
147 // Generates an error if the given variable is not of type function (macro)
148 function optimbase_typefunction ( var , varname , ivar )
149 if ( type ( var ) <> 13 ) then
150 errmsg = msprintf(gettext("%s: Expected function but for variable %s at input #%d, got %s instead."),"optimbase_typefunction", varname , ivar , typeof(var) );
154 // Generates an error if the given variable is not of type boolean
155 function optimbase_typeboolean ( var , varname , ivar )
156 if ( type ( var ) <> 4 ) then
157 errmsg = msprintf(gettext("%s: Expected boolean but for variable %s at input #%d, got %s instead."),"optimbase_typeboolean", varname , ivar , typeof(var) );
162 // Generates an error if the value corresponding to an option is unknown.
163 function unknownValueForOption ( value , optionname )
164 errmsg = msprintf(gettext("%s: Unknown value %s for %s option"),"unknownValueForOption",value , optionname );
168 function optimbase_typecallable ( var , varname , ivar )
169 // Check that var is a function or a list
170 if ( and ( type ( var ) <> [11 13 15] ) ) then
171 errmsg = msprintf(gettext("%s: Expected function or list for variable %s at input #%d, but got %s instead."),"optimbase_typecallable", varname , ivar , typeof(var) );
174 if ( type ( var ) == 15 ) then
175 // Check that var(1) is a function
176 if ( and ( type ( var(1) ) <> [11 13] ) ) then
177 errmsg = msprintf(gettext("%s: Expected function for variable %s(1) at input #%d, but got %s instead."),"optimbase_typecallable", varname , ivar , typeof(var) );
183 function optimbase_checkrange ( funname , var , varname , ivar , vmin , vmax )
184 if ( ~and ( vmin <= var & var <= vmax ) ) then
185 k = find ( vmin > var | var > vmax )
187 errmsg = msprintf(gettext("%s: Expected that all entries of input argument %s at input #%d are in the range [%s,%s], but entry #%d is equal to %s."),funname,varname,ivar,string(vmin),string(vmax),k,string(var(k)));
192 function optimbase_checkgreq ( funname , var , varname , ivar , thr )
193 if ( or ( var < thr ) ) then
194 k = find ( var < thr )
196 errmsg = msprintf(gettext("%s: Expected that all entries of input argument %s at input #%d are greater or equal than %s, but entry #%d is equal to %s."),funname,varname,ivar,string(thr),k,string(var(k)));
201 function optimbase_checkflint ( funname , var , varname , ivar )
202 if ( or ( round(var)<>var ) ) then
203 k = find ( round(var)<>var )
205 errmsg = msprintf(gettext("%s: Expected floating point integer for input argument %s at input #%d, but entry #%d is equal to %s."),funname,varname,ivar,k,string(var(k)));
210 function optimbase_checkscalar ( funname , var , varname , ivar )
211 if ( or(size(var) <> [1 1]) ) then
212 strcomp = strcat(string(size(var))," ")
213 errmsg = msprintf(gettext("%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n"), funname, ivar , 1, 1 );
218 function optimbase_checkoption ( funname , var , varname , ivar , expectedopt )
219 if ( and ( var <> expectedopt ) ) then
221 strexp = """" + strcat(string(expectedopt),stradd) + """"
222 errmsg = msprintf(gettext("%s: Expected value [%s] for input argument %s at input #%d, but got ""%s"" instead."),funname,strexp,varname,ivar,string(var));