USING MODIFICATION OF PRIM’S ALGORITHM AND GNU OCTAVE AND TO SOLVE THE MULTIPERIODS INSTALLATION PROBLEM

The Minimum Spanning Tree (MST) is one of the famous problems that is used mostly as the backbone in many network design problems. Given a graph G(V,E), where V is the set of vertices and E is the set of edges connecting vertices in V, and for every edge eij there is an associated weight cij ≥0. The Multi Period Degree Constrained Minimum Spanning Tree (MPDCMST) is a problem of finding an MST while also considering the degree constrained on every vertex, and satisfying vertices installation requirement on every period. Two algorithms (WWM1 and WWM2) are proposed for solving this problem. GNU OCTAVE is used for coding and visualization. GNU is a recursive acronym for "GNU's Not Unix!", and that name is chosen because it is like Unix but differs from Unix because it is free and contains no Unix code. Those algorithms were implemented using 300 randomly generated problems. Moreover, we compare WWM1 and WWM2 algorithms using existing data from the literature and the results show that WWM2 is the best. ABSTRAK: Minimum Spanning Tree (MST) merupakan salah satu masalah mahsyur yang banyak digunakan sebagai tulang belakang kepada masalah banyak rekaan jaringan. Menerusi graf G(V,E), di mana V adalah himpunan titik dan E adalah himpunan garis yang menghubungkan titik-titik dalam V, dan bagi setiap garis eij terdapat berat berhubung cij ≥0, Multi-period Degree Constrained Minimum Spanning Tree (MPDCMST) merupakan masalah dalam menentukan MST, pada masa sama turut menimbangkan kekangan pada setiap titik vertek, dan memenuhi syarat keperluan pemasangan pada setiap detik. Dua algoritma (WWM1 dan WWM2) dicadangkan bagi menyelesaikan masalah ini. GNU OCTAVE digunakan bagi pengaturcaraan dan visualisasi. GNU merupakan suatu singkatan kepada “GNU's Not Unix”, dan nama tersebut dipilih karena ianya seperti Unix, tetapi berbeza dari Unix kerana ia percuma dan tidak mempunyai kod Unix. Algoritma tersebut dilaksana dengan menggunakan 300 masalah terhasil secara rawak. Tambahan, algoritma WWM1 dan WWM2 dibandingkan dengan kajian terdahulu dan hasil kajian menunjukkan WWM2 adalah terbaik.


