Genetic algorithm for solving transportation problems on networks with one source and multiple sinks

In this paper we propose a genetic algorithm for solving the nonlinear transportation problem on a network with multiple sinks and concave piecewise cost functions. We prove that the complexity of one iteration of the algorithm is O(n2) and the algorithm converges to a local optimum solution. We show that the algorithm can be used to solve large-scale problems and present the implementation and several testing examples of the algorithm using Wolfram Language.


Introduction
There are often situations where a manufacturer of a type of product has sale contracts with traders from various cities and/or countries. In turn, traders have many warehouses in various cities, from which they deliver the product to other entrepreneurs. Finally, after the product is transported through several intermediary points, it is placed on store shelves and bought by the customer. This structure can be described by a transportation network with one source, several destinations and a set of intermediary points.
Despite being able to solve the problem, the algorithms presented in [1], [2], [3] and [4] have an unreasonably big execution time for transportation networks of big dimensions. There are no known polynomial algorithms that would provide the solution to these largescale problems. This is due to the NP-difficult problem with concave cost functions, which can have several local minima, to which, in most cases, the algorithm often converges.
Even if no genetic algorithms [5] are known that are able to deliver the exact solution for all optimization problems, their use is recommended, because they do not need the gradient or Hessian information. These algorithms are resistant to blockages in an optimal local even if the structure of the restrictions that describe the range of admissible solutions is quite complex. Genetic algorithms are successful for solving large-scale nonlinear optimization problems.
A first step in using a genetic algorithm is the correct coding of the problem, i.e. the description of the chromosomes that represent the coding of an admissible solution of the problem. When we talk about the solution obtained following the execution of a genetic algorithm [5], [6] a balance must be kept between the exploration of as many of the admissible solutions as possible and the exploitation of the solution as close to the optimal solution as possible. That means that we have to carefully choose the size of the population generated at the initial step, which depends on the size of the network describing the problem. Another important factor is the number of iterations after which the algorithm is stopped and the solution associated with the chromosome with the best characteristics is accepted as the optimal solution.
The elitism [7] implemented in the proposed algorithm is a technique that allow us to keep the chromosomes with the best characteristics from one population to another. Otherwise, individuals may be lost due to non selection or modification through mutation. Incorporating techniques that improve the solution in the genetic algorithm produces a hybrid that can obtain better results [8].

Problem formulation
In the following, the non-linear transportation problem on a network with a source and several destinations is solved. The network is described by the acyclic connected graph G = (V, E), V the set of vertices, |V| = n and E the set of arcs, |E| = m. On the set of vertices, the consumption and production function is defined q : V −→ R, and on the set of arcs, the piesewise non-decreasing concave cost functions φ e (x e ) are defined. Thus, the following problem must be solved: where the set of constraints defines the set of admissible solutions X of the formulated problem. The consumption and production function has the form: where v 0 source of the network, v i ∈ V t , i = 1, k destination i of the network, V t ⊂ V the set of all destinations and |V t | = k. It is assumed that all data are real values and it is desired to obtain an optimal solution that describes the minimum cost of transport. The nonlinear transportation problem on a network (1) -(3), (4) with piecewise concave cost functions can be solved using finite algorithms that are based on researching all spanning trees. In case the problems are described by dense and/or large graphs, for the solution of which the verification of all solutions, associated with the spanning trees, is impossible, it is recommended to use genetic algorithms. Such algorithms allow the keeping of promising candidates and the elimination of candidates with high transport costs. Thus, significantly reducing the number of admissible solutions that need to be researched in order to obtain a good result.

