<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta>
      <issn pub-type="ppub">1613-0073</issn>
    </journal-meta>
    <article-meta>
      <title-group>
        <article-title>Fast Approximate Pathfinding Based on 2D Convolution</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Marius Teleiša</string-name>
          <email>marius.teleisa@gmail.com</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Dalia Čalnerytė</string-name>
          <email>dalia.calneryte@ktu.lt</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Workshop</string-name>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Kaunas University of Technology</institution>
          ,
          <addr-line>Studentų str. 50, Kaunas, LT-51368</addr-line>
          ,
          <country country="LT">Lithuania</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>The goal of pathfinding algorithms is to find a path between the desired points. An optimal path is more complex and time consuming to find, which is why some industries, such as the video game industry, can sacrifice optimality for reduced run-time. A grid map can be represented as an image, so techniques used in image processing, such as filtering, may be applied to pathfinding. In this paper we propose a convolution inspired hierarchical pathfinding algorithm that achieved 4% longer paths and 97% shorter runtime than A* on average.</p>
      </abstract>
      <kwd-group>
        <kwd>Hierarchical pathfinding</kwd>
        <kwd>Grid graphs</kwd>
        <kwd>Heuristic search</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1. Introduction</title>
      <p>2023 Copyright for this paper by its authors.
CEUR</p>
      <p>ceur-ws.org</p>
    </sec>
    <sec id="sec-2">
      <title>Path symmetry</title>
      <p>One of the biggest problems with grid maps is path symmetry, where there are multiple equally
optimal paths for two given points, as shown in Figure 1. Path symmetry is often a property of
uniformcost grid maps, where the order of steps can often be rearranged to form another equally optimal path.</p>
      <p>
        The number of symmetric paths increases with path length, and a pathfinding algorithm, such as A*,
must evaluate all the redundant symmetric paths to find an optimal path. JPS is a pathfinding algorithm
based on elimination of symmetric paths and can run up to 3.5 times faster than A* [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ], which shows
that path symmetry can hinder pathfinding algorithm performance significantly.
2.2.
      </p>
      <p>A*</p>
      <p>
        One of the most popular and effective pathfinding algorithms is A* [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ], [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ]. A* is a best-first search
algorithm that can use various heuristic functions to adapt to the available space, its rules or the required
solution. This algorithm can find the optimal path if a suitable heuristic function is chosen, which
depends on graph type.
      </p>
      <p>Each iteration A* adds a node to current paths, which is determined by current cost of the path and
the estimated cost from this node to goal by a heuristic function. The nodes keep track of which node
they were reached from, and once the algorithm reaches the goal, it traces back to the start to form a
path and terminates.</p>
      <p>
        One of the ways to reduce search time for A* is to have a better heuristic. Standard online heuristics,
such as Manhattan distance, do not consider obstacles and can only estimate an optimistic scenario
without obstacles, which leads to the pathfinding algorithm having to expand many nodes when
encountering obstacles. A heuristic function that can accurately evaluate distance between nodes may
result in the pathfinding algorithm expanding only nodes on the optimal path [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ].
2.3.
      </p>
      <p>HPA*</p>
      <p>
        Hierarchical Pathfinding A* (HPA*) is a pathfinding algorithm that was developed in 2004, with
the aim of reducing the pathfinding time by sacrificing path optimality [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ]. HPA* uses a hierarchical
pathfinding approach, which allows the information of the network-type space to be processed once, so
that this information can be used to speed up the performance of A*.
      </p>
      <p>
        HPA* algorithm creates an abstraction layer by dividing the map into rectangular parts called
clusters, as marked by the red rectangles in Figure 2. Next, the passage points, shown in green, are
searched between the clusters and added to the graph of the abstraction layer. This algorithm has been
applied to 4-way connected graphs and experimental results have shown up to a 10-fold speedup in
pathfinding and a 1% degradation in path quality compared to the optimal [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ].
      </p>
      <p>( ,  ) = ∑|  −   |
 ( ,  ) = √∑(  −   )2


 =1
 =1</p>
      <p>
        To speed up the computation, square root can be removed from the equation (2). This makes the
