{'fraction_non_alphanumeric': 0.04712756662297947, 'fraction_numerical': 0.013488422892092617, 'mean_word_length': 3.9215264713786615, 'pattern_counts': {'":': 0, '<': 1, '<?xml version=': 0, '>': 1, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Average Shortest Path Length of Graphs of Diameter 3

A network topology with low average shortest path length (ASPL) provides efficient data transmission while the number of nodes and the number of links incident to each node are often limited due to physical constraints. In this paper, we consider the construction of low ASPL graphs under these constraints by using stochastic local search (SLS) algorithms. Since the ASPL cannot be calculated efficiently, the ASPL is not suitable for the evaluation function of SLS algorithms. We first derive an equality and bounds for the ASPL of graphs of diameter 3. Then, we propose use the simpliest upper bound represented by the number of triangles and squares in the graph as an evaluation function for graphs of diameter 3. We show that the proposed evaluation function can be evaluated in O(1) time as the number of nodes and the maximum degree tend to infinity by using some data tables. By using the simulated annealing with the proposed evaluation function, we construct low ASPL regular graphs of diameter 3 with 10 000 nodes.


I. INTRODUCTION
The network topology is significant on the performance of the interconnection network, and thus various kinds of topologies have been proposed and analyzed in many areas such as Datacenter network, High Performance Computing (HPC), Peer-to-peer system, Network-on-Chip (NoC), and so on [1], [2], [3], [4], [5], [6], [7]. In these areas, topologies with small diameter and low average shortest path length (ASPL) are desired. For example, the Hypercube topologies and the de Bruijn graphs are known to be effective for NoC architectures [5] and peer-to-peer networks [1], [3], respectively. Some topologies based on randomness have been proposed and explored in the area of Datacenter network and HPC [2], [6], [7].
The problem of finding the maximum graph for given maximum degree and diameter is called the degree/diameter problem, and has been studied in graph theory [8]. However, in practice, the order (the number of nodes) is often limited due to several reasons. Hence, for many applications, we are given order and maximum degrees, and try to minimize the diameter and the ASPL. This problem is called the order/degree problem, and has not been studied sufficiently. Recently, the importance of the order/degree problem is pointed out [9].
Some of the authors of [9] and their coworkers held a competition called "Graph Golf" on the order/degree problem [10].
The stochastic local search (SLS) is a framework of approximation algorithms for general optimization problems. In this paper, we consider the construction of low ASPL graphs of given order and given maximum degrees by using SLS algorithms. In a SLS algorithm, an initial feasible solution is generated (possibly be a random solution). Then, the solution is iteratively replaced by one of its neighborhoods. For our problem, we use a simple local modification procedure called switch for defining the neighborhoods. In this paper, we assume that SLS algorithms use the evaluation function which represents a quality of feasible solutions [11]. Since huge number of feasible solutions must be evaluated in SLS algorithms in general, efficient evaluation algorithms are strongly desired. However, the ASPL cannot be calculated efficiently at least in our knowledge, and hence is not suitable for the evaluation function.
In this paper, we assume that for given n and d, the dregular random graph of order n has the diameter 3 with high probability, and propose the evaluation function for graphs of diameter 3 which can be evaluated efficiently. More precisely, first, we derive an equality and bounds for the ASPL of graphs of diameter 3. On the basis of the simplest upper bound of the ASPL, we propose to use 3 +22 as the evaluation function of SLS algorithms where and 2 denote the number of triangles and squares in a graph, respectively. The proposed evaluation function can be evaluated in O(1) time as n and d tend to infinity by using some data tables. By using the proposed evaluation function in the iterative first improvement (IFI) and the simulated annealing (SA), we construct low ASPL regular graphs of diameter 3 with 10 000 nodes, which are the best graphs in the competition Graph Golf.
The remainder of this paper is organized as follows. In Section II, notions and notations used in this paper are introduced. In Section III, the equality and bounds for the ASPL of graphs of diameter 3 are shown. In Section IV, we propose the new evaluation function, and show an efficient algorithm for calculating the new evaluation function using data tables. In Section V, we show results of numerical experiments. Section VI concludes this paper.

II. PRELIMINARIES A. Notations and definitions
A graph G is a pair of two finite sets V and E where every element of E is a subset of V of size 2. Each element of V is called a node. Each element of E is called an edge. Let e ij := {i, j} for {i, j} ∈ E. The number n of nodes is called the order of G. For nodes u, v ∈ V , u is said to be connected to v if there is an edge {u, v} ∈ E. The degree d v of a node v is the number of nodes connected to v. A graph is d-regular if the degrees of all the nodes are equal to d.
For two graphs G = (V, E) and G = (V , E ), G is a subgraph of G if V ⊆ V and E ⊆ E. If G is a subgraph of G, we say G contains G . We say G is isomorphic to G if there is a bijection f : V → V that satisfies the following condition: For two graphs G and H, the number of H in G is the number of subgraphs of G that are isomorphic to H. For two nodes s and t, a s-t path or a path is a graph is called a cycle. The length of the cycle C is + 1. We call a cycle of length 3 and 4 a triangle and a square, respectively. Definition 1. For k = 0, 1, . . . a k-multiple triangle is a graph Such a k-multiple triangle is called a k-multiple triangle sharing i, j when we specify the two nodes i and j.
Such a k-multiple square is called a k-multiple square sharing i, j when we specify the two nodes i and j. Fig. 1 shows k-multiple triangles and k-multiple squares sharing i, j for k = 0, 1, 2. Note that the 1-multiple triangle and the 1-multiple square are equivalent to the triangle and the square, respectively. The number of k-multiple triangles and  the number of k-multiple squares in a graph are denoted by (k) and 2 (k) , respectively. Let := (1) and 2 := 2 (1) . For a graph G = (V, E) and s, t ∈ V , a s-t path whose length is minimum among all s-t paths contained in G is called the shortest path between s and t. The length of the shortest path between s and t is called the distance between s and t, denoted by dist(s, t). If G contains no s-t paths, we define dist(s, t) = ∞. The diameter of G is defined by max {i,j}⊆V,i =j dist(i, j).
Definition 3. For a graph G = (V, E), the average shortest path length of G is defined by In this paper, we consider the following graph optimization problem: For given n and d, Here, V (G) denotes the node set of G. Note that the set of feasible solutions of this problem is the set of all d-regular graphs of order n.

B. Stochastic local search for our problem
In this paper, we consider SLS algorithms described below. First, an initial d-regular graph G of order n is chosen randomly. Then, G is iteratively replaced by a local modification procedure called switch. In the switch procedure, a pair of edges (e ab , e cd ) is chosen and replaced by (e ac , e bd ) or (e ad , e bc ) as in Fig. 2. If the new graph G is not d-regular, i.e., at least one of the edges introduced by the switch already exists in G, a new pair of edges in G is chosen for the switch until a d-regular graph G is found. Here, the d-regular graph G , which can be obtained by a single switch of G, is called a neighborhood of G. Once a neighborhood G is found, G is evaluated by the evaluation function. According to the value of the evaluation function on G , it is determined whether or not the current graph G is replaced by G . This updating procedure continues until further improvement is not expected.
It is natural to define the evaluation function by the ASPL of G . In order to calculate the ASPL of a d-regular graph of order n, the distances of all node pairs have to be calculated, which takes O(n 2 d) time by using the breadth first search. Since it is not sufficiently efficient, low ASPL graphs cannot be obtained within a reasonable time for large n and d.
In this paper, we consider an optimization of d-regular graphs of diameter 3. The Moore bound implies that any graph of diameter 2 satisfies n ≤ d 2 + 1 and any graph of diameter 3 satisfies n ≤ d 3 − d 2 + d + 1 [8]. Furthermore, almost all graphs of diameter 2 satisfy n < d 2 [8], [12]. Therefore, if n ≥ d 2 and n is close to d 2 , then a random d-regular graph of order n is expected to have diameter 3 with high probability. For such n and d, if we choose a random d-regular graph of order n as the initial graph of a SLS algorithm, the diameter of every graph appearing in the SLS algorithm is empirically 3. By assuming that the diameter of graphs found by the SLS algorithm is always 3, the ASPL can be calculated in O(d) time 1 , which is still not sufficiently efficient for large n. In this paper, we give an upper bound of the ASPL of graphs of diameter 3, and propose SLS algorithms which uses the upper bound as the evaluation function. It will be shown that the upper bound can be calculated in O(1) time.

III. BOUNDS FOR THE ASPL OF GRAPHS OF DIAMETER 3
In this section, an equality and bounds for the ASPL of graphs of diameter 3 are shown. They are stated not only for d-regular graphs but also for general graphs.
For m = 1, 2, . . . , n − 1, (1) 1 The ASPL of graph of diameter 3 is determined by the adjacency matrix A of the graph and its square A 2 . Therefore, we can calculate the difference of the ASPLs of G and G by updating A and A 2 . The updating requires Note that S i,j k is either {{i, j}} or the empty set. Lemma 5. For a graph G = (V, E), where n k = #{{i, j} ∈ V 2 : dist(i, j) = k} for k = 1, 2.
We can obtain the lemma by using the inclusion-exclusion principle.
Proof: When m = 1 Here, we used the fact and | k∈K S i,j k | = 0 otherwise. If 0 ∈ K, (4) holds if and only if there is an (m − 1)-multiple triangle sharing i, j whose node set is {i, j}∪K \{0}. Similarly, if 0 / ∈ K, the equality (4) holds if and only if there is an (m−1)-multiple square sharing i, j whose node set is {i, j} ∪ K.
Assume m = 2. If there is a triangle consisting of three nodes i, j and k and of edge set {e ij , e jk , e ki }, it holds If there is a square consisting of four nodes a, b, c and d and of edge set {e ab , e bc , e cd , e da }, it holds Proof: ASPL(G) can be represented by where n k = #{{i, j} ∈ V 2 : dist(i, j) = k} for k = 1, 2, 3.

Theorem 8. When t is even
When t is odd Proof: When t is even, by applying the Bonferroni inequality to (2) [13], one obtains The theorem for odd t can be proved in the same way.
Corollary 9. For a d-regular graph G of order n and diameter 3, Corollary 10. For a d-regular graph G of order n and diameter 3, The lower bound (7) agrees with the Moore bound [8].

IV. PROPOSED EVALUATION FUNCTION AND ALGORITHM
A. SLS using the upper bound as the evaluation function In this paper, we propose SLS using (8) as the evaluation function. More precisely, the evaluation function g in our SLS is defined by g(G) = 3 + 22.
Since the minimization of (9) is equivalent to the minimization of (8), we can expect that the SLS algorithm using the above evaluation function finds a graph with low ASPL if all graphs appearing in the SLS algorithm have diameter 3. In this section, we show that a difference g(G )−g(G) for a d-regular graph G of order n and its neighborhood G can be calculated in O(1) time by using three two-dimensional arrays. We also show that these three arrays can be updated in O(d 2 ) time.
In SLS algorithms, the frequency of the evaluations is much higher than the frequency of the updates. Therefore, our SLS is much faster than SLS using the ASPL as the evaluation function, which needs O(d) time both for the evaluation and the update.
We assume that a neighborhood G of G is obtained by replacing e ab , e cd ∈ E(G) with e ac , e bd ∈ E(G). The switch can be divided into two steps: the removal of e ab , e cd and the addition of e ac , e bd . First, we consider the removal of e ab and e cd . Since no triangles contain both of e ab and e cd , the number of triangles decreases by

T2[a][b] + T2[c][d].
(11) Next, we consider the addition of e ac and e bd to the graph obtained by the removal of e ab and e cd . Note that the arrays T1, T2 and T3 remain unchanged at this time. After the removal of e ab and e cd , the addition of e ac increases the number of triangles by Here, the terms T1[a][d] and T1[b][c] take account of nonexistent paths a-d-c and a-b-c, respectively. Similarly, the addition of e bd increases the number of triangles by Hence, from (11), (12) and (13) We conclude that we can calculate g(G ) − g(G) in O(1) time if T1, T2 and T3 for G are given.

C. Array update
When e ab is removed, T2 can be updated by decrementing

A. Accuracy of approximations
In this section, we show by numerical experiments that the upper bounds and lower bounds obtained by Theorem 8 are also good approximations for the ASPL. Table I shows the relative error ( ASPL(G) − ASPL(G))/ASPL(G) of the approximations where ASPL(G) denotes the bounds obtained by Theorem 8 for t = 1, 2, 3, and where G denotes a random d-regular graph of order n where (n, d) = (4096, 60), (4096, 64), (10 000, 60), (10 000, 64). The diameters of these graphs are 3. Table I implies that the approximations are more accurate as t increases. Furthermore, Table I also implies that the approximations are more accurate for sparse graphs. It can be easily understood since , 2, (2) , 2 (2) , . . . are small when a graph is sparse.

B. Construction by Iterative First Improvement
The Iterative First Improvement (IFI) algorithm is one of the simplest SLS algorithms. The IFI algorithm evaluates neighborhoods one after another. When the IFI finds the neighborhood whose value of the evaluation function is lower than that of the current solution, it replaces the current solution by the neighborhood and then starts to evaluate the next neighborhood. The evaluation and replacement continues until the IFI algorithm finds the local optimum. We consider the IFI algorithm with the O(1)-time evaluation function proposed in Section IV.
In order to improve the efficiency of the IFI algorithm, we modify the IFI algorithm as follows: At every 50 replacements, the set of edges are sorted by the number of triangles and squares that contain the edge. More precisely, all edges are sorted in descending order of 3 e + 22 e where e and 2 e denote the number of triangles and squares that contain the edge e, respectively. After the sort, all pairs of edges are chosen in the order of (e 1 , e 2 ), (e 1 , e 3 ), . . . , (e 1 , e |E| ), (e 2 , e 3 ), (e 2 , e 4 ), . . . . This modification is useful for finding efficiently a neighborhood improving the value of the evaluation function. Table II shows the ASPL, the Moore bound (7), denoted by L, and the ASPL gap (ASPL(G) − L)/L for random d-regular graph G of order n. From these random graphs, we applied the above modified IFI algorithm, and obtained local optimals. Table III shows the ASPL, the ASPL gap for the local optimals and the required time for the modified IFI. These numerical experiments are performed on MacBook Pro, Intel Core i7 2.6GHz. The modified IFI found a local optimal within two days. The obtained local optimals have  smaller ASPL gap than the original random graphs. Especially, for (n, d) = (10 000, 60), (10 000, 64), the ASPL gaps are significantly improved.

C. Construction by Simulated Annealing
The Simulated Annealing (SA) is one of the most successful SLS algorithms. The SA in our numerical experiments works as follows. At each step, a neighborhood is chosen uniformly at random and evaluated. If the value E of evaluation function for the neighborhood is lower than that E for the current solution, then the current solution is replaced by the neighborhood. Also, even if the neighborhood has the higher evaluation value than the current solution, i.e., E > E, the current graph is also replaced by the neighborhood with probability P where Here, T is a parameter called the temperature which decreases at each step of SA. The annealing schedule, which determines the temperature at each step, is crucial to the SA. In the numerical experiments, we set T (k) := 11/ ln(k + 1) where k denotes the number of graphs which are evaluated until that time. Table IV shows the ASPL of graphs constructed by applying the SA 60 days, and then applying the modified IFI. They are the best graphs obtained in the Graph Golf [10].

VI. CONCLUSION
We derived the equality and bounds for the ASPL of graphs of diameter 3 by using the number of triangles, squares, and some other structures in a graph. By numerical experiments, we confirmed that the upper and lower bounds obtained are also accurate approximation for the ASPL. On the basis of one of our bounds, we propose to use 3 + 22 as the evaluation function of SLS for the ASPL minimization problem where n is at least and close to d 2 , so that the random graph has diameter 3 with high probability. We show that the proposed SLS algorithms requires O(1) time for the evaluation and O(d 2 ) time for the update. We construct low ASPL graphs of diameter 3 by IFI and SA using our evaluation function. While the upper bound evaluated by the proposed algorithm is represented only by the number of triangles and squares, the other bounds represented by the number of more complicated structures such as (2) , 2 (2) are confirmed to be more accurate. Thus, if there exists O(1)-time evaluation algorithm that calculates one of these bounds, then we can use the bound as the evaluation function of SLS. It would construct graphs with lower ASPL.
Finally, we note that our bounds of ASPL for graphs of diameter 3 can be generalized to larger diameter in a similar way. The construction of low ASPL graphs of larger diameter by similar algorithm is an interesting future work.