344 | | //Defining the problem |
345 | | NonLinGloOpt::@Problem problem = [[ |
346 | | //Optimization method. If not specified the system will choose one |
347 | | //by calling method select_automatic_algorithm |
348 | | //In this case we want to use MMA (Method of Moving Asymptotes) |
349 | | // http://ab-initio.mit.edu/wiki/index.php/NLopt_Algorithms#MMA_.28Method_of_Moving_Asymptotes.29 |
350 | | Real id_algorithm = NonLinGloOpt::Algorithm::LD_MMA; |
351 | | //We want to minimize the target function |
352 | | Real sign = -1; |
353 | | //We want just a local minimum |
354 | | Real neededGlobal = False; |
355 | | //The problem is almost twice differentiable |
356 | | Real id_analyticalClass = |
357 | | NonLinGloOpt::AnalyticalClass::TWICE_DIFFERENTIABLE; |
358 | | //The gradient of all functions is known |
359 | | Real id_useGradient = True; |
360 | | //Target given as simple Code |
361 | | Anything target = my_function; |
362 | | //Lower bounds |
363 | | Matrix lower_bounds = Col(-1/0, 0); // -x2 <= 0 |
364 | | //No upper bounds. You can skip next line |
365 | | Matrix upper_bounds = Col( 1/0, 1/0); |
366 | | //There are two non linear constraining inequations |
367 | | Set inequations = [[ |
368 | | [[ineq1, ineq1::constraint]], //Inequation given by class method |
369 | | [[ineq2, ineq2::constraint]] //Inequation given by class method |
370 | | ]]; |
371 | | //Initial values |
372 | | Matrix x0 = Col(1.234, 5.678); |
373 | | //Stopping criteria of relative tolerance for both x and y |
374 | | Real relativeTolerance = 1E-4; // |
375 | | //Stopping criteria of maximum running time |
376 | | Real maxTime = 60; |
377 | | //Functions will be traced every "verboseEach" evaluations |
378 | | Real verboseEach = 1 |
| 342 | NonLinGloOpt::@PipeLine pipe_line = [[ |
| 343 | //Defining the problem |
| 344 | Set problems = [[ NonLinGloOpt::@Problem problem = [[ |
| 345 | //We want to minimize the target function |
| 346 | Real sign = -1; |
| 347 | //We want just a local minimum |
| 348 | Real neededGlobal = False; |
| 349 | //The problem is almost twice differentiable |
| 350 | Real id_analyticalClass = |
| 351 | NonLinGloOpt::AnalyticalClass::TWICE_DIFFERENTIABLE; |
| 352 | //The gradient of all functions is known |
| 353 | Real id_useGradient = True; |
| 354 | //Problem dimension |
| 355 | Real n = 2; |
| 356 | //Target given as simple Code |
| 357 | Anything target = my_function; |
| 358 | //Lower bounds |
| 359 | Matrix lower_bounds = Col(-10, 0); //x1>=-10, x2 >= 0 |
| 360 | //Upper bounds |
| 361 | Matrix upper_bounds = Col( 10, 10); //x1<= 10, x2 <=10 |
| 362 | //There are two non linear constraining inequations |
| 363 | Set inequations = [[ |
| 364 | [[ineq1, ineq1::constraint]], //Inequation given by class method |
| 365 | [[ineq2, ineq2::constraint]] //Inequation given by class method |
| 366 | ]] |
| 367 | ]] ]]; |
| 368 | //Initial point |
| 369 | Matrix x0 = Col(1.234, 5.678), |
| 370 | Real verboseEach = 100 |