heuristic function overestimate the distance to the destination, which results in the pathfinding
algorithm finding paths faster at the cost of no longer guaranteeing optimality [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ]. This version of the
heuristic function is called squared Euclidean Distance (SED).
      </p>
    </sec>
    <sec id="sec-3">
      <title>3. Proposed pathfinding algorithm</title>
      <p>Convolutional Hierarchical Pathfinding A* is a pathfinding algorithm that utilizes offline
preprocessing to construct an abstraction layer, which is used to perform an online search. The
abstraction layer is smaller than the original search space, which results in reduced search time. As the
name suggests, the process for creating the abstraction layer is based on 2D image convolution, where
a sliding window is used to generalize information inside the window.</p>
      <p>During preprocessing, a non-square sliding window is used to partition the map into square
segments, as shown in Figure 3. If necessary, a map is padded to the required length by copying the
nearest pixel of the original image. The shape of the sliding window is derived from the square segment
shape and should be one tile longer to allow overlap with neighboring segments.</p>
      <p>Within each window, a search is performed to find any valid path along the window, and the purpose
of the overlap with neighboring segment is to guarantee, that the neighboring segment can be entered.
A clockwise rotated window is also used to perform the same operations and store vertical traversal
information. The abstraction layer graph is created by using the segments as nodes, and the traversal
information from sliding windows to connect the nodes.</p>
      <p>Increasing the segment size will result in a smaller abstraction layer and faster search time, however
more information will be lost during preprocessing, which can reduce path optimality. For this paper a
segment size of 3x3 was chosen to introduce some data loss and evaluate the effect of it on pathfinding
performance.</p>
      <p>During phase 1 of online search, an initial path is found in the abstraction layer using A*, which is
presented in Figure 4. In phase 2, the nodes of this path are then used as checkpoints and guide the A*
algorithm in the real grid. For this to work, a coordinate translation must be performed between
abstraction layer path nodes and real grid nodes. The translation method first determines the direction
of movement and shifts the translated center point of the target segment towards the origin segment. A
valid unoccupied tile is then needed as a goal, which is searched in a predetermined order along the
wall of the origin segment.</p>
      <p>This method of coordinate translation may reduce path optimality. To reduce errors caused by the
coordinate translation, a Pstep parameter is introduced, which defines the interval of checkpoints to be
used for pathfinding in the real grid. An example of Pstep effect on final path can be seen in Figure 5,
where the resulting final path using Pstep=2 is more optimal than Pstep=1. Increasing Pstep value
reduces the checkpoint, and the associated coordinate translation count, which results in fewer
opportunities for sub-optimal translations and should on average increase path optimality.</p>
    </sec>
    <sec id="sec-4">
      <title>4. Experimental setup</title>
      <p>The proposed algorithm was tested against the A* algorithm using various heuristic functions. The
same A* implementation was also used for CHPA*, which will make for a fair comparison as there will
not be an implementation optimization difference.</p>
      <p>
        The benchmark set of maps and scenarios used for testing were created by Sturtevant [
        <xref ref-type="bibr" rid="ref12">12</xref>
        ], and
features maps from games such as Starcraft, Warcraft III, labyrinths, randomly generated maps, etc.
The algorithms were implemented using Python, and pathfinding for path lengths above 700 tiles can
take more than a minute depending on obstacles, so path counts had to be reduced to have a reasonable
testing time. The scenarios were ordered by path length and divided into 200 segments, where one path
was chosen at random from each segment. The maps chosen for testing were:
 ArcticStation
 BrokenSteppes
 Enigma
 Nightshade
The tests were carried out using a personal desktop computer, and the specifications are as follows:
 CPU – AMD Ryzen 5 3600
 GPU – Nvidia GEFORCE GTX 1080Ti GPU
 RAM – 16GB
 OS – Windows 10
      </p>
    </sec>
    <sec id="sec-5">
      <title>5. Results</title>
      <p>The effects of CHPA* parameter Pstep were tested and can be seen in Figure 6. As the value of
Pstep increases, the path length approaches optimal, however that also causes more nodes to be explored
in the real grid, which will increase search time.</p>
      <p>We can also see that on average, with Pstep=2 the path length was reduced by 8%, and explored
