plan
Description
Examples
Load the Queensland road network.
load("queenslandRoutes","places","routes")
Specify states, links, and weights for a navGraph
object.
states = places.utm; % UTM coordinates of cities names = places.name; % Names of cities links = [routes.start routes.end]; % Adjacent cities weights = routes.time; % Travel time between adjacent cities
Create a navGraph
object.
graphObj = navGraph(states,links,Weight=weights, ...
Name=names);
Create a graph-based A* path planner.
planner = plannerAStar(graphObj);
Create a deep copy of the plannerAStar
object.
planner2 = copy(planner)
planner2 = plannerAStar with properties: HeuristicCostFcn: @nav.algs.distanceManhattan TieBreaker: 0 Graph: [1×1 navGraph]
Specify a heuristic function returns an estimated time to reach the goal.
planner.HeuristicCostFcn = @(state1,state2) ...
sum(abs(state1-state2),2)/100;
Define the start and goal cities.
start = "Hughenden"; goal = "Brisbane";
Find the shortest path using the graph-based A* algorithm.
[pathOutput,solutionInfo] = plan(planner,start,goal);
Visualize the results.
h = show(graphObj); set(h,XData=graphObj.States.StateVector(:,1), ... YData=graphObj.States.StateVector(:,2)) pathStateIDs = solutionInfo.PathStateIDs; highlight(h,pathStateIDs,EdgeColor="#EDB120",LineWidth=4) highlight(h,pathStateIDs(1),NodeColor="#77AC30",MarkerSize=5) highlight(h,pathStateIDs(end),NodeColor="#D95319",MarkerSize=5)
Input Arguments
A* path planner, specified as a plannerAStar
object.
Start state of the path, specified as a positive integer, string scalar, character vector, or numeric vector.
Example: 1
Example: "Brisbane"
Example: [1095.91458671447 6947.04365801860]
Data Types: single
| double
| char
| string
Goal state of the path, specified as a positive integer, string scalar, character vector, or numeric vector.
Example: 5
Example: "Hughenden"
Example: [208.622393818849 7691.91766093269]
Data Types: single
| double
| char
| string
Output Arguments
Shortest path between states, returned as a numeric matrix.
Data Types: double
Solution information, returned as a structure. The fields of the structure are:
Field | Description |
---|---|
IsPathFound | Indicates whether a path has been found. Returns
|
PathStateIDs | List of IDs of the states along the path found by A*. By default, the IDs are the numeric indices of the states in the graph object. If you specify names for the states while constructing the graph object, this field contains the names instead. |
PathCost | Total cost of the path. If no path is found, then the cost is
|
ExploredStateIDs | List of IDs of the states explored by A* during the search. By default, the IDs are the numeric indices of the states in the graph object. If you specify names for the states while constructing the graph object, this field contains the names instead. |
NumExploredStates | Number of states explored during the search. Equal to the length of
the |
Data Types: struct
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Version History
Introduced in R2023a
See Also
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)