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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.20"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>QuantLib: GlobalOptimizer.cpp</title>
<link href='https://fonts.googleapis.com/css?family=Merriweather+Sans:800' rel='stylesheet' type='text/css'>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
extensions: ["tex2jax.js"],
jax: ["input/TeX","output/HTML-CSS"],
});
</script>
<script type="text/javascript" async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="quantlibextra.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname"><a href="http://quantlib.org">
<img alt="QuantLib" src="QL-title.jpg"></a>
<div id="projectbrief">A free/open-source library for quantitative finance</div>
<div id="projectnumber">Reference manual - version 1.20</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.20 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div class="header">
<div class="headertitle">
<div class="title">GlobalOptimizer.cpp</div> </div>
</div><!--header-->
<div class="contents">
<p>This example shows the use of several different optimizers: firefly algorithm, hybrid simulated annealing, particle swarm optimization, simulated annealing, and differential evolution.</p>
<div class="fragment"><div class="line"><span class="comment">/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */</span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#include <ql/qldefines.hpp></span></div>
<div class="line"><span class="preprocessor">#ifdef BOOST_MSVC</span></div>
<div class="line"><span class="preprocessor"># include <ql/auto_link.hpp></span></div>
<div class="line"><span class="preprocessor">#endif</span></div>
<div class="line"><span class="preprocessor">#include <ql/math/optimization/differentialevolution.hpp></span></div>
<div class="line"><span class="preprocessor">#include <ql/math/optimization/simulatedannealing.hpp></span></div>
<div class="line"><span class="preprocessor">#include <ql/experimental/math/fireflyalgorithm.hpp></span></div>
<div class="line"><span class="preprocessor">#include <ql/experimental/math/hybridsimulatedannealing.hpp></span></div>
<div class="line"><span class="preprocessor">#include <ql/experimental/math/particleswarmoptimization.hpp></span></div>
<div class="line"><span class="preprocessor">#include <ql/functional.hpp></span></div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#include <ql/tuple.hpp></span></div>
<div class="line"><span class="preprocessor">#include <iostream></span></div>
<div class="line"><span class="preprocessor">#include <iomanip></span></div>
<div class="line"> </div>
<div class="line"><span class="keyword">using namespace </span><a class="code" href="namespace_quant_lib.html">QuantLib</a>;</div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#if defined(QL_ENABLE_SESSIONS)</span></div>
<div class="line"><span class="keyword">namespace </span><a class="code" href="namespace_quant_lib.html">QuantLib</a> {</div>
<div class="line"> </div>
<div class="line"> ThreadKey sessionId() { <span class="keywordflow">return</span> 0; }</div>
<div class="line"> </div>
<div class="line">}</div>
<div class="line"><span class="preprocessor">#endif</span></div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> seed = 127;</div>
<div class="line"> </div>
<div class="line"><span class="comment">/*</span></div>
<div class="line"><span class="comment"> Some benchmark functions taken from</span></div>
<div class="line"><span class="comment"> https://en.wikipedia.org/wiki/Test_functions_for_optimization</span></div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment"> Global optimizers have generally a lot of hyper-parameters, and one</span></div>
<div class="line"><span class="comment"> * usually requires some hyper-parameter optimization to find appropriate values</span></div>
<div class="line"><span class="comment">*/</span></div>
<div class="line"> </div>
<div class="line"><a name="a0"></a><a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> ackley(<span class="keyword">const</span> <a name="_a1"></a><a class="code" href="class_quant_lib_1_1_array.html" title="1-D array used in linear algebra.">Array</a>& x) {</div>
<div class="line"> <span class="comment">//Minimum is found at 0</span></div>
<div class="line"> <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> p1 = 0.0, p2 = 0.0;</div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">for</span> (<a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a> i = 0; i < x.<a name="a2"></a><a class="code" href="class_quant_lib_1_1_array.html#acce0ab2cacc475b2434f24c65c91685a" title="dimension of the array">size</a>(); i++) {</div>
<div class="line"> p1 += x[i] * x[i];</div>
<div class="line"> p2 += std::cos(M_TWOPI*x[i]);</div>
<div class="line"> }</div>
<div class="line"> p1 = -0.2*std::sqrt(0.5*p1);</div>
<div class="line"> p2 *= 0.5;</div>
<div class="line"> <span class="keywordflow">return</span> M_E + 20.0 - 20.0*std::exp(p1)-std::exp(p2);</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><a name="_a3"></a><a class="code" href="class_quant_lib_1_1_disposable.html" title="generic disposable object with move semantics">Disposable<Array></a> ackleyValues(<span class="keyword">const</span> <a class="code" href="class_quant_lib_1_1_array.html" title="1-D array used in linear algebra.">Array</a>& x) {</div>
<div class="line"> <a class="code" href="class_quant_lib_1_1_array.html" title="1-D array used in linear algebra.">Array</a> y(x.<a class="code" href="class_quant_lib_1_1_array.html#acce0ab2cacc475b2434f24c65c91685a" title="dimension of the array">size</a>());</div>
<div class="line"> <span class="keywordflow">for</span> (<a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a> i = 0; i < x.<a class="code" href="class_quant_lib_1_1_array.html#acce0ab2cacc475b2434f24c65c91685a" title="dimension of the array">size</a>(); i++) {</div>
<div class="line"> <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> p1 = x[i] * x[i];</div>
<div class="line"> p1 = -0.2*std::sqrt(0.5*p1);</div>
<div class="line"> <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> p2 = 0.5*std::cos(M_TWOPI*x[i]);</div>
<div class="line"> y[i] = M_E + 20.0 - 20.0*std::exp(p1)-std::exp(p2);</div>
<div class="line"> }</div>
<div class="line"> <span class="keywordflow">return</span> y;</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> sphere(<span class="keyword">const</span> <a class="code" href="class_quant_lib_1_1_array.html" title="1-D array used in linear algebra.">Array</a>& x) {</div>
<div class="line"> <span class="comment">//Minimum is found at 0</span></div>
<div class="line"> <span class="keywordflow">return</span> DotProduct(x, x);</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><a class="code" href="class_quant_lib_1_1_disposable.html" title="generic disposable object with move semantics">Disposable<Array></a> sphereValues(<span class="keyword">const</span> <a class="code" href="class_quant_lib_1_1_array.html" title="1-D array used in linear algebra.">Array</a>& x) {</div>
<div class="line"> <a class="code" href="class_quant_lib_1_1_array.html" title="1-D array used in linear algebra.">Array</a> y(x.<a class="code" href="class_quant_lib_1_1_array.html#acce0ab2cacc475b2434f24c65c91685a" title="dimension of the array">size</a>());</div>
<div class="line"> <span class="keywordflow">for</span> (<a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a> i = 0; i < x.<a class="code" href="class_quant_lib_1_1_array.html#acce0ab2cacc475b2434f24c65c91685a" title="dimension of the array">size</a>(); i++) {</div>
<div class="line"> y[i] = x[i]*x[i];</div>
<div class="line"> }</div>
<div class="line"> <span class="keywordflow">return</span> y;</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> rosenbrock(<span class="keyword">const</span> <a class="code" href="class_quant_lib_1_1_array.html" title="1-D array used in linear algebra.">Array</a>& x) {</div>
<div class="line"> <span class="comment">//Minimum is found at f(1, 1, ...)</span></div>
<div class="line"> QL_REQUIRE(x.<a class="code" href="class_quant_lib_1_1_array.html#acce0ab2cacc475b2434f24c65c91685a" title="dimension of the array">size</a>() > 1, <span class="stringliteral">"Input size needs to be higher than 1"</span>);</div>
<div class="line"> <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> result = 0.0;</div>
<div class="line"> <span class="keywordflow">for</span> (<a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a> i = 0; i < x.<a class="code" href="class_quant_lib_1_1_array.html#acce0ab2cacc475b2434f24c65c91685a" title="dimension of the array">size</a>() - 1; i++) {</div>
<div class="line"> <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> temp = (x[i + 1] - x[i] * x[i]);</div>
<div class="line"> result += (x[i] - 1.0)*(x[i] - 1.0) + 100.0*temp*temp;</div>
<div class="line"> }</div>
<div class="line"> <span class="keywordflow">return</span> result;</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> easom(<span class="keyword">const</span> <a class="code" href="class_quant_lib_1_1_array.html" title="1-D array used in linear algebra.">Array</a>& x) {</div>
<div class="line"> <span class="comment">//Minimum is found at f(\pi, \pi, ...)</span></div>
<div class="line"> <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> p1 = 1.0, p2 = 0.0;</div>
<div class="line"> <span class="keywordflow">for</span> (<a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a> i = 0; i < x.<a class="code" href="class_quant_lib_1_1_array.html#acce0ab2cacc475b2434f24c65c91685a" title="dimension of the array">size</a>(); i++) {</div>
<div class="line"> p1 *= std::cos(x[i]);</div>
<div class="line"> p2 += (x[i] - M_PI)*(x[i] - M_PI);</div>
<div class="line"> }</div>
<div class="line"> <span class="keywordflow">return</span> -p1*std::exp(-p2);</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><a class="code" href="class_quant_lib_1_1_disposable.html" title="generic disposable object with move semantics">Disposable<Array></a> easomValues(<span class="keyword">const</span> <a class="code" href="class_quant_lib_1_1_array.html" title="1-D array used in linear algebra.">Array</a>& x) {</div>
<div class="line"> <a class="code" href="class_quant_lib_1_1_array.html" title="1-D array used in linear algebra.">Array</a> y(x.<a class="code" href="class_quant_lib_1_1_array.html#acce0ab2cacc475b2434f24c65c91685a" title="dimension of the array">size</a>());</div>
<div class="line"> <span class="keywordflow">for</span> (<a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a> i = 0; i < x.<a class="code" href="class_quant_lib_1_1_array.html#acce0ab2cacc475b2434f24c65c91685a" title="dimension of the array">size</a>(); i++) {</div>
<div class="line"> <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> p1 = std::cos(x[i]);</div>
<div class="line"> <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> p2 = (x[i] - M_PI)*(x[i] - M_PI);</div>
<div class="line"> y[i] = -p1*std::exp(-p2);</div>
<div class="line"> }</div>
<div class="line"> <span class="keywordflow">return</span> y;</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> eggholder(<span class="keyword">const</span> <a class="code" href="class_quant_lib_1_1_array.html" title="1-D array used in linear algebra.">Array</a>& x) {</div>
<div class="line"> <span class="comment">//Minimum is found at f(512, 404.2319)</span></div>
<div class="line"> QL_REQUIRE(x.<a class="code" href="class_quant_lib_1_1_array.html#acce0ab2cacc475b2434f24c65c91685a" title="dimension of the array">size</a>() == 2, <span class="stringliteral">"Input size needs to be equal to 2"</span>);</div>
<div class="line"> <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> p = (x[1] + 47.0);</div>
<div class="line"> <span class="keywordflow">return</span> -p*std::sin(std::sqrt(std::abs(0.5*x[0] + p))) -</div>
<div class="line"> x[0] * std::sin(std::sqrt(std::abs(x[0] - p)));</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> printFunction(<a name="_a4"></a><a class="code" href="class_quant_lib_1_1_problem.html" title="Constrained optimization problem.">Problem</a>& p, <span class="keyword">const</span> <a class="code" href="class_quant_lib_1_1_array.html" title="1-D array used in linear algebra.">Array</a>& x) {</div>
<div class="line"> std::cout << <span class="stringliteral">" f("</span> << x[0];</div>
<div class="line"> <span class="keywordflow">for</span> (<a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a> i = 1; i < x.size(); i++) {</div>
<div class="line"> std::cout << <span class="stringliteral">", "</span> << x[i];</div>
<div class="line"> }</div>
<div class="line"> <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> val = p.<a name="a5"></a><a class="code" href="class_quant_lib_1_1_problem.html#ab5a7fc79ae2c7a09f08d7ab169a52dc7" title="call cost function computation and increment evaluation counter">value</a>(x);</div>
<div class="line"> std::cout << <span class="stringliteral">") = "</span> << val << std::endl;</div>
<div class="line"> <span class="keywordflow">return</span> val;</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="keyword">class </span>TestFunction : <span class="keyword">public</span> <a name="_a6"></a><a class="code" href="class_quant_lib_1_1_cost_function.html" title="Cost function abstract class for optimization problem.">CostFunction</a> {</div>
<div class="line"><span class="keyword">public</span>:</div>
<div class="line"> <span class="keyword">typedef</span> ext::function<<a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a>(<span class="keyword">const</span> <a class="code" href="class_quant_lib_1_1_array.html" title="1-D array used in linear algebra.">Array</a>&)> RealFunc;</div>
<div class="line"> <span class="keyword">typedef</span> ext::function<Disposable<Array>(<span class="keyword">const</span> <a class="code" href="class_quant_lib_1_1_array.html" title="1-D array used in linear algebra.">Array</a>&)> ArrayFunc;</div>
<div class="line"> <span class="keyword">explicit</span> TestFunction(<span class="keyword">const</span> RealFunc & f, <span class="keyword">const</span> ArrayFunc & fs = ArrayFunc()) : f_(f), fs_(fs) {}</div>
<div class="line"> <span class="keyword">explicit</span> TestFunction(<a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a>(*f)(<span class="keyword">const</span> <a class="code" href="class_quant_lib_1_1_array.html" title="1-D array used in linear algebra.">Array</a>&), <a class="code" href="class_quant_lib_1_1_disposable.html" title="generic disposable object with move semantics">Disposable<Array></a>(*fs)(<span class="keyword">const</span> <a class="code" href="class_quant_lib_1_1_array.html" title="1-D array used in linear algebra.">Array</a>&) = NULL) : f_(f), fs_(fs) {}</div>
<div class="line"> <span class="keyword">virtual</span> ~TestFunction(){}</div>
<div class="line"> <span class="keyword">virtual</span> <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> value(<span class="keyword">const</span> <a class="code" href="class_quant_lib_1_1_array.html" title="1-D array used in linear algebra.">Array</a>& x)<span class="keyword"> const </span>{</div>
<div class="line"> <span class="keywordflow">return</span> f_(x);</div>
<div class="line"> }</div>
<div class="line"> <span class="keyword">virtual</span> <a class="code" href="class_quant_lib_1_1_disposable.html" title="generic disposable object with move semantics">Disposable<Array></a> values(<span class="keyword">const</span> <a class="code" href="class_quant_lib_1_1_array.html" title="1-D array used in linear algebra.">Array</a>& x)<span class="keyword"> const </span>{</div>
<div class="line"> <span class="keywordflow">if</span>(!fs_)</div>
<div class="line"> <span class="keywordflow">throw</span> std::runtime_error(<span class="stringliteral">"Invalid function"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> fs_(x);</div>
<div class="line"> }</div>
<div class="line"><span class="keyword">private</span>:</div>
<div class="line"> RealFunc f_;</div>
<div class="line"> ArrayFunc fs_;</div>
<div class="line">};</div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">int</span> test(<a name="_a7"></a><a class="code" href="class_quant_lib_1_1_optimization_method.html" title="Abstract class for constrained optimization method.">OptimizationMethod</a>& method, <a class="code" href="class_quant_lib_1_1_cost_function.html" title="Cost function abstract class for optimization problem.">CostFunction</a>& f, <span class="keyword">const</span> <a name="_a8"></a><a class="code" href="class_quant_lib_1_1_end_criteria.html" title="Criteria to end optimization process:">EndCriteria</a>& endCriteria,</div>
<div class="line"> <span class="keyword">const</span> <a class="code" href="class_quant_lib_1_1_array.html" title="1-D array used in linear algebra.">Array</a>& start, <span class="keyword">const</span> <a name="_a9"></a><a class="code" href="class_quant_lib_1_1_constraint.html" title="Base constraint class.">Constraint</a>& constraint = <a class="code" href="class_quant_lib_1_1_constraint.html" title="Base constraint class.">Constraint</a>(),</div>
<div class="line"> <span class="keyword">const</span> <a class="code" href="class_quant_lib_1_1_array.html" title="1-D array used in linear algebra.">Array</a>& optimum = <a class="code" href="class_quant_lib_1_1_array.html" title="1-D array used in linear algebra.">Array</a>()) {</div>
<div class="line"> QL_REQUIRE(!start.<a name="a10"></a><a class="code" href="class_quant_lib_1_1_array.html#a644718bb2fb240de962dc3c9a1fdf0dc" title="whether the array is empty">empty</a>(), <span class="stringliteral">"Input size needs to be at least 1"</span>);</div>
<div class="line"> std::cout << <span class="stringliteral">"Starting point: "</span>;</div>
<div class="line"> <a class="code" href="class_quant_lib_1_1_constraint.html" title="Base constraint class.">Constraint</a> c;</div>
<div class="line"> <span class="keywordflow">if</span> (!constraint.empty())</div>
<div class="line"> c = constraint;</div>
<div class="line"> <a class="code" href="class_quant_lib_1_1_problem.html" title="Constrained optimization problem.">Problem</a> p(f, c, start);</div>
<div class="line"> printFunction(p, start);</div>
<div class="line"> method.<a name="a11"></a><a class="code" href="class_quant_lib_1_1_optimization_method.html#a6bf9f0581475e7a28bdf478f941f116e" title="minimize the optimization problem P">minimize</a>(p, endCriteria);</div>
<div class="line"> std::cout << <span class="stringliteral">"End point: "</span>;</div>
<div class="line"> <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> val = printFunction(p, p.<a name="a12"></a><a class="code" href="class_quant_lib_1_1_problem.html#a2640a08249de104b1944e52e352400a9" title="current value of the local minimum">currentValue</a>());</div>
<div class="line"> <span class="keywordflow">if</span>(!optimum.empty())</div>
<div class="line"> {</div>
<div class="line"> std::cout << <span class="stringliteral">"Global optimum: "</span>;</div>
<div class="line"> <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> optimVal = printFunction(p, optimum);</div>
<div class="line"> <span class="keywordflow">if</span>(std::abs(optimVal) < 1e-13)</div>
<div class="line"> <span class="keywordflow">return</span> <span class="keyword">static_cast<</span><span class="keywordtype">int</span><span class="keyword">></span>(std::abs(val - optimVal) < 1e-6);</div>
<div class="line"> <span class="keywordflow">else</span></div>
<div class="line"> <span class="keywordflow">return</span> <span class="keyword">static_cast<</span><span class="keywordtype">int</span><span class="keyword">></span>(std::abs((val - optimVal) / optimVal) < 1e-6);</div>
<div class="line"> }</div>
<div class="line"> <span class="keywordflow">return</span> 1;</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">void</span> testFirefly() {</div>
<div class="line"> <span class="comment">/*</span></div>
<div class="line"><span class="comment"> The Eggholder function is only in 2 dimensions, it has a multitude</span></div>
<div class="line"><span class="comment"> * of local minima, and they are not symmetric necessarily</span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"> <a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a> n = 2;</div>
<div class="line"> <a name="_a13"></a><a class="code" href="class_quant_lib_1_1_nonhomogeneous_boundary_constraint.html" title="Constraint imposing i-th argument to be in [low_i,high_i] for all i">NonhomogeneousBoundaryConstraint</a> constraint(<a class="code" href="class_quant_lib_1_1_array.html" title="1-D array used in linear algebra.">Array</a>(n, -512.0), <a class="code" href="class_quant_lib_1_1_array.html" title="1-D array used in linear algebra.">Array</a>(n, 512.0));</div>
<div class="line"> <a class="code" href="class_quant_lib_1_1_array.html" title="1-D array used in linear algebra.">Array</a> x(n, 0.0);</div>
<div class="line"> <a class="code" href="class_quant_lib_1_1_array.html" title="1-D array used in linear algebra.">Array</a> optimum(n);</div>
<div class="line"> optimum[0] = 512.0;</div>
<div class="line"> optimum[1] = 404.2319;</div>
<div class="line"> <a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a> agents = 150;</div>
<div class="line"> <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> vola = 1.5;</div>
<div class="line"> <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> intense = 1.0;</div>
<div class="line"> ext::shared_ptr<FireflyAlgorithm::Intensity> intensity =</div>
<div class="line"> ext::make_shared<ExponentialIntensity>(10.0, 1e-8, intense);</div>
<div class="line"> ext::shared_ptr<FireflyAlgorithm::RandomWalk> randomWalk =</div>
<div class="line"> ext::make_shared<LevyFlightWalk>(vola, 0.5, 1.0, seed);</div>
<div class="line"> std::cout << <span class="stringliteral">"Function eggholder, Agents: "</span> << agents</div>
<div class="line"> << <span class="stringliteral">", Vola: "</span> << vola << <span class="stringliteral">", Intensity: "</span> << intense << std::endl;</div>
<div class="line"> TestFunction f(eggholder);</div>
<div class="line"> <a name="_a14"></a><a class="code" href="class_quant_lib_1_1_firefly_algorithm.html">FireflyAlgorithm</a> fa(agents, intensity, randomWalk, 40);</div>
<div class="line"> <a class="code" href="class_quant_lib_1_1_end_criteria.html" title="Criteria to end optimization process:">EndCriteria</a> ec(5000, 1000, 1.0e-8, 1.0e-8, 1.0e-8);</div>
<div class="line"> test(fa, f, ec, x, constraint, optimum);</div>
<div class="line"> std::cout << <span class="stringliteral">"================================================================"</span> << std::endl;</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">void</span> testSimulatedAnnealing(<a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a> dimension, <a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a> maxSteps, <a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a> staticSteps){</div>
<div class="line"> </div>
<div class="line"> <span class="comment">/*The ackley function has a large amount of local minima, but the</span></div>
<div class="line"><span class="comment"> structure is symmetric, so if one could simply just ignore the</span></div>
<div class="line"><span class="comment"> walls separating the local minima, it would look like almost</span></div>
<div class="line"><span class="comment"> like a parabola</span></div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment"> Andres Hernandez: I could not find a configuration that was able</span></div>
<div class="line"><span class="comment"> to fix the problem</span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"> </div>
<div class="line"> <span class="comment">//global minimum is at 0.0</span></div>
<div class="line"> TestFunction f(ackley, ackleyValues);</div>
<div class="line"> </div>
<div class="line"> <span class="comment">//Starting point</span></div>
<div class="line"> <a class="code" href="class_quant_lib_1_1_array.html" title="1-D array used in linear algebra.">Array</a> x(dimension, 1.5);</div>
<div class="line"> <a class="code" href="class_quant_lib_1_1_array.html" title="1-D array used in linear algebra.">Array</a> optimum(dimension, 0.0);</div>
<div class="line"> </div>
<div class="line"> <span class="comment">//Constraint for local optimizer</span></div>
<div class="line"> <a class="code" href="class_quant_lib_1_1_array.html" title="1-D array used in linear algebra.">Array</a> lower(dimension, -5.0);</div>
<div class="line"> <a class="code" href="class_quant_lib_1_1_array.html" title="1-D array used in linear algebra.">Array</a> upper(dimension, 5.0);</div>
<div class="line"> <a class="code" href="class_quant_lib_1_1_nonhomogeneous_boundary_constraint.html" title="Constraint imposing i-th argument to be in [low_i,high_i] for all i">NonhomogeneousBoundaryConstraint</a> constraint(lower, upper);</div>
<div class="line"> </div>
<div class="line"> <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> lambda = 0.1;</div>
<div class="line"> <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> temperature = 350;</div>
<div class="line"> <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> epsilon = 0.99;</div>
<div class="line"> <a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a> ms = 1000;</div>
<div class="line"> std::cout << <span class="stringliteral">"Function ackley, Lambda: "</span> << lambda</div>
<div class="line"> << <span class="stringliteral">", Temperature: "</span> << temperature</div>
<div class="line"> << <span class="stringliteral">", Epsilon: "</span> << epsilon</div>
<div class="line"> << <span class="stringliteral">", Iterations: "</span> << ms</div>
<div class="line"> << std::endl;</div>
<div class="line"> </div>
<div class="line"> <a name="_a15"></a><a class="code" href="class_quant_lib_1_1_mersenne_twister_uniform_rng.html" title="Uniform random number generator.">MersenneTwisterUniformRng</a> rng(seed);</div>
<div class="line"> <a name="_a16"></a><a class="code" href="class_quant_lib_1_1_simulated_annealing.html" title="Simulated Annealing.">SimulatedAnnealing<MersenneTwisterUniformRng></a> sa(lambda, temperature, epsilon, ms, rng);</div>
<div class="line"> <a class="code" href="class_quant_lib_1_1_end_criteria.html" title="Criteria to end optimization process:">EndCriteria</a> ec(maxSteps, staticSteps, 1.0e-8, 1.0e-8, 1.0e-8);</div>
<div class="line"> test(sa, f, ec, x, constraint, optimum);</div>
<div class="line"> std::cout << <span class="stringliteral">"================================================================"</span> << std::endl;</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">void</span> testGaussianSA(<a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a> dimension,</div>
<div class="line"> <a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a> maxSteps,</div>
<div class="line"> <a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a> staticSteps,</div>
<div class="line"> <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> initialTemp,</div>
<div class="line"> <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> finalTemp,</div>
<div class="line"> GaussianSimulatedAnnealing::ResetScheme resetScheme =</div>
<div class="line"> GaussianSimulatedAnnealing::ResetToBestPoint,</div>
<div class="line"> <a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a> resetSteps = 150,</div>
<div class="line"> GaussianSimulatedAnnealing::LocalOptimizeScheme optimizeScheme =</div>
<div class="line"> GaussianSimulatedAnnealing::EveryBestPoint,</div>
<div class="line"> <span class="keyword">const</span> ext::shared_ptr<OptimizationMethod>& localOptimizer =</div>
<div class="line"> ext::make_shared<LevenbergMarquardt>()) {</div>
<div class="line"> </div>
<div class="line"> <span class="comment">/*The ackley function has a large amount of local minima, but the</span></div>
<div class="line"><span class="comment"> * structure is symmetric, so if one could simply just ignore the</span></div>
<div class="line"><span class="comment"> * walls separating the local minima, it would look like almost like</span></div>
<div class="line"><span class="comment"> * a parabola*/</span></div>
<div class="line"> </div>
<div class="line"> <span class="comment">//global minimum is at 0.0</span></div>
<div class="line"> TestFunction f(ackley, ackleyValues);</div>
<div class="line"> </div>
<div class="line"> std::cout << <span class="stringliteral">"Function: ackley, Dimensions: "</span> << dimension</div>
<div class="line"> << <span class="stringliteral">", Initial temp:"</span> << initialTemp</div>
<div class="line"> << <span class="stringliteral">", Final temp:"</span> << finalTemp</div>
<div class="line"> << <span class="stringliteral">", Reset scheme:"</span> << resetScheme</div>
<div class="line"> << <span class="stringliteral">", Reset steps:"</span> << resetSteps</div>
<div class="line"> << std::endl;</div>
<div class="line"> <span class="comment">//Starting point</span></div>
<div class="line"> <a class="code" href="class_quant_lib_1_1_array.html" title="1-D array used in linear algebra.">Array</a> x(dimension, 1.5);</div>
<div class="line"> <a class="code" href="class_quant_lib_1_1_array.html" title="1-D array used in linear algebra.">Array</a> optimum(dimension, 0.0);</div>
<div class="line"> </div>
<div class="line"> <span class="comment">//Constraint for local optimizer</span></div>
<div class="line"> <a class="code" href="class_quant_lib_1_1_array.html" title="1-D array used in linear algebra.">Array</a> lower(dimension, -5.0);</div>
<div class="line"> <a class="code" href="class_quant_lib_1_1_array.html" title="1-D array used in linear algebra.">Array</a> upper(dimension, 5.0);</div>
<div class="line"> <a class="code" href="class_quant_lib_1_1_nonhomogeneous_boundary_constraint.html" title="Constraint imposing i-th argument to be in [low_i,high_i] for all i">NonhomogeneousBoundaryConstraint</a> constraint(lower, upper);</div>
<div class="line"> </div>
<div class="line"> <span class="comment">//Simulated annealing setup</span></div>
<div class="line"> <a name="_a17"></a><a class="code" href="class_quant_lib_1_1_sampler_gaussian.html" title="Gaussian Sampler.">SamplerGaussian</a> sampler(seed);</div>
<div class="line"> <a name="_a18"></a><a class="code" href="class_quant_lib_1_1_probability_boltzmann_downhill.html" title="Boltzmann Downhill Probability.">ProbabilityBoltzmannDownhill</a> probability(seed);</div>
<div class="line"> TemperatureExponential temperature(initialTemp, dimension);</div>
<div class="line"> <a name="_a19"></a><a class="code" href="class_quant_lib_1_1_hybrid_simulated_annealing.html">GaussianSimulatedAnnealing</a> sa(sampler, probability, temperature, <a name="_a20"></a><a class="code" href="struct_quant_lib_1_1_reannealing_trivial.html" title="Reannealing Trivial.">ReannealingTrivial</a>(),</div>
<div class="line"> initialTemp, finalTemp, 50, resetScheme,</div>
<div class="line"> resetSteps, localOptimizer,</div>
<div class="line"> optimizeScheme);</div>
<div class="line"> </div>
<div class="line"> <a class="code" href="class_quant_lib_1_1_end_criteria.html" title="Criteria to end optimization process:">EndCriteria</a> ec(maxSteps, staticSteps, 1.0e-8, 1.0e-8, 1.0e-8);</div>
<div class="line"> test(sa, f, ec, x, constraint, optimum);</div>
<div class="line"> std::cout << <span class="stringliteral">"================================================================"</span> << std::endl;</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">void</span> testPSO(<a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a> n){</div>
<div class="line"> <span class="comment">/*The Rosenbrock function has a global minima at (1.0, ...) and a local minima at (-1.0, 1.0, ...)</span></div>
<div class="line"><span class="comment"> The difficulty lies in the weird shape of the function*/</span></div>
<div class="line"> <a class="code" href="class_quant_lib_1_1_nonhomogeneous_boundary_constraint.html" title="Constraint imposing i-th argument to be in [low_i,high_i] for all i">NonhomogeneousBoundaryConstraint</a> constraint(<a class="code" href="class_quant_lib_1_1_array.html" title="1-D array used in linear algebra.">Array</a>(n, -1.0), <a class="code" href="class_quant_lib_1_1_array.html" title="1-D array used in linear algebra.">Array</a>(n, 4.0));</div>
<div class="line"> <a class="code" href="class_quant_lib_1_1_array.html" title="1-D array used in linear algebra.">Array</a> x(n, 0.0);</div>
<div class="line"> <a class="code" href="class_quant_lib_1_1_array.html" title="1-D array used in linear algebra.">Array</a> optimum(n, 1.0);</div>
<div class="line"> <a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a> agents = 100;</div>
<div class="line"> <a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a> kneighbor = 25;</div>
<div class="line"> <a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a> threshold = 500;</div>
<div class="line"> std::cout << <span class="stringliteral">"Function: rosenbrock, Dimensions: "</span> << n</div>
<div class="line"> << <span class="stringliteral">", Agents: "</span> << agents << <span class="stringliteral">", K-neighbors: "</span> << kneighbor</div>
<div class="line"> << <span class="stringliteral">", Threshold: "</span> << threshold << std::endl;</div>
<div class="line"> ext::shared_ptr<ParticleSwarmOptimization::Topology> topology =</div>
<div class="line"> ext::make_shared<KNeighbors>(kneighbor);</div>
<div class="line"> ext::shared_ptr<ParticleSwarmOptimization::Inertia> inertia =</div>
<div class="line"> ext::make_shared<LevyFlightInertia>(1.5, threshold, seed);</div>
<div class="line"> TestFunction f(rosenbrock);</div>
<div class="line"> <a name="_a21"></a><a class="code" href="class_quant_lib_1_1_particle_swarm_optimization.html">ParticleSwarmOptimization</a> pso(agents, topology, inertia, 2.05, 2.05, seed);</div>
<div class="line"> <a class="code" href="class_quant_lib_1_1_end_criteria.html" title="Criteria to end optimization process:">EndCriteria</a> ec(10000, 1000, 1.0e-8, 1.0e-8, 1.0e-8);</div>
<div class="line"> test(pso, f, ec, x, constraint, optimum);</div>
<div class="line"> std::cout << <span class="stringliteral">"================================================================"</span> << std::endl;</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">void</span> testDifferentialEvolution(<a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a> n, <a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a> agents){</div>
<div class="line"> <span class="comment">/*The Rosenbrock function has a global minima at (1.0, ...) and a local minima at (-1.0, 1.0, ...)</span></div>
<div class="line"><span class="comment"> The difficulty lies in the weird shape of the function*/</span></div>
<div class="line"> <a class="code" href="class_quant_lib_1_1_nonhomogeneous_boundary_constraint.html" title="Constraint imposing i-th argument to be in [low_i,high_i] for all i">NonhomogeneousBoundaryConstraint</a> constraint(<a class="code" href="class_quant_lib_1_1_array.html" title="1-D array used in linear algebra.">Array</a>(n, -4.0), <a class="code" href="class_quant_lib_1_1_array.html" title="1-D array used in linear algebra.">Array</a>(n, 4.0));</div>
<div class="line"> <a class="code" href="class_quant_lib_1_1_array.html" title="1-D array used in linear algebra.">Array</a> x(n, 0.0);</div>
<div class="line"> <a class="code" href="class_quant_lib_1_1_array.html" title="1-D array used in linear algebra.">Array</a> optimum(n, 1.0);</div>
<div class="line"> </div>
<div class="line"> TestFunction f(rosenbrock);</div>
<div class="line"> </div>
<div class="line"> <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> probability = 0.3;</div>
<div class="line"> <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> stepsizeWeight = 0.6;</div>
<div class="line"> DifferentialEvolution::Strategy strategy = DifferentialEvolution::BestMemberWithJitter;</div>
<div class="line"> </div>
<div class="line"> std::cout << <span class="stringliteral">"Function: rosenbrock, Dimensions: "</span> << n << <span class="stringliteral">", Agents: "</span> << agents</div>
<div class="line"> << <span class="stringliteral">", Probability: "</span> << probability</div>
<div class="line"> << <span class="stringliteral">", StepsizeWeight: "</span> << stepsizeWeight</div>
<div class="line"> << <span class="stringliteral">", Strategy: BestMemberWithJitter"</span> << std::endl;</div>
<div class="line"> DifferentialEvolution::Configuration config;</div>
<div class="line"> config.withBounds(<span class="keyword">true</span>)</div>
<div class="line"> .withCrossoverProbability(probability)</div>
<div class="line"> .withPopulationMembers(agents)</div>
<div class="line"> .withStepsizeWeight(stepsizeWeight)</div>
<div class="line"> .withStrategy(strategy)</div>
<div class="line"> .withSeed(seed);</div>
<div class="line"> </div>
<div class="line"> <a name="_a22"></a><a class="code" href="class_quant_lib_1_1_differential_evolution.html" title="Differential Evolution configuration object.">DifferentialEvolution</a> de(config);</div>
<div class="line"> <a class="code" href="class_quant_lib_1_1_end_criteria.html" title="Criteria to end optimization process:">EndCriteria</a> ec(5000, 1000, 1.0e-8, 1.0e-8, 1.0e-8);</div>
<div class="line"> test(de, f, ec, x, constraint, optimum);</div>
<div class="line"> std::cout << <span class="stringliteral">"================================================================"</span> << std::endl;</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span>, <span class="keywordtype">char</span>* []) {</div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">try</span> {</div>
<div class="line"> std::cout << std::endl;</div>
<div class="line"> </div>
<div class="line"> std::cout << <span class="stringliteral">"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"</span> << std::endl;</div>
<div class="line"> std::cout << <span class="stringliteral">"Firefly Algorithm Test"</span> << std::endl;</div>
<div class="line"> std::cout << <span class="stringliteral">"----------------------------------------------------------------"</span> << std::endl;</div>
<div class="line"> testFirefly();</div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"> std::cout << <span class="stringliteral">"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"</span> << std::endl;</div>
<div class="line"> std::cout << <span class="stringliteral">"Hybrid Simulated Annealing Test"</span> << std::endl;</div>
<div class="line"> std::cout << <span class="stringliteral">"----------------------------------------------------------------"</span> << std::endl;</div>
<div class="line"> testGaussianSA(3, 500, 200, 100.0, 0.1, GaussianSimulatedAnnealing::ResetToBestPoint, 150, GaussianSimulatedAnnealing::EveryNewPoint);</div>
<div class="line"> testGaussianSA(10, 500, 200, 100.0, 0.1, GaussianSimulatedAnnealing::ResetToBestPoint, 150, GaussianSimulatedAnnealing::EveryNewPoint);</div>
<div class="line"> testGaussianSA(30, 500, 200, 100.0, 0.1, GaussianSimulatedAnnealing::ResetToBestPoint, 150, GaussianSimulatedAnnealing::EveryNewPoint);</div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"> std::cout << <span class="stringliteral">"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"</span> << std::endl;</div>
<div class="line"> std::cout << <span class="stringliteral">"Particle Swarm Optimization Test"</span> << std::endl;</div>
<div class="line"> std::cout << <span class="stringliteral">"----------------------------------------------------------------"</span> << std::endl;</div>
<div class="line"> testPSO(3);</div>
<div class="line"> testPSO(10);</div>
<div class="line"> testPSO(30);</div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"> std::cout << <span class="stringliteral">"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"</span> << std::endl;</div>
<div class="line"> std::cout << <span class="stringliteral">"Simulated Annealing Test"</span> << std::endl;</div>
<div class="line"> std::cout << <span class="stringliteral">"----------------------------------------------------------------"</span> << std::endl;</div>
<div class="line"> testSimulatedAnnealing(3, 10000, 4000);</div>
<div class="line"> testSimulatedAnnealing(10, 10000, 4000);</div>
<div class="line"> testSimulatedAnnealing(30, 10000, 4000);</div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"> std::cout << <span class="stringliteral">"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"</span> << std::endl;</div>
<div class="line"> std::cout << <span class="stringliteral">"Differential Evolution Test"</span> << std::endl;</div>
<div class="line"> std::cout << <span class="stringliteral">"----------------------------------------------------------------"</span> << std::endl;</div>
<div class="line"> testDifferentialEvolution(3, 50);</div>
<div class="line"> testDifferentialEvolution(10, 150);</div>
<div class="line"> testDifferentialEvolution(30, 450);</div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">return</span> 0;</div>
<div class="line"> } <span class="keywordflow">catch</span> (std::exception& e) {</div>
<div class="line"> std::cerr << e.what() << std::endl;</div>
<div class="line"> <span class="keywordflow">return</span> 1;</div>
<div class="line"> } <span class="keywordflow">catch</span> (...) {</div>
<div class="line"> std::cerr << <span class="stringliteral">"unknown error"</span> << std::endl;</div>
<div class="line"> <span class="keywordflow">return</span> 1;</div>
<div class="line"> }</div>
<div class="line">}</div>
</div><!-- fragment --> </div><!-- contents -->
<!-- HTML footer for doxygen 1.8.9.1-->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by <a href="http://www.doxygen.org/index.html">Doxygen</a>
1.8.20
</small></address>
</body>
</html>
|