Ant Colony Optimization A threaded application in Java.

Slides:



Advertisements
Similar presentations
Practical techniques & Examples
Advertisements

Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. Multithreading Example from Liang textbook.
Ant colony algorithm Ant colony algorithm mimics the behavior of insect colonies completing their activities Ant colony looking for food Solving a problem.
Ant Colony Optimization. Brief introduction to ACO Ant colony optimization = ACO. Ants are capable of remarkably efficient discovery of short paths during.
Evolved and Timed Ants Optimizing the Parameters of a Time-Based Ant System Approach to the Traveling Salesman Problem Using a Genetic Algorithm.
Ant Colony Optimization Optimisation Methods. Overview.
Java ThreadsGraphics Programming Graphics Programming: Java Threads.
Multithreading in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Multithreading in Java Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Ant Colony Optimization: an introduction
Multithreading.
Threading in Java – a Tutorial QMUL IEEE SB. Why Threading When we need to run two tasks concurrently So multiple parts (>=2) of a program can run simultaneously.
Programming Task: Task 1 Controlled Assessment Practice.
Ant colony optimization algorithms Mykulska Eugenia
Genetic Algorithms and Ant Colony Optimisation
EE4E,M.Sc. C++ Programming Assignment Introduction.
Complete Coverage Path Planning Based on Ant Colony Algorithm International conference on Mechatronics and Machine Vision in Practice, p.p , Dec.
Threads, Thread management & Resource Management.
Object Oriented Programming Lecture 8: Introduction to laboratorial exercise – part II, Introduction to GUI frames in Netbeans, Introduction to threads.
Threads some important concepts Simon Lynch
REVIEW On Friday we explored Client-Server Applications with Sockets. Servers must create a ServerSocket object on a specific Port #. They then can wait.
A Genetic Solution to the Travelling Salesman Problem Ryan Honig.
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 2 Processes and Threads Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
Java Threads 11 Threading and Concurrent Programming in Java Introduction and Definitions D.W. Denbo Introduction and Definitions D.W. Denbo.
Object Oriented Programming Assignment Introduction Dr. Mike Spann
1 (Worker Queues) cs What is a Thread Pool? A collection of threads that are created once (e.g. when a server starts) That is, no need to create.
CS 346 – Chapter 4 Threads –How they differ from processes –Definition, purpose Threads of the same process share: code, data, open files –Types –Support.
Threading Eriq Muhammad Adams J
1 Object Oriented Programming Lecture XII Multithreading in Java, A few words about AWT and Swing, The composite design pattern.
Multithreading in Java Sameer Singh Chauhan Lecturer, I. T. Dept., SVIT, Vasad.
Concurrency in Java Brad Vander Zanden. Processes and Threads Process: A self-contained execution environment Thread: Exists within a process and shares.
1 CSE 373 Introduction to Concurrency reading: Grossman slides created by Marty Stepp
Traveling Salesman Problem IEOR 4405 Production Scheduling Professor Stein Sally Kim James Tsai April 30, 2009.
Multithreading Chapter Introduction Consider ability of human body to ___________ –Breathing, heartbeat, chew gum, walk … In many situations we.
Threads II IS Outline  Quiz  Thread review  Stopping a thread  java.util.Timer  Swing threads javax.swing.Timer  ProgressMonitor.
Optimizing Pheromone Modification for Dynamic Ant Algorithms Ryan Ward TJHSST Computer Systems Lab 2006/2007 Testing To test the relative effectiveness.
Java Thread and Memory Model
Ant colony optimization. HISTORY introduced by Marco Dorigo (MILAN,ITALY) in his doctoral thesis in 1992 Using to solve traveling salesman problem(TSP).traveling.
Session 13 Pinball Game Construction Kit (Version 3):
DRILL Answer the following question’s in your notebook: 1.How does ACO differ from PSO? 2.What does positive feedback do in a swarm? 3.What does negative.
Software and Threading Geza Kovacs Maslab Abstract Design: State Machines By using state machine diagrams, you can find flaws in your behavior without.
1 OS Review Processes and Threads Chi Zhang
Project 2 Overview (Threads in Practice) CSE451 Andrew Whitaker.
Ant Colony Optimization Andriy Baranov
Lecture 3 Concurrency and Thread Synchronization     Mutual Exclusion         Dekker's Algorithm         Lamport's Bakery Algorithm.
Multithreading. Multitasking The multitasking is the ability of single processor to perform more than one operation at the same time Once systems allowed.
L6: Threads “the future is parallel” COMP206, Geoff Holmes and Bernhard Pfahringer.
Concurrency (Threads) Threads allow you to do tasks in parallel. In an unthreaded program, you code is executed procedurally from start to finish. In a.
…in java DThread Pools x. Thread Pools: Why? Source code updates – copy/paste of run/runnable method for each thread is exhausting There is overhead to.
Concurrency in Java MD. ANISUR RAHMAN. slide 2 Concurrency  Multiprogramming  Single processor runs several programs at the same time  Each program.
Concurrency Idea. 2 Concurrency idea Challenge –Print primes from 1 to Given –Ten-processor multiprocessor –One thread per processor Goal –Get ten-fold.
A brief intro to: Parallelism, Threads, and Concurrency
Prepared by Oussama Jebbar
Concurrency 2 CS 2110 – Spring 2016.
Thread Pools (Worker Queues) cs
Asynchronous Programming
Thread Pools (Worker Queues) cs
Scientific Research Group in Egypt (SRGE)
Lecture 21 Concurrency Introduction
Atomicity CS 2110 – Fall 2017.
Chapter 19 Java Never Ends
Threads II IS
MODERN OPERATING SYSTEMS Third Edition ANDREW S
CNT 4007C Project 2 Good morning, everyone. In this class, we will have a brief look at the project 2. Project 2 is basically the same with project 1.
Android Topics UI Thread and Limited processing resources
Ant Colony Optimization
Ants and the TSP.
Lecture 19 Threads CSE /6/2019.
Java Chapter 3 (Estifanos Tilahun Mihret--Tech with Estif)
Threads and concurrency / Safety
Presentation transcript:

