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 error(msprintf(gettext("%s: Wrong size for x0 argument: A vector expected."),"optimbase_configure"));
55 this.numberofvariables = n; // Setting x0 also sets the size of the system
56 case "-maxfunevals" then
57 optimbase_typereal ( value , "value" , 3 );
58 optimbase_checkscalar ( "optimbase_configure" , value , "value" , 3 )
59 optimbase_checkgreq ( "optimbase_configure" , value , "value" , 3 , 1 )
60 this.maxfunevals = value;
62 optimbase_typereal ( value , "value" , 3 );
63 optimbase_checkscalar ( "optimbase_configure" , value , "value" , 3 )
64 optimbase_checkgreq ( "optimbase_configure" , value , "value" , 3 , 1 )
66 case "-tolfunabsolute" then
67 optimbase_typereal ( value , "value" , 3 );
68 optimbase_checkscalar ( "optimbase_configure" , value , "value" , 3 )
69 optimbase_checkgreq ( "optimbase_configure" , value , "value" , 3 , 0 )
70 this.tolfunabsolute = value;
71 case "-tolfunrelative" then
72 optimbase_typereal ( value , "value" , 3 );
73 optimbase_checkscalar ( "optimbase_configure" , value , "value" , 3 )
74 optimbase_checkgreq ( "optimbase_configure" , value , "value" , 3 , 0 )
75 this.tolfunrelative = value;
76 case "-tolxabsolute" then
77 optimbase_typereal ( value , "value" , 3 );
78 optimbase_checkscalar ( "optimbase_configure" , value , "value" , 3 )
79 optimbase_checkgreq ( "optimbase_configure" , value , "value" , 3 , 0 )
80 this.tolxabsolute = value;
81 case "-tolxrelative" then
82 optimbase_typereal ( value , "value" , 3 );
83 optimbase_checkscalar ( "optimbase_configure" , value , "value" , 3 )
84 optimbase_checkgreq ( "optimbase_configure" , value , "value" , 3 , 0 )
85 this.tolxrelative = value;
86 case "-tolxmethod" then
87 optimbase_typeboolean ( value , "value" , 3 );
88 optimbase_checkscalar ( "optimbase_configure" , value , "value" , 3 )
89 this.tolxmethod = value;
90 case "-tolfunmethod" then
91 optimbase_typeboolean ( value , "value" , 3 );
92 optimbase_checkscalar ( "optimbase_configure" , value , "value" , 3 )
93 this.tolfunmethod = value;
95 optimbase_typecallable ( value , "value" , 3)
97 case "-outputcommand" then
98 optimbase_typecallable ( value , "value" , 3)
99 this.outputcommand = value;
100 case "-numberofvariables" then
101 optimbase_typereal ( value , "value" , 3 );
102 optimbase_checkscalar ( "optimbase_configure" , value , "value" , 3 )
103 optimbase_checkgreq ( "optimbase_configure" , value , "value" , 3 , 1 )
104 this.numberofvariables = value;
105 case "-storehistory" then
106 optimbase_typeboolean ( value , "value" , 3 );
107 optimbase_checkscalar ( "optimbase_configure" , value , "value" , 3 )
108 this.storehistory = value;
109 case "-boundsmin" then
110 optimbase_typereal ( value , "value" , 3 );
111 this.boundsmin = value;
112 case "-boundsmax" then
113 optimbase_typereal ( value , "value" , 3 );
114 this.boundsmax = value;
115 case "-nbineqconst" then
116 optimbase_typereal ( value , "value" , 3 );
117 optimbase_checkscalar ( "optimbase_configure" , value , "value" , 3 )
118 optimbase_checkgreq ( "optimbase_configure" , value , "value" , 3 , 0 )
119 this.nbineqconst = value;
120 case "-withderivatives" then
121 optimbase_typeboolean ( value , "value" , 3 );
122 optimbase_checkscalar ( "optimbase_configure" , value , "value" , 3 )
123 this.withderivatives = value;
128 errmsg = msprintf(gettext("%s: Unknown key %s"),"optimbase_configure",key)
132 // Generates an error if the given variable is not of type real
133 function optimbase_typereal ( var , varname , ivar )
134 if ( type ( var ) <> 1 ) then
135 errmsg = msprintf(gettext("%s: Expected real variable for variable %s at input #%d, but got %s instead."),"optimbase_typereal", varname , ivar , typeof(var) );
139 // Generates an error if the given variable is not of type string
140 function optimbase_typestring ( var , varname , ivar )
141 if ( type ( var ) <> 10 ) then
142 errmsg = msprintf(gettext("%s: Expected string variable for variable %s at input #%d, but got %s instead."),"optimbase_typestring", varname , ivar , typeof(var) );
146 // Generates an error if the given variable is not of type function (macro)
147 function optimbase_typefunction ( var , varname , ivar )
148 if ( type ( var ) <> 13 ) then
149 errmsg = msprintf(gettext("%s: Expected function but for variable %s at input #%d, got %s instead."),"optimbase_typefunction", varname , ivar , typeof(var) );
153 // Generates an error if the given variable is not of type boolean
154 function optimbase_typeboolean ( var , varname , ivar )
155 if ( type ( var ) <> 4 ) then
156 errmsg = msprintf(gettext("%s: Expected boolean but for variable %s at input #%d, got %s instead."),"optimbase_typeboolean", varname , ivar , typeof(var) );
161 // Generates an error if the value corresponding to an option is unknown.
162 function unknownValueForOption ( value , optionname )
163 errmsg = msprintf(gettext("%s: Unknown value %s for %s option"),"unknownValueForOption",value , optionname );
167 function optimbase_typecallable ( var , varname , ivar )
168 // Check that var is a function or a list
169 if ( and ( type ( var ) <> [11 13 15] ) ) then
170 errmsg = msprintf(gettext("%s: Expected function or list for variable %s at input #%d, but got %s instead."),"optimbase_typecallable", varname , ivar , typeof(var) );
173 if ( type ( var ) == 15 ) then
174 // Check that var(1) is a function
175 if ( and ( type ( var(1) ) <> [11 13] ) ) then
176 errmsg = msprintf(gettext("%s: Expected function for variable %s(1) at input #%d, but got %s instead."),"optimbase_typecallable", varname , ivar , typeof(var) );
182 function optimbase_checkrange ( funname , var , varname , ivar , vmin , vmax )
183 if ( ~and ( vmin <= var & var <= vmax ) ) then
184 k = find ( vmin > var | var > vmax )
186 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)));
191 function optimbase_checkgreq ( funname , var , varname , ivar , thr )
192 if ( or ( var < thr ) ) then
193 k = find ( var < thr )
195 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)));
200 function optimbase_checkflint ( funname , var , varname , ivar )
201 if ( or ( round(var)<>var ) ) then
202 k = find ( round(var)<>var )
204 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)));
209 function optimbase_checkscalar ( funname , var , varname , ivar )
210 if ( or(size(var) <> [1 1]) ) then
211 strcomp = strcat(string(size(var))," ")
212 errmsg = msprintf(gettext("%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n"), funname, ivar , 1, 1 );
217 function optimbase_checkoption ( funname , var , varname , ivar , expectedopt )
218 if ( and ( var <> expectedopt ) ) then
220 strexp = """" + strcat(string(expectedopt),stradd) + """"
221 errmsg = msprintf(gettext("%s: Expected value [%s] for input argument %s at input #%d, but got ""%s"" instead."),funname,strexp,varname,ivar,string(var));