| | 96 | === Características obligatorias en la definición del problema === |
| | 97 | |
| | 98 | {{{ |
| | 99 | #!cpp |
| | 100 | //If you sign ==- 1 minimized, and if sign == 1 maximizes |
| | 101 | Real sign; |
| | 102 | |
| | 103 | //If true, a global optimal point will be searched. Else just a |
| | 104 | //local one. |
| | 105 | Real neededGlobal; |
| | 106 | |
| | 107 | //Minimum analytical class of target and constraining functions must be one |
| | 108 | //of elements of |
| | 109 | //Set NonLinGloOpt::AnalyticalClass = |
| | 110 | //{[[ |
| | 111 | // Real ARBITRARY = -1, // Arbitrary functions |
| | 112 | // Real CONTINUOUS = 0, // Class C_0: Continuous |
| | 113 | // Real DIFFERENTIABLE = 1, // Class C_1: Differentiable |
| | 114 | // Real TWICE_DIFFERENTIABLE = 2 // Class C_2: Twice differentiable |
| | 115 | //]]}; |
| | 116 | Real id_analyticalClass; |
| | 117 | |
| | 118 | //Indicates if the gradient known or unknown in an analytical or |
| | 119 | //numerical way. Must be one element of |
| | 120 | //Set NonLinGloOpt::GradientKnowneledge = |
| | 121 | //[[ |
| | 122 | //Real NONE = 0, //Doesn't exists or it's too hard to calculate |
| | 123 | //Real ANALITICAL = 1, //Use analitical gradient |
| | 124 | //Real NUMERICAL = 2 //Use numerical gradient |
| | 125 | //]]; |
| | 126 | Real id_useGradient; |
| | 127 | |
| | 128 | //Target function could be a simple Code or a class method of an |
| | 129 | //instance owner. |
| | 130 | // - Real target(Matrix x, Matrix gradient) |
| | 131 | // - Set target = [[NameBlock owner, Code method]] |
| | 132 | //When argument gradient is not empty, then the function, or the |
| | 133 | //method must update it. |
| | 134 | Anything target; |
| | 135 | |
| | 136 | //Initial values of variables |
| | 137 | Matrix x0; |
| | 138 | |
| | 139 | }}} |
| | 140 | |
| | 141 | === Características opcionales en la definición del problema === |
| | 142 | |
| | 143 | Hay otra serie de carcterísticas del problema que son opcionales pues o bien tienen |
| | 144 | un valor por defecto predefinido o bien existe un método interno que les da un valor |
| | 145 | adecuado. |
| | 146 | {{{ |
| | 147 | #!cpp |
| | 148 | //Optimization method. If not specified the system will choose one |
| | 149 | //by calling method select_automatic_algorithm |
| | 150 | Real id_algorithm = ?; //Numerical identifier NonLinGloOpt::Algorithm |
| | 151 | Text co_algorithm = ""; //Codified name |
| | 152 | |
| | 153 | //Lower bounds of the variables (-1/0 if none) |
| | 154 | Matrix lower_bounds = Rand(0,0,0,0); |
| | 155 | |
| | 156 | //Variable upper bounds (+1/0 if none) |
| | 157 | Matrix upper_bounds = Rand(0,0,0,0); |
| | 158 | |
| | 159 | //Set of inequality constraints g(x)<=0 |
| | 160 | //Conjunto de elementos Code o [[NameBlock owner, Code target]] para métodos |
| | 161 | //Constraining function could be a simple Code or a class method of an |
| | 162 | //instance owner. |
| | 163 | // - Real g (Matrix x, Matrix gradient) |
| | 164 | // - Set g = [[NameBlock owner, Code method]] |
| | 165 | //When argument gradient is not empty, then the function, or the |
| | 166 | //method must update it. |
| | 167 | Set inequations = Copy(Empty); |
| | 168 | |
| | 169 | //Set of equality constraints h(x)<=0 |
| | 170 | //Conjunto de elementos Code o [[NameBlock owner, Code target]] para métodos |
| | 171 | //Constraining function could be a simple Code or a class method of an |
| | 172 | //instance owner. |
| | 173 | // - Real h (Matrix x, Matrix gradient) |
| | 174 | // - Set h = [[NameBlock owner, Code method]] |
| | 175 | //When argument gradient is not empty, then the function, or the |
| | 176 | //method must update it. |
| | 177 | Set equations = Copy(Empty); |
| | 178 | |
| | 179 | //Tolerance for the evaluation of inequality constraints |
| | 180 | Real inequationTolerance = 1E-8; |
| | 181 | |
| | 182 | //Tolerance for the evaluation of the equality constraints |
| | 183 | Real equationTolerance = 1E-8; |
| | 184 | |
| | 185 | //Relative tolerance of the stop criteria |
| | 186 | Real relativeTolerance = 1E-6; |
| | 187 | |
| | 188 | //Maximum run time |
| | 189 | Real maxTime = ?; |
| | 190 | |
| | 191 | //If verboseEach>0, evaluation of target funciton will be traced |
| | 192 | //each the specified number of evaluations. |
| | 193 | Real verboseEach = 100; |
| | 194 | |
| | 195 | }}} |
| | 196 | |
| | 197 | |
| | 198 | === Creación y lanzamiento de la optimización === |
| | 199 | |
| | 200 | Una vez definido un problema hay que crear el motor de optimización como una instancia de {{{Class @Opt}}} definida en [source:/tolp/OfficialTolArchiveNetwork/NonLinGloOpt/opt.tol opt.tol] |
| | 201 | {{{ |
| | 202 | #!cpp |
| | 203 | //Creating the optimizer instance |
| | 204 | NonLinGloOpt::@Opt opt = problem::create_optimizer(?); |
| | 205 | }}} |
| | 206 | |
| | 207 | y finalmente se llamará al método de optimización para que ejecute el algoritmo |
| | 208 | |
| | 209 | {{{ |
| | 210 | #!cpp |
| | 211 | //Running the optimization |
| | 212 | Real opt::optimize_problem(problem); |
| | 213 | }}} |
| | 214 | |
| | 215 | Entre medio de ambas acciones, el usuario avanzado puede retocar la instancia |
| | 216 | {{{opt}}} mediante los métodos de {{{@Opt}}}, cada uno de los cuales implementa |
| | 217 | los métodos de la clase C++ interna {{{nlopt::opt}}} cuya API puede verse |
| | 218 | [http://ab-initio.mit.edu/wiki/index.php/NLopt_C-plus-plus_Reference aquí] |
| | 219 | Estos métodos pueden leerse directamente en el [source:/tolp/OfficialTolArchiveNetwork/NonLinGloOpt/opt.tol código TOL] o exporarse en la interfaz de TOLBase. |
| | 220 | |
| | 221 | [[Image(source:/tolp/OfficialTolArchiveNetwork/NonLinGloOpt/doc/opt_methods.png)]] |
| | 222 | |