Académique Documents
Professionnel Documents
Culture Documents
OPTIMIZATION
Introduction
• The ant colony algorithm is an algorithm for finding optimal paths
that is based on the behavior of ants searching for food.
• Because the ants drop pheromones every time they bring food,
shorter paths are more likely to be stronger, hence optimizing the
"solution.“
• In the meantime, some ants are still randomly scouting for closer
food sources.
• A similar approach can be used find near-optimal solution to
the traveling salesman problem.
Working of ACO:-
CODE:-
#include <iostream> struct antType{
#include <math.h>
#include <stdlib.h> int curCity, nextCity, pathIndex;
#include <fstream> int tabu[MAX_CITIES];
#include <ctime> int path[MAX_CITIES];
#include "assert.h" double tourLength;
using namespace std; };
//parameters required for the Ant Colony //the parameters by which the algorithm will
Algorithms. converge to a solution.
#define MAX_CITIES 5
#define MAX_DIST 15 #define ALPHA 1.0
#define MAX_TOUR (MAX_CITIES * #define BETA 5.0 //This parameter raises the weight
MAX_DIST) of distance over pheromone
#define MAX_ANTS 5 #define RHO 0.5 //Evapouration rate
//the environment fro the Traveling #define QVAL 100
Salesman Problem (TSP). #define MAX_TOURS 20
//Initial Definiton of the problem #define MAX_TIME (MAX_TOURS * MAX_CITIES)
struct cityType #define INIT_PHER (1.0/MAX_CITIES)
{ //weigh the edges with pheromones with the value
int x,y; of (1/MAX_CITIES).
}; //runtime Structures and global variables
cityType cities[MAX_CITIES]; for(to=0;to<MAX_CITIES;to++)
antType ants[MAX_ANTS]; {
dist[from][to] = 0.0;
double dist[MAX_CITIES][MAX_CITIES]; phero[from][to] = INIT_PHER;
}
double phero[MAX_CITIES][MAX_CITIES]; }
from=ants[ant].curCity; break;
}
for(to=0;to<MAX_CITIES;to++) }
{ }while(1);
if(ants[ant].tabu[to] == 0)
{ return to;
} }
int simulateAnts() }
{
int k; return moving;
int moving = 0; }
init();
optimvar('trips',lendist,1,'Type','integer','LowerBound',0,'UpperBo
und',1);
end