ai4r 1.5 → 1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (216) hide show
  1. data/examples/clusterers/simple_website_clustering.rb +47 -0
  2. data/lib/ai4r.rb +7 -0
  3. data/lib/ai4r/classifiers/hyperpipes.rb +118 -0
  4. data/lib/ai4r/clusterers/average_linkage.rb +22 -23
  5. data/lib/ai4r/clusterers/centroid_linkage.rb +66 -0
  6. data/lib/ai4r/clusterers/complete_linkage.rb +17 -12
  7. data/lib/ai4r/clusterers/diana.rb +139 -0
  8. data/lib/ai4r/clusterers/median_linkage.rb +61 -0
  9. data/lib/ai4r/clusterers/single_linkage.rb +57 -42
  10. data/lib/ai4r/clusterers/ward_linkage.rb +64 -0
  11. data/lib/ai4r/clusterers/weighted_average_linkage.rb +61 -0
  12. data/lib/ai4r/data/constants.rb +18 -0
  13. data/lib/ai4r/data/data_set.rb +5 -3
  14. data/lib/ai4r/data/proximity.rb +18 -0
  15. data/test/clusterers/average_linkage_test.rb +14 -11
  16. data/test/clusterers/bisecting_k_means_test.rb +9 -0
  17. data/test/clusterers/centroid_linkage_test.rb +50 -0
  18. data/test/clusterers/complete_linkage_test.rb +14 -5
  19. data/test/clusterers/diana_test.rb +69 -0
  20. data/test/clusterers/k_means_test.rb +9 -0
  21. data/test/clusterers/median_linkage_test.rb +50 -0
  22. data/test/clusterers/single_linkage_test.rb +15 -6
  23. data/test/clusterers/ward_linkage_test.rb +50 -0
  24. data/test/clusterers/weighted_average_linkage_test.rb +50 -0
  25. data/test/data/data_set_test.rb +14 -0
  26. data/test/data/proximity_test.rb +10 -0
  27. metadata +87 -298
  28. data/site/build/site/en/broken-links.xml +0 -2
  29. data/site/build/site/en/build/tmp/build-info.xml +0 -5
  30. data/site/build/site/en/build/tmp/plugins-1.xml +0 -212
  31. data/site/build/site/en/build/tmp/plugins-2.xml +0 -252
  32. data/site/build/site/en/build/tmp/projfilters.properties +0 -41
  33. data/site/build/site/en/downloads.html +0 -200
  34. data/site/build/site/en/downloads.pdf +0 -151
  35. data/site/build/site/en/geneticAlgorithms.html +0 -591
  36. data/site/build/site/en/geneticAlgorithms.pdf +0 -934
  37. data/site/build/site/en/images/ai4r-logo.png +0 -0
  38. data/site/build/site/en/images/built-with-forrest-button.png +0 -0
  39. data/site/build/site/en/images/c.png +0 -0
  40. data/site/build/site/en/images/c_wbn.png +0 -0
  41. data/site/build/site/en/images/c_wn.png +0 -0
  42. data/site/build/site/en/images/ero.gif +0 -0
  43. data/site/build/site/en/images/europe2.png +0 -0
  44. data/site/build/site/en/images/europe3.png +0 -0
  45. data/site/build/site/en/images/fitness.png +0 -0
  46. data/site/build/site/en/images/genetic_algorithms_example.png +0 -0
  47. data/site/build/site/en/images/instruction_arrow.png +0 -0
  48. data/site/build/site/en/images/jadeferret.png +0 -0
  49. data/site/build/site/en/images/my_email.png +0 -0
  50. data/site/build/site/en/images/neural_network_example.png +0 -0
  51. data/site/build/site/en/images/rubyforge.png +0 -0
  52. data/site/build/site/en/images/s.png +0 -0
  53. data/site/build/site/en/images/s_wbn.png +0 -0
  54. data/site/build/site/en/images/s_wn.png +0 -0
  55. data/site/build/site/en/images/sigmoid.png +0 -0
  56. data/site/build/site/en/images/t.png +0 -0
  57. data/site/build/site/en/images/t_wbn.png +0 -0
  58. data/site/build/site/en/images/t_wn.png +0 -0
  59. data/site/build/site/en/index.html +0 -390
  60. data/site/build/site/en/index.pdf +0 -657
  61. data/site/build/site/en/linkmap.html +0 -261
  62. data/site/build/site/en/linkmap.pdf +0 -94
  63. data/site/build/site/en/locationmap.xml +0 -72
  64. data/site/build/site/en/machineLearning.html +0 -340
  65. data/site/build/site/en/machineLearning.pdf +0 -337
  66. data/site/build/site/en/neuralNetworks.html +0 -521
  67. data/site/build/site/en/neuralNetworks.pdf +0 -671
  68. data/site/build/site/en/skin/CommonMessages_de.xml +0 -23
  69. data/site/build/site/en/skin/CommonMessages_en_US.xml +0 -23
  70. data/site/build/site/en/skin/CommonMessages_es.xml +0 -23
  71. data/site/build/site/en/skin/CommonMessages_fr.xml +0 -23
  72. data/site/build/site/en/skin/basic.css +0 -166
  73. data/site/build/site/en/skin/breadcrumbs-optimized.js +0 -90
  74. data/site/build/site/en/skin/breadcrumbs.js +0 -237
  75. data/site/build/site/en/skin/fontsize.js +0 -166
  76. data/site/build/site/en/skin/getBlank.js +0 -40
  77. data/site/build/site/en/skin/getMenu.js +0 -45
  78. data/site/build/site/en/skin/images/README.txt +0 -1
  79. data/site/build/site/en/skin/images/add.jpg +0 -0
  80. data/site/build/site/en/skin/images/built-with-forrest-button.png +0 -0
  81. data/site/build/site/en/skin/images/chapter.gif +0 -0
  82. data/site/build/site/en/skin/images/chapter_open.gif +0 -0
  83. data/site/build/site/en/skin/images/current.gif +0 -0
  84. data/site/build/site/en/skin/images/error.png +0 -0
  85. data/site/build/site/en/skin/images/external-link.gif +0 -0
  86. data/site/build/site/en/skin/images/fix.jpg +0 -0
  87. data/site/build/site/en/skin/images/forrest-credit-logo.png +0 -0
  88. data/site/build/site/en/skin/images/hack.jpg +0 -0
  89. data/site/build/site/en/skin/images/header_white_line.gif +0 -0
  90. data/site/build/site/en/skin/images/info.png +0 -0
  91. data/site/build/site/en/skin/images/instruction_arrow.png +0 -0
  92. data/site/build/site/en/skin/images/label.gif +0 -0
  93. data/site/build/site/en/skin/images/page.gif +0 -0
  94. data/site/build/site/en/skin/images/pdfdoc.gif +0 -0
  95. data/site/build/site/en/skin/images/poddoc.png +0 -0
  96. data/site/build/site/en/skin/images/printer.gif +0 -0
  97. data/site/build/site/en/skin/images/rc-b-l-15-1body-2menu-3menu.png +0 -0
  98. data/site/build/site/en/skin/images/rc-b-r-15-1body-2menu-3menu.png +0 -0
  99. data/site/build/site/en/skin/images/rc-b-r-5-1header-2tab-selected-3tab-selected.png +0 -0
  100. data/site/build/site/en/skin/images/rc-t-l-5-1header-2searchbox-3searchbox.png +0 -0
  101. data/site/build/site/en/skin/images/rc-t-l-5-1header-2tab-selected-3tab-selected.png +0 -0
  102. data/site/build/site/en/skin/images/rc-t-l-5-1header-2tab-unselected-3tab-unselected.png +0 -0
  103. data/site/build/site/en/skin/images/rc-t-r-15-1body-2menu-3menu.png +0 -0
  104. data/site/build/site/en/skin/images/rc-t-r-5-1header-2searchbox-3searchbox.png +0 -0
  105. data/site/build/site/en/skin/images/rc-t-r-5-1header-2tab-selected-3tab-selected.png +0 -0
  106. data/site/build/site/en/skin/images/rc-t-r-5-1header-2tab-unselected-3tab-unselected.png +0 -0
  107. data/site/build/site/en/skin/images/remove.jpg +0 -0
  108. data/site/build/site/en/skin/images/rss.png +0 -0
  109. data/site/build/site/en/skin/images/spacer.gif +0 -0
  110. data/site/build/site/en/skin/images/success.png +0 -0
  111. data/site/build/site/en/skin/images/txtdoc.png +0 -0
  112. data/site/build/site/en/skin/images/update.jpg +0 -0
  113. data/site/build/site/en/skin/images/valid-html401.png +0 -0
  114. data/site/build/site/en/skin/images/vcss.png +0 -0
  115. data/site/build/site/en/skin/images/warning.png +0 -0
  116. data/site/build/site/en/skin/images/xmldoc.gif +0 -0
  117. data/site/build/site/en/skin/menu.js +0 -48
  118. data/site/build/site/en/skin/note.txt +0 -50
  119. data/site/build/site/en/skin/print.css +0 -54
  120. data/site/build/site/en/skin/profile.css +0 -163
  121. data/site/build/site/en/skin/prototype.js +0 -1257
  122. data/site/build/site/en/skin/screen.css +0 -587
  123. data/site/build/site/en/sourceCode.html +0 -244
  124. data/site/build/site/en/sourceCode.pdf +0 -278
  125. data/site/build/site/en/svn.html +0 -244
  126. data/site/build/site/en/svn.pdf +0 -278
  127. data/site/build/tmp/brokenlinks.xml +0 -2
  128. data/site/build/tmp/build-info.xml +0 -5
  129. data/site/build/tmp/cocoon-work/cache-dir/cocoon-ehcache-1.data +0 -0
  130. data/site/build/tmp/cocoon-work/cache-dir/cocoon-ehcache-1.index +0 -0
  131. data/site/build/tmp/input.xmap +0 -32
  132. data/site/build/tmp/internal.xmap +0 -32
  133. data/site/build/tmp/locationmap.xml +0 -29
  134. data/site/build/tmp/output.xmap +0 -38
  135. data/site/build/tmp/pluginlist2fetchbuild.xml +0 -144
  136. data/site/build/tmp/plugins-1.xml +0 -201
  137. data/site/build/tmp/plugins-2.xml +0 -401
  138. data/site/build/tmp/projfilters.properties +0 -41
  139. data/site/build/tmp/resources.xmap +0 -32
  140. data/site/build/webapp/WEB-INF/logs/access.log +0 -0
  141. data/site/build/webapp/WEB-INF/logs/core.log +0 -775
  142. data/site/build/webapp/WEB-INF/logs/debug.log +0 -0
  143. data/site/build/webapp/WEB-INF/logs/error.log +0 -213
  144. data/site/build/webapp/WEB-INF/logs/flow.log +0 -0
  145. data/site/build/webapp/WEB-INF/logs/idgen.log +0 -0
  146. data/site/build/webapp/WEB-INF/logs/linkrewriter.log +0 -0
  147. data/site/build/webapp/WEB-INF/logs/locationmap.log +0 -0
  148. data/site/build/webapp/WEB-INF/logs/sitemap.log +0 -0
  149. data/site/build/webapp/WEB-INF/logs/xmlform.log +0 -0
  150. data/site/forrest.properties +0 -152
  151. data/site/forrest.properties.dispatcher.properties +0 -25
  152. data/site/forrest.properties.xml +0 -29
  153. data/site/src/documentation/README.txt +0 -7
  154. data/site/src/documentation/classes/CatalogManager.properties +0 -62
  155. data/site/src/documentation/content/locationmap.xml +0 -72
  156. data/site/src/documentation/content/xdocs/downloads.html +0 -9
  157. data/site/src/documentation/content/xdocs/geneticAlgorithms.xml +0 -294
  158. data/site/src/documentation/content/xdocs/index.xml +0 -129
  159. data/site/src/documentation/content/xdocs/machineLearning.xml +0 -131
  160. data/site/src/documentation/content/xdocs/neuralNetworks.xml +0 -270
  161. data/site/src/documentation/content/xdocs/site.xml +0 -54
  162. data/site/src/documentation/content/xdocs/sourceCode.xml +0 -43
  163. data/site/src/documentation/content/xdocs/tabs.xml +0 -35
  164. data/site/src/documentation/resources/images/ai4r-logo.png +0 -0
  165. data/site/src/documentation/resources/images/c.png +0 -0
  166. data/site/src/documentation/resources/images/c_wbn.png +0 -0
  167. data/site/src/documentation/resources/images/c_wn.png +0 -0
  168. data/site/src/documentation/resources/images/ellipse-2.svg +0 -30
  169. data/site/src/documentation/resources/images/ero.gif +0 -0
  170. data/site/src/documentation/resources/images/europe2.png +0 -0
  171. data/site/src/documentation/resources/images/europe3.png +0 -0
  172. data/site/src/documentation/resources/images/fitness.png +0 -0
  173. data/site/src/documentation/resources/images/genetic_algorithms_example.png +0 -0
  174. data/site/src/documentation/resources/images/icon-a.png +0 -0
  175. data/site/src/documentation/resources/images/icon-b.png +0 -0
  176. data/site/src/documentation/resources/images/icon.png +0 -0
  177. data/site/src/documentation/resources/images/jadeferret.png +0 -0
  178. data/site/src/documentation/resources/images/my_email.png +0 -0
  179. data/site/src/documentation/resources/images/neural_network_example.png +0 -0
  180. data/site/src/documentation/resources/images/project-logo.png +0 -0
  181. data/site/src/documentation/resources/images/rubyforge.png +0 -0
  182. data/site/src/documentation/resources/images/s.png +0 -0
  183. data/site/src/documentation/resources/images/s_wbn.png +0 -0
  184. data/site/src/documentation/resources/images/s_wn.png +0 -0
  185. data/site/src/documentation/resources/images/sigmoid.png +0 -0
  186. data/site/src/documentation/resources/images/sub-dir/icon-c.png +0 -0
  187. data/site/src/documentation/resources/images/t.png +0 -0
  188. data/site/src/documentation/resources/images/t_wbn.png +0 -0
  189. data/site/src/documentation/resources/images/t_wn.png +0 -0
  190. data/site/src/documentation/resources/schema/catalog.xcat +0 -29
  191. data/site/src/documentation/resources/schema/hello-v10.dtd +0 -51
  192. data/site/src/documentation/resources/schema/symbols-project-v10.ent +0 -26
  193. data/site/src/documentation/resources/stylesheets/hello2document.xsl +0 -33
  194. data/site/src/documentation/sitemap.xmap +0 -66
  195. data/site/src/documentation/skinconf.xml +0 -418
  196. data/site/src/documentation/translations/langcode.xml +0 -29
  197. data/site/src/documentation/translations/languages_de.xml +0 -24
  198. data/site/src/documentation/translations/languages_en.xml +0 -24
  199. data/site/src/documentation/translations/languages_es.xml +0 -22
  200. data/site/src/documentation/translations/languages_fr.xml +0 -24
  201. data/site/src/documentation/translations/languages_nl.xml +0 -24
  202. data/site/src/documentation/translations/menu.xml +0 -33
  203. data/site/src/documentation/translations/menu_af.xml +0 -33
  204. data/site/src/documentation/translations/menu_de.xml +0 -33
  205. data/site/src/documentation/translations/menu_es.xml +0 -33
  206. data/site/src/documentation/translations/menu_fr.xml +0 -33
  207. data/site/src/documentation/translations/menu_it.xml +0 -33
  208. data/site/src/documentation/translations/menu_nl.xml +0 -33
  209. data/site/src/documentation/translations/menu_no.xml +0 -33
  210. data/site/src/documentation/translations/menu_ru.xml +0 -33
  211. data/site/src/documentation/translations/menu_sk.xml +0 -33
  212. data/site/src/documentation/translations/tabs.xml +0 -22
  213. data/site/src/documentation/translations/tabs_de.xml +0 -22
  214. data/site/src/documentation/translations/tabs_es.xml +0 -22
  215. data/site/src/documentation/translations/tabs_fr.xml +0 -22
  216. data/site/src/documentation/translations/tabs_nl.xml +0 -22