node count by 0.5%. Increasing Pstep further has diminishing returns on path length reduction of 1.5%
and 0.5% for Pstep value of 3 and 4 respectively, and increases explored node count by 1.5%. Pstep=2
resulted in the best balance of path quality and search area, so further experiments will be carried out
only using this value.</p>
      <p>Next, A* and CHPA* algorithms were tested using various heuristic functions, and the results can
be seen in Table 1.</p>
      <p>A* algorithm with ED and MD heuristics achieved the expected optimal average path length,
however MD heuristic explored 33% less tiles and was less computationally expensive, so it led to
significantly shorter search times. Using SED heuristic results in 19% longer paths on average, but it
explores 80% less nodes than MD, which can be valuable in situations where computation time is strict.</p>
      <p>Shifting focus to CHPA*, phase 1 and phase 2 ED heuristic on average explored only 8% more
nodes than A* with SED, while having only 4% longer path than optimal. Other CHPA* configurations
explored even less nodes, while preserving average path length within 0.2% of other configurations, so
choosing a heuristic for CHPA* largely comes down to minimizing explored nodes. Out of the tested
configurations with CHPA*, MD heuristic resulted in longest average path, which is still 14% better
than A* with SED, and 20% less explored nodes.</p>
      <p>A* + ED
A* + SED
A* + MD</p>
      <sec id="sec-5-1">
        <title>CHPA* + F1-ED F2-ED</title>
      </sec>
      <sec id="sec-5-2">
        <title>CHPA* + F1-ED F2-SED</title>
        <p>CHPA* + F1-MD F2-MD
CHPA* + F1-MD F2-ED</p>
        <p>Surprisingly, ED heuristic outperforms MD heuristic on CHPA* average path length by 0.2%, but
explored 34% more nodes. MD and ED heuristics both find optimal paths, however those paths may
differ and cause different errors in CHPA* coordinate translation, which results in paths of different
length in the real map.</p>
        <p>The last test was performed to compare average search time between the algorithms, and the results
are shown in Table 2.</p>
        <p>During this testing, CHPA* achieved only 2% longer path, however on average it took 97% less
time to find them, which is the result of heavily reducing search space.</p>
        <p>The implemented system includes capability to visualize the pathfinding process, which was used
to observe general pathfinding algorithm behavior. In Figure 7 a comparison between A* and CHPA*
is shown for a short path, where CHPA* has a smaller exploration footprint than A*. Unfortunately,
this system does not visualize the abstraction layer, and the total explored nodes count is very similar
to A* in this instance.</p>
        <p>a) b)
Figure 7 Pathfinding result visualization on 12x12 map. a) A* b) CHPA*. Heuristic – MD, Pstep=1, green
– start, blue – goal, orange – path, yellow – checkpoint, red – closed list tile, green – open list tile</p>
        <p>Figure 8, Figure 9, and Figure 10 present pathfinding algorithm behavior over a longer distance,
and here the benefits of CHPA* can be seen. A* explored most of the map due to the walls obstructing
the optimal path, whereas CHPA* performs pathfinding in the compressed abstraction layer, which
greatly reduces node expansion.</p>
      </sec>
    </sec>
    <sec id="sec-6">
      <title>6. Future work</title>
      <p>Main problems of current CHPA* implementation:
1. Only works with 4-way connected graphs.
2. Simplistic coordinate translation logic reduces path quality.
3. Preprocessing edge cases lead to obstacles not being recognized and producing extremely long
paths.</p>
      <p>In the future, an analysis on the effect of different window sizes for path quality and search times
can be performed.</p>
      <p>The proposed algorithm finds paths between multiple checkpoints, which could be done in any order,
so parallel processing may be applied to speed up the search even further.</p>
    </sec>
    <sec id="sec-7">
      <title>7. Conclusion</title>
      <p>In this paper a new pathfinding algorithm is proposed for fast approximate pathfinding called
CHPA*. The algorithm utilizes preprocessing, inspired by 2D image convolution, to create an
abstraction layer, reduce search space and improve path search times.</p>
      <p>Results in worst case show 4% path length degradation on average, more than 80% less explored
nodes, and takes 97% less time to find a path compared to A* with an optimal MD heuristic. During
our testing, the heuristic function for CHPA* had very low impact on path length (only 0.2%
difference), but significantly changed explored node count, so the heuristic choice in most cases will
come down to minimizing search space.</p>
      <p>The drawbacks of the algorithm are preprocessing edge cases that can lead to not recognizing
