AntColony.aco
— Methodaco(dist_mat; start_node=nothing, end_node=nothing; is_tour=false, beta=2, rho=0.1,
q=0.1, Q=1.0, tau_min=1.0, tau_max=10.0, max_iter=20, reset_iter=10,
top_perc_ants=0.05, verbose=false)
Ant Colony Optimization for directed graphs based on Max-Min Ant System, Elitist Ant System and Ant Colony System.
Arguments
dist_mat
: must be a square distance matrix (NxN) and edges are accessed like thisdist_mat[to, from]
start_node
: must be an integer <= N ornothing
(both nodes or none must be specified)end_node
: must be an integer <= N ornothing
(both nodes or none must be specified)is_tour
: whether path should start and end with same node (will setend_node = start_node
)beta
: influences how important distance is for the ants decision makingrho
: pheromones evaporation percentage for each iteration (0.0 <= rho <= 1.0
)q
: percentage of roulette wheel style decisions of antsQ
: pheromone deposit factortau_min
: lower bound for pheromone levels for any edgetau_max
: upper bound for pheremone levels for any edge (initial level of pheromones)max_iter
: number of iterations run for the algorithmreset_iter
: number of iterations after which the pheromone levels are reset totau_max
top_perc_ants
: the percentage of top perfoming ants which deposit pheromones on their trailsverbose
: print to console whenever a better path was found
Examples
Find a tour
Find any path with the same start and end node i.e. a tour. Note that the start node only appears once!
julia> distances = rand(5, 5);
julia> aco(distances, is_tour = true)
5-element Array{Int64,1}:
4
3
5
1
2
Find a path
Finda a specific path from node 1 to node 5
julia> distances = rand(5, 5);
julia> aco(distances, start_node = 1, end_node = 5)
5-element Array{Int64,1}:
1
2
4
3
5
AntColony.edge_distances
— Methodedge_distances(dist_mat, path, is_tour)
Generate a distances for each edge in path
AntColony.edges
— Methodedges(path, is_tour)
Generate node pairs representing edges in path
AntColony.sample
— Methodsample(x, weights)
Sample from x
with a custom distribution defined by weights
AntColony.travel
— Functiontravel(P, q, start_node, end_node)
Travel through graph based on probability P