{'fraction_non_alphanumeric': 0.0454646099343125, 'fraction_numerical': 0.0037641154328732747, 'mean_word_length': 4.072819168850618, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
A Generalized A* Algorithm for Finding Globally Optimal Paths in Weighted Colored Graphs

Both geometric and semantic information of the search space is imperative for a good plan. We encode those properties in a weighted colored graph (geometric information in terms of edge weight and semantic information in terms of edge and vertex color), and propose a generalized A* to find the shortest path among the set of paths with minimal inclusion of low-ranked color edges. We prove the completeness and optimality of this Class-Ordered A* (COA*) algorithm with respect to the hereto defined notion of optimality. The utility of COA* is numerically validated in a ternary graph with feasible, infeasible, and unknown vertices and edges for the cases of a 2D mobile robot, a 3D robotic arm, and a 5D robotic arm with limited sensing capabilities. We compare the results of COA* to that of the regular A* algorithm, the latter of which finds the shortest path regardless of uncertainty, and we show that the COA* dominates the A* solution in terms of finding less uncertain paths.


I. INTRODUCTION
Path planning in partially known or unstructured environments is a relatively under-studied problem [1], compared to the vast effort dedicated in past decades to efficiently solve for optimal paths in fully known search spaces [2]- [11]. In many applications however, the environment is rarely fully known to the planning agent because of either sensor limitations and/or memory constraints. What is a suitable notion of optimality in such a search space, so that the autonomous agent can make reasonable and consistent decisions? While the notion of optimality is clear and consistent when the search space is known, in the case of uncertain search spaces one has several options. For example, the space can be approximated with a weighted graph, with each edge assigned a cost; then the optimal path is simply the path with minimum cost (e.g., the shortest path) in this graph. Search methods based on this idea have been the backbone to many numerical approaches developed for planning in dynamic or partially known environments [12]- [19].
A common framework to cope with partially observable or dynamic environments is re-planning [12]- [15]. In this framework, obstacles are a priori unknown and are only revealed during the course of the plan execution; a plan is first found on an optimistically perceived environment with no obstacles and then repaired whenever it is found to be infeasible. The benefit of these methods is their algorithmic efficiency to optimally repair the graph based on the newly perceived part of the environment. A fundamental question remains unanswered, however: "what should an optimal policy strive for in an unknown space?" [1]. In the works of [16]- [19], when the search space is only partially known, the "risk" of traversing unknown edges is combined to the original distance of the edge to construct a new cost measure. The optimal path is then defined as the one that minimizes the cost with respect to this new measure. These methods treat planning in partially known search spaces as a shortest path planning problem with respect to a user-defined measure, where uncertain paths are deferred. Yet, traversing through some high-uncertainty edges cannot be explicitly avoided, if such a path is short enough in terms of the userdefined measure. Moreover, the user-defined measure is not consistent, in general, for re-planning purposes, e.g., when new information changes the perceived environment, reusing the previous search results becomes difficult.
To illustrate the issues with potential inconsistencies, consider two agents with identical planning strategies acting in the same environment. Assume that one agent has more accurate information about the environment than the other agent. If we were to choose one of the two solution paths provided by either agent, then a reasonable choice would be to choose the path computed by the agent having more information, regardless of the path length. This is because a reasonable measure on the quality of the path should be that it is monotonic with the information of the underlying planner. However, monotonicity cannot be imposed, in general, in a soft-constrained framework. One can easily construct counter-examples where the less knowledgeable agent produces a "shorter" path than the more knowledgeable agent, by modifying how much the uncertainty is penalized.
To this end, we pay close attention to a more explicit approach presented in [20], [21], which defines a notion of optimality in the semantic search space. In that approach, the vertices and edges of the graph are classified into equivalent classes (or "colors") so as to encode semantic information of the perceived environment. Afterwards, a constrained shortest path planning problem is solved in this weighted colored graph. The optimal path is not necessarily the shortest path, but it is constrained by the constituent colors. In [20] the planning problem in an unknown environment is cast as a constrained shortest path planning problem in a weighted bicolored graph, where the vertices are partitioned into white (known) or gray (unknown) vertices to approximate partially known environments by excluding known, but infeasible vertices. The authors then find the shortest path in the graph such that the number of gray vertices does not exceed a certain number, or the path that has the least number of gray vertices and whose length does not exceed a certain threshold.
A general weighted colored graph is used in [21] to relax the binary representation of the environment to encode various ranked semantic information of the search space. A weight function devised in [21] assigns each edge to a positive real number incorporating the original edge weight and color, such that a total ordering is placed over paths with mixed colors. This total ordering favors paths with a fewer number of edges of inferior classes, and favors shorter paths if the constituting colors are the same. With the modified weight, a standard graph search (e.g., Dijkstra [2]) ensures that the optimal path respects the total order. That is, the resulting path is guaranteed to be the shortest path among the set of paths which include the minimum number of inferior class edges. However, global properties of the entire graph, such as the cardinality of the edge set of each color, are required to compute the modified weight, which may be intractable to compute online.
In this work, we extend regular edge-relaxation algorithms (for instance, A * [3]) to find an optimal path in a weighted colored graph based on the notion of optimality defined in [21]. We will adopt the term "class" over "color" as in [21] to differentiate from the graph-theoretic coloring problem, since the color of a vertex is not dictated by its adjacency, i.e., there may be two adjacent vertices with the same color. Informally, an optimal path is the shortest path in the set of paths with minimal inclusion of inferior-class edges. The original weight or the length of the path is used only as a tie-breaker among paths within the same class. For example, a shorter path with bad edges will be considered worse than a longer path with better constitute edges. This total ordering over the set of paths will be formally defined in the next section. The aim of our work is to find an optimal path without resorting to the global properties of the graph by propagating forward the cost-to-come and the path-class information to build an optimal search tree. The key insight is to use an abstract priority queue to order the expansion of optimal path candidates. We call this algorithm Class-Ordered A * (COA * ).
One immediate application of planning on a colored graph is that we can plan for an information-conservative path in a partially known environment. Suppose we partition the search environment into three classes: feasible, infeasible, unknown. Then, we can find the shortest path that maximizes feasibility (i.e., minimize infeasible and unknown vertices). For example, if there exist two paths, an unknown short path and a feasible longer path, then the feasible path is ranked higher over the short, unknown path. Consequently, the agent traverses through the region that is already known. This may be useful for planning problems such as a surgical robot, a marine probe, or a rescue robot where the impact on the surroundings should be minimized.
Another application where planning on a colored graph is beneficial is the case of a cooperative multi-agent plan-ning problem, where agents having only local information communicate with each other by exchanging their local plans in order to to achieve a consensus on a globally acceptable optimal solution [22]- [24]. We can encode information passed to other agents with a "color" depending on the information quality (e.g., agent credibility, noiselevel, etc.,) such that we can suppress the communication of inferior information below a certain class. In a softconstrained framework, each agent must receive and merge the transmitted information fully before determining whether to use it or discard it, and the agents will use any "shorter" path regardless of the quality of the path. The colored graph planning provides another layer of ordering of paths (besides a single length+risk measure, for instance), and hence it is capable of rejecting shorter paths of inferior class.
The contributions of this paper can be summarized as follows. First, we develop a complete and optimal algorithm to solve for the shortest path among the set of paths with minimal inclusion of low-class edges in a weighted colored graph. Second, we prove the completeness and optimality of the proposed algorithm. The proposed algorithm efficiently builds an optimal search tree by heuristically and lazily expanding only the optimal path candidates. Third, we validate the utility of planning on a weighted colored graph using numerical experiments.

II. PROBLEM FORMULATION
Before discussing the problem to be solved in this paper, let us define some background notation that will be frequently used in the rest of the paper.

A. Weighted Colored Graph
Let G = (V, E) be a graph with vertices V and edges E. Let φ V : V → K be a perception vertex function that classifies each vertex v ∈ V to a class k ∈ K = {1, ..., K}, We will assume that the edge class set is larger than the vertex class set, i.e., L ≥ K, and that, for each edge, This assumption allows us to quickly underestimate the edge class by classifying the end vertices first. This serves as a heuristic edge classification before the actual, and perhaps expensive, edge classification takes place. Also, for each edge e ∈ E, a weight function c : E → R + assigns a non-negative real number, e.g., the distance to traverse this edge. We will assume that the functions φ E and c are given, but are expensive to compute. Hence, we will approximate them with functionsφ E , andĉ, respectively, that underestimate their true values, i.e.,φ E ≤ φ E andĉ ≤ c. We will use these admissible heuristic estimators to prioritize the expansion of optimal path candidates, in an attempt to delay the actual computation until it becomes necessary.

B. Optimal Path
Define a path π = (v 1 , v 2 , . . . , v m ) on the graph G = (V, E) as an ordered set of distinct vertices v i ∈ V , i = 1, . . . , m such that for any two consecutive vertices v i , v i+1 , there exists an edge e = (v i , v i+1 ) ∈ E. Throughout this paper, we will interchangeably denote a path as the set of such edges. Let v s , v g ∈ V be the start and goal vertices, respectively. Denote by Π(v s , v g ), or Π for short if there is no danger for ambiguity, the set of all acyclic paths connecting v s and v g in G. Let Π k be the set of paths in which the worst (greatest) edge class included in each path in Π k is exactly k. That is, where N (π, k) = |{e ∈ π : φ E (e) = k}| is the number of edges that are of class k in path π. Furthermore, define to be the set of class-k paths which have exactly i edges of class k. We shall impose a total order on the set of paths with Π i k ≺ Π j for any i, j whenever k < and Π i k ≺ Π j k for all i < j. Hence, we define the optimal path set Π * as the nonempty set of paths having best worst-class edge with the least number of worst-class edges, that is, where the minimum is defined with respect to the total path order. We wish to solve for the optimal path π * which is the shortest path in Π * , that is,

C. Search Tree
Initially, all vertices and edges of G are implicitly defined and are unclassified. As the search propagates, an explicit search tree T rooted at v s is built by adding classified vertices and edges. Each vertex v in the tree T has the following values explicitly assigned.
• cost-to-come: cost-to-come accumulated along the current best path in the tree, denoted with g T (v). • path-class: number of edges of each class in the current best path, denoted with θ T (v).
The range of g T is the set of non-negative real numbers, whereas the range of θ T is the set of sequences of integers of finite length |K|, i.e., θ T (v) = (N (π, k)) k∈K , where the number of edges that are of class k in the current path π = (v s , . . . , v) is stored in the k-th index. By the total order defined in the previous section, any two paths π 1 = (u 1 , . . . , u m ) and π 2 = (v 1 , . . . , v n ) with the same first and end vertices (i.e., u 1 = v 1 and u m = v n ) can be compared. For example, if there exists another tree T that has a better path from v s to v, then we have θ T (v) ≺ θ T (v). We will denote the sequence of integers (N (π, k)) k∈K for a path π = (v, . . . , v ) with θ(v, v ). Then θ is sub-additive along the path, θ(v, v ) θ(v, v )+θ(v , v ). We also define an admissible estimate of θ(v, v ) withθ(v, v ), such that θ θ. A trivial heuristic estimate ofθ is the zero sequence.
Note that the standard A * algorithm stores for each vertex in a search tree T a back-pointer to its parent vertex and also stores the cost-to-come accumulated by traversing the back-pointed path. Despite the fact that the cost-to-come of a vertex in T can be retrieved by following the back-pointed path in the forward direction, the numerical value of the costto-come is explicitly stored at each vertex to expedite the ordering of expanding leaf vertices so that the completeness and optimality of the algorithm with respect to the cost-tocome are preserved. The same idea can be generalized to a total ordering of vertices, based on an order defined over a set of paths, without losing correctness of the algorithm. The completeness and optimality of such generalization with respect to any ordered set of paths can be also proven, as it will be shown formally in Section IV.

D. Priority Queue
We will use an edge queue Q to prioritize the expansion (i.e., evaluation) of edges based on an admissible estimate of the path class, breaking ties using conventional path cost estimates. For each edge e = (u, v) in Q, we associate four keys: , and k 4 (e) = g T (u)+ c(u, v) to prioritize edges in lexicographical order. Note that θ θ,ĉ ≤ c, andĥ ≤ h are admissible estimates of the path class, edge cost, and cost-to-go functions respectively, and θ T and g T are the path class and the cost-to-come of the best path found so far by the algorithm. These heuristic estimates of the path class and the path cost delay the actual evaluation of the edge, as the priority queue prioritizes edges based on their heuristic estimates.

III. ALGORITHM
We begin the search by initiating a search tree T with the start vertex as the root and by putting the promising outgoing edges in the priority queue Q, where a promising edge is an edge such that the path utilizing this edge may improve the current search tree T . That is, only edges that could potentially improve the current solution with heuristic estimates are first chosen, and then among the chosen edges, only those that can potentially improve the current path to the child vertex of the edge with the heuristic estimates are selected to be inserted in the queue. The edge with the highest index is removed from Q for evaluation, and then the edge is added to the tree T if such an evaluation reveals that the edge either improves the child vertex's path-class or reduces the child vertex's cost-to-come value within the same class. The outgoing edges of the newly added leaf vertex of T are then inserted in the queue accordingly. The iteration continues until the goal vertex is reached. The resulting search tree consists of connected classified edges rooted at v s , and it contains an optimal path from v s to v g . The solution path is traced back from v g to its parent up to v s . if u = v g then 8: break 9: if θ T (u) + θ(u, v) ≺ θ T (v) then 10: rewireTree((u, v), T ) 11: enqueueOutgoingEdges(v, Q) 12: else if θ T (u) + θ(u, v) = θ T (v) then 13: if g T (u) + c(u, v) < g T (v) then 14: rewireTree((u, v), T ) 15:

IV. ANALYSIS
We prove the completeness and optimality of COA * by extending the results of [3]. The key observation here is that the original A * algorithm uses an ordinary ordering of real numbers for expanding paths to find a path minimizing the cost-to-come, but the vertex ordering of the algorithm can be generalized to a total ordering of paths. In our analysis, we will assume that a total path ordering exists such that for any pair of paths having the same start and goal vertices, the order gives a binary relation between the two. Then we will prove that the resulting path of such an algorithm is optimal with respect to the defined ordering.
We will present an edge queue version of the proof instead of the vertex queue proof of the original A * to utilize admissible estimators of edge evaluation functions. This choice relaxes the heuristic look-ahead over to an edge, such that the actual evaluation of the edge is delayed until it is necessary, under the assumption that edge evaluations are computationally expensive [8], [11], [25]. However, since the goal is to find a path from a start vertex to a goal vertex, we need to first define the trivial edges involving the start and goal vertices. To this end, we define a start edge s = (v s , v s ) for a start vertex v s , and a goal edge t = (v g , v g ) for a goal vertex v g , where the evaluations of these trivial edges are naturally defined as: . With some abuse of notation, we will denote the optimal path (e, . . . , e ) from a start edge e to an end edge e in the graph with π(e, e ). Also, we will denote the path from an edge e to e found by the COA * algorithm so far with π T (e, e ), where T represents the current search tree. We will assume that there exists an ordering for any pair of paths from the same start and end edges. For example, we have π(e, e ) π T (e, e ) since any search tree built by the algorithm cannot contain a strictly better path than the optimal path. Also, we denote an underestimating heuristic path from e to e withπ(e, e ), such thatπ(e, e ) π(e, e ) for any edges e, e . Concatenation of paths is denoted with π(e, e ) ∪ π(e , e ) = π(e, e ) for two adjacent paths. If e and e are adjacent edges on the optimal path, then, π(e, e ) ∪ e = π(e, e ). We will use π(e, e) = ∅ for any e ∈ E, and ∅ π(e, e ) for any edges e, e .
We are now ready to present Lemma 1, which states that the path ordering is invariant under the concatenation with the same subpath.
In either case, we have π(s, e) ∪π(e, t) π(s, e) ∪ π(e, t), thus completing the proof. Next, Lemma 2 states that if an edge on an optimal path is not evaluated, then the edge queue Q must contain an edge such that an optimal subpath from the start edge to this edge is in the search tree T.
Lemma 2: For any unevaluated edge e, and for any optimal path P from s to e, there exists an edge e ∈ Q on P such that π(s, e ) = π T (s, e ).  Fig. 2: Evolution of search tree T from left to right in a ternary graph with green, yellow, and red classes. COA * builds the optimal tree T by revealing the classes of the frontier edges in the order defined by the priority queue.
Proof: Let P = (s = e 0 , e 1 , . . . , e n = e). If s ∈ Q, that is, if COA * has not completed the first iteration, let e = s. Then π(s, s) = π T (s, s) = ∅, and hence the lemma is trivially true. Now, suppose s is evaluated. Let ∆ be the set of all evaluated edges e i in P such that π(s, e i ) = π T (s, e i ). Then, ∆ is not empty, since by assumption s ∈ ∆. Let e * be the element of ∆ with the highest index. Clearly, e * = e, since e has not yet been evaluated. Let e be the successor of e * on P . Then, π T (s, e ) π T (s, e * ) ∪ e . However, π T (s, e * ) = π(s, e * ) since e * ∈ ∆. Moreover, π(s, e ) = π(s, e * ) ∪ e , since e * and e are on P. Therefore π T (s, e ) π(s, e ). In general, π T (s, e ) π(s, e ), and hence π T (s, e ) = π(s, e ). Also, e must be inserted in Q since e is adjacent to e * , the highest index edge in ∆.
Corollary 1: Supposeπ(e, t) π(e, t) for all e, and suppose COA * has not terminated. Then, for any optimal path P from s to a goal t, there exists an edge e ∈ Q on P with π T (s, e ) ∪π(e , t) π(s, t).
Proof: By the Lemma 2, there exists an edge e ∈ Q in P with π(s, e ) = π T (s, e ). Then, by applying the Lemma 1, π T (s, e ) ∪π(e , t) = π(s, e ) ∪π(e , t) π(s, e ) ∪ π(e , t) = π(s, t), where the last equality holds since e ∈ P . Now we are ready to prove the completeness and optimality properties of COA * .
π(e, t) for all e. Then COA * terminates in a finite number of iterations and finds the optimal path from s to a goal t, if one exists.
Proof: We prove this theorem by contradiction. Suppose the algorithm does not terminate by finding an optimal solution. There are three cases to consider: 1) The algorithm terminates at a non-goal. This contradicts the termination condition (Line 7, Algorithm 1).
2) The algorithm fails to terminate. Let π(s, t) be an optimal path from s to the goal t. Clearly, no edges with π T (s, e) ∪π(e, t) π(s, t) will ever be evaluated, since by Corollary 1 there is some e with π T (s, e )∪π(e , t) π(s, t), and hence, COA * will select e instead of e. Since there is only a finite number of acyclic paths from the start edge to any edge, all edges with π(s, e)∪π(e, t) π(s, t) can be re-evaluated at most a finite number of times. Hence, the only possibility left for COA * that fails to terminate is when the queue Q becomes empty before a goal is reached. Suppose, ad absurdum, that Q becomes empty before the goal is reached. If there exists a path to the goal, and the goal is not already in the tree T, then there exists at least one edge that could improve the current solution path. Then, this edge would have been inserted in the queue Q by Algorithm 2, contradicting the assumption that Q becomes empty. Hence, COA * must terminate.
3) The algorithm terminates at the goal without finding an optimal solution. Suppose COA * terminates at some goal edge t with π T (s, t) π(s, t). By Corollary 1, just before termination, there must exist an edge such that e ∈ Q with π T (s, e ) ∪π(e , t) π(s, t). Hence, at this stage, e would have been selected for evaluation rather than t, contradicting the assumption that COA * terminated. Therefore, the algorithm must terminate by finding the optimal solution, if one exists.
Note that we proved the completeness and optimality with respect to the total order defined in Section II. However, the same technique can be applied to a different total order using more general properties of paths if the properties are additive along the path and the start vertex is already on the optimal path. An immediate corollary of this observation is that COA * can also find a shortest path among the set of paths with shortest inferior class edges. This is useful, especially for computing heuristics in high-dimensional search spaces, as the distance between two vertices is easier to obtain than counting the possible number of edges in the path connecting the two vertices.

