M-File Help: Pgraph View code for Pgraph

Pgraph

Simple graph class

g = PGraph() create a 2D, planar, undirected graph
g = PGraph(n) create an n-d, undirected graph

Graphs

Graph connectivity is maintained by a labeling algorithm and this is updated every time an edge is added.

Methods

Constructing the 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

Information from 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

Planning paths through 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

Graph and world points

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
To change the distance metric create a subclass of PGraph and override the method distance_metric().

Object properties (read/write)

g.n number of nodes

Pgraph.PGraph

Graph class constructor

g = 'distance', M Use the distance metric M for path planning 'verbose' Specify verbose operation

Note


Pgraph.add_edge

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.

Pgraph.add_node

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.

Pgraph.char

Convert graph to string

s = G.

Pgraph.clear

Clear the graph

G.

Pgraph.closest

Find closest node

v = G.closest to coordinate x. [v,d] = G.

Pgraph.connectivity

Graph connectivity

C = G.

Pgraph.coord

Coordinate of node

x = G.

Pgraph.cost

Cost of edge

C = G.cost of edge id E.

Pgraph.display

Display state of the graph

G.PGraph.char


Pgraph.distance

Distance between nodes

d = G.distance between the nodes with id v1 and v2.

Pgraph.distances

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.

Pgraph.edges

Find edges given vertex

E = G.edges from node id v.

Pgraph.goal

Set goal node

G.goal node. The cost of reaching every node in the graph connected to vg is computed.

See also

PGraph.path

cost is total distance from

Pgraph.neighbours

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.

Pgraph.next

Find next node toward goal

v = G.PGraph.goal, PGraph.path


Pgraph.path

Find path to goal node

p = G.path from the starting node vs to the previously specified goal. The PGraph.goal


Pgraph.pick

Graphically select a node

v = G.PGraph.plot


Pgraph.plot

Plot the graph

G.plot the graph in the current figure. Nodes are shown as colored circles.

Options

'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

Pgraph.showComponent

t

G.

Pgraph.showVertex

Highlight a vertex

G.

Pgraph.vertices

Find vertices given edge

v = G.  

© 1990-2011 Peter Corke.