GraphTheory - Maple Programming Help

Home : Support : Online Help : Mathematics : Discrete Mathematics : Graph Theory : GraphTheory Package : GraphTheory/SetEdgeWeight

GraphTheory

 SetEdgeWeight
 GetEdgeWeight

 Calling Sequence SetEdgeWeight(G, e, w) GetEdgeWeight(G, e)

Parameters

 G - weighted graph e - edge/arc w - numeric; edge weight

Description

 • SetEdgeWeight is used to change the weight of an edge of a weighted graph. It returns the old weight of the edge.
 • GetEdgeWeight is used to get the weight of an edge of a weighted graph.

Examples

 > $\mathrm{with}\left(\mathrm{GraphTheory}\right):$
 > $G≔\mathrm{MakeWeighted}\left(\mathrm{CompleteGraph}\left(4\right)\right)$
 ${G}{≔}{\mathrm{Graph 1: an undirected weighted graph with 4 vertices and 6 edge\left(s\right)}}$ (1)
 > $\mathrm{GetEdgeWeight}\left(G,\left\{1,2\right\}\right)$
 ${1}$ (2)
 > $\mathrm{SetEdgeWeight}\left(G,\left\{1,2\right\},3\right)$
 ${1}$ (3)
 > $\mathrm{GetEdgeWeight}\left(G,\left\{1,2\right\}\right)$
 ${3}$ (4)
 > $\mathbf{for}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}e\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{in}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathrm{Edges}\left(\mathrm{CycleGraph}\left(4\right)\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{do}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathrm{SetEdgeWeight}\left(G,e,2\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{end do}$
 ${1}$ (5)
 > $\mathrm{WeightMatrix}\left(G\right)$
 $\left[\begin{array}{cccc}{0}& {2}& {1}& {2}\\ {2}& {0}& {2}& {1}\\ {1}& {2}& {0}& {2}\\ {2}& {1}& {2}& {0}\end{array}\right]$ (6)