1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2008-2009 - INRIA - Michael Baudin
//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// you should have received as part of this distribution. The terms
// are also available at
// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
//
// optimbase_configure --
// Configure the current object with the given value for the given key.
//
function this = optimbase_configure (this,key,value)
select key
case "-verbose" then
assert_typereal ( value , "value" , 3 );
this.verbose = value;
case "-verbosetermination" then
assert_typereal ( value , "value" , 3 );
this.verbosetermination = value;
case "-logfile" then
if ( this.logstartup ) then
this = optimbase_logshutdown ( this )
end
this.logfile = value;
this = optimbase_logstartup ( this );
case "-x0" then
assert_typereal ( value , "value" , 3 );
[n,m] = size(value);
if m<>1 then
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);
error(errmsg);
end
this.x0 = value;
case "-maxfunevals" then
assert_typereal ( value , "value" , 3 );
this.maxfunevals = value;
case "-maxiter" then
assert_typereal ( value , "value" , 3 );
this.maxiter = value;
case "-tolfunabsolute" then
assert_typereal ( value , "value" , 3 );
this.tolfunabsolute = value;
case "-tolfunrelative" then
assert_typereal ( value , "value" , 3 );
this.tolfunrelative = value;
case "-tolxabsolute" then
assert_typereal ( value , "value" , 3 );
this.tolxabsolute = value;
case "-tolxrelative" then
assert_typereal ( value , "value" , 3 );
this.tolxrelative = value;
case "-tolxmethod" then
assert_typeboolean ( value , "value" , 3 );
select value
case %t then
this.tolxmethod = %t;
case %f then
this.tolxmethod = %f;
else
unknownValueForOption ( value , "-tolxmethod" )
end
case "-tolfunmethod" then
assert_typeboolean ( value , "value" , 3 );
select value
case %t then
this.tolfunmethod = %t;
case %f then
this.tolfunmethod = %f;
else
unknownValueForOption ( value , "-tolfunmethod" )
end
case "-function" then
assert_typefunction ( value , "value" , 3 );
this.fun = value;
case "-outputcommand" then
assert_typefunction ( value , "value" , 3 );
this.outputcommand = value;
case "-outputcommandarg" then
this.outputcommandarg = value;
case "-numberofvariables" then
assert_typereal ( value , "value" , 3 );
this.numberofvariables = value;
case "-storehistory" then
assert_typeboolean ( value , "value" , 3 );
if ( value ) then
this.storehistory = %t;
else
this.storehistory = %f;
end
case "-costfargument" then
this.costfargument = value;
case "-boundsmin" then
assert_typereal ( value , "value" , 3 );
this.boundsmin = value;
case "-boundsmax" then
assert_typereal ( value , "value" , 3 );
this.boundsmax = value;
case "-nbineqconst" then
assert_typereal ( value , "value" , 3 );
this.nbineqconst = value;
case "-withderivatives" then
assert_typeboolean ( value , "value" , 3 );
if ( value ) then
this.withderivatives = %t;
else
this.withderivatives = %f;
end
else
errmsg = msprintf(gettext("%s: Unknown key %s"),"optimbase_configure",key)
error(errmsg)
end
endfunction
// Generates an error if the given variable is not of type real
function assert_typereal ( var , varname , ivar )
if ( type ( var ) <> 1 ) then
errmsg = msprintf(gettext("%s: Expected real variable for variable %s at input #%d, but got %s instead."),"assert_typereal", varname , ivar , typeof(var) );
error(errmsg);
end
endfunction
// Generates an error if the given variable is not of type string
function assert_typestring ( var , varname , ivar )
if ( type ( var ) <> 10 ) then
errmsg = msprintf(gettext("%s: Expected string variable for variable %s at input #%d, but got %s instead."),"assert_typestring", varname , ivar , typeof(var) );
error(errmsg);
end
endfunction
// Generates an error if the given variable is not of type function (macro)
function assert_typefunction ( var , varname , ivar )
if ( type ( var ) <> 13 ) then
errmsg = msprintf(gettext("%s: Expected function but for variable %s at input #%d, got %s instead."),"assert_typefunction", varname , ivar , typeof(var) );
error(errmsg);
end
endfunction
// Generates an error if the given variable is not of type boolean
function assert_typeboolean ( var , varname , ivar )
if ( type ( var ) <> 4 ) then
errmsg = msprintf(gettext("%s: Expected boolean but for variable %s at input #%d, got %s instead."),"assert_typeboolean", varname , ivar , typeof(var) );
error(errmsg);
end
endfunction
// Generates an error if the value corresponding to an option is unknown.
function unknownValueForOption ( value , optionname )
errmsg = msprintf(gettext("%s: Unknown value %s for %s option"),"unknownValueForOption",value , optionname );
error(errmsg);
endfunction
|