Isula: A java framework for ant colony algorithms

Ant Colony Optimisation (ACO) algorithms emulate the foraging behaviour of ants to solve optimisation problems. They have proven effective in both academic and industrial settings. ACO algorithms share many features among them. Isula encapsulates these commonalities and exposes them for reuse in the form of a Java library. In this paper


Motivation and significance
Ant Colony Optimisation (ACO) algorithms, proposed by Dorigo et al. [1], solve optimisation problems by emulating the behaviour of ants in nature.When ants traverse a territory searching for food, they mark their path with pheromone.After they have located food, they make several trips from the food source to the nest, increasing the intensity of their path's pheromone trail.In case several ants have located the same food source and are also transporting food to the nest, the pheromone trail of the ant with the shortest path is more intense.The shortest path, in the same amount of time, has more two-way trips than longer paths that require more time for their traversal.Fellow ants are sensitive to pheromone and tend to select the path with the most intense pheromone trail.This behaviour also increases the pheromone intensity of the shortest path.Over time, the whole colony converges towards the optimal solution.ACO algorithms are well-suited for generating high-quality solutions for computationally expensive problems.They have been successfully applied to a wide array of domains.Let us take path planning, an NP-complete problem, as an example.ACO algorithms have proven effective in producing short and collision-free routes [2,3], even in dynamic environments [4].ACO algorithms are not limited to academic research: practitioners are using them in real-world scenarios -like industry and telecommunicationsto solve optimisation problems [5].
Ant System (AS) is the first ACO algorithm proposed [1].Researchers later developed new algorithms -also inspired by ant behaviour -either by improving, extending or adapting AS.Although these algorithms differ, given their common inspiration they have several commonalities.We rely on this reutilisation potential to offer a software framework -called Isula 1 -for quick implementation of ant colony algorithms [6].We choose Java as programming language since is the most popular programming language at the time of this publication [7].Isula includes several After each ant has built a solution, it deposits the corresponding pheromone increment to each solution component.

Perform Evaporation (AS)
Applies the evaporation ratio, hence reducing the pheromone amount in all the elements of the pheromone matrix. 3

Random Node Selection (AS)
Dictates how ants select the components to add to their current solution.The ant selects the component at random, where the probability of selection is a function of the pheromone value of the component and its heuristic information.[8].We approach it to illustrate the framework internals by solving a TSP instance using AS.We also show how to reutilise the code we built for AS for a quick implementation of ACS for TSP.
Section 3 shows the second use case.We describe how to develop a medical image segmentation method by composing and adapting Isula components.We segment a brain MRI (magnetic resonance image) by combining two ant colony algorithms: an image thresholding algorithm [9] and an image segmentation one [10].
Our contribution follows: • An introduction to Isula, a java framework for ACO algorithms (Section 2.1).
• A detailed description of how to use Isula's components outof-the box to solve the travelling salesman problem using two well-established ACO algorithms (Ant System and Ant Colony System in Section 2.2).
• A complete example of how to use Isula to develop new algorithms by composing and adapting algorithm components.We implemented an brain MRI segmentation method (Section 3).

Software description
In this section, we start by giving a high-level overview of the main characteristics of the algorithms in the ACO metaheuristic, to later use the Travelling Salesman Problem to illustrate how to implement Java ACO algorithms using the Isula framework.

DaemonActions()
▷ Optional this framework [11].The algorithms that belong to the metaheuristic follow the structure depicted in Algorithm 1, taken from the book from Dorigo [8].
The ScheduleActivities function coordinates algorithm execution.During an iteration, the artificial ants traverse the problem graph and build a candidate solution each.While traversing the problem graph, ants randomly select which solution component to add to the candidate solution under construction.Depending on the algorithm, solution components can correspond to nodes or edges of the problem graph.The transition probability of each solution component guides this random selection process.This probability is a function the amount of pheromone on the solution component and a domain-dependent metric, also called heuristic information.The ConstructAntSolutions function represents the solution building process in Algorithm 1.The solution building process impacts the amount of pheromone available in each solution component.Ants deposit pheromone on the components of their candidate solution.Also, pheromone evaporation can be part of ACO algorithms to avoid rapid convergence and favour graph exploration.The UpdatePheromones function controls the pheromone update process.Finally, the DaemonActions functions implement behaviours on a global scale, instead of at ant-level.
Isula's goal is to accelerate the programming of instances of the ACO metaheuristic.It is a Java library that contains working implementations of the most common components of ACO algorithms.We show how to use Isula to solve optimisation problems in  daemon actions, node selection policies, and parameters like number of ants or evaporation rate.We show a subset of the types available at Isula in Table 1.
Algorithm Execution Call the AcoProblemSolver.solve-Problem() method to obtain a result.
In the next subsection, we take a deep look at Isula internals and see how researchers and practitioners can use it to solve combinatorial optimisation problems.

