Skip to content

About

C implementation of an ant colony optimization algorithm on weighted graphs, with SDL2 visualization.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

28 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ant Colony Algorithm

This is a small C project implementing an ant colony optimization approach to find a short path in a weighted graph.

The program loads a graph from a text file, runs the ant colony simulation, displays the graph with SDL2, and writes the final pheromone state to graph_result.txt.

This project was originally written in 2022 as a school project

Ant colony algorithm visualization

Requirements

On Ubuntu/Debian:

sudo apt update
sudo apt install build-essential libsdl2-dev

The project uses:

  • gcc
  • make
  • SDL2
  • the math library (libm)

Build

From the project root:

make

This creates the main executable.

To remove build outputs:

make clean

Run

./main

The SDL window shows the graph while the algorithm is running.

Controls:

  • Press Escape once to stop the computation.
  • Press Escape again to close the program after the result is printed.

After the run, the program writes the result to:

graph_result.txt

This file is generated locally and is intentionally ignored by Git.

Input Graph

The current input graph is hardcoded in main.c:

file_to_matrix_graph("graph_files/directed_graph/graph_file");

The start and finish nodes are also hardcoded:

int start = 0;
int finish = 7;

To run the algorithm on another graph, edit these values in main.c.

Graph files are stored in:

graph_files/

The first line is the graph size. The following lines are the adjacency matrix. A value of 0 means there is no edge between two nodes.

Notes

The algorithm expects a connected directed or undirected graph with positive edge weights.

The project currently focuses on the original interactive SDL visualization rather than command-line arguments or a packaged API.

About

C implementation of an ant colony optimization algorithm on weighted graphs, with SDL2 visualization.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages