O'Reilly logo

Genetic Algorithms and Machine Learning for Programmers by Frances Buontempo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Let’s March Some Ants

You can code this in JavaScript and display the routes with the HTML canvas. You can reuse the HMTL here. Add an input checkbox to decide if all the ants start in the same place, like this:

 <input name=​"middle_start"​ id=​"middle_start"​ type=​"checkbox"​>
  Start in middle?
 </input>

The button calls init so you can set up your ACO, or stop if it is already running. Use the checked property to decide where to start, then begin:

 var​ id = 0;
 var​ middle_start = ​false​;
 
 function​ init() {
 if​ (id === 0) {
  document.getElementById(​"click_draw"​).innerHTML=​"stop"​;
 var​ opt = document.getElementById(​"middle_start"​);
 if​ (opt) {
  middle_start = opt.checked;
  }
  begin(); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required