obstacles in abstraction layer, creating extremely long paths during online search, or even not being
able to find a path.</p>
    </sec>
    <sec id="sec-8">
      <title>8. References</title>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>T.</given-names>
            <surname>Cormen</surname>
          </string-name>
          ,
          <string-name>
            <given-names>C.</given-names>
            <surname>Leiserson</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R.</given-names>
            <surname>Rivest</surname>
          </string-name>
          , and
          <string-name>
            <given-names>C.</given-names>
            <surname>Stein</surname>
          </string-name>
          , “Introduction to Algorithms, Second Edition,”
          <year>2001</year>
          , pp.
          <fpage>451</fpage>
          -
          <lpage>507</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>X.</given-names>
            <surname>Cui</surname>
          </string-name>
          and
          <string-name>
            <given-names>H.</given-names>
            <surname>Shi</surname>
          </string-name>
          , “A *
          <article-title>-based Pathfinding in Modern Computer Games</article-title>
          ,”
          <source>International Journal of Computer Science and Network Security</source>
          , vol.
          <volume>11</volume>
          , no.
          <issue>1</issue>
          , pp.
          <fpage>125</fpage>
          -
          <lpage>130</lpage>
          ,
          <year>2011</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>A.</given-names>
            <surname>Botea</surname>
          </string-name>
          ,
          <string-name>
            <given-names>B.</given-names>
            <surname>Bouzy</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Buro</surname>
          </string-name>
          ,
          <string-name>
            <given-names>C.</given-names>
            <surname>Bauckhage</surname>
          </string-name>
          , and
          <string-name>
            <given-names>D.</given-names>
            <surname>Nau</surname>
          </string-name>
          , “Pathfinding in Games,” in Artificial and Computational Intelligence in Games, S. M.
          <string-name>
            <surname>Lucas</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          <string-name>
            <surname>Mateas</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          <string-name>
            <surname>Preuss</surname>
            ,
            <given-names>P.</given-names>
          </string-name>
          <string-name>
            <surname>Spronck</surname>
          </string-name>
          , and J. Togelius, Eds., in
          <string-name>
            <surname>Dagstuhl</surname>
          </string-name>
          Follow-Ups, vol.
          <volume>6</volume>
          . Dagstuhl, Germany: Schloss
          <string-name>
            <surname>Dagstuhl-LeibnizZentrum fuer Informatik</surname>
          </string-name>
          ,
          <year>2013</year>
          , pp.
          <fpage>21</fpage>
          -
          <lpage>31</lpage>
          . doi:
          <volume>10</volume>
          .4230/DFU.Vol6.
          <volume>12191</volume>
          .21.
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>C.</given-names>
            <surname>Solomon</surname>
          </string-name>
          and
          <string-name>
            <given-names>T.</given-names>
            <surname>Breckon</surname>
          </string-name>
          , “Fundamentals of Digital Image Processing,” Wiley,
          <year>2010</year>
          , p.
          <fpage>87</fpage>
          . doi:
          <volume>10</volume>
          .1002/9780470689776.
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>D.</given-names>
            <surname>Harabor</surname>
          </string-name>
          and
          <string-name>
            <given-names>A.</given-names>
            <surname>Botea</surname>
          </string-name>
          , “
          <article-title>Breaking Path Symmetries on 4-Connected Grid Maps</article-title>
          .,
          <source>” in Proceedings of the 6th AAAI Conference on Artificial Intelligence and Interactive Digital Entertainment, AIIDE</source>
          <year>2010</year>
          ,
          <year>2010</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <given-names>Y.</given-names>
            <surname>Björnsson</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Enzenberger</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R. C.</given-names>
            <surname>Holte</surname>
          </string-name>
          , and
          <string-name>
            <given-names>J.</given-names>
            <surname>Schaeffer</surname>
          </string-name>
          , “
          <article-title>Fringe search: Beating A* at pathfinding on game maps</article-title>
          ,
          <source>” IEEE 2005 Symposium on Computational Intelligence and Games</source>
          , CIG'
          <volume>05</volume>
          , no.
          <source>January</source>
          <year>2005</year>
          , pp.
          <fpage>125</fpage>
          -
          <lpage>132</lpage>
          ,
          <year>2005</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <given-names>A.</given-names>
            <surname>Suryadibrata</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J. C.</given-names>
            <surname>Young</surname>
          </string-name>
          , and
          <string-name>
            <given-names>R.</given-names>
            <surname>Luhulima</surname>
          </string-name>
          , “
          <article-title>Review of Various A* Pathfinding Implementations in Game Autonomous Agent,” IJNMT (</article-title>
          <source>International Journal of New Media Technology)</source>
          , vol.
          <volume>6</volume>
          , no.
          <issue>1</issue>
          , pp.
          <fpage>43</fpage>
          -
          <lpage>49</lpage>
          , Aug.
          <year>2019</year>
          , doi: 10.31937/ijnmt.v6i1.
          <fpage>1075</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <given-names>C.</given-names>
            <surname>Hu</surname>
          </string-name>
          ,
          <string-name>
            <given-names>Q.</given-names>
            <surname>Yin</surname>
          </string-name>
          ,
          <string-name>
            <given-names>Y.</given-names>
            <surname>Hu</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Zeng</surname>
          </string-name>
          , and L. Qin, “
          <article-title>Speeding up FastMap for Pathfinding on Grid Maps,” in 2019 IEEE International Conference on Mechatronics and Automation (ICMA), IEEE</article-title>
          , Aug.
          <year>2019</year>
          , pp.
          <fpage>2501</fpage>
          -
          <lpage>2506</lpage>
          . doi:
          <volume>10</volume>
          .1109/ICMA.
          <year>2019</year>
          .
          <volume>8816354</volume>
          .
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          [9]
          <string-name>
            <given-names>A.</given-names>
            <surname>Botea</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Müller</surname>
          </string-name>
          , and
          <string-name>
            <given-names>J.</given-names>
            <surname>Schaeffer</surname>
          </string-name>
          , “
          <article-title>Near optimal hierarchical path-finding (HPA*</article-title>
          ),
          <source>” Journal of Game Development</source>
          , vol.
          <volume>1</volume>
          ,
          <string-name>
            <surname>Mar</surname>
          </string-name>
          .
          <year>2004</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          [10]
          <string-name>
            <given-names>A.</given-names>
            <surname>Strand-Holm Vinther</surname>
          </string-name>
          and
          <string-name>
            <given-names>M.</given-names>
            <surname>Strand-Holm</surname>
          </string-name>
          <string-name>
            <surname>Vinther</surname>
          </string-name>
          , “
          <article-title>Pathfinding in Two-dimensional Worlds. A survey of modern pathfinding algorithms, and a description of a new algorithm for pathfinding in dynamic two-dimensional polygonal worlds</article-title>
          ,” Aarhus University,
          <year>2015</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          [11]
          <string-name>
            <given-names>J.</given-names>
            <surname>Fürnkranz</surname>
          </string-name>
          et al., “Manhattan Distance,” in Encyclopedia of Machine Learning,
          <string-name>
            <given-names>C.</given-names>
            <surname>Sammut</surname>
          </string-name>
          and
          <string-name>
            <given-names>G. I.</given-names>
            <surname>Webb</surname>
          </string-name>
          , Eds., Boston, MA: Springer US,
          <year>2011</year>
          , pp.
          <fpage>639</fpage>
          -
          <lpage>639</lpage>
          . doi:
          <volume>10</volume>
          .1007/978-0-
          <fpage>387</fpage>
          -30164- 8_
          <fpage>506</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          [12]
          <string-name>
            <given-names>N. R.</given-names>
            <surname>Sturtevant</surname>
          </string-name>
          , “
          <article-title>Benchmarks for Grid-Based Pathfinding,”</article-title>
          <source>IEEE Trans Comput Intell AI Games</source>
          , vol.
          <volume>4</volume>
          , no.
          <issue>2</issue>
          , pp.
          <fpage>144</fpage>
          -
          <lpage>148</lpage>
          , Jun.
          <year>2012</year>
          , doi: 10.1109/TCIAIG.
          <year>2012</year>
          .
          <volume>2197681</volume>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>