Introduction
When a company needs to define the best delivery sequence, organize pickups across multiple cities, or reduce operational travel, it enters a type of problem that may look simple at first and quickly becomes difficult to solve. In logistics, every new point added to a route increases the number of possible combinations, and that growth is often much faster than intuition suggests.
This is one of the reasons why optimization is so important in business technology. In many cases, testing every possible route to find the best answer is not feasible in terms of time or computing cost. Organizations need practical ways to find a good solution within a very large space of possible combinations.
This type of challenge also helps broaden the conversation about artificial intelligence. Although the market is heavily focused on generative artificial intelligence, many business applications still depend on techniques designed for search, planning, and decision-making. In logistics, this becomes very clear: choosing a better route can reduce distance, save resources, and make the operation more predictable.
In this article, we will look at a class of algorithms that remains relevant in this context: heuristics and metaheuristics. The focus will be Ant Colony Optimization, an approach inspired by how ants behave when searching for food. Throughout the article, we will connect the concepts to logistics and use a real example in C# with .NET to show how this type of solution can be structured in practice.
What is optimization, and why does it matter for businesses?
Optimization is the process of looking for the best possible solution within a set of alternatives, considering objectives and constraints. In a company, this usually means reducing costs, saving time, or making better use of available resources.
In logistics, optimization can appear in the definition of a delivery sequence. In a maintenance operation, it can appear in the order of technical visits. In a factory, it can appear in production planning. Despite the differences between these scenarios, they share an important characteristic: there are many possible ways to organize the decision.
A classic example is the Traveling Salesperson Problem. The idea is to find a route that visits every point once and returns to the starting point while considering the shortest possible distance and time.
From a purely logical perspective, solving this problem may sound straightforward. You calculate the distances between all points that need to be visited and then find the route that takes the least time and covers the shortest distance.
In practice, it is not that simple. Imagine a scenario where a company needs to calculate the best route across 100 different locations. Testing every possible route would take far too long with today’s computing capabilities.
Instead of calculating the absolute best route, which may be impractical, we can approach the problem differently: we can use heuristics to calculate a route that is good enough, rather than focusing only on the best route theoretically possible.
What are heuristics and metaheuristics?
Heuristics are practical rules used to find solutions efficiently. They do not guarantee the best possible answer, but they can produce good results with low computing cost.
A simple route-planning heuristic is Nearest Neighbor. The rule is direct: from the current point, move to the closest destination that has not yet been visited.
This approach is easy to implement and often produces a reasonable solution. The limitation is that it can make decisions that do not work well when the full route is considered. Always choosing the closest next point may look efficient at the beginning, while still leaving a very long final segment.
Metaheuristics operate at a broader level. They define search strategies that try to balance two behaviors: testing different paths and reinforcing choices that have already produced good results.
Among well-known metaheuristics, we can mention Genetic Algorithms, Simulated Annealing, Tabu Search, and Ant Colony Optimization. We will explore some of these algorithms in future articles. For this article, we will focus on the ant colony approach, applying the algorithm to find a good enough route for a logistics need.
What is the ant colony algorithm?
Ant Colony Optimization is a bio-inspired metaheuristic. The idea comes from the way real ants find paths between the colony and a food source.
When an ant moves, it can leave behind a chemical trail called pheromone. Other ants tend to follow paths with more pheromone. If a path is short and efficient, more ants can travel through it in less time, reinforcing that trail.
At the same time, the pheromone gradually evaporates. This matters because it prevents an old trail from influencing the group forever. If a better route appears, it can still be discovered and reinforced.
In the computational version, this behavior becomes an optimization strategy. Instead of real ants, we use artificial agents. Each agent builds a possible route. Then, the best routes reinforce the paths they used.
In a routing application, each artificial ant chooses the next destination based on two main signals: the amount of pheromone accumulated between two points and the distance between them. The pheromone represents the collective memory of the search. The distance represents a practical preference for shorter movements.
The result is an iterative process. The colony creates routes, evaluates results, reinforces better paths, reduces the influence of older paths, and repeats the cycle.
How does the algorithm find good routes?
Each “artificial ant” starts at one point and builds a sequence of visits. At each step, it chooses the next destination among the points that have not yet been visited.
This choice is probabilistic. The algorithm does not always follow the same fixed rule. A connection with more pheromone has a higher chance of being selected. A shorter connection also becomes more attractive. Even so, other options can still be tested.
This detail helps the algorithm avoid overly rigid behavior. If it followed only the shortest distance, it could run into the same limitations as a simple heuristic. If it followed only pheromone, it could converge too early to a route that looked good in the first iterations.
The basic cycle works like this:
- The application loads the points that need to be visited.
- The algorithm calculates the distance between each pair of points.
- A pheromone matrix is initialized.
- The ants build complete routes.
- The routes are evaluated by total distance.
- Part of the pheromone evaporates.
- The best routes reinforce the paths they used.
- The process repeats until it reaches the final result.
This combination of memory, controlled randomness, and continuous evaluation is what makes the approach interesting for routing problems.
Practical example in C# and .NET
To show the concept in action, this article uses the following GitHub repository as a reference: evgomes/net-ant-colony-optmiziation. The project implements an application in C# with .NET to calculate a short circular route across several Brazilian locations.
The example was structured as a practical logistics application. It reads a list of locations in JSON, calculates distances between points, runs the ant colony algorithm, and generates an HTML visualization with the route found.
The goal is to show how an optimization technique can move from conceptual explanation to organized software. The code does not try to reproduce a full navigation platform. It focuses on a specific problem: given a list of points, find an efficient circular route of visits.
This design choice is useful. It allows us to understand the algorithm without mixing the example with external integrations, map APIs, or traffic data. In a more complete business application, those layers could be added later.
The main point is that the optimization algorithm can be treated as a business component. It receives data, applies a cost function, runs a guided search, and returns a route that can be analyzed or visualized.
How does the project represent locations using latitude and longitude?
In the example, each location is represented by latitude and longitude. This is a simple way to model cities, branches, clients, or delivery points.
To transform these coordinates into travel cost, the project uses the Haversine Formula. In practical terms, this formula calculates the approximate geographic distance between two points. From there, the system can build a distance matrix. This matrix stores the cost between each pair of locations and prevents the same distance from being recalculated repeatedly while the algorithm runs.
This approach makes sense for the example because it makes the process reproducible. The optimization can run as long as the latitude and longitude data is available.
At the same time, it is important to recognize the limitation of this model. The distance calculated by the Haversine Formula represents a geographic approximation, not the real road distance. It does not consider roads, traffic, or tolls.
In a real logistics operation, the cost function could be replaced by data from a routing engine or by a previously calculated road-distance matrix. The algorithm would follow the same general logic, while evaluating routes with data closer to the actual operation.
How was the solution organized?
The project was organized into simple layers to separate responsibilities.
The domain layer contains the main concepts of the problem, such as location, geographic coordinate, algorithm parameters, and route result.
The application layer contains the optimization logic. This is where the ant colony algorithm builds routes, evaluates distances, and updates pheromones.
The infrastructure layer handles tasks such as loading files, calculating distances, and generating the final visualization.
The presentation layer handles command-line execution.
This separation helps bring the example closer to a real project. The algorithm is not locked inside a single file that is hard to maintain. Data input, optimization logic, and output generation are handled in different parts of the solution.
The general repository structure follows this format:
.
|-- AntColonyOptimization.slnx
|-- README.md
|-- data/
| `-- brazilian-places.json
|-- artifacts/
| `-- .gitkeep
`-- src/
`-- AntColonyOptimization/
|-- Application/
|-- Domain/
|-- Infrastructure/
|-- Presentation/
|-- AntColonyOptimization.csproj
`-- Program.cs
If you are not a programmer, the structure may not be immediately meaningful. The important point is that it makes maintenance easier and allows the solution to expand as the project evolves.
How to run the application
The data/brazilian-places.json file contains the locations used by the application. From this file, the system calculates distances, runs the optimization, and stores the result in the artifacts folder.
To run the project, you need the .NET SDK installed.
On Windows, the basic commands are:
dotnet restore
dotnet run --project src\AntColonyOptimization -- optimize
dotnet run --project src\AntColonyOptimization -- visualize
start artifacts\best-route.html
On macOS or Linux, the commands can be run like this:
dotnet restore
dotnet run --project src/AntColonyOptimization -- optimize
dotnet run --project src/AntColonyOptimization -- visualize
The first execution calculates the best route found by the algorithm. The second generates an HTML visualization.
It is also possible to run the application with explicit parameters:
dotnet run --project src/AntColonyOptimization -- optimize \
--places data/brazilian-places.json \
--output artifacts/best-route.json \
--ants 64 \
--iterations 250 \
--alpha 1.0 \
--beta 4.0 \
--evaporation 0.45 \
--deposit 100 \
--seed 42
These parameters influence the behavior of the optimization.
The ants parameter defines how many artificial ants will be used in each iteration. The iterations parameter defines how many rounds the search will run. When we work with artificial intelligence and optimization problems, algorithms usually need multiple iterations to improve their results. The alpha parameter controls the weight of pheromone. The beta parameter controls the weight of distance. The evaporation rate defines how much old pheromone disappears in each cycle. The deposit parameter controls the intensity of the reinforcement applied to good routes. The seed helps reproduce a run.
These parameters can be adjusted according to the size of the problem and the time available to calculate the route. In artificial intelligence, it is common to test optimization and training processes with different parameters to compare results.
How to interpret the results
When using a metaheuristic, the analysis should go beyond asking whether the mathematically best route was found. A more useful question is whether the route found improves the previous route within an acceptable amount of time.
This difference matters. A company can gain value by reducing a route consistently, even when the solution does not come with a formal proof of optimality. The benefit comes from improving the operation through a systematic approach.
The result saved by the application includes information such as total distance, sequence of locations, parameters used, and convergence history. These data points help evaluate both the final route and the behavior of the search over the iterations.
To make the analysis clearer, it is worth comparing the route found with a simple reference. This reference can be the original order in the file or a heuristic such as Nearest Neighbor.
Is this example ready to be used in a real application?
The example is useful to demonstrate a practical optimization application, but it still simplifies several aspects of a real logistics operation.
The main simplification is in distance calculation. The application uses approximate geographic distance, not road distance. In a real route, the distance between two cities depends on the available road network.
Another point is that the example works with a single circular route. It does not handle multiple vehicles, cargo capacity, or delivery time windows.
These limitations are expected in an initial implementation of the problem. The most important point is that they are mainly concentrated in the modeling of the cost function and constraints. The algorithm can still be useful, but it would need information closer to the real operation.
A natural evolution would be to transform the problem into a Vehicle Routing Problem. In that case, the application would consider more than one vehicle, capacity limits, and service rules.
It would also be possible to replace geographic distance with a matrix of real travel times. With that, the route would reflect the logistics operation more accurately.
If you have a similar problem to solve and see the need to develop a more complex logistics solution, you can contact us so we can evaluate how we may help.
Where else can metaheuristics be applied in companies?
Although the route example is intuitive, metaheuristics also appear in other business decisions.
They can help define the sequence of tasks on machines. In field teams, they can help combine scheduling, travel, and availability. In distribution centers, they can support picking and grouping decisions.
The common point is the presence of many possible combinations. Whenever a company needs to organize limited resources under several constraints, optimization techniques can be evaluated.
This is one of the reasons why the topic remains relevant even with the progress of generative artificial intelligence. Generative models help interpret, summarize, and produce content. Metaheuristics help search for good decisions in complex spaces.
The two approaches can also be combined. A language model could help the user describe business rules in natural language, while an optimization algorithm calculates the route, schedule, or final allocation.
Conclusion
Heuristics and metaheuristics remain important tools for artificial intelligence applied to business. They are especially useful when a company needs to make decisions in problems with many possible combinations.
Ant Colony Optimization illustrates this idea well. Based on behavior inspired by nature, the algorithm creates a computational strategy built on trial, reinforcement, and collective memory.
The example in C# with .NET shows how this logic can be applied to a logistics scenario. The application reads locations, calculates distances, runs the algorithm, and generates a route that can be visualized. Even with simplifications, it demonstrates how optimization techniques can be organized as software and connected to real business decisions.
For companies, this type of approach reinforces an important point: artificial intelligence goes beyond conversational interfaces and content generation. In many cases, the value lies in supporting operational decisions, reducing waste, and finding better paths within a space of choices too large to evaluate manually.
Sources
DORIGO, Marco; STÜTZLE, Thomas. Ant Colony Optimization. MIT Press. Available at: https://direct.mit.edu/books/monograph/2313/Ant-Colony-Optimization. Accessed on: June 28, 2026.
DORIGO, Marco; STÜTZLE, Thomas. The Ant Colony Optimization Metaheuristic: Algorithms, Applications, and Advances. Available at: https://staff.washington.edu/paymana/swarm/stutzle99-eaecs.pdf. Accessed on: June 28, 2026.
MOVABLE TYPE SCRIPTS. Calculate distance, bearing and more between Latitude/Longitude points. Available at: https://www.movable-type.co.uk/scripts/latlong.html. Accessed on: June 28, 2026.
FEDERAL UNIVERSITY OF OURO PRETO (UFOP). Ant Colony Algorithm – Applied to the Traveling Salesperson Problem. YouTube. Available at: https://www.youtube.com/watch?v=sDBe6R0axAY. Accessed on: June 28, 2026.