1. Introduction
In this work, we will show that the two seemingly unrelated problems in physics and computer science are, in fact, closely related. The physics problem is finding the optimum trajectory or configuration of a system that minimizes a functional integral. This is the variational problem that frequently occurs in physics and engineering [
1]. The computer science problem is finding the shortest path between two vertices in a weighted graph. The commonly used algorithm is Dijkstra’s algorithm [
2], which is a single-source path-finding algorithm that finds the shortest paths from an initial vertex to all vertices in a network.
The motivation for the work comes from our need for an algorithm to find the ray path of a wave traveling through a complex medium. The simplest approximation is to assume that the ray path is a straight line. However, due to the inhomogeneity and anisotropy of the medium, the ray path can be curved. The question arises: How can we obtain a suitable ray path that joins two points in the medium? A way to find the ray path is to apply Fermat’s principle of least time, which states that the wave will follow the path that takes the shortest time of flight (ToF) [
3]. Thus, our problem of finding the ray path becomes an optimization problem. If we define the shortest path as the path with the smallest accumulated ToF, the ray path in a medium could be obtained by a suitable path-finding algorithm.
The application of Fermat’s principle is an example of a variational problem, where the basic question is finding the function that minimizes a functional integral. We know from calculus that an integration is nothing but the accumulation of its integrand along the integration path [
4]. Thus, if we define the shortest path as the path that gives the minimum value of the integral, the variational problem could also be solved by a suitable path-finding algorithm.
Interpreting the variational problem as a shortest path finding can be very useful since we can use a single framework of path-finding algorithms to solve a variety of variational problems, which can be vastly different in detail. However, we found very few works in this line of study [
5,
6]. To develop the path-finding algorithm that gives satisfying numerical solutions to the variational problems, further investigation is needed.
Many algorithms have been developed to solve the shortest path-finding problem. In this work, we focus on Dijkstra’s path-finding algorithm. Due to its simplicity and speed, the algorithm is commonly used in the shortest path-finding problem. The application ranges from production planning process [
7], video game design [
8], finding the optimum path for autonomous vehicles [
9,
10] and maritime transportation [
11], logistics robots path planning [
12], VLSI circuit optimization [
13], and software-defined networks [
14].
The objective of this work is to propose a general idea of how to numerically solve a variational problem using Dijkstra’s shortest path-finding algorithm. We also validate our proposal by applying the algorithm to solve three famous variational problems, i.e., the optical ray tracing, the brachistochrone, and the catenary problems. The structure of the paper is as follows. In the next section, we propose the general idea of how to formulate a variational problem as a shortest path-finding problem. We also describe the space discretization. Since the path-finding algorithm works on a discrete network, proper space discretization is needed. The resulting spatial discrete network should have a large number of surrounding edges joining each vertex to achieve an accurate numerical approximation. In
Section 3, we briefly describe Dijkstra’s algorithm. Even though the algorithm is well known, the description of the algorithm explained in the computer science literature can be complicated. Our simplified description should be useful, especially for the people outside the field. In
Section 4,
Section 5,
Section 6 and
Section 7, we apply Dijkstra’s algorithm to solve three variational problems. The first two problems have no constraints and can be solved directly by Dijkstra’s algorithm. The last problem has a constraint, so we need to modify Dijkstra’s algorithm to solve it, in which we apply the Lagrangian relaxation technique to incorporate the constraint into the algorithm. Since these three problems have exact solutions, we can use them to validate our proposal. In the last two sections, we summarize our work and discuss the further application of the path-finding algorithm to the more complicated variational problems.
2. Variational Problems as the Shortest Path Finding
The basic question of the variational problem involves finding a function y(x) that minimizes an integral I of a functional F,
where y′ = dy/dx. The function y(x) can be interpreted as a path on the two-dimensional xy-plane, joining the points (x
a,y(x
a)) and (x
b,y(x
b)). Conventionally, we can use the technique of calculus of variations to show that the optimum path that minimizes the integral I is the solution of the Euler–Lagrange differential equation [
1].
The problem can be generalized to three or more dimensions. For a three-dimensional problem, the functional F can be expressed as F(x,y,z,y′,z′), where z′ = dz/dx. The Euler–Lagrange equations are generalized to be a set of differential equations,
Similar to the two-dimensional case, the solutions y(x) and z(x) of Equation (3) can be interpreted as the optimal path in three dimensions joining the points (xa,y(xa),z(xa)) and (xb,y(xb),z(xb)).
There are various techniques to solve the Euler–Lagrange Equations (2) or (3), depending on the exact form of the functional F [
1]. In some cases, solving the equations can be hard. For some problems, deriving equations can be hard in the first place [
15,
16,
17,
18,
19,
20,
21,
22]. As mentioned in the previous section, we raise the following question: Is it possible to find the optimal path directly from the definition of the problem in Equation (1), avoiding the complications of solving Equations (2) or (3)?
In graph theory, there is a class of problems called shortest path finding, which aims to find the shortest path joining two vertices in a weighted graph. The definition of the shortest path here is the path with the smallest accumulated weight among all possible paths. To clearly see the problem statement, let us consider a simple example.
Figure 1 shows a simple graph with six vertices. Each edge connected by two adjacent vertices is assigned a weight. The problem involves finding the shortest path from vertex a to b. We can see that the green path is the shortest path with the minimum accumulated weights of 9 + 2 + 9 = 20. For this simple graph, the shortest path can be easily obtained by hand. In practice, the graph can be complicated, with large numbers of vertices and edges. Sophisticated algorithms have been developed to solve this kind of problem [
23,
24].
It is interesting that the goals of variational problems and shortest path finding are almost identical. If we discretize the domain of a variational problem into a spatial network and properly define the weight of each edge using the integrand in Equation (1), it is possible to find the solution of a variational problem using a path-finding algorithm from the graph theory.
The first crucial step is the space discretization. Since the path-finding algorithms are discrete in nature, the original continuous domain of a variational problem has to be discretized to a spatial network of a finite number of vertices connected by edges. To achieve the accurate numerical approximation of the optimum path, the Euclidian distance between adjacent vertices must be small to approximate the original continuous domain. However, it is more important that a vertex must be connected by a large number of surrounding edges. In the original variational problem, a path lies in the continuous domain. Its trajectory directions can vary continuously. When the domain is discretized, the trajectory directions are limited. Thus, each vertex must be surrounded and joined by a large number of edges to approximate the infinitely possible directions of the trajectories passing through the vertex. Obviously, the conventional square lattice is not qualified since it allows only the vertical and horizontal edges to join a vertex. In this work, we adopt the Moser lattice [
25], which is basically the square lattice with sub-lattices on the sides of a plaquette. The edges are defined as the pair-wise connection between the lattice points on the same plaquette. We can see that introducing sub-lattices increases the number of edges and path directions joining a vertex. Since each edge always lies inside or on the side of a plaquette, the lattice is short-range connected. The Euclidian distances between adjacent vertices on the lattice are of the order of the main lattice spacing. Thus, our discrete network gives a good approximation of the continuous medium when the lattice spacing is small, and the number of sub-lattices is large.
Figure 2 shows an example of a two-dimensional Moser lattice with 3×3 main lattices and five sub-lattices on each plaquette side. Even though the edges connecting vertices are abstract entities, it is useful to picture them as the real paths joining the vertices. In
Figure 2, the edges are the thin straight line joining the vertices on the sides of the same plaquette.
Next, we define the weight w
ij of the edge joining the vertices i and j as
Here, F is the functional defined in Equation (1);
and
are the sets of values of x, y, and y′ on edge, respectively; and
is the Euclidian distance between vertices i and j along the x-axis. The accumulated weight along a path can be defined as
Figure 3 shows the examples of paths connecting the lower left and upper right vertices (vertices a and b, respectively) in the network in
Figure 2. The accumulated weight along the red path is
= w
ac + w
cd + w
db, and the accumulated weight along the blue path is
= w
ae + w
ef + w
fg + w
gh + w
hb. We can use a path-finding algorithm to find, among all possible paths, including these red and blue paths, the path that gives the smallest value of
.
The main message of this work is that, for a spatial network with lattice spacing l and a number of sub-lattices s, we have
In other words, for the spatial network with infinitesimal small lattice spacing and an infinitely large number of sub-lattices, the shortest path obtained from a path-finding algorithm is identical to that in the variation problem. Practically, we expect that the shortest path connects two vertices on a spatial network with small lattice spacing, and a large number of sub-lattices can be used to approximate the optimal path with the same initial and final points in the variational problem.
3. Dijkstra’s Algorithm
The next step is choosing the path-finding algorithm. Among various path-finding algorithms available, Dijkstra’s algorithm is the one that is commonly used in research. We adopted the algorithm since it is very convenient to implement in our work. The algorithm is used in many scientific computing programs. For example, in MATLAB, we can use the command shortestpath to find the shortest path in a network (
https://www.mathworks.com/help/matlab/ref/graph.shortestpath.html, accessed on 10 November 2024). If all edges have positive weights, the program will use Dijkstra’s algorithm to do the job.
In 1959, E. W. Dijkstra published his path-finding algorithm [
2], originally used to find the best route to travel between cities. The algorithm can be described as follows:
Define a network of vertices and edges connecting vertices;
Define the weight of each edge;
Define the lists of visited vertices, unvisited vertices, and previous vertices;
Define a starting vertex;
Initially, define the score of the starting vertex as zero and the score of other vertices as infinity;
Check the unvisited vertices list. Set the unvisited vertex with the smallest score as the current vertex;
From the current vertex, calculate the cumulated weight from the starting vertex to the unvisited neighbors;
If the cumulated weight is less than the score of the neighbor, update the score with the cumulated weight and update the previous vertices list of the updated neighbors with the current vertex;
Add the current vertex to the visited vertices list;
Repeat step 3.6 until all nodes are visited.
Once finished, the score of each vertex gives the shortest distance from the starting vertex. The corresponding shortest path can be obtained by backtracking the data from the previous vertices list. The algorithm will find the shortest paths from the starting vertex to all vertices in the network. If we want just the shortest path connected to the starting and destination vertices, we can stop the searching once the destination vertex is visited. Note that, from steps 3.6 to 3.9, the algorithm implicitly assumes a larger accumulated weight for a longer path. This can be true only when all weights are positive.
We now have all the ingredients to solve a variational problem using Dijkstra’s path-finding algorithm. In the following sections, we will validate our proposal by applying Dijkstra’s algorithm to solve three famous variational problems, i.e., the optical ray tracing, the brachistochrone, and the catenary problems. We will show that in all cases, when the lattice spacing is small enough, and the number of sub-lattices is large enough, the shortest paths in the networks can be accurately used to approximate the exact optimum path. We will also show that, despite the different corresponding Euler–Lagrange equations and their solutions, we can use a single framework of Dijkstra’s path-finding algorithm to solve all three problems. The only difference is the detail of functional F, which depends on the physics of each problem.
4. Ray Tracing and Snell’s Law
We first apply Dijkstra’s algorithm to describe the optical ray tracing in a medium. According to Fermat’s principle of least time, the trajectory of energy transfer, or the ray, of a wave from points a to b in a medium will follow the path that takes the minimum ToF. The principle can also be stated in terms of the optical path length [
3],
where n(x,y,z) is the refractive index of the medium at the position (x,y,z). The actual path is the one with the shortest L. We can show that this is also the path with minimum ToF. By definition, n = c/v, where c is the light speed in vacuum, and v = v(x,y,z) is the wave speed at the position (x,y,z) in the medium. We can rewrite Equation (7) as
Since c is a constant, minimizing L in Equation (8) is equivalent to minimizing the integral:
Obviously, is the total ToF of the wave traveling from point a to b. The ray path with minimum optical path length is thus the path that a traveling wave takes with minimum ToF.
Compared with Equation (1), is the functional integral in which its value depends on the ray path (y(x),z(x)). Finding the actual ray path becomes a variational problem of finding the path (y(x),z(x)) that is minimized .
In a homogeneous medium, n is a constant. The wave speed is constant throughout the medium. From Equation (9), minimizing is equivalent to minimizing the Euclidian path length connecting points a and b. It is well known from basic geometry that the path is a straight line. Light will take a straight path through a homogeneous medium.
When a wave travels through a boundary of two homogeneous mediums with different wave speeds, refraction occurs. The ray path changes its direction at the incident point. The relation between the incident angle
and the refracted angle
, with respect to the normal line at the incident position, can be expressed as [
26]
where
and
are the wave speeds of the incident and refracted waves, respectively. For the light wave, Equation (10) can be expressed as the well-known Snell’s law,
where
and
are the refractive indices of the medium of the incident and refracted waves, respectively.
To trace the ray path of a refracted wave using Dijkstra’s algorithm, we first need to discretize the space into a spatial network. Since the incident ray, the refracted ray, and the normal line lie on the same plane, the problem is two-dimensional. A preliminary study of this simulation can be found in [
6]. However, they used a network on a square lattice with long-range connections, which introduced large numerical errors in the calculation. As discussed in
Section 2, applying the two-dimensional Moser lattice to the problem can improve the accuracy of the simulation.
The next step is to define the weight of each edge. We define the weight of the edge joining vertices i and j as the ToF of a wave traveling along a straight path joining vertices i and j. If the wave speed at vertices i and j are
and
, respectively, the average wave speed along the joining edge can be estimated to be
, and the weight can be defined as
where
is the Euclidian distance between vertices i and j. The total ToF can be estimated as
The summation is evaluated along the path from the starting to destination vertices.
Figure 4 shows an example of the weight of an edge on the simple network in
Figure 2. The ToF along the red path is, thus,
= t
ac + t
cd + t
db, and the ToF along the blue path is
= t
ae + t
ef + t
fg + t
gh + t
hb. Note that the details of all edges are removed for the clarity of the figure.
The final step is to apply Dijkstra’s algorithm to find the shortest path that minimizes the summation in Equation (13).
Figure 5 shows the simulation result of the refraction between the mediums that
, which resembles the refraction of light through the boundary of glass (lower medium 1) and air (upper medium 2). In the simulations, we use the 10 × 10-unit square- lattice (Δx = Δy = 1), with 10 sub-lattices on each plaquette side. The starting and destination points are the lower left vertex at the coordinate (0,0) and the upper right vertex at the coordinate (10,10), respectively. For clarity, we omit the details of the vertices and edges. The path obtained by Dijkstra’s algorithm is the red line. The blue line is the boundary of the two mediums, and the green line is the normal line. The wave speeds at the vertices below the boundary are set to be v
1 = c/1.5, and those on the boundary and above are v
2 = c. We can see that the algorithm gives the correct straight paths in each medium. The direction of the ray path changes only at the incident point on the boundary. In
Figure 5, the coordinate of the refraction point (the black dot) is (3.1812,5); thus,
, which agrees well with the prediction of Snell’s law in Equations (10) and (11).
When the incident angle of the light ray, traveling from the medium with higher to lower refractive indices, is approaching a critical angle, we will see the onset of the total internal reflection. This critical angle can be obtained from the relation
[
26]. In the case of glass-air refraction described above, we have
. Since the refracted angle is
, we can simulate this phenomenon by placing the destination vertices on the boundary.
Figure 6 shows the shortest path obtained by the Dijkstra’s algorithm. We place the starting vertex at the lower left corner of the lattice. The destination point is placed at the rightmost vertex on the boundary. In
Figure 6, the coordinate of the refraction point (the black dot) is (4.4546, 5); thus,
, which agrees well with the theoretical prediction.
5. Ray Tracing for the Gradient-Index Waveguide
When a light wave travels through a medium where the index of refraction is not constant but varies with position, the light ray can be bent. This kind of medium is known as the gradient-index (GRIN) medium [
27]. The GRIN material has many applications in optics, i.e., in the fabrication of a flat lens or the graded-index optical waveguide. In nature, the human eye’s lens is a GRIN material with a refractive index that varies from about 1.406 in the inner core to approximately 1.386 in the less dense cortex [
28]. Some common mirages are caused by a spatially varying refractive index of the air [
3].
The ray path in GRIN material can be obtained from Fermat’s principle of least time. As described in the previous section, the actual path can be obtained by minimizing the optical path length in Equation (7). If the ray path is described by the functions y(x) and z(x), the optical path length can be rewritten as
Comparing with Equation (1), we can see that F =
. Since F depends on two functions, y(x) and z(x), the corresponding Euler–Lagrange equations can be written as a system of differential equations. By substituting the functional F into Equation (3), we have
and
We can see that the resulting differential equations are complicated. The exact solutions for these differential equations are not always available. Several algorithms are proposed to solve the problem numerically [
15,
16,
17,
18]. Here, we propose how to use the path-finding algorithm as an alternative method to solve this problem.
To validate our proposal, let us consider the case where the problem can be solved analytically. In many waveguide applications, the refractive index does not depend on the optical axis of the waveguide. If we denote the optical axis as the x-axis, the refractive index is independent of x; thus, n = n(y,z). It can be shown [
3] that the quantity
Since the ray always points along the infinitesimal displacement ds, dx/ds = cos θ, where θ is the angle between the ray and the x-axis, the product n cos θ is a constant or invariant along the ray path. In terms of β, the Euler–Lagrange equations can be rewritten as
and
Solving these two coupled equations gives the ray path as a parametric function y(x) and z(x).
As an example, consider the GRIN waveguide with the axial refractive index profile,
where α is a constant, and
is the refractive index at
. From symmetry, the problem is two-dimensional. The optical path will lie on a plane perpendicular to the xz-plane. If we place the x-axis on this plane, the optical path will lie on the xy-plane and can be described as the functions y = y(x) and z = 0. The analytic solution of the ray path can be obtained by solving Equation (18), which is given by
Here, , and is the incident angle of the ray at the origin of the coordinate system relative to the x-axis.
To simulate the ray path using Dijkstra’s algorithm, we can simply use the method described in the previous section. The change is only in the definition of wave speed. From the definition of refractive index, the wave speed can be written as c/n(y) = c/
. Thus, the wave speed of vertex i at the coordinate y
i can be written as
The weight of each edge can be defined from Equation (12). The ray path can be finally traced by executing Dijkstra’s algorithm.
Figure 7 shows the ray paths through the GRIN medium with the axial index of refraction profile described by Equation (20) with various values of α. The dashed lines are the paths obtained from Dijkstra’s algorithm, while the solid lines are the exact solutions from Equation (21). We perform the simulation on the Moser lattice lying on the xy-plane. In all simulations, we use the 40 × 10-unit square lattice
with 30 sub-lattices on each plaquette side. The light speed c is set to 1 for convenience. The starting and destination points are the lower left vertex at the coordinate (0,0) and the lower right vertex at the coordinate (0,40), respectively. We define the simulation step length Δs as the average edge length <s
ij> along the shortest path. The percentage errors E of the area under the curves are calculated to indicate the discrepancy between the simulation and the exact results. For the results shown in
Figure 7, Δs = 0.927, 0.857, 0.867, and 0.815, and E = 0.274, 0.357, –0.252, and 0.399 for α = 0.070, 0.080, 0.090, 0.100, respectively. The simulation results agree well with the theoretical predictions.
6. Brachistochrone Problem
Consider a particle is constrained to move from rest along a path on the xy-plane between two fixed endpoints in a uniform gravitational field near the Earth’s surface. The brachistochrone problem is finding the path where the particle will take the minimal ToF. This problem was first solved by Johann Bernoulli in 1696 and is the milestone in the invention of the calculus of variations [
29]. Engineers and designers of roller coasters use the path to accelerate the car to the highest speed possible in the shortest possible vertical drop. The skier and cyclist follow the path, which results in a minimal lap time [
30].
Assuming no air resistance and friction, the speed of the particle at the vertical distance y can be obtained from the principle of energy conservation,
where g is the gravitational acceleration near the Earth’s surface. Note that the initial position of the particle is at the origin of the coordinate system, and the positive direction of the y-axis points downward. If the particle path is described by the functions y(x), the ToF of the particle can be calculated from the integral:
The optimum path can be obtained by minimizing this integral.
Now, we have the functional F =
. Since F does not explicitly depend on x, we can use the Beltrami identity [
31] to rewrite the Euler–Lagrange equation as
where
is a constant. Substituting for F, we can express the Euler–Lagrange differential equation as
where
. The solution of this equation has the shape of a cycloid [
32], which can be represented in a parametric form as
The constant c′ = 1/2C′
2 needs to be evaluated numerically from the endpoint position. The minimum ToF can be determined analytically as
where
is the value of
at the endpoint.
To simulate the ray path using Dijkstra’s algorithm, we can simply use the method described in
Section 3. The change is only on the definition of the particle speed. We can define the particle speed at each vertex as
where
is the y-coordinate of the vertex i. The weight of each edge can then be defined as in Equation (12). The actual path can be approximated as the one that minimizes the ToF in Equation (13). A preliminary study of this simulation can be found in [
5]. However, the numerical results in this work are quite poor. The square network with next-nearest neighbor connections is used in this work, which introduces large numerical errors into the calculation. We improve the accuracy of the calculations by using the two-dimensional Moser lattice in our simulation.
Figure 8 shows the resulting brachistochrone curves with various endpoints. The dashed lines are the paths obtained from Dijkstra’s algorithm, while the solid lines are the exact solutions from Equation (27). In all simulations, we use the 40×30-unit square lattice
with 15 sub-lattices on each plaquette side. The gravitational acceleration g is set to be 1 for convenience. The starting point is at the upper left vertex at the coordinate (0,0), and the x-coordinate of the destination point is x = 40. The y-coordinate of the destination points, together with the optimized ToF obtained from the simulation and Equation (28), are given in
Table 1. For the results shown in
Figure 8, Δs = 0.815, 0.836, 0.830, and 0.792, and E = 0.251, –0.238, –0.127, and –0.238 for the endpoints at y = 0, 10, 20, and 30, respectively. We can see that the simulation results of the trajectory and ToF agree well with the analytic solutions.
7. Catenary Problem
Consider a rope hanging between two fixed supports of the same height by its own weight. The catenary problem involves finding the shape of the rope. The problem was solved independently for the ideal case where the linear density of the rope is a constant by Christiaan Huygens, Gottfried Leibniz, and Johann Bernoulli in 1691 [
33]. The name catenary was coined by Huygens in 1690, which in Latin means a chain. The curve has many applications in architecture and engineering. The inverted catenary arch, with no additional load or stress placed upon it, will produce no excess shear or pressure on its building materials. It can stand on its own indefinitely with no outer support or maintenance [
34]. In civil engineering, the catenary curve is used in the design of hanging cables where the maximum tension is minimum [
35]. Interestingly, the catenary curve has been adapted to approximate interesting curves in some medical applications, e.g., the dental arches [
36,
37] and the women’s breast contours [
38].
The shape of a catenary curve can be obtained by minimizing the potential energy of the rope. Since the gravitational force points vertically downward, the rope will lie on a vertical plane, which we define as the xy-plane. Thus, the problem is two-dimensional. If the shape of the rope is described by the functions y(x), the potential function can be written as
where
is the linear density of the rope. Note that the reference level of the potential energy is at y = 0. Here, we have F =
. Since F does not explicitly depend on x, we can use the Euler–Lagrange Equation (25) to find the optimum shape of the rope. With some algebra, we have [
39]
where a is a constant. The solution of this equation has the form of a hyperbolic cosine function:
Here, we set the lowest point of the rope on the y-axis at the position
. We can see that the length of the rope depends on the vertical distance of the supporting points and the lowest point of the rope. In practice, this length is usually specified. This catenary problem with a specific length is an example of the isoperimetric problem, which is a class of variational problems subject to a constraint with the form of an integral. For the catenary problem, the constraint can be expressed as
, where
is the length of the rope. To solve the problem, we can use the technique of Lagrange multiplier [
1]. By rewriting the function as
the adjustable parameter λ can be used to relax the minimization condition to incorporate the length constraint. The solution of the Euler–Lagrange equation for the functional in Equation (33) is
Here,
, and ±x
s are the x-coordinate of the supporting points of the rope. The constant b has to be evaluated numerically from the equation
To simulate the shape of a hanging rope using Dijkstra’s algorithm, we can simply use the method described in
Section 3. The change is only on the definition of the edge’s weight. As mentioned above, the edge is an abstract entity. We can assign any suitable physical value and geometrical shape to an edge. In this case, we define an edge as a small straight segment of s
ij connecting the vertices i and j. The mass of each segment is
. The gravitational potential of each segment is
where
and
are the y-coordinate of the adjacent vertices joined by the edge. We can define this gravitational potential as the weight of the edge joining vertices i and j. The actual shape of the rope can be approximated as the one that minimizes the total gravitational potential:
The Dijkstra’s algorithm will find, among all possible paths, the path with minimum potential. Solving the problem with the length constraint is a bit tricky. We will use the technique of Lagrangian relaxation [
23] by introducing an adjustable parameter z to the weight in Equation (36), then minimizing the new potential function,
where
We can see that this is the discrete version of the Lagrange multiplier technique used in Equation (33) to solve the problem analytically.
The parameter z can be adjusted to relax the minimization condition. We may interpret that z can be used to adjust the reference point of the gravitational potential. When
, the rope is farther away from the reference point, and the optimized path becomes shorter than the path when
. It is straightforward to expect that when
, the rope is closer to the reference point, and the optimized path becomes longer than the path when
. However, the negative z can cause some problems. If z is “too negative”, it can introduce the negative weights to the system. Summing up the negative weights results in the total weight that is even smaller. The algorithm will find the possible longest path regardless of the value of z. To solve this problem, we must change our question a bit [
39]. Instead of finding the optimal path joining the two supporting points, we will find the optimum path joining the lowest point and, let us say, the right supporting point. The left half of the curve is the mirror reflection of the right half, with the vertical line passing the lower point as the axis of symmetry.
Since we do not know the position of the lowest point in advance, we will gauss the initial position as the lowest point. The parameter z is adjusted until the slope at, and only at, the lowest point is equal to zero. The length of the optimal path is compared with the desired length. The position of the lowest point and the value of z is then adjusted until the desired length is achieved.
Figure 9 shows the resulting catenary curves with various lengths. The dashed lines are the paths obtained from Dijkstra’s algorithm, while the solid lines are the exact solutions from Equations (34) and (35). In all simulations, we use the 20 × 20-unit square lattice
with 20 sub-lattices on each plaquette side. The product μg is set to 1 for convenience. Note that the supporting points of all curves are shifted to the same positions at (0,0) and (20,0), and the reference level of the gravitational potential is shifted to the level of y = −20. For the results shown in
Figure 9, Δs = 0.718, 0.823, 0.746, and 0.784, and E = 0.841, 0.773, –0.904, and –0.934 for the shortest to longest curves, respectively. Again, we can see that the simulation results of the optimum curves agree well with the exact solutions.
8. Discussions
We can see from all the calculations above that, despite the different physical backgrounds, mathematical formulations, and complexities of the problems, we can use a single framework of shortest path finding to solve the problems. It is reasonable to imply that we can use the same framework of path-finding algorithms to solve even more complicated problems. This becomes interesting when an analytical solution is not possible. Applying the path-finding algorithm to optical ray tracing provides an alternative method to solve the problems, for the exact solutions are not always available. Even in classic problems like brachistochrone and catenary problems, little changes in the description of the problem can forbid analytic solutions. For example, realizing that the gravitational force is not uniform but follows an inverse square law can drastically complicate the problems [
19,
20,
21,
22]. Nevertheless, we can always apply the path-finding algorithm to solve the problems by just changing the weights in Equations (22), (29), and (39) to fit with the new problem descriptions.
As mentioned in the introduction, our preliminary need is finding a ray tracing algorithm to find the ray path of a wave traveling through a complex medium. To be precise, the complex medium here is the wood. The information on acoustic ray path in the wood is very useful in the forestry study since it gives information on the health, elasticity, and decay in the wood timber. However, wood is an orthotropic medium where the wave speed can vary not only with the position but also with the ray direction [
40,
41,
42]. The orthotropic property makes the acoustic ray tracing in a wood sample much more complicated than the optical ray tracing discussed above. Formulation of the Euler–Lagrange equations can be very complicated, and the analytical solutions are not expected. The applications of the path-finding algorithm discussed here provide a simple and straightforward way to obtain the ray path requested.
We have shown that the path-finding algorithm provides the solutions to the variational problems. This means that it provides the solutions to the corresponding Euler–Lagrange differential equations as well. Since it is well known that a boundary-value differential equation can be formulated as a variational problem, it is interesting to investigate further how to apply the path-finding algorithm to numerically solve the boundary-value problems in general.
Among various path-finding algorithms available, we adopt Dijkstra’s algorithm due to its simplicity and straightforwardness. The algorithm is easy to implement since it is embedded in sophisticated commercial, scientific software like MATLAB (R2024a). However, the method has some limitations. Dijkstra’s algorithm works only with the positive weight. Introducing the negative weights to a network makes it possible to have a longer path with a smaller accumulated weight. As explained in
Section 3, Dijkstra’s algorithm is designed to assume a larger accumulated weight for a longer path, and it may not find the correct shortest path when the negative weights exist. When some negative weights exist in the network, we need to use slower algorithms, such as the Bellman–Ford algorithm, to find the shortest path. Another limitation is that Dijkstra’s algorithm is a single-source path-finding algorithm that finds all the shortest paths from the starting vertex to all the rest of the vertices in the network. It is wasting computational time if we just want the path to join a single or a few destination vertices. However, this can be an advantage if we want to see the global propagation related to the shortest path. For example, because a wavefront with the same ToF will have the same phase, we can use all information given by the algorithm to construct the wavefront from the contour of the ToF in the network.
Unlike the conventional numerical methods that provide more accurate results with reduced lattice spacing, the number of sub-lattice points is more important in the application of the path-finding algorithm. For all calculations discussed, the lattice spacing is 1, which is not very small compared to the total lattice size. However, we can obtain satisfying results that agree very well with the exact solutions once the number of sub-lattice points is large enough. This is an important caution for the further application of the algorithm.