INTRODUCTION
In most network design problems, The Minimum Spanning Tree (MST) is usually used as the backbone. If we add degree restriction on the vertices (can represent cities, https://doi.org/10.31436/iiumej.v21i1.1088 stations, etc.) of the graph (represents the network), the problem becomes a Degree Constrained Minimum Spanning Tree (DCMST) problem. Moreover, if we restrict and divide the stages or periods of the network's installation, the problem emerges as a Multi Period Degree Constrained Minimum Spanning Tree (MPDCMST) problem. The later constraint usually occurs because of the fund limitation for installing (connecting) the network. This problem arises when we want to design a network that requires that every vertex (node) restricts the number of connections/interfaces whilst also considering a set of vertices that have to be connected/ installed in a certain period due to the fund restriction (weather, etc.) In this paper, we organize the discussion as follows: in Section, 2 we give the history of the problem; in Section 3, we discuss how to apply the algorithms developed using GNU Octave and implement them; in Section 4, we discuss the results; followed by a conclusion.

THE CONSTRAINED MINIMUM SPANNING TREE PROBLEM
It Because of its specific structure and use in many network design problems, the Minimum spanning tree problem has been studied extensively and a variety of fast algorithms have been developed. An efficient and fast minimum spanning tree algorithm that requires computational time nearly linear in the number of edges had been developed [1]. The MST problem is one of the classical problems where the objective is to construct a minimum cost/weight network. This problem usually arises in network design applications that must satisfy other graph parameters such as: degree, distance, diameter, connectivity, flow, etc. For instance, in a transportation network, a distance restriction on the flow commodities could represent the maximum distance allowed for delivery.
The Degree Constrained Minimum Spanning Tree (DCMST) problem is a Minimum Spanning Tree with a degree restriction on every vertex. This problem arises when designing networks where the degree restriction represents the number of allowable links on that vertex, i.e. the handling capacity of each of the vertices imposes a restriction on the number of edges (or wires/roads) that can be connected to a vertex. For example, the application of The DCMST is present in designing the road system, where the set of roads must connect a collection of suburbs/towns, but there is a restriction that no more than a certain number of roads (example: four roads) are allowed to meet at an intersection.
There are lots of investigations regarding the DCMST problem. This problem is considered to be an NP-Complete problem. An NP-complete problem is any of a class of computational problems for which no efficient solution algorithm has been found. Because of its NP-completeness [2], heuristic methods have dominated such as: the greedy algorithm based on Prim's and Kruskal's algorithm by [3], the Genetic Algorithm by Zhou and Gen [4], the Iterative Refinement by Deo and Kumar [5], the Simulated Annealing by Krishnamoorthy et al [6], the Modified Penalty by Wamiliana [7], and the Tabu Search by Caccetta and Wamiliana [8], Wamiliana and Caccetta [9][10].
In real situations, connecting all components in a network requires a certain time and process in order to be completed. The time of completion can vary depending on the need and priority of the network itself. The Multi Period Degree Constrained Minimum Spanning Tree (MPDCMST) problem was introduced in 2002 by Kawatra [11] and it proposed the hybrid of branch exchange and Lagrangean relaxation method to solve the problem on directed graph with vertex order ranging from 40 to 100. By modifying the problem in using the undirected graph, some algorithms based on Kruskal's and Prim's https://doi.org/10.31436/iiumej.v21i1.1088 algorithms were developed. WADR1 and WADR2 algorithms were developed by doing some modifications on Kruskal's algorithm [12], while WADR3 and WADR4 are the algorithms developed as varians of WADR1 and WADR2 [13]. Motivated by the connectivity property on the process of finding MST by Prim's algorithm, some algorithms were developed by Wamiliana et al. [14][15][16]. Wamiliana et al. [17] illustrated why the quality of the solution also depends on the number of vertices in HVTi (the set of vertices that must be installed/connected in i th period or before). The comparison of some algorithms developed and implemented on undirected graphs was given in Wamiliana et al [18] especially on the process of installation/connection of vertices in HVTi.

GNU OCTAVE
GNU Octave is a free software that runs on GNU/Linux, macOS, BSD, and windows. This software originally was intended as a companion to a chemical reactor design course, but the one who first developed it is John W. Eaton [19]. Since this is free software, users are encouraged to modify and develop this software and are free to distribute it as well.
The difference in using GNU Octave as opposed to other language programming (such as Java), is that GNU Octave is more rigid. Certain rules must be followed (such as converting to matrix form or others). Java is more flexible to development of the program. For example, the data used for implementation represent the edges of the complete graph for certain vertex orders. For vertex order 10, the number of edges is 45, which is obtained from the formula n(E) = , n =10. Before putting in GNU Octave, we have to modify this equation to be . This is a quadratic equation and to find n, is used. Thus, to read the data, the source code for reading the data (vertex order) is as follows ( let n(E) = Un): function vertex = check_vertex(matrix) bykedge=length(matrix);%bykedge=Un c=2*bykedge; n=(1+sqrt(1+(4*c)))/2; vertex=n; end In GNU Octave, the graph was represented using a matrix, therefore a source code was designed so that when a problem is entered as a data problem, then the program would automatically detect the data and arrange it as two matrices, one as the matrix for original vertices (X) and the other for terminal vertices (Y). For example, if the data of a complete graph with order ten (consists of 45 edges) is entered, then the program automatically defines X and Y as follows: After the X and Y are generated, the value of the weight will be put to connect X and Y in the form of a symmetrical matrix K, as follows (example for datafile 10.dat): For implementation, the same data used as in [12,14,16]. The data are generated randomly with the edge weight varying from 1 to 1000. For every vertex order, 30 problems were generated.

WWM1 and WWM2 Algorithms
We developed two algorithms to solve the MPDCMST based on Prim's algorithm and modified them to satisfy the given constraints. The reason for choosing Prim's algorithm was that Prim's maintains the connectivity property during the connection/installation process. In these algorithms, we used the terminologies HVTi as the set of vertices that must be installed/connected on i th period or before, and MAXVTi as the maximum number of vertices that can be connected on the i th period. The reason for using HVTi was that in reality, it is possible to add some requirements that some components in the network be connected early due to public needs or other reasons. For example, in designing a fresh water pipe or electricity network, there is a requirement that some buildings (hospitals, police stations, government buildings, etc.) must be installed/connected within a certain period or earlier in the network.

WWM1 Algorithm
The WWM1 algorithm starts by setting vertex 1 as the root and puts it in set V. V is the set of vertices in the network. Initially, V only contains vertex 1 as the central vertex, V ={1}, and no edges in T, T ={}. Then, the algorithm checks the nearest vertices in HVTi to be connected/installed in V and the corresponding edges to the network (T). The algorithm will continue connecting/installing those vertices in HVTi as long as the connection neither violates the degree restriction nor constitutes a cycle. If degree violation occurs, then edge exchange will be performed while also maintaining the connectivity of vertices in HVTi. Next, the algorithm will check the MAXVTi, and connect the edges with the smallest edge weight to T, as long as the connection neither violates the degree constraint nor constitutes a cycle. If the number of vertices connected on that period is already the same as MAXVTi, the algorithm will continue to the next period, and the process is similar to the previous period until all vertices are connected/installed. To illustrate the WWM1 algorithm we used one problem with vertex 5  6  7  8  9  10  5  6  7   8  9  10  6  7  8  9  10  7   8  9  10  8  9  10  9 10 10 order 10 in the data (datafile.22 dat). The weight of the problem is given in Table 1. The data represents a complete graph of order 10, and the graph is illustrated in the Fig. 1. Moreover, we use the same set of HVTi as in [12][13][14][15][16][17] as given in Table 2, and also use MaXVTi as the floor function of , .  For the first period, the algorithm checks the vertices in HVT1= {2}. Vertex 2 is the only vertex in HVT1 then the algorithm connects vertex 2 to T using edge e12 with weight 740. V and T are updated to V= {1,2} and T ={e1-2}. Next, the algorithm checks the difference of MAXVT1 = = 3 and the number of vertices in HVT1. HVT1 is the number of vertices in HVT1, HVT1 =1. Since the difference of MAXVT1 and HVT1 is 2, then it is possible to add two more vertices. Therefore, the algorithm searches for the next smallest edge with the vertices in the network which is e2-4 with weight 109. Adding e2-4 to T neither creates a cycle on T nor violates degree restriction on the vertices in V. Then, e2-4 is added to T and vertex 4 to V. V and T are again updated to V= {1,2,4} and T = {e1-2, e2-4}. Since vertex 4 was already added to V, then only one more vertex can be added, and e1-10 is the next smallest edge with weight 120. Adding e1-10 neither creates a cycle in T nor violates degree restriction on vertices in V. Therefore e1-10 was added to T and vertex 10 to V. V and T are updated to V= {1,2,4,10} and T = {e1-2, e2-4, e1-10}. Since MAXVT1 is achieved, the first period is finished. The following figure shows the network after the first period is finished. On the second period, HVT2 ={3}, therefore the algorithm connects vertex 3 to the network using the smallest edge of incidence with vertex 3; edge e2-3 is the smallest. Adding e2-3 to T neither violates the degree condition nor constitutes a cycle, therefore e2-3 is added to T and vertex 3 to V. V and T are updated to V= {1,2,4,10,3} and T = {e1-2, e2-4, e1-10, e2-3}. Then, the algorithm checks MAXVT2 HVT2 which is 2. Therefore, in this period, we can add two more edges to T and two more vertices in V. The next smallest edge of incidence with the vertices in V is e5-10 with a weight of 112. Adding e5-10 to T neither violates the degree condition nor constitutes a cycle, therefore e5-10 is added to T and vertex 5 to V. V and T are updated to V= {1,2,4,10,3,5} and T = {e1-2, e2-4, e1-10, e2-3, e5-10}. Next, the algorithm searches the smallest edge of incidence with the vertices in V which is e4-9 with a weight of 187. Adding e4-9 to T neither violates the degree condition nor constitutes a cycle, therefore e4-9 is added to T and vertex 9 to V. V and T are updated to V= {1,2,4,10,3,5,9} and T = {e1-2, e2-4, e1-10, e2-3, e5-10, e4-9 }. This is the end of the second period, and the network is illustrated in Fig. 3. first period). After the second period was done, vertex 3 (the member of vertices in HVT2) was in the network, as well as vertex 4 (an element in HVT3). Therefore, the algorithm is just searching for the smallest edges of incidence to the uninstalled vertices and to connect them to the network. Three edges that satisfy that condition and also neither create a cycle nor violate the degree condition (maximum degree is 3 for every vertex) are e4-8, e6-8, e6-7 with weight 251, 411, and 559 respectively. V and T are updated to V= {1,2,4,10,3,5,9,8,6,7} and T = {e1-2, e2-4, e1-10, e2-3, e5-10, e4-9, e4-8, e6-8, e6-7}. All vertices are then in set V, so the algorithm stops. Figure 4 represents the network when the third period is finished. Fig. 4: The network when the third period is finished. Table 3 gives the information about the period when the edges are installed/connected, the weight, and the total weight after the connection are done.

