Main Content

copy

Create deep copy of A* path planner object

Since R2023a

    Description

    example

    planner2 = copy(planner1) creates a deep copy of the plannerAStar object planner1.

    Examples

    collapse all

    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: [1x1 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

    collapse all

    A* path planner, specified as a plannerAStar object.

    Output Arguments

    collapse all

    Copy of A* path planner, returned as a plannerAStar object.

    Extended Capabilities

    C/C++ Code Generation
    Generate C and C++ code using MATLAB® Coder™.

    Version History

    Introduced in R2023a

    See Also

    |