Solving the Travelling Salesman Problem
Let us explore how to approach optimisation problems with Isula by solving an instance of the Travelling Salesman Problem (TSP).Given a list of cities the salesman needs to visit, we want to know in what order to visit them -i.e obtain a permutation of the cities -in order to minimise the distance travelled.

Environment and artificial ant definition. The first two steps for
Isula problem solving require the definition of the environment and artificial ants.In the case of TSP, the environment would contain a matrix-like data structure for the storage of distance between cities, as well as its corresponding pheromone matrix.An artificial ant for solving TSP would need information about the distance travelled so far, and if it has already traversed all cities.For TSP, we developed AntForTsp and TspEnvironment, extending the abstract classes Ant and Environment available in the framework.These classes are available in GitHub at https://github.com/cptanalatriste/aco-tsp,along with all the code contained in this section.
Algorithm configuration.Listing 1 address the algorithm configuration step using the Ant System (AS) algorithm [1] to solve the berlin52 problem of the TSPLIB library [12].The TspProblemConfiguration class implements the ConfigurationProvider interface from Isula.Configura-tionProvider instances contain the parameters of the ACO algorithm to execute, like the number of ants, pheromone evaporation ratio and the number of iterations.The TspEnvironment class extends the Environment class from the framework, which represents the environment the ants traverse while building solutions.It also stores the pheromone matrix that contains the pheromone value per solution component.To use AS we need to provide our AcoProblemSolver instance with the appropriate daemon actions and ant policies.AS was the first ACO algorithm proposed, and its main feature is that all the ants that build a solution after an iteration have the right to perform pheromone deposits.Other ACO algorithms prefer to restrict this behaviour.
We rely on the types antsystem.OfflinePheromoneUpdate (getPheromoneUpdatePolicy() returns an instance of this class), antsystem.PerformEvaporation and antsystem.StartPheromoneMatrix to update pheromone values according to AS requirements.Table 1 contains a description of each of these classes.
The ants in the colony are the ones in charge of making candidate solutions.Hence, a key component in algorithm implementation with Isula is constructing the ant colony and its members.
In Listing 1, the getAntColony() method produces an instance of the AntColony class of the framework, but overriding the createAnt() method to produce instances of the AntForTsp class.This class is tailored for TSP solution construction.We have also added the antsystem.RandomNodeSelection policy to all the ants in the colony.This policy guides the criteria the ants use to add components to their candidate solution.Listing  As mentioned in Section 2.1, ants select components for their solutions randomly, with a transition probability dependant on pheromone values and heuristic information.antsystem.RandomNodeSelection obtains this probability for all valid solution components and randomly selects one according to the transition probability values.This class is a part of the Isula framework and is ready to use without modifications in the case of TSP.The AntForTsp class is tailored to build solutions for the TSP.Hence, its getHeuristicValue() method returns the distance of a potential solution component, with respect to the ant's position in the problem graph.When using Isula to solve a novel optimisation problem, framework users should extend the base Ant class and provide an adequate implementation of getHeuristicValue() to guide the solution construction process.
Algorithm execution.Lets now address the algorithm execution step to look in detail how Isula approaches combinatorial optimisation.Fig. 2 is a sequence diagram of the AcoProblem-Solver.solveProblem()method, which is the Isula's implementation of the procedure described in Algorithm 1. Isula distributes most of the ScheduleActivities responsibilities between the AcoProblemSolver class and the AntColony class.The AcoProblemSolver class delegates the solution building responsibilities to the AntColony class, while it keeps track of the best solution produced so far.The AcoProblemSolver class is also in charge of triggering DaemonActions, that can happen either before or after the ConstructAntSolutions phase, implemented by the AntColony.buildSolutions()method.Users of the framework can instantiate the AcoProblemSolver class without modifications, as it should support most of the ACO algorithms.If is not the case, Isula supports its extension.
In summary, in order to solve a combinatorial optimisation problem Isula requires its users to implement three types: (1) A Environment subclass for representing the problem context, (2) An Ant subclass for the ants that traverse the environment and build candidate solutions, and (3) a ConfigurationProvider implementation containing the algorithm parameters.The Isula framework handles the rest.
Code reuse opportunities.Now that we solved TSP using an Isula implementation, we can reuse the code we developed to use other ACO algorithms to solve TSP problems.We will use Ant Colony System (ACS) and Ant System (AS) to showcase the reuse potential between ACO algorithms and their Isula implementations.ACS changes the way pheromone updates: It happens both when ants are building solutions (called local pheromone update) and when the whole colony has finished (called global pheromone update).Also, ants in an ACS algorithm use a pseudo-random node selection policy, unlike the random node selection policy used in AS.Listing 3, available in Github at https://github.com/cptanalatriste/aco-acs-tsp, shows how to solve a TSP using Ant Colony System (ACS) [13], reusing the types we developed while applying AS.We can use the AntForTsp and TspEnvironment classes without modifications.We can also reuse the antsystem.OfflinePheromoneUpdate and antsystem.StartPherom-oneMatrix during pheromone update process.Due to the nature of the ACS algorithm, we need to include two additional policies already present in the Isula framework: acs.PseudoRandom-NodeSelection and antsystem.OnlinePheromoneUpdate.
We detail the behaviour of these classes in Table 1.