WWM2 Algorithm
The WWM2 algorithm is similar with the WWM1 algorithm, except in the WWM2, the process of connecting the vertices in HVTi is more flexible. Those vertices in HVTi can be installed in the beginning of the period or at the end, as long as the installation/connection process is still within that period or before. In the first period of the WWM2 algorithm, vertex 2 is not installed first, but the algorithm searches for possible smallest edges among those in the data that connect to vertex 1. This is possible because MAXVT1 = 3 and the number of HVT1 = HVT1 =1 (only consist of vertex 2). Therefore, it is possible to add two more vertices (but not vertex 2) in the network. Therefore vertex (node) 10 was connected first, followed by vertex 5, and finally, because vertex 2 must be installed/connected in the first period, then vertex 2 is installed. Figure 5 shows the network after the first period of the WWM2 algorithm is done. For the second period of the WWM2 Algorithm, the vertex in HVT2 is vertex 3. However, the algorithm first checks the difference between MAXVT2 and the number of HVT2. Since MAXVT2 -HVT2 = 2, then it is possible to add the other two vertices (besides vertex 3). However, if vertex 3's incidence with the smallest edge that connected with the vertices already in the network during the first period, then vertex 3 will be installed/connected first on the second period (of course, without violating the degree requirement on the vertices that are already in the network). Since the smallest edge on the second period is edge e24 then that edge is connected first on the second period, followed by edge e49. After edge e49 was added in the network, then there are no more choices except adding the smallest edge of incidence with vertex 3, because vertex 3 must be installed/connected on the second period or before. Figure 6 shows the network after the second period of the WWM2 algorithm is done.
Similar with the WWM1 algorithm, on the third period of the WWM2 there are 7 vertices already in the network and there are three more vertices still uninstalled. Those vertices are vertex 6, 7, and 8. The difference between WWM1 and WWM2 is that vertex 4 in WWM1 is installed/connected on the first period, while in WWM2, vertex 4 is connected on the second period. The next three smallest are e48, e28, and e210. There are no degree restrictions and cycle occurrences by adding e48, therefore vertex 8 is connected. However, there is a problem with adding e28. The degree of vertex 2 is already 3, then adding e28 will violate the degree restriction, therefore e28 is omitted, and not connected. A different reason is applied to e210. Adding e210 will create a cycle, therefore e210 is also omitted. Now, the algorithm is just searching for the next two smallest edges of incidence to the uninstalled vertices to connect them to the network (as long as the connection neither violates the degree restriction nor creates a cycle). The next two smallest are e68 and e67. Figure 7 shows the network after the third period is finished.     Table 4 gives the information about the period when the edges are installed/connected, the weight, and the total weight after the WWM2 Algorithm finishes the process.