V. NUMERICAL RESULTS
In this section, we present numerical results of COA * in scenarios where the planning agent has limited perception of the search space and incrementally gains knowledge of the space as it moves along the local plan. We then compare the results of COA * to a regular A * which finds a shortest path regardless of uncertainty on an optimistically perceived environment, namely, assuming the unknown region is free of obstacles. The perception-plan-action loop is iterated until the agent reaches the goal on a graph with uniformly distributed vertices. At each planning instance, the edges of the graph are classified into three classes: feasible, unknown, and infeasible. A sensor with a radial field of view is attached to the moving agent, and all the vertices outside the sensing region are classified as unknown, while each vertex within the sensing region is classified either as feasible or infeasible depending on the corresponding configuration [26], [27].
Once the agent finds a locally optimal solution in the current map, the agent executes the first action of the plan, i.e., it moves along the first vertex of the locally optimal path, and then updates its map accordingly, as shown in Figure 4. During the perception-plan-action loop, two measures of interest for each locally optimal plan were recorded at each planning instance, namely, the path length (distance) and the uncertainty ratio. The local uncertainty ratio is the proportion of the sum of the length of the uncertain edges to the length of the sum of all the edges in a path, which measures the percentage of the uncertain segment for the path. Using sensors with different ranges, about 100 paths were collected for each robot in several search spaces. Figure 3 shows the results of A * in comparison to COA * for a 2D mobile robot, a 3D robotic arm, and a 5D robotic arm. On average, COA * finds less uncertain paths compared to A * . This becomes more evident in the higher dimensional search spaces.

VI. CONCLUSION
We have introduced the notion of optimality on a weighted colored graph, which encodes both geometric and semantic information of the search space. We present a new search algorithm, the Class-Ordered A * (COA * ) to find a globally optimal path in a weighted colored graph by incrementally building an optimal search tree using a heuristic, and we proved the completeness and optimality of the algorithm. The optimal path of COA * is the shortest path among the set of paths with minimal inferior class edges. In addition, COA * monotonically finds a better path when the underlying graph has a strictly better class of vertices and edges. Finally, COA * was numerically evaluated on a ternary graph with feasible, unknown, and infeasible classes against the standard A * algorithm, which finds a shortest path regardless of uncertainty. The results of these numerical experiments confirmed the superiority of COA * in terms of finding safer plans when the search space is partially known.