-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2013-11-23-island-model-with-paradiseo-heterogeneous-island-model.html
193 lines (146 loc) · 14.8 KB
/
2013-11-23-island-model-with-paradiseo-heterogeneous-island-model.html
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
<!DOCTYPE html>
<html lang="">
<head>
<link href='https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,700,400italic' rel='stylesheet' type='text/css'>
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="css/main.css" />
<link rel="stylesheet" type="text/css" href="css/friendly.css" />
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="HandheldFriendly" content="True" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="robots" content="" />
<script src="https://unpkg.com/[email protected]/dist/mermaid.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" integrity="sha384-AfEj0r4/OFrOo5t7NnNe46zW/tFgW6x/bCJG8FqQCEo3+Aro6EYUG4+cU+KJWu/X" crossorigin="anonymous">
<!-- The loading of KaTeX is deferred to speed up page rendering -->
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js" integrity="sha384-g7c+Jr9ZivxKLnZTDUhnkOnsh30B4H0rpLUpJ4jAIKs4fnJI+sEnkvrMWph2EDg4" crossorigin="anonymous"></script>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-PWL24785Z6"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-PWL24785Z6');
</script>
<!-- To automatically render math in text elements, include the auto-render extension: -->
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/auto-render.min.js" integrity="sha384-mll67QQFJfxn0IYznZYonOWZ644AWYC+Pt2cHqMaRhXVrursRwvLnLaebdGIlYNa" crossorigin="anonymous"
onload="renderMathInElement(document.body);"></script>
<meta name="author" content="" />
<meta name="description" content="" />
<title>Alexandre Quemy - Blog - Island Model with ParadisEO: heterogeneous island model</title>
</head>
<body id="index" class="home">
<div class="wrapper">
<!-- Use icons from fontawesome when you are adding new item in the contact list -->
<div class="sidebar-wrapper">
<div class="profile-container">
<img class="profile-img" src="images/profile.jpeg" alt="profile picture" />
<h1 class="name">Alexandre Quemy</h1>
<h3 class="tagline">Tech Staff @ Proof.io</h3>
<h3 class="tagline">Freelance @ Hother.io</h3>
</div><!--//profile-container-->
<div class="contact-container container-block">
<ul class="list-unstyled contact-list">
<li class="email"><i class="fa fa-envelope"></i><a href="mailto: [email protected]">[email protected]</a></li>
<li class="linkedin"><i class="fab fa-linkedin"></i><a href="https://in.linkedin.com/in/aquemy" target="_blank">linkedin.com/in/aquemy</a></li>
<li class="github"><i class="fab fa-github"></i><a href="http://github.com/aquemy" target="_blank">github.com/aquemy</a></li>
<li class="twitter"><i class="fa fa-twitter"></i><a href="https://twitter.com/@alexandre_quemy" target="_blank">@alexandre_quemy</a></li>
<!--<li class="acclaim"><i class="fa fa-certificate"></i><a href="https://www.youracclaim.com/user/alexandre-quemy" target="_blank">alexandre-quemy</a></li>-->
<div itemscope itemtype="https://schema.org/Person"><a itemprop="sameAs" content="https://orcid.org/0000-0002-5865-6403" href="https://orcid.org/0000-0002-5865-6403" target="orcid.widget" rel="me noopener noreferrer" style="vertical-align:top;"><img src="https://orcid.org/sites/default/files/images/orcid_16x16.png" style="width:1em;margin-right:.5em;" alt="ORCID iD icon">0000-0002-5865-6403</a></div>
</ul>
</div>
</div><!--//sidebar-wrapper-->
<div class="top-menu">
<ul>
<li id="selected"><a href="./index.html">Home</a></li>
<li><a href="./research.html">Research</a></li>
<li><a href="./cv.html">CV</a></li>
<!-- <li><a href="./portfolio.html">Portfolio</a></li> -->
<!-- <li><a href="./passions.html">Passions</a></li> -->
<!-- <li><a href="./blog.html">Blog</a></li> -->
<li><a href="https://endomorphis.me" target="_blank">Blog</a></li>
</ul>
</div>
<div class="main-wrapper">
<div class="recent-post-header" id="top-menu-entry">
<p><a href="./blog.html">Back to entries</a></p>
</div>
<div class="blog_entry">
<h1 class="section-title">Island Model with ParadisEO: heterogeneous island model</h1>
<div class="item">
<div class="meta">
<div class="upper-row">
<h3 class="job-title"><cite>2013-11-23</cite></h3>
<div class="time">#Mathématiques</div>
</div><!--//upper-row-->
</div><!--//meta-->
<div class="details">
</div>
</div>
<div class="toc">
<ul>
<li><a href="#introduction">Introduction</a></li>
<li><a href="#base-individual-concept">Base individual concept</a></li>
<li><a href="#concrete-example">Concrete example</a></li>
</ul>
</div>
<h3 id="introduction">Introduction<a class="headerlink" href="#introduction" title="Permanent link">¶</a></h3>
<p>Depending on the problem, one might want to create a model that contains different types of algorithms such as Evolutionary Algorithms or Particle Swarm Optmization algorithms. Hopefully, SMP proposes a mechanism to create such a model.</p>
<h3 id="base-individual-concept">Base individual concept<a class="headerlink" href="#base-individual-concept" title="Permanent link">¶</a></h3>
<p>The only difference between an heterogeneous and an homogeneous model is that it requires to define a <em>base individual</em> notion which is the <em>main</em> type of individuals to exchange. Most of the time, it will be the type used by the largest amount of islands, but it can be more specific, depending on the problem.</p>
<p>When an island sends individuals, it converts individuals to the <em>base type</em> before sending them. In addition, when an island receives individuals, itconverts individuals from the <em>base type</em> to its own type.</p>
<p>The API is strictly the same thanthe homogeneous model’s one. The only difference is the need to specify to the islands running with different indidividual type than the <em>base type</em>, functions to convert <em>from</em> and <em>to</em> base type. Those functions can be lambda, functor, free function or method performed by an object.</p>
<h3 id="concrete-example">Concrete example<a class="headerlink" href="#concrete-example" title="Permanent link">¶</a></h3>
<p>A complete example is available in the file <code>/smp/tutorial/Lesson3/heterogeneous.cpp</code>.</p>
<p>Assuming we have a base type called <code>Indi</code>, and a second type called <code>Indi2</code>, we need to create our conversion functions:
<div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">1</span>
<span class="normal">2</span>
<span class="normal">3</span>
<span class="normal">4</span>
<span class="normal">5</span>
<span class="normal">6</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="c1">// Conversion functions</span>
<span class="n">Indi2</span><span class="w"> </span><span class="nf">fromBase</span><span class="p">(</span><span class="n">Indi</span><span class="o">&</span><span class="w"> </span><span class="n">i</span><span class="p">,</span><span class="w"> </span><span class="kt">unsigned</span><span class="w"> </span><span class="n">size</span><span class="p">)</span><span class="w"></span>
<span class="p">{}</span><span class="w"></span>
<span class="n">Indi</span><span class="w"> </span><span class="nf">toBase</span><span class="p">(</span><span class="n">Indi2</span><span class="o">&</span><span class="w"> </span><span class="n">i</span><span class="p">)</span><span class="w"></span>
<span class="p">{}</span><span class="w"></span>
</code></pre></div></td></tr></table></div></p>
<p>Note that it it possible to have more that one parameter. In our example, we need the size of the <code>Indi2</code> to convert an <code>Indi</code> to an <code>Indi2</code>.</p>
<p>Then, we need to bind our functions in a <code>std::function</code> object (one per island that does not work on base type :
<div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">1</span>
<span class="normal">2</span>
<span class="normal">3</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="c1">// We bind conversion functions</span>
<span class="k">auto</span><span class="w"> </span><span class="n">frombase</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">bind</span><span class="p">(</span><span class="n">fromBase</span><span class="p">,</span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">placeholders</span><span class="o">::</span><span class="n">_1</span><span class="p">,</span><span class="w"> </span><span class="n">VEC_SIZE</span><span class="p">);</span><span class="w"></span>
<span class="k">auto</span><span class="w"> </span><span class="n">tobase</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">bind</span><span class="p">(</span><span class="n">toBase</span><span class="p">,</span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">placeholders</span><span class="o">::</span><span class="n">_1</span><span class="p">);</span><span class="w"></span>
</code></pre></div></td></tr></table></div></p>
<p>As the expected prototype for conversion function in the island contains only one parameter (a reference or value of the original type), we need to fix the second one which is the size. That is why we fixed it with the constant <code>VEC_SIZE</code>.</p>
<p>Finally, create your islands :
<div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">1</span>
<span class="normal">2</span>
<span class="normal">3</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="n">Island</span><span class="o"><</span><span class="n">eoSGA</span><span class="p">,</span><span class="n">Indi2</span><span class="p">,</span><span class="w"> </span><span class="n">Indi</span><span class="o">></span><span class="w"> </span><span class="n">gga</span><span class="p">(</span><span class="n">frombase</span><span class="p">,</span><span class="w"> </span><span class="n">tobase</span><span class="p">,</span><span class="w"> </span><span class="n">pop</span><span class="p">,</span><span class="w"> </span><span class="n">intPolicy</span><span class="p">,</span><span class="w"> </span><span class="n">migPolicy</span><span class="p">,</span><span class="w"> </span><span class="n">select</span><span class="p">,</span><span class="w"></span>
<span class="w"> </span><span class="n">xover</span><span class="p">,</span><span class="w"> </span><span class="n">CROSS_RATE</span><span class="p">,</span><span class="w"> </span><span class="n">mutation</span><span class="p">,</span><span class="w"> </span><span class="n">MUT_RATE</span><span class="p">,</span><span class="w"> </span><span class="n">eval</span><span class="p">,</span><span class="w"> </span><span class="n">continuator</span><span class="p">);</span><span class="w"></span>
<span class="n">Island</span><span class="o"><</span><span class="n">eoEasyEA</span><span class="p">,</span><span class="n">Indi</span><span class="o">></span><span class="w"> </span><span class="n">ea</span><span class="p">(</span><span class="n">pop2</span><span class="p">,</span><span class="w"> </span><span class="n">intPolicy2</span><span class="p">,</span><span class="w"> </span><span class="n">migPolicy2</span><span class="p">,</span><span class="w"> </span><span class="n">genCont</span><span class="p">,</span><span class="w"> </span><span class="n">plainEval</span><span class="p">,</span><span class="w"> </span><span class="n">select2</span><span class="p">,</span><span class="w"> </span><span class="n">transform</span><span class="p">,</span><span class="w"> </span><span class="n">replace</span><span class="p">);</span><span class="w"></span>
</code></pre></div></td></tr></table></div></p>
<p>The third template parameter of the <code>eoSGA</code> island is the base type.</p>
<p>And finally, we add islands and start the model:</p>
<div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">1</span>
<span class="normal">2</span>
<span class="normal">3</span>
<span class="normal">4</span>
<span class="normal">5</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="n">IslandModel</span><span class="o"><</span><span class="n">Indi</span><span class="o">></span><span class="w"> </span><span class="n">model</span><span class="p">(</span><span class="n">topo</span><span class="p">);</span><span class="w"></span>
<span class="n">model</span><span class="p">.</span><span class="n">add</span><span class="p">(</span><span class="n">ea</span><span class="p">);</span><span class="w"></span>
<span class="n">model</span><span class="p">.</span><span class="n">add</span><span class="p">(</span><span class="n">gga</span><span class="p">);</span><span class="w"></span>
<span class="n">model</span><span class="p">();</span><span class="w"></span>
</code></pre></div></td></tr></table></div>
<p>Obviously, the number of individual types is not limited to two.</p>
</div>
</div><!--//main-body-->
</div>
<footer class="footer">
</footer><!--//footer-->
<script type="text/javascript" src="js/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/main.js"></script>
</body>
</html>