M-File Help: Pgraph | View code for Pgraph |
Simple graph class
g = PGraph() | create a 2D, planar, undirected graph |
g = PGraph(n) | create an n-d, undirected graph |
g.add_node(coord) | add vertex, return vid |
g.add_node(coord, v) | add vertex and edge to v, return vid |
g.add_edge(v1, v2) | add edge from v1 to v2, return eid |
g.clear() | remove all nodes and edges from the graph |
g.edges(e) | return vid for edge |
g.cost(e) | return cost for edge list |
g.coord(v) | return coordinate of node v |
g.neighbours(v) | return vid for edge |
g.component(v) | return component id for vertex |
g.connectivity() | return number of edges for all nodes |
g.plot() | set goal vertex for path planning |
g.pick() | return vertex id closest to picked point |
char(g) | display summary info about the graph |
g.goal(v) | set goal vertex, and plan paths |
g.next(v) | return d of neighbour of v closest to goal |
g.path(v) | return list of nodes from v to goal |
g.distance(v1, v2) | distance between v1 and v2 as the crow flies |
g.closest(coord) | return vertex closest to coord |
g.distances(coord) | return sorted distances from coord and vertices |
g.n | number of nodes |
Graph class constructor
g =Add an edge to the graph
E = G.add_edge(v1, v2, C) add an edge between nodes with id v1 and v2 with cost C.Add a node to the graph
v = G.add_node(x, v) adds a node with coordinate x and connected to node v by an edge. v = G.Convert graph to string
s = G.Clear the graph
G.Find closest node
v = G.closest to coordinate x. [v,d] = G.Graph connectivity
C = G.Coordinate of node
x = G.Cost of edge
C = G.cost of edge id E.Display state of the graph
G.PGraph.charDistance between nodes
d = G.distance between the nodes with id v1 and v2.Distance to all nodes
d = G.distances(v) returns vector of geometric distance from node id v to every other node (including v) sorted into increasing order by d where elements of w are the corresponding node id.Find edges given vertex
E = G.edges from node id v.Set goal node
G.goal node. The cost of reaching every node in the graph connected to vg is computed.Neighbours of a node
n = G.neighbours of node id v. [n,C] = G.neighbours of node id v. The elements of C are the edge costs of the paths to the corresponding node ids in n.Find next node toward goal
v = G.PGraph.goal, PGraph.pathFind path to goal node
p = G.path from the starting node vs to the previously specified goal. The PGraph.goalGraphically select a node
v = G.PGraph.plotPlot the graph
G.plot the graph in the current figure. Nodes are shown as colored circles.'labels' | Display node id (default false) |
'edges' | Display edges (default true) |
'edgelabels' | Display edge id (default false) |
'MarkerSize', S | Size of node circle |
'MarkerFaceColor', C | Node circle color |
'MarkerEdgeColor', C | Node circle edge color |
'componentcolor' | Node color is a function of graph component |
t
G.Highlight a vertex
G.Find vertices given edge
v = G.© 1990-2011 Peter Corke.