Illustrative example
In the previous section, we applied well-known ant colony algorithms to a well-known problem.Here, we implement an ant colony algorithm for the medical imaging domain, proposed by us in previous work [14].As shown in Fig. 3, our method takes as input a magnetic resonance (MR) image of a brain (like Fig. 5 from the BrainWeb [15]) to produce three segments from it: grey matter, white matter and cerebrospinal fluid (CF).Fig. 4 contains the grey matter segment our method extracted from the MR brain image in Fig. 5.This segmentation task is useful for computerassisted surgery, anomaly detection and the quantification of sclerosis lesions [16].
Our method is a composition of two ACO algorithms.After image pre-processing, the ACO image thresholding algorithm extracts the cerebrum -our region of interest -and excludes the  pixels corresponding to skull, muscle and fat.Then, the cerebrum pixels are then processed by the ACO image segmentation algorithm, which produces images corresponding to each relevant segment.The image segmentation algorithm is resource intensive, so it benefits greatly from the reduced input produced by image thresholding.The implementation of our method in Isula is available at GitHub (https://github.com/cptanalatriste/aco-image-segmentation), including image pre-processing.In this section, we do not cover image pre-processing and focus only on the two ACO algorithm components.ACO Image thresholding.Malisia and Tizhoosh proposed the ACO algorithm we selected for thresholding [9].They based their algorithm on Ant System, discussed in Section 2. The algorithm divides the input image in two regions: region of interest -the cerebrum -and background.To accomplish this, they assign artificial ants to each image pixel, making them seek low-greyscale pixel values.While traversing the image they deposit pheromone in each pixel.Pixel pheromone is used as feature for the clustering algorithm that produce the final segments.We show the image thresholding algorithm configuration code in Listing 4. This code  We reutilise Isula types like ConfigurationProvider and AcoProblemSolver.Also, since the algorithm is an extension of AS we can also rely on the antsystem.PerformEvaporation and antsystem.StartPheromoneMatrix daemon actions.Due to the new domain, we require further customisation.We designed Isula with these scenarios in mind, and it supports its extension and modification.For image thresholding with AS, we developed a specialised ant colony type (ImageThresholding-AntColony).We also adapted the pseudo-random node selection (NodeSelectionForImageThresholding) and online pheromone updated policies available in Isula (OnlinePheromone-UpdateForThresholding).Since we based these extensions on existing Isula implementations, only the relevant methods were over-written.The algorithm requires to place ants at random pixels at the beginning of each iteration.We developed the RandomizeHive daemon action to accomplish this.

ACO Image segmentation.
Once the image thresholding algorithm extracts the cerebrum, the image segmentation algorithm can start processing it.We implemented the algorithm proposed by Ouadfel and Batouche [10].In their approach, each artificial ant is in charge of building a partition.They based their algorithm on Max-Min Ant System (MMAS) [17] -another classic ACO algorithm -so we can rely on Isula types for its implementation.In MMAS, only the best performing ant can deposit pheromone at the end of the iteration.Also, the pheromone values per solution component must belong to a specific range.Listing 5 shows how to configure the solver:  The complete implementation is available in GitHub at https: //github.com/cptanalatriste/aco-image-segmentation.Like with the thresholding algorithm, the segmentation algorithm also uses the pseudo-random node selection policy from ACS, so Image-SegmentationNodeSelection extends acs.PseudoRandom-NodeSelection.The pheromone update process follows MMAS rules, so we use the Isula types maxmin.StartPheromone-MatrixForMaxMin and maxmin.UpdatePheromoneMatrix-ForMaxMin (extended by ImageSegmentationUpdatePhero-moneMatrix).We describe these types in Table 1.Like in the previous examples, we developed subclasses of Environment, Ant and AntColony, adapted to the problem domain.This custom code can be used along with Isula's built-in types.

Impact
ACO algorithms are not restricted to the academic domain: they are actively used to solve optimisation problems at industry [5].Being Java the most popular programming language [7], there is a need for a robust java library for quick ACO implementations.The development of Isula started as part of one of the author's Master dissertation in 2015 [14].At the time of publication, Isula has been used for implementing ACO algorithms for image segmentation [18] and road extraction [19].
Isula is an open source project at GitHub, the world's largest coding platform.Table 2 contains the Isula implementations of ACO algorithms we have developed so far.We built these opensource projects to showcase Isula capabilities, so the code follows a tutorial-style and its fully documented.At the time of this publication, Isula is the most popular ant colony optimisation project in Java at GitHub, in both forks and stars, among 24 code repositories in the area [20].Without considering programming language, is the third most popular project [21] among 98 code repositories .
Thanks to the feedback received over the years we have greatly improved Isula's tutorials and documentation.We hope to continue enabling the practitioners and research community on the implementation of ACO algorithms.As seen in this paper, the framework is flexible enough to support several problem domains and different ACO algorithms.

Isula roadmap
In this subsection, we present the extensions of the Isula framework we have planned.
Multi-objective optimisation.The ACO metaheuristic (Section 2.1) was originally designed to support single-objective combinatorial optimisation problems [24].The current version of Isula has the same limitation: it does not provide multi-objective support out-of-the-box.Researchers have later developed ant-inspired algorithms that can produce a set of Pareto-optimal solutions for a given multi-objective optimisation problem [25].The architecture of such algorithms differs the original ACO metaheuristic proposal, requiring multiple pheromone matrices, multiple colonies and multi-dimensional heuristic information.López-Ibáñez and Stützle proposed MOACO as an algorithmic framework for multiobjective ACO algorithms [24].As part of our roadmap, we plan for Isula to support MOACO algorithms in the future.
Parallel ACO.Our roadmap also includes extending Isula to support parallel implementations of ACO algorithms.Current proposals require the concurrent execution of ant sub-colonies over multiple processors, along with a policy for information exchange between them [25].This information can be the best solution found by each sub-colony, or even the entirety of the pheromone matrix [26].The current version of Isula does not support these architectures, but we expect a future release addressing these concerns.
Parameter optimisation.The performance of ACO algorithms is highly dependent of their parameter values [27].The current version of Isula, as most ACO algorithms in the literature, keep parameter values constant during algorithm execution.A new generation of ACO algorithms are able to adapt parameter values at runtime [28][29][30].These algorithms can be grouped in two categories: Those that schedule parameter update before algorithm execution, and those that update parameters according to the current search state.We planned to extend Isula to support these parameter update strategies.

Conclusion
The ACO metaheuristic has proven effective in solving optimisation problems.The instances of this algorithmic framework share many features: Isula relies on this to offer ready-to-use building blocks in the form of a robust Java library.This way, the implementation of new ACO algorithms is faster.Isula supports multiple domains and ACO algorithms, and is easily extensible as shown in this paper.It is currently the most popular GitHub project for ant colony optimisation in Java, and we hope more researchers and practitioners adopt Isula and help with its improvement.
Dorigo et al.  proposed the ACO metaheuristic as an algorithmic framework for ACO algorithms, who would be then instances of Algorithm 1 The ACO metaheuristic is pseudo-code 1:

Fig. 1 .
It involves four steps: Environment Definition Define a problem context by extending the Environment class.Artificial Ant Definition Extend the Ant class to provide information necessary for building solutions.Algorithm Configuration Configure an AcoProblemSolver instance according to the algorithm to use.This includes

Fig. 1 .
Fig. 1.Solving optimisation problems with Isula.This process has four steps: environment definition, artificial ant definition, algorithm configuration and algorithm execution.

Listing 3 :
Solving the Travelling Salesmen Problem, using an Isula-based implementation of Ant Colony System.

Table 1
Daemon actions and policies included in Isula.
MMAS keeps pheromone values between a range, restricting the evaporation and deposit of pheromone.At the beginning of the algorithm, this daemon action sets pheromones values to the maximum value.
[5]lding blocks of ACO algorithms, which can be used out-ofthe box or adapted in case the problem requires it.Among the building blocks available in the framework, we can mention node selection policies, pheromone update strategies, and ant colony initialisation procedures.Table1contains a subset of them.Isula currently supports the three top performing ACO algorithms[5]: Ant System (AS), Ant Colony Systems (ACS) and Max-Min Ant System (MMAS).We envision two use cases for Isula: (1) use Isula implementations of ACO algorithms out-of-the box, and (2) Built new ACO algorithms by reusing and adapting components already available in the framework.Section 2 illustrates the first use case.The Travelling Salesman Problem (TSP) is usually used to showcase ACO algorithms 2, available in Github at https://github.com/cptanalatriste/isula, is a snippet from this class.

Table 2
Isula-based implementations of ACO algorithms at GitHub.