Description of the genetic algorithm AG
The size of the population generated in Step 1 and the method to code the problem are important elements that determine the amount of memory needed to store the data. In the following algorithm each chromosome is described only by the arcs that are part of the spanning tree that describes an admissible solution to the problem. Each chromosome, which describes an admissible solution, contains n − 1 genes given by pairs of numbers (i, j), which indicate that the arc starts from vertex i and enters the vertex j. At the same time, the size of the population must allow the processing of a sufficient number of admissible solutions so that the right one can be found in a reasonable time.
Selection applies a local search to the population, so that chromosomes with good characteristics of the current population are selected and transferred to the new population to participate in the creation of new chromosomes.
Crossover involves the transmission of genes from two parent chromosomes and the mutation involves the modification of a randomly selected gene. The application of crossover and mutation operators in the AG algorithm described below, can lead to situations where the restrictions of the existence of the network flow are not respected, which means that an admissible solution cannot be associated to the chromosome. In such situations, methods from graph theory are used to adapt the chromosome, which brings them to a shape that allows after decoding to obtain admissible solutions.
The genetic algorithm AG proposed for solving the transportation problem with concave non-decreasing piecewise functions consists of the following steps: Step 1 Initialization. A random initial population of 4n chromosomes is generated: each chromosome is described by a list of the form T = (i, j) | i, j = 1, n , where T is a spanning tree of the graph G = (V, E), |T | = n − 1 and each (i, j) is an arc that starts from the vertex i and enters the vertex j. Duplicates are deleted and the dimension of the population is adapted (see Remark 2.1).
Step 2 Decoding and Evaluation of the chromosomes. In the decoding process, to each chromosome an admissible solution is associated. For this purpose: • a zero flow is associated with the arcs of the initial graph that are not part of the spanning tree that describes the chromosome; • flow equal to the amount required by each destination is associated with the arcs that enter the respective destination; • by traversing the tree in depth, the remaining arcs (i, j) are associated with a flow equal to the total flow going passing through the outgoing arcs of the vertex j.
Evaluation involves determining the value of the objective function for each of the solutions obtained.
Step 3 Chromosome selection. Chromosomes are sorted in increasing order of the value of the objective function associated with the chromosome. Chromosomes in the first half of the population are transferred to the new population.
Step 4 Chromosome crossover. It takes place between the chromosomes transferred to the population P(i) from the population P(i − 1) through selection. The same random cut is applied to both parent chromosomes, in which the set of destinations is divided in two.
Chromosome crossover implies: • the first offspring obtains the arcs that form the paths from the source to the destinations from the set V t 1 of the mother-chromosome and the arcs that form the paths from the source to the destinations from the set V t 2 of the father-chromosome; • the second offspring obtains the arcs that form the paths from the source to the destinations from the set V t 1 of the father-chromosome and the arcs that form the paths from the source to the destinations from the set V t 2 of the mother-chromosome.
To each offspring the missing vertices are added together with the paths from the source to each vertex in the following way: 1. the first offspring gets the paths from the mother-chromosome; 2. the second offspring gets the paths from the father-chromosome.
In order to be able to associate each offspring chromosome with an admissible solution, a spanning tree is generated on the obtained graph. In this way, every pair of parent chromosome produces two offspring and the size of the population remains constant.
Step 5 Mutation. One gene of an offspring chromosome is mutated with the probability ϵ ∈ [0.1, 0.5]. Through mutation, one arc (i, j) is deleted and a new arc (i * , j) is chosen from the initial graph.
Step 6 Checking the stopping condition. This implies stopping the algorithm after k iterations. As the solution to the problem serves the solution with the minimal objective function associated with a chromosome from the last population.
In the following we will exemplify how the coding of an admissible solution takes place and also how a chromosome is decoded.
Example (coding) Consider the transportation network, in Figure 1, described by the graph with the set of vertices 1, 2, 3, 4, 5, where 1 is the source and 4, 5 are destinations, and the set of arcs {e 1 , e 2 , e 3 , e 4 , e 5 , e 6 , e 7 }. It is required to transport to destination 4 product flow of 45 u. c. and to destination 5 product flow of 55 u. c. from the source which contains 100 u. c. such that the transportation cost is minimal. A chromosome, in this case, is a set of 4 arcs which describe a spanning tree of this graph.
is constructed in the following way: 1. initially, a zero flow is associated with the arcs that are not part of the spanning tree: 2. flow is associated with the arcs that enter the destinations and do not have already zero flow: x 5 = 45 u.c., x 7 = 55 u.c.; 3. the remaining arcs are associated with flow: x 4 = 0 + 55 = 55 u.c., x 1 = 45 + 55 = 100 u.c..
The obtained admissible solution is x = (100, 0, 0, 55, 45, 0, 55). Knowing the admissible solution, the cost of transport on each arc and the value of the objective function are calculated, i.e. the total cost of transporting the flow from the source to all the destinations of the network.
In the following we will exemplify how the application of the crossover and mutation operator takes place on a chromosome of the population. Figure 2 a) and b) two spanning trees are presented that describe the two parent-chromosomes that are taking part in crossover:

Theoretical results
Remark 2.1 Because of the random generation of spanning trees in the initialization step, duplicates can appear. These are deleted from the population, so that the algorithm is not be forced to tend to a local minimum, instead of the global one. After eliminating the duplicates, the size of the population is reduced to the biggest number of the form 4p that is smaller than the number of available spanning trees. If necessary, other randomly chosen trees may have to be deleted in this step. This new size of the population is used in the steps 2-6 to determine the solution of the problem. Proof. The graph G = (V, E) is described by an adjacency list of size m < n 2 . Every chromosome consists of a list T of size n − 1. Thus, a population of 4n chromosomes is of size 4n(n − 1). The population is renewed at each step in-place, without any additional memory. Therefore, the algorithm AG requires O(n 2 ) memory.

Theorem 2.3 Algorithm AG converges to a local optimum.
Proof. From the P(i − 1) population, chromosomes, for which the value of the objective function is the smallest, are transferred to the P(i) population. The chromosomes constructed at each iteration represent spanning trees and each chromosome has an associated admissible solution. After a finite number of iterations, a chromosome will be found which has the solution associated, which describes a local optimum. Therefore, the AG algorithm converges to a local optimum.

Implementation and testing of the AG algorithm
Let the transportation network described by the graph in Figure 5 be given.
The set of vertices is associated with a production and consumption function of the form: Each arc {e 1 , e 2 , ..., e 23 } is associated with a cost function of the form  Initialization involves randomly generating a population of chromosomes. Each of them describes a spanning tree and has associated an admissible solution. After the value of the objective function is calculated, the chromosomes are sorted in increasing order and the first half of the chromosomes will be transferred to the next population. They will participate in crossover and each pair of parent -chromosomes will have 2 child -chromosomes.
If we make only 4 iterations, then the optimum solution to the problem will be considered the last one. The AG algorithm is implemented in the Wolfram language and tested on a set of examples transportation networks of various dimensions with different number of vertices, destinations and arcs.
In Table 1, the results of solving a set of transportation problems on networks with n vertices, m arcs and d destinations are presented, for which the concave piecewise cost functions are known, which depend on the transported flow and the consumption and production function.
Note that the cost functions are piecewise functions and are the same as φ 1 (x) and φ 2 (x) from the example above. By analyzing the table, it can be observed, that F T (x) always decreases from one iteration to another, which means that the population after each iteration contains more chromosomes with better characteristics than the ones after the previous iteration. Although the F(x) value is repeated in several consecutive iterations, the algorithm is able to exit from such a blockage through the operators of mutation, selection and crossover.
The execution time of the algorithm depends on the number of vertices of the graph, which is proved by the results presented in Table 2.
The tests were made on an Intel i5-2500 machine with 4 Cores and 8 GB of DDR3 memory in Wolfram Mathematica 12.