Ant Colony Optimization A threaded application in Java

What is it? An ant colony optimization algorithm seeks to solve hard problem by mimicking the behavior of ants. This presentation shows an application of a basic ant colony algorithm to generate reasonably good solutions to the Travelling Salesperson Problem.

Input params Map graphic Text output The Ant Colony Simulation GUI

Program flow Send some number of ants to explore the problem space (visit each city, then return) in a probabilistic fashion. Ants deposit pheromones on the trails they visit. The intensity of these pheromones increases as the path distance decreases. Thus, the probability increases that more favorable paths get used more often. Pheromones evaporate by some percentage each time an iteration occurs. (run only by threads[0]) Return the result when the processing budget has been exhausted.

Parallelism The activities of the ants can be run using threads. Running the course/collecting the distance data. Depositing the pheromones The GUI and ActionListener also run in threads.

Synchronized methods private synchronized void applyPheromone( int distance, int bestPathDistance, String[] run) { long newpheromoneLevel; newpheromoneLevel = (long) (distance/Math.sqrt(distance)); // each ant deposits pheromone for (int i=1; i < run.length; i++) { pheromoneLevels[getCityIndex(run[i-1])][getCityIndex(run[i])] += newpheromoneLevel; } pheromoneLevels[getCityIndex(run[(run.length)-1][getCityIndex(run[0])] += newpheromoneLevel; } This is how a mutex lock is implemented in Java:

Synchronized code within a method private void applyPheromone(int distance, int bestPathDistance, String[] run) { long newpheromoneLevel; newpheromoneLevel = (long) (distance/Math.sqrt(distance)); // each ant deposits pheromone synchronized(pheromoneLevels) { for (int i=1; i < run.length; i++) { pheromoneLevels[getCityIndex(run[i-1])][getCityIndex(run[i])] += newpheromoneLevel; } pheromoneLevels[getCityIndex(run[(run.length)-1])][getCityIndex(run[0])] += newpheromoneLevel; }

Interleaved synchronization If you have class variables that are never used together, create a mutex for each of them, thus: public class MsLunch { private long c1 = 0; private long c2 = 0; private Object lock1 = new Object(); private Object lock2 = new Object(); public void inc1() { synchronized(lock1) { c1++; } public void inc2() { synchronized(lock2) { c2++; }

Implementing threads // In the run() method // Evaporate once each run, before any pheromone is applied. // Only thread 0 gets to evaporate. if (k > 0 && Thread.currentThread().getName().equals("0")) { evaporate(); } // In the actionPerformed method (Run button has been clicked) for (int i = 0; i < numThreads; i++) { //ThreadRunner contains the run() method threads[i] = new Thread(new ThreadRunner(), Integer.toString(i)); threads[i].start(); } for (int i = 0; i < numThreads; i++) { threads[i].join(); }

Volatility The volatile keyword, applied to variables, guarantees that a thread sees the latest version of it. // read from memory, not from thread cache private volatile int[][] pheromoneLevels;

Resource usage Workload is more or less shared equally between processors if run in server mode. (ex. java –jar [path]/SwingAnts.jar -server) Otherwise, using one or all the CPUs depends on the platform you’re using.

Performance On (DogNet machine) grey: – 1 thread/ runs: ms – 2 threads/50000 runs: 6600 ms – 4 threads/25000 runs: 6700 ms – 8 threads/12500 runs: 6800 ms

Java support for parallelism Plain Old Threads (the Runnable class) java.util.concurrent Packages (Java 7) – executors – Callables – Fork/join

ExecutorTest output run: Pool size: 10: 679 ms. (this run was a “warm up”) Pool size: 5: 651 ms Pool size: 100: 675 ms. Pool size: 500: 746 ms. Pool size: 1000: 851 ms. BUILD SUCCESSFUL (total time: 36 seconds)

SerialTest output (tail end of the output) result 46 start - Task 47 run time secs result 47 start - Task 48 run time secs result 48 start - Task 49 run time secs result 49 run time secs BUILD SUCCESSFUL (total time: 55 seconds)

ExecutorServiceTest output (the tail end of the output) result 45 start - Task 49 run time 1.19 secs result 46 run time 1.19 secs result 47 run time secs result 48 run time 1.12 secs result 49 run time secs BUILD SUCCESSFUL (total time: 16 seconds)

Useful references/tutorials -processing-and-multi-core-utilization-with- java/ -processing-and-multi-core-utilization-with- java/ RuntimeOverview.html RuntimeOverview.html rency/article.html rency/article.html