@@ -1,41 +0,0 @@
1
- #Ant properties
2
- #Wed Apr 01 12:23:20 BST 2009
3
- project.sitemap=src/documentation/sitemap.xmap
4
- project.war=/home/sfierens/workspace/ai4r/site/build/site/en/build/my-project.war
5
- project.name=my-project
6
- project.brokenlinkfile=/home/sfierens/workspace/ai4r/site/build/site/en/build/tmp/brokenlinks.xml
7
- project.stylesheets-dir=src/documentation/resources/stylesheets
8
- project.webapp=/home/sfierens/workspace/ai4r/site/build/site/en/build/webapp
9
- project.skinconf=src/documentation/skinconf.xml
10
- project.debuglevel=ERROR
11
- project.skin=pelt
12
- project.configfile=/usr/local/forrest/main/webapp/WEB-INF/cli.xconf
13
- project.images-dir=src/documentation/resources/images
14
- project.conf-dir=src/documentation/conf
15
- project.temp-dir=/home/sfierens/workspace/ai4r/site/build/site/en/build/tmp
16
- project.translations-dir=src/documentation/translations
17
- project.menu-scheme=tab_attributes
18
- project.lib-dir=src/documentation/lib
19
- project.build-dir=/home/sfierens/workspace/ai4r/site/build/site/en/build
20
- project.classes-dir=src/documentation/classes
21
- project.resources-dir=src/documentation/resources
22
- project.grammars-dir=src/documentation/resources/grammars
23
- project.start-uri=linkmap.html
24
- project.sitemap-dir=src/documentation
25
- project.required.plugins.src=/usr/local/forrest/plugins,/usr/local/forrest/whiteboard/plugins
26
- project.logger=debug
27
- project.cocoon-work-dir=/home/sfierens/workspace/ai4r/site/build/site/en/build/tmp/cocoon-work
28
- project.schema-dir=src/documentation/resources/schema
29
- project.status=status.xml
30
- project.xdocs-dir=src/documentation/content/xdocs
31
- project.required.plugins=org.apache.forrest.plugin.output.pdf
32
- project.bugtracking-url=http\://issues.apache.org/jira/browse/
33
- project.skins-dir=src/documentation/skins
34
- project.i18n=false
35
- project.catalog=src/documentation/resources/schema/catalog.xcat
36
- project.site-dir=/home/sfierens/workspace/ai4r/site/build/site/en/build/site
37
- project.site=site
38
- project.raw-content-dir=src/documentation/content
39
- project.content-dir=src/documentation
40
- project.logkitfile=/usr/local/forrest/main/webapp/WEB-INF/logkit.xconf
41
- project.home=/home/sfierens/workspace/ai4r/site/build/site/en
@@ -1,200 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2
- <html>
3
- <head>
4
- <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
5
- <meta content="Apache Forrest" name="Generator">
6
- <meta name="Forrest-version" content="0.8">
7
- <meta name="Forrest-skin-name" content="pelt">
8
- <meta name="generator" content="">
9
- <title>Artificial intelligence for ruby :: ai4r :: download page at RubyForge</title>
10
- <link type="text/css" href="skin/basic.css" rel="stylesheet">
11
- <link media="screen" type="text/css" href="skin/screen.css" rel="stylesheet">
12
- <link media="print" type="text/css" href="skin/print.css" rel="stylesheet">
13
- <link type="text/css" href="skin/profile.css" rel="stylesheet">
14
- <script src="skin/getBlank.js" language="javascript" type="text/javascript"></script><script src="skin/getMenu.js" language="javascript" type="text/javascript"></script><script src="skin/fontsize.js" language="javascript" type="text/javascript"></script>
15
- <link rel="shortcut icon" href="">
16
- </head>
17
- <body onload="init()">
18
- <script type="text/javascript">ndeSetTextSize();</script>
19
- <div id="top">
20
- <!--+
21
- |header
22
- +-->
23
- <div class="header">
24
- <!--+
25
- |start group logo
26
- +-->
27
- <div class="grouplogo">
28
- <a href="http://www.jadeferret.com"><img class="logoImage" alt="Jade Ferret" src="images/jadeferret.png" title="Jade Ferret"></a>
29
- </div>
30
- <!--+
31
- |end group logo
32
- +-->
33
- <!--+
34
- |start Project Logo
35
- +-->
36
- <div class="projectlogo">
37
- <a href="http://ai4r.rubyforge.org/"><img class="logoImage" alt="ai4r" src="images/ai4r-logo.png" title="AI4R - Artificial Intelligence for Ruby"></a>
38
- </div>
39
- <!--+
40
- |end Project Logo
41
- +-->
42
- <!--+
43
- |start Search
44
- +-->
45
- <div class="searchbox">
46
- <div class="roundtopsmall">
47
- <form target="_top" action="http://www.google.com/custom" method="get">
48
- <input value="ai4r.rubyforge.org;raa.ruby-lang.org;rubyforge.org" name="domains" type="hidden"><label style="display: none" for="sbi">Enter your search terms</label><input id="sbi" value="" maxlength="255" size="31" name="q" type="text"><label style="display: none" for="sbb">Submit search form</label><input id="sbb" value="Search" name="sa" type="submit"><span style="display:none"><input id="ss0" value="" name="sitesearch" style="display=none" type="radio"><input id="ss1" checked value="ai4r.rubyforge.org" name="sitesearch" style="display=none" type="radio"><input id="ss2" value="raa.ruby-lang.org" name="sitesearch" style="display=none" type="radio"><input id="ss3" value="rubyforge.org" name="sitesearch" style="display=none" type="radio"></span><input value="pub-2578934938711895" name="client" type="hidden"><input value="1" name="forid" type="hidden"><input value="ISO-8859-1" name="ie" type="hidden"><input value="ISO-8859-1" name="oe" type="hidden"><input value="active" name="safe" type="hidden"><input value="0000" name="flav" type="hidden"><input value="XEZZoGuMPMQqvUG_" name="sig" type="hidden"><input value="GALT:#008000;GL:1;DIV:#336699;VLC:663399;AH:center;BGC:FFFFFF;LBGC:336699;ALC:0000FF;LC:0000FF;T:000000;GFNT:0000FF;GIMP:0000FF;LH:50;LW:78;L:http://ai4r.rubyforge.org/images/ai4r-logo.png;S:http://ai4r.rubyforge.org/;FORID:1" name="cof" type="hidden"><input value="en" name="hl" type="hidden">
49
- </form>
50
- </div>
51
- </div>
52
- <!--+
53
- |end search
54
- +-->
55
- <!--+
56
- |start Tabs
57
- +-->
58
- <ul id="tabs">
59
- <li class="current">
60
- <a class="selected" href="index.html">Home</a>
61
- </li>
62
- </ul>
63
- <!--+
64
- |end Tabs
65
- +-->
66
- </div>
67
- </div>
68
- <div id="main">
69
- <div id="publishedStrip">
70
- <!--+
71
- |start Subtabs
72
- +-->
73
- <div id="level2tabs"></div>
74
- <!--+
75
- |end Endtabs
76
- +-->
77
- <script type="text/javascript"><!--
78
- document.write("Last Published: " + document.lastModified);
79
- // --></script>
80
- </div>
81
- <!--+
82
- |breadtrail
83
- +-->
84
- <div class="breadtrail">
85
-
86
- &nbsp;
87
- </div>
88
- <!--+
89
- |start Menu, mainarea
90
- +-->
91
- <!--+
92
- |start Menu
93
- +-->
94
- <div id="menu">
95
- <div onclick="SwitchMenu('menu_selected_1.1', 'skin/')" id="menu_selected_1.1Title" class="menutitle" style="background-image: url('skin/images/chapter_open.gif');">Home</div>
96
- <div id="menu_selected_1.1" class="selectedmenuitemgroup" style="display: block;">
97
- <div class="menuitem">
98
- <a href="index.html" title="ai4r - Artificial Intelligence for Ruby">Index</a>
99
- </div>
100
- <div onclick="SwitchMenu('menu_1.1.2', 'skin/')" id="menu_1.1.2Title" class="menutitle">Practical Examples</div>
101
- <div id="menu_1.1.2" class="menuitemgroup">
102
- <div class="menuitem">
103
- <a href="geneticAlgorithms.html" title="Genetic Algorithms in ruby">Genetic Algorithms</a>
104
- </div>
105
- <div class="menuitem">
106
- <a href="machineLearning.html" title="ID3 Decision Trees in ruby">Machine Learning</a>
107
- </div>
108
- <div class="menuitem">
109
- <a href="neuralNetworks.html" title="Backpropagation Neural Network in ruby">Neural Networks</a>
110
- </div>
111
- </div>
112
- <div class="menupage">
113
- <div class="menupagetitle">Downloads</div>
114
- </div>
115
- <div class="menuitem">
116
- <a href="http://forum.jadeferret.com/viewforum.php?f=3" title="Ai4r Forum">Forum</a>
117
- </div>
118
- <div class="menuitem">
119
- <a href="sourceCode.html" title="ai4r source code repository">Source Code repository</a>
120
- </div>
121
- <div class="menuitem">
122
- <a href="http://wiki.jadeferret.com/Category:AI4R" title="ai4r wiki with How-to guides and more documentation">AI4R Wiki</a>
123
- </div>
124
- <div class="menuitem">
125
- <a href="http://ai4r.rubyforge.org/rdoc/index.html" title="Ai4 RDoc docs">API doc (Rdoc)</a>
126
- </div>
127
- </div>
128
- <div id="credit">
129
- <script type="text/javascript">
130
- google_ad_client = "pub-2578934938711895";
131
- google_ad_slot = "6111091580";
132
- google_ad_width = 125;
133
- google_ad_height = 125;
134
- </script><script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script>
135
- <hr>
136
- </div>
137
- <div id="roundbottom">
138
- <img style="display: none" class="corner" height="15" width="15" alt="" src="skin/images/rc-b-l-15-1body-2menu-3menu.png"></div>
139
- <!--+
140
- |alternative credits
141
- +-->
142
- <div id="credit2"></div>
143
- </div>
144
- <!--+
145
- |end Menu
146
- +-->
147
- <!--+
148
- |start content
149
- +-->
150
- <div id="content">
151
- <div title="Portable Document Format" class="pdflink">
152
- <a class="dida" href="downloads.pdf"><img alt="PDF -icon" src="skin/images/pdfdoc.gif" class="skin"><br>
153
- PDF</a>
154
- </div>
155
- <h1>Artificial intelligence for ruby :: ai4r :: download page at RubyForge</h1>
156
- <div id="minitoc-area">
157
- <ul class="minitoc">
158
- <li>
159
- <a href="#intro">Artificial intelligence for ruby - ai4r - download page at RubyForge</a>
160
- </li>
161
- </ul>
162
- </div>
163
- <a name="N10010"></a><a name="intro"></a>
164
- <h2 class="boxed">Artificial intelligence for ruby - ai4r - download page at RubyForge</h2>
165
- <div class="section">
166
- <iframe frameborder="0" height="800px" src="http://rubyforge.org/frs/?group_id=4942" width="100%"></iframe>
167
- </div>
168
- </div>
169
- <!--+
170
- |end content
171
- +-->
172
- <div class="clearboth">&nbsp;</div>
173
- </div>
174
- <div id="footer">
175
- <!--+
176
- |start bottomstrip
177
- +-->
178
- <div class="lastmodified">
179
- <script type="text/javascript"><!--
180
- document.write("Last Published: " + document.lastModified);
181
- // --></script>
182
- </div>
183
- <div class="copyright">
184
- Copyright &copy;
185
- 2007-2009 <a href="http://www.jadeferret.com/">Sergio Fierens, Jade Ferret</a>
186
- </div>
187
- <div class="host">
188
- <a href="http://rubyforge.org/projects/ai4r/"><img class="logoImage" alt="" src="images/rubyforge.png"></a>
189
- </div>
190
- <!--+
191
- |end bottomstrip
192
- +-->
193
- </div>
194
- <script src="http://www.google-analytics.com/ga.js" type="text/javascript"></script><script type="text/javascript">
195
- var pageTracker = _gat._getTracker("UA-3234625-1");
196
- pageTracker._initData();
197
- pageTracker._trackPageview();
198
- </script>
199
- </body>
200
- </html>
@@ -1,151 +0,0 @@
1
- %PDF-1.3
2
- %����
3
- 4 0 obj
4
- << /Type /Info
5
- /Producer (FOP 0.20.5) >>
6
- endobj
7
- 5 0 obj
8
- << /Length 485 /Filter [ /ASCII85Decode /FlateDecode ]
9
- >>
10
- stream
11
- Gas1\_,>n>&A@ZMlO@JP9gV0[a)Ru!jNsC=9g);YQl1Pq:rg<e8DAg_#RC(jk3['[/Xt6o,U$!=0VkP#a%u,3W&t-+GR5ok?c4W*UDVE<Gk0It=/F&><aS0Y76JM:eb$/M<@+,>>&W)/$hVL-gS36@g6lDr*dN<YHe&3(D$NN,e^SG:=OKC6S@VjAm>%BOdcrPLAR-Pa#W:5)<T'Aj&i3JFqB?2]NZbhlYlt^4(HZ.U$7!G`ZX#`%_oIkrQIa@9@8]hWSapbCGb0uSYrt:\Qbqf.mch(7a[C>Kch0#(ch0$LK0BJZoe@l!k#%^W!ETKc3Qc:`p==CtQn\C:)2LZl'TN_!oPjiBe9dgREuI'T!XT?Q.Y&,mTI#iZ]selGR\&Z!;+q/Rc;#$-9Io80$kY]4mC(i#CK8&/S+B<6Z%uj?/:*Pl;Q[opP$0d"Q1\t"_V*!uC+Z"3le;/[VRi=NALI/K/<IR=&&Vl,D?~>
12
- endstream
13
- endobj
14
- 6 0 obj
15
- << /Type /Page
16
- /Parent 1 0 R
17
- /MediaBox [ 0 0 612 792 ]
18
- /Resources 3 0 R
19
- /Contents 5 0 R
20
- /Annots 7 0 R
21
- >>
22
- endobj
23
- 7 0 obj
24
- [
25
- 8 0 R
26
- ]
27
- endobj
28
- 8 0 obj
29
- << /Type /Annot
30
- /Subtype /Link
31
- /Rect [ 102.0 519.166 435.272 507.166 ]
32
- /C [ 0 0 0 ]
33
- /Border [ 0 0 0 ]
34
- /A 9 0 R
35
- /H /I
36
- >>
37
- endobj
38
- 10 0 obj
39
- << /Length 467 /Filter [ /ASCII85Decode /FlateDecode ]
40
- >>
41
- stream
42
- Garo>9iHZu&;KZL'mm#<2J,<C6>ru9Sa"6,DX)e]!Af@);q1'H2jDb;C53[iG;iZLp>&kDmS`UI(tFEl#/A/_$,7fL&I@;%\=@rX#Egd`+I9mZKl$KnPS>>CcG5T*P$(CpjpJ=UOQM3^5nKE5&A"ndo#G625N$++oErTc?Y2-;NQpk5An?eOW\J(!$WF0$Luu)Q_L4"[6&ic?Zbl[1=P#c;=_I%3fjr'pI+EuLPHR0R?(6:qFQ(V,BI[2kSr+nc9!(CQ#NJA\FpauY9iT@:nf/;JUnd@WNe,=57.tSdnjCE,Yf@/PRM0rVgJ*PaE,Q^O7?p!&c7#$]j*C)QT!q/bG!nBC6r9uq?$SF0!Bt0IZGXUWm>"FHjp%*C5V580hdGeCh:A'dZc.8]TNeU+\\t.#@k+EiisJuq4h&G!C3psFMem57H/kD4e=Mt;&Gtp6#MO!Rq_i4.qXt;J9?7Y~>
43
- endstream
44
- endobj
45
- 11 0 obj
46
- << /Type /Page
47
- /Parent 1 0 R
48
- /MediaBox [ 0 0 612 792 ]
49
- /Resources 3 0 R
50
- /Contents 10 0 R
51
- >>
52
- endobj
53
- 13 0 obj
54
- <<
55
- /Title (\376\377\0\61\0\40\0\101\0\162\0\164\0\151\0\146\0\151\0\143\0\151\0\141\0\154\0\40\0\151\0\156\0\164\0\145\0\154\0\154\0\151\0\147\0\145\0\156\0\143\0\145\0\40\0\146\0\157\0\162\0\40\0\162\0\165\0\142\0\171\0\40\0\55\0\40\0\141\0\151\0\64\0\162\0\40\0\55\0\40\0\144\0\157\0\167\0\156\0\154\0\157\0\141\0\144\0\40\0\160\0\141\0\147\0\145\0\40\0\141\0\164\0\40\0\122\0\165\0\142\0\171\0\106\0\157\0\162\0\147\0\145)
56
- /Parent 12 0 R
57
- /A 9 0 R
58
- >> endobj
59
- 14 0 obj
60
- << /Type /Font
61
- /Subtype /Type1
62
- /Name /F3
63
- /BaseFont /Helvetica-Bold
64
- /Encoding /WinAnsiEncoding >>
65
- endobj
66
- 15 0 obj
67
- << /Type /Font
68
- /Subtype /Type1
69
- /Name /F5
70
- /BaseFont /Times-Roman
71
- /Encoding /WinAnsiEncoding >>
72
- endobj
73
- 16 0 obj
74
- << /Type /Font
75
- /Subtype /Type1
76
- /Name /F1
77
- /BaseFont /Helvetica
78
- /Encoding /WinAnsiEncoding >>
79
- endobj
80
- 17 0 obj
81
- << /Type /Font
82
- /Subtype /Type1
83
- /Name /F2
84
- /BaseFont /Helvetica-Oblique
85
- /Encoding /WinAnsiEncoding >>
86
- endobj
87
- 18 0 obj
88
- << /Type /Font
89
- /Subtype /Type1
90
- /Name /F7
91
- /BaseFont /Times-Bold
92
- /Encoding /WinAnsiEncoding >>
93
- endobj
94
- 1 0 obj
95
- << /Type /Pages
96
- /Count 2
97
- /Kids [6 0 R 11 0 R ] >>
98
- endobj
99
- 2 0 obj
100
- << /Type /Catalog
101
- /Pages 1 0 R
102
- /Outlines 12 0 R
103
- /PageMode /UseOutlines
104
- >>
105
- endobj
106
- 3 0 obj
107
- <<
108
- /Font << /F3 14 0 R /F5 15 0 R /F1 16 0 R /F2 17 0 R /F7 18 0 R >>
109
- /ProcSet [ /PDF /ImageC /Text ] >>
110
- endobj
111
- 9 0 obj
112
- <<
113
- /S /GoTo
114
- /D [11 0 R /XYZ 85.0 659.0 null]
115
- >>
116
- endobj
117
- 12 0 obj
118
- <<
119
- /First 13 0 R
120
- /Last 13 0 R
121
- >> endobj
122
- xref
123
- 0 19
124
- 0000000000 65535 f
125
- 0000002622 00000 n
126
- 0000002687 00000 n
127
- 0000002779 00000 n
128
- 0000000015 00000 n
129
- 0000000071 00000 n
130
- 0000000647 00000 n
131
- 0000000767 00000 n
132
- 0000000792 00000 n
133
- 0000002902 00000 n
134
- 0000000927 00000 n
135
- 0000001486 00000 n
136
- 0000002965 00000 n
137
- 0000001594 00000 n
138
- 0000002066 00000 n
139
- 0000002179 00000 n
140
- 0000002289 00000 n
141
- 0000002397 00000 n
142
- 0000002513 00000 n
143
- trailer
144
- <<
145
- /Size 19
146
- /Root 2 0 R
147
- /Info 4 0 R
148
- >>
149
- startxref
150
- 3016
151
- %%EOF
@@ -1,591 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2
- <html>
3
- <head>
4
- <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
5
- <meta content="Apache Forrest" name="Generator">
6
- <meta name="Forrest-version" content="0.8">
7
- <meta name="Forrest-skin-name" content="pelt">
8
- <title>Genetics Algorithms in Ruby :: ai4r</title>
9
- <link type="text/css" href="skin/basic.css" rel="stylesheet">
10
- <link media="screen" type="text/css" href="skin/screen.css" rel="stylesheet">
11
- <link media="print" type="text/css" href="skin/print.css" rel="stylesheet">
12
- <link type="text/css" href="skin/profile.css" rel="stylesheet">
13
- <script src="skin/getBlank.js" language="javascript" type="text/javascript"></script><script src="skin/getMenu.js" language="javascript" type="text/javascript"></script><script src="skin/fontsize.js" language="javascript" type="text/javascript"></script>
14
- <link rel="shortcut icon" href="">
15
- </head>
16
- <body onload="init()">
17
- <script type="text/javascript">ndeSetTextSize();</script>
18
- <div id="top">
19
- <!--+
20
- |header
21
- +-->
22
- <div class="header">
23
- <!--+
24
- |start group logo
25
- +-->
26
- <div class="grouplogo">
27
- <a href="http://www.jadeferret.com"><img class="logoImage" alt="Jade Ferret" src="images/jadeferret.png" title="Jade Ferret"></a>
28
- </div>
29
- <!--+
30
- |end group logo
31
- +-->
32
- <!--+
33
- |start Project Logo
34
- +-->
35
- <div class="projectlogo">
36
- <a href="http://ai4r.rubyforge.org/"><img class="logoImage" alt="ai4r" src="images/ai4r-logo.png" title="AI4R - Artificial Intelligence for Ruby"></a>
37
- </div>
38
- <!--+
39
- |end Project Logo
40
- +-->
41
- <!--+
42
- |start Search
43
- +-->
44
- <div class="searchbox">
45
- <div class="roundtopsmall">
46
- <form target="_top" action="http://www.google.com/custom" method="get">
47
- <input value="ai4r.rubyforge.org;raa.ruby-lang.org;rubyforge.org" name="domains" type="hidden"><label style="display: none" for="sbi">Enter your search terms</label><input id="sbi" value="" maxlength="255" size="31" name="q" type="text"><label style="display: none" for="sbb">Submit search form</label><input id="sbb" value="Search" name="sa" type="submit"><span style="display:none"><input id="ss0" value="" name="sitesearch" style="display=none" type="radio"><input id="ss1" checked value="ai4r.rubyforge.org" name="sitesearch" style="display=none" type="radio"><input id="ss2" value="raa.ruby-lang.org" name="sitesearch" style="display=none" type="radio"><input id="ss3" value="rubyforge.org" name="sitesearch" style="display=none" type="radio"></span><input value="pub-2578934938711895" name="client" type="hidden"><input value="1" name="forid" type="hidden"><input value="ISO-8859-1" name="ie" type="hidden"><input value="ISO-8859-1" name="oe" type="hidden"><input value="active" name="safe" type="hidden"><input value="0000" name="flav" type="hidden"><input value="XEZZoGuMPMQqvUG_" name="sig" type="hidden"><input value="GALT:#008000;GL:1;DIV:#336699;VLC:663399;AH:center;BGC:FFFFFF;LBGC:336699;ALC:0000FF;LC:0000FF;T:000000;GFNT:0000FF;GIMP:0000FF;LH:50;LW:78;L:http://ai4r.rubyforge.org/images/ai4r-logo.png;S:http://ai4r.rubyforge.org/;FORID:1" name="cof" type="hidden"><input value="en" name="hl" type="hidden">
48
- </form>
49
- </div>
50
- </div>
51
- <!--+
52
- |end search
53
- +-->
54
- <!--+
55
- |start Tabs
56
- +-->
57
- <ul id="tabs">
58
- <li class="current">
59
- <a class="selected" href="index.html">Home</a>
60
- </li>
61
- </ul>
62
- <!--+
63
- |end Tabs
64
- +-->
65
- </div>
66
- </div>
67
- <div id="main">
68
- <div id="publishedStrip">
69
- <!--+
70
- |start Subtabs
71
- +-->
72
- <div id="level2tabs"></div>
73
- <!--+
74
- |end Endtabs
75
- +-->
76
- <script type="text/javascript"><!--
77
- document.write("Last Published: " + document.lastModified);
78
- // --></script>
79
- </div>
80
- <!--+
81
- |breadtrail
82
- +-->
83
- <div class="breadtrail">
84
-
85
- &nbsp;
86
- </div>
87
- <!--+
88
- |start Menu, mainarea
89
- +-->
90
- <!--+
91
- |start Menu
92
- +-->
93
- <div id="menu">
94
- <div onclick="SwitchMenu('menu_selected_1.1', 'skin/')" id="menu_selected_1.1Title" class="menutitle" style="background-image: url('skin/images/chapter_open.gif');">Home</div>
95
- <div id="menu_selected_1.1" class="selectedmenuitemgroup" style="display: block;">
96
- <div class="menuitem">
97
- <a href="index.html" title="ai4r - Artificial Intelligence for Ruby">Index</a>
98
- </div>
99
- <div onclick="SwitchMenu('menu_selected_1.1.2', 'skin/')" id="menu_selected_1.1.2Title" class="menutitle" style="background-image: url('skin/images/chapter_open.gif');">Practical Examples</div>
100
- <div id="menu_selected_1.1.2" class="selectedmenuitemgroup" style="display: block;">
101
- <div class="menupage">
102
- <div class="menupagetitle">Genetic Algorithms</div>
103
- </div>
104
- <div class="menuitem">
105
- <a href="machineLearning.html" title="ID3 Decision Trees in ruby">Machine Learning</a>
106
- </div>
107
- <div class="menuitem">
108
- <a href="neuralNetworks.html" title="Backpropagation Neural Network in ruby">Neural Networks</a>
109
- </div>
110
- </div>
111
- <div class="menuitem">
112
- <a href="downloads.html" title="ai4r - Download Files">Downloads</a>
113
- </div>
114
- <div class="menuitem">
115
- <a href="http://forum.jadeferret.com/viewforum.php?f=3" title="Ai4r Forum">Forum</a>
116
- </div>
117
- <div class="menuitem">
118
- <a href="sourceCode.html" title="ai4r source code repository">Source Code repository</a>
119
- </div>
120
- <div class="menuitem">
121
- <a href="http://wiki.jadeferret.com/Category:AI4R" title="ai4r wiki with How-to guides and more documentation">AI4R Wiki</a>
122
- </div>
123
- <div class="menuitem">
124
- <a href="http://ai4r.rubyforge.org/rdoc/index.html" title="Ai4 RDoc docs">API doc (Rdoc)</a>
125
- </div>
126
- </div>
127
- <div id="credit">
128
- <script type="text/javascript">
129
- google_ad_client = "pub-2578934938711895";
130
- google_ad_slot = "6111091580";
131
- google_ad_width = 125;
132
- google_ad_height = 125;
133
- </script><script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script>
134
- <hr>
135
- </div>
136
- <div id="roundbottom">
137
- <img style="display: none" class="corner" height="15" width="15" alt="" src="skin/images/rc-b-l-15-1body-2menu-3menu.png"></div>
138
- <!--+
139
- |alternative credits
140
- +-->
141
- <div id="credit2"></div>
142
- </div>
143
- <!--+
144
- |end Menu
145
- +-->
146
- <!--+
147
- |start content
148
- +-->
149
- <div id="content">
150
- <div title="Portable Document Format" class="pdflink">
151
- <a class="dida" href="geneticAlgorithms.pdf"><img alt="PDF -icon" src="skin/images/pdfdoc.gif" class="skin"><br>
152
- PDF</a>
153
- </div>
154
- <h1>Genetics Algorithms in Ruby :: ai4r</h1>
155
- <div id="minitoc-area">
156
- <ul class="minitoc">
157
- <li>
158
- <a href="#Example">The European Rock Tour Problem (Also known as the Travelling salesman problem)</a>
159
- </li>
160
- <li>
161
- <a href="#Introduction">Introduction to Genetics Algorithms in Ruby</a>
162
- </li>
163
- <li>
164
- <a href="#chromosome-impl">Implementation of Chromosome class for the Travelling salesman problem</a>
165
- <ul class="minitoc">
166
- <li>
167
- <a href="#chromosome-impl-data">Data representation</a>
168
- </li>
169
- <li>
170
- <a href="#chromosome-impl-fitness">Fitness function</a>
171
- </li>
172
- <li>
173
- <a href="#chromosome-impl-reproduce">Reproduce function</a>
174
- </li>
175
- <li>
176
- <a href="#chromosome-impl-mutation">Mutation function</a>
177
- </li>
178
- <li>
179
- <a href="#chromosome-impl-seed">Seed function</a>
180
- </li>
181
- </ul>
182
- </li>
183
- <li>
184
- <a href="#search-impl">Implementation of GeneticSearch</a>
185
- <ul class="minitoc">
186
- <li>
187
- <a href="#search-impl-init">Initialize the search</a>
188
- </li>
189
- <li>
190
- <a href="#search-impl-run">Run method</a>
191
- </li>
192
- <li>
193
- <a href="#search-impl-selection">Selection</a>
194
- </li>
195
- <li>
196
- <a href="#search-impl-reproduction">Reproduction</a>
197
- </li>
198
- </ul>
199
- </li>
200
- <li>
201
- <a href="#how-to-run">How to use AI4R Genetic Search implementation</a>
202
- </li>
203
- <li>
204
- <a href="#example-run">How to run the example</a>
205
- </li>
206
- <li>
207
- <a href="#Results">Results of using Genetic Algorithms to the The European Rock Tour Problem (or Travelling salesman problem)</a>
208
- </li>
209
- <li>
210
- <a href="#more-genetic-run">More about Genetic Algorithms and the Travelling salesman problem</a>
211
- </li>
212
- </ul>
213
- </div>
214
-
215
- <a name="N1000C"></a><a name="Example"></a>
216
- <h2 class="boxed">The European Rock Tour Problem (Also known as the Travelling salesman problem)</h2>
217
- <div class="section">
218
- <p>An ageing rock band was planning its (hopefully) last european tour. They were planning to visite 15 european cities: Barcelona, Berlin, Brussels, Dublin, Hamburg, Kiev, London, Madrid, Milan, Moscow, Munich, Paris, Rome, Vienna, and Warsaw.</p>
219
- <p>
220
- <img alt="European Tour" src="images/europe2.png"></p>
221
- <p>They start planning the trip, when they realize that they could save a lot of money, if they ordered the cities to minimize the traveling cost. So they decided to try all possible combinations. The sat in front of the computer, visited they favorite traveling site, and started typing. 53 hours and several liters of coffee later, they realized it was a little bit more complicated than what they expected. They called their drummer (who was on vacations) and explained the problem to him. Fortunately, their drummer had a Master in Computer Science degree.</p>
222
- <p>
223
- <em><strong>Drummer</strong> &ndash; Boys, if you continue, you will have to try 1,307,674,368,000 combinations. You are in front of a NP Problem.</em>
224
-
225
- </p>
226
- <p>
227
- <em><strong>Band member #1</strong> &ndash; Oh man! So it is going to take us all day!</em>
228
-
229
- </p>
230
- <p>
231
- <em><strong>Band member #2</strong> &ndash; And maybe more, 'cause this internet connection sucks...</em>
232
-
233
- </p>
234
- <p>
235
- <em><strong>Drummer</strong> &ndash; err... yes, it would take a while. But don't worry, I am sure we can get to a good solution using stochastic search algorithms applied to this problem..</em>
236
-
237
- </p>
238
- <p>
239
- <em><strong>Band</strong> &ndash; (Silence)</em>
240
-
241
- </p>
242
- <p>
243
- <em><strong>Drummer</strong> &ndash; .. that is, we are going to move from solution to solution in the space of candidate solutions, using techniques similar to what nature use for evolution, these are known as genetic algorithms.</em>
244
-
245
- </p>
246
- <p>
247
- <em><strong>Band</strong> &ndash; (Silence)</em>
248
-
249
- </p>
250
- <p>
251
- <em><strong>Drummer</strong> - ... What I mean is, we will pick some of them randomly, leave the ugly ones behind, and mate with the good looking ones...</em>
252
-
253
- </p>
254
- <p>
255
- <em><strong>Band</strong> &ndash; YEAH! THAT'S THE MAN! LET'S DO IT!</em>
256
-
257
- </p>
258
- <p>I forgot to tell another restriction of this problem: This band is really bad (What did you expect? Their drummer is a computer geek!) so once they visited a city, they cannot go back there.
259
- </p>
260
- </div>
261
-
262
-
263
- <a name="N10060"></a><a name="Introduction"></a>
264
- <h2 class="boxed">Introduction to Genetics Algorithms in Ruby</h2>
265
- <div class="section">
266
- <p>A Genetic Algorithm is a particular class of evolutionary algorithm and stochastic search.
267
- It aims to find the best possible solution in a solution domain, by selecting a simple
268
- set of solutions (chosed randomly or with a simple heuristic), and making it "evolve".
269
- </p>
270
- <p>It works based on the following pseudocode:</p>
271
- <ol>
272
-
273
- <li>Choose initial population</li>
274
-
275
- <li>Evaluate the fitness of each individual in the population</li>
276
-
277
- <li>Repeat as many times as generations we allow
278
- <ol>
279
-
280
- <li>Select randomly best-ranking individuals to reproduce</li>
281
-
282
- <li>Breed new generation through crossover and mutation (genetic operations) and give birth to offspring</li>
283
-
284
- <li>Evaluate the individual fitnesses of the offspring</li>
285
-
286
- <li>Replace worst ranked part of population with offspring</li>
287
-
288
- </ol>
289
-
290
- </li>
291
-
292
- </ol>
293
- </div>
294
-
295
-
296
- <a name="N10088"></a><a name="chromosome-impl"></a>
297
- <h2 class="boxed">Implementation of Chromosome class for the Travelling salesman problem</h2>
298
- <div class="section">
299
- <p>In AI4R, the GeneticAlgorithm module implements the GeneticSearch and Chromosome classes.
300
- GeneticSearch is a generic class, and can be used to solved any kind of problems.
301
- The GeneticSearch class performs a stochastic search following the algorithm mentioned in the
302
- previous section.
303
- </p>
304
- <p>
305
- However, the Chromosome class implementation is problem specific.
306
- Ai4r built-in Chromosomeclass was designed to model the
307
- <a class="external" href="http://en.wikipedia.org/wiki/Traveling_salesman_problem">
308
- Travelling salesman problem.
309
- </a>
310
- You have to provide a matrix with the cost of traveling from one point to another
311
- (array of arrays of float values).
312
- If you want to solve other type of problem, you will have to modify the Chromosome class,
313
- by overwriting its fitness, reproduce, and mutate functions, to model you specific problem.
314
- </p>
315
- <a name="N10099"></a><a name="chromosome-impl-data"></a>
316
- <h3 class="boxed">Data representation</h3>
317
- <p>Each chromosome must represent a posible solution for the problem. This class conatins an array
318
- with the list of visited nodes (cities of the tour). The size of the tour is obtained automatically from the traveling costs matrix. You have to assign the costs matrix BEFORE you run the genetic search. The following costs matrix could be used to solve the problem with only 3 cities:</p>
319
- <pre class="code">
320
-
321
- data_set = [ [ 0, 10, 5],
322
- [ 6, 0, 4],
323
- [25, 4, 0]
324
- ]
325
- Ai4r::GeneticAlgorithm::Chromosome.set_cost_matrix(data_set)
326
-
327
- </pre>
328
- <a name="N100A7"></a><a name="chromosome-impl-fitness"></a>
329
- <h3 class="boxed">Fitness function</h3>
330
- <p>The fitness function quantifies the optimality of a solution (that is, a chromosome) in a genetic algorithm so that that particular chromosome may be ranked against all the other chromosomes.
331
- Optimal chromosomes, or at least chromosomes which are more optimal, are allowed to breed and mix their datasets by any of several techniques, producing a new generation that will (hopefully) be even better.</p>
332
- <p>The fitness function will return the complete tour cost represented by the chromosome, multiplied by -1.
333
- For example:</p>
334
- <pre class="code">
335
-
336
- data_set = [ [ 0, 10, 5],
337
- [ 6, 0, 4],
338
- [25, 4, 0]
339
- ]
340
- Ai4r::GeneticAlgorithm::Chromosome.set_cost_matrix(data_set)
341
- chromosome = Ai4r::GeneticAlgorithm::Chromosome.new([0, 2, 1])
342
- chromosome.fitness
343
- # =&gt; -9
344
-
345
- </pre>
346
- <p>That is: From 0 to 2 costs 5. From 2 to 1 costs 4. Total cost is 9.</p>
347
- <a name="N100BB"></a><a name="chromosome-impl-reproduce"></a>
348
- <h3 class="boxed">Reproduce function</h3>
349
- <p>Reproduction is used to vary the programming of a chromosome or chromosomes from one generation to the next. There are several ways to combine two chromosomes: One-point crossover, Two-point crossover, "Cut and splice", edge recombination, and more. The method is usually dependant of the problem domain. In this case, we have implemented edge recombination, wich is the most used reproduction algorithm for the Travelling salesman problem. The edge recombination operator (ERO) is an operator that creates a path that is similar to a set of existing paths (parents) by looking at the edges rather than the vertices.</p>
350
- <p>
351
- <img alt="Edge recombination" src="images/ero.gif"></p>
352
- <p>The previous image was taken from the wikipedia, so hail to the author: Koala man (not me).</p>
353
- <a name="N100CD"></a><a name="chromosome-impl-mutation"></a>
354
- <h3 class="boxed">Mutation function</h3>
355
- <p>Mutation funtion will be called fro every member of the population, on each generations. But you do not want to mutate your chromosomes every time, specialy if the are very fit. This is how it is currently implemented: With a probabilty of changing inversely proportional to its fitness, we swap 2 consecutive random nodes.</p>
356
- <pre class="code">
357
-
358
- def self.mutate(chromosome)
359
- if chromosome.normalized_fitness &amp;&amp; rand &lt; ((1 - chromosome.normalized_fitness) * 0.3)
360
- data = chromosome.data
361
- index = rand(data.length-1)
362
- data[index], data[index+1] = data[index+1], data[index]
363
- chromosome.data = data
364
- @fitness = nil
365
- end
366
- end
367
-
368
- </pre>
369
- <a name="N100DB"></a><a name="chromosome-impl-seed"></a>
370
- <h3 class="boxed">Seed function</h3>
371
- <p>Initializes an individual solution (chromosome) for the initial population. The built in seed function generates a chromosome randomly, but you can use some problem domain knowledge, to generate better initial solutions (although this not always deliver better results, it improves convergency times).</p>
372
- <pre class="code">
373
-
374
- def self.seed
375
- data_size = @@costs[0].length
376
- available = []
377
- 0.upto(data_size-1) { |n| available &lt;&lt; n }
378
- seed = []
379
- while available.length &gt; 0 do
380
- index = rand(available.length)
381
- seed &lt;&lt; available.delete_at(index)
382
- end
383
- return Chromosome.new(seed)
384
- end
385
-
386
- </pre>
387
- </div>
388
-
389
-
390
- <a name="N100EA"></a><a name="search-impl"></a>
391
- <h2 class="boxed">Implementation of GeneticSearch</h2>
392
- <div class="section">
393
- <p>The GeneticSearch class is an generic class to try to solve any kind of problem using genetic algorithms. If you
394
- want to model another type of problem, you will have to modify the Chromosome class, defining its fitness, mutate, and reproduce functions.</p>
395
- <a name="N100F3"></a><a name="search-impl-init"></a>
396
- <h3 class="boxed">Initialize the search</h3>
397
- <p>You have to provide two parameters during instantiation: The initial population size, and the how many generations produce. Large numbers will usually converge to better results, while small numbers will have better performance.</p>
398
- <pre class="code">
399
-
400
- search = Ai4r::GeneticAlgorithm::GeneticSearch.new(10, 20)
401
- result = search.run
402
-
403
- </pre>
404
- <a name="N10101"></a><a name="search-impl-run"></a>
405
- <h3 class="boxed">Run method</h3>
406
- <p>Once you initialize an instance of GeneticSearch class, you can perform the search executing the run method.
407
- This method will:</p>
408
- <ol>
409
-
410
- <li>Choose initial population</li>
411
-
412
- <li>Evaluate the fitness of each individual in the population</li>
413
-
414
- <li>Repeat as many times as generations we allow
415
- <ol>
416
-
417
- <li>Select randomly the best-ranking individuals to reproduce</li>
418
-
419
- <li>Breed new generation through crossover and mutation (genetic operations) and give birth to offspring</li>
420
-
421
- <li>Evaluate the individual fitnesses of the offspring</li>
422
-
423
- <li>Replace worst ranked part of population with offspring</li>
424
-
425
- </ol>
426
-
427
- </li>
428
-
429
- </ol>
430
- <a name="N10126"></a><a name="search-impl-selection"></a>
431
- <h3 class="boxed">Selection</h3>
432
- <p>Selection is the stage of a genetic algorithm in which individual genomes are chosen from a population for later breeding. There are several generic selection algorithms, such as tournament selection and roulette wheel selection. We implemented the latest.</p>
433
- <ol>
434
-
435
- <li>The fitness function is evaluated for each individual, providing fitness values</li>
436
-
437
- <li>The population is sorted by descending fitness values.</li>
438
-
439
- <li>The fitness values ar then normalized. (Highest fitness gets 1, lowest fitness gets 0). The normalized value is stored in the "normalized_fitness" attribute of the chromosomes.</li>
440
-
441
- <li> A random number R is chosen. R is between 0 and the accumulated normalized value (all the normalized fitness values added togheter).</li>
442
-
443
- <li>The selected individual is the first one whose accumulated normalized value (its is normalized value plus the normalized values of the chromosomes prior it) greater than R.</li>
444
-
445
- <li>We repeat steps 4 and 5, 2/3 times the population size.</li>
446
-
447
- </ol>
448
- <p>
449
- <img alt="Edge recombination" src="images/fitness.png"></p>
450
- <p>The previous image was taken from the wikipedia, so hail to the author: Simon Hatthon.</p>
451
- <a name="N1014D"></a><a name="search-impl-reproduction"></a>
452
- <h3 class="boxed">Reproduction</h3>
453
- <p>The reproduction function combines each pair of selected chromosomes using the method Chromosome.reproduce.</p>
454
- <p>The reproduction will also call the Chromosome.mutate method with each member of the population. You should implement Chromosome.mutate to only change (mutate) randomly. E.g. You could effectivly change the chromosome only if: </p>
455
- <pre class="code">
456
-
457
- rand &lt; ((1 - chromosome.normalized_fitness) * 0.4)
458
-
459
- </pre>
460
- </div>
461
-
462
- <a name="N1015F"></a><a name="how-to-run"></a>
463
- <h2 class="boxed">How to use AI4R Genetic Search implementation</h2>
464
- <div class="section">
465
- <pre class="code">
466
-
467
- #Cost of traveling from one point to another. E.g. Travelling from Node 0 to Node 2 costs 5.
468
- data_set = [ [ 0, 10, 5],
469
- [ 6, 0, 4],
470
- [25, 4, 0]
471
- ]
472
-
473
- Ai4r::GeneticAlgorithm::Chromosome.set_cost_matrix(data_set)
474
-
475
- search = Ai4r::GeneticAlgorithm::GeneticSearch.new(10, 20)
476
- result = search.run
477
- puts "Result cost: #{result.fitness}"
478
- puts "Result nodes: #{result.data.inspect}"
479
-
480
- </pre>
481
- </div>
482
-
483
-
484
- <a name="N1016A"></a><a name="example-run"></a>
485
- <h2 class="boxed">How to run the example</h2>
486
- <div class="section">
487
- <p>You can run the example with "ruby genetic_algorithm_example.rb". The genetic_algorithm_example.rb file
488
- contains:</p>
489
- <pre class="code">
490
-
491
- require "rubygems"
492
- require "ai4r/genetic_algorithm/genetic_algorithm"
493
- require "csv"
494
-
495
- # Load data from data_set.csv
496
- data_set = []
497
- CSV::Reader.parse(File.open("#{File.dirname(__FILE__)}/travel_cost.csv", 'r')) do |row|
498
- data_set &lt;&lt; row
499
- end
500
- data_labels = data_set.shift
501
- data_set.collect! do |column|
502
- column.collect { |element| element.to_f}
503
- end
504
-
505
- Ai4r::GeneticAlgorithm::Chromosome.set_cost_matrix(data_set)
506
-
507
- puts "Beginning genetic search, please wait... "
508
- search = Ai4r::GeneticAlgorithm::GeneticSearch.new(800, 100)
509
- result = search.run
510
- puts "Result cost: #{result.fitness}"
511
- puts "Result tour: "
512
- result.data.each { |c| print " #{data_labels[c]}"}
513
-
514
- </pre>
515
- </div>
516
-
517
-
518
- <a name="N10178"></a><a name="Results"></a>
519
- <h2 class="boxed">Results of using Genetic Algorithms to the The European Rock Tour Problem (or Travelling salesman problem)</h2>
520
- <div class="section">
521
- <p>The cost of 3 randomly selected tours:</p>
522
- <ul>
523
-
524
- <li>$17486.01 : Madrid Vienna Moscow Berlin Brussels Munich Milan Barcelona London Hamburg Warsaw Dublin Kiev Paris Rome</li>
525
-
526
- <li>$20198.92 : London Rome Brussels Kiev Hamburg Warsaw Barcelona Paris Munich Dublin Vienna Moscow Madrid Milan Berlin</li>
527
-
528
- <li>$17799.34 : Madrid Milan Kiev Vienna Warsaw London Barcelona Hamburg Paris Munich Dublin Berlin Moscow Rome Brussels</li>
529
-
530
- </ul>
531
- <p>3 tours obtained with an initial population of 800, and after 100 generations:</p>
532
- <ul>
533
-
534
- <li>$7611.99 : Moscow Kiev Warsaw Hamburg Berlin Munich Vienna Milan Rome Barcelona Madrid Paris Brussels London Dublin</li>
535
-
536
- <li>$7596.74 : Moscow Kiev Warsaw Berlin Hamburg Munich Vienna Milan Rome Barcelona Madrid Paris Brussels London Dublin (See Image)</li>
537
-
538
- <li>$7641.61 : Madrid Barcelona Rome Milan Paris Dublin London Brussels Hamburg Berlin Vienna Munich Warsaw Kiev Moscow</li>
539
-
540
- </ul>
541
- <p>
542
- <img alt="Best tour result using Genetic Algorithms in ruby" src="images/europe3.png"></p>
543
- <p>The GeneticSearch class is an generic class to try to solve any kind of problem using genetic algorithms. If you
544
- want to model another type of problem, you will have to modify the Chromosome class, defining its fitness, mutate, and reproduce functions.</p>
545
- </div>
546
-
547
-
548
- <a name="N101A5"></a><a name="more-genetic-run"></a>
549
- <h2 class="boxed">More about Genetic Algorithms and the Travelling salesman problem</h2>
550
- <div class="section">
551
- <p>
552
- <a class="external" href="http://en.wikipedia.org/wiki/Traveling_salesman_problem">Travelling salesman problem at Wikipedia</a>
553
- </p>
554
- <p>
555
- <a class="external" href="http://en.wikipedia.org/wiki/Genetic_algorithm">Genetic Algorithms at Wikipedia</a>
556
- </p>
557
- </div>
558
-
559
- </div>
560
- <!--+
561
- |end content
562
- +-->
563
- <div class="clearboth">&nbsp;</div>
564
- </div>
565
- <div id="footer">
566
- <!--+
567
- |start bottomstrip
568
- +-->
569
- <div class="lastmodified">
570
- <script type="text/javascript"><!--
571
- document.write("Last Published: " + document.lastModified);
572
- // --></script>
573
- </div>
574
- <div class="copyright">
575
- Copyright &copy;
576
- 2007-2009 <a href="http://www.jadeferret.com/">Sergio Fierens, Jade Ferret</a>
577
- </div>
578
- <div class="host">
579
- <a href="http://rubyforge.org/projects/ai4r/"><img class="logoImage" alt="" src="images/rubyforge.png"></a>
580
- </div>
581
- <!--+
582
- |end bottomstrip
583
- +-->
584
- </div>
585
- <script src="http://www.google-analytics.com/ga.js" type="text/javascript"></script><script type="text/javascript">
586
- var pageTracker = _gat._getTracker("UA-3234625-1");
587
- pageTracker._initData();
588
- pageTracker._trackPageview();
589
- </script>
590
- </body>
591
- </html>