RESULTS AND DISCUSSION
The WWWM1 and WWM2 algorithms were compared against WADR5, WAC1 and WAC2 algorithms because those three algorithms are developed based on the same algorithm (Prim's algorithm). Moreover, those algorithms were implemented using the same data, same set of HVTi,, MAXVTi and the number of periods. The data used for implementation was random problems generated using uniform distribution with weight ranging from 1 to 1000 (integer). For every vertex order, there are 30 problems generated and the vertex order used are 10 to 100 in increments of 10. Therefore, there are a total of 300 problems implemented. The solution taken is the average solution from 30 problems for every vertex order. The following table shows the result: From Table 5 we can see the average solutions for MST, DCMST, WWM1, WWM2, WADR5, WAC1, and WAC2. For the algorithms developed for solving MPDCMST (WWM1, WWM2, WADR5, WAC1, and WAC2) the best performance is gained by the WWM2 algorithm, which is slightly close to the performance of WAC2, while the WWM1 and WAC1 are the two worse algorithms compared in this study. WWM1 and WAC1 are two algorithms developed based on the Modified Prim's algorithm where the priority vertices in the set HVTi must be installed/connected as soon as possible, while WWM2 is a modification of WWM1, and WAC2 is a modification of WAC1. The modification made for those two algorithms is the same: relaxing the process of connecting the priority vertices in HVTi whilst also maintaining those vertices to be connected in the i th period or before. WADR5 is an algorithm developed based on Modified Prim's algorithm where the algorithm searches two smallest edges for being considered to be connected in the network, except the last one in the period. In this study, we compared the ratio of the algorithms (WWM1, WWM2, WADR5, WAC1, and WAC2) against their lower bound (DCMST). The ratio is

LB LB H
, where H is the heuristic (algorithm) and LB is the lower bound (DCMST).  From Table 6 we see that average ratio of the WWM1 and WAC1 algorithms against the lower bound are above 50%. These values show that the performance of the algorithm is not good. The performance of WWM2 and WAC2 are below 20%, while the ratio of WADR5 is around 34%. The smaller the value of the ratio, the better the performance. The closer the solution of the algorithm to the solution of the DCMST, the better the algorithm. Figure 8 shows the performance of the algorithm.

CONCLUSIONS
From the results and discussion we can see that among WWM1, WWM2, WADR5, WAC1, and WAC2 algorithms, WWM2 performs the best, followed by WAC2 algorithm. These two algorithms have similar approaches: relaxing the time of installation for vertices in HVTi or adding flexibility to the algorithm. Accepting flexibility in the process of connecting/installing the vertices without violating the rules gives a better solution rather than sticking with the schedule of connecting the vertices in a certain order.