GraphTheory - Maple Programming Help

# Online Help

###### All Products    Maple    MapleSim

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

GraphTheory

 MakeWeighted

 Calling Sequence MakeWeighted(G) MakeWeighted(G, M)

Parameters

 G - unweighted graph M - (optional) Matrix

Description

 • The MakeWeighted command returns a graph with vertices and edges from G. If M is part of the input, then the edge weights are taken from it; otherwise edge weights are assumed to be 1. If G is undirected, then M is assumed to be a symmetric matrix.
 • For efficiency, use datatype=integer for wordsize integer weights and datatype=float[8] for numerical (decimal) edge weights.
 • To read or modify the edge weights of a weighted graph, use the GetEdgeWeight and SetEdgeWeight commands.

Examples

 > $\mathrm{with}\left(\mathrm{GraphTheory}\right):$
 > $G≔\mathrm{Graph}\left(\left\{\left\{1,2\right\},\left\{1,3\right\},\left\{2,3\right\}\right\}\right)$
 ${G}{≔}{\mathrm{Graph 1: an undirected unweighted graph with 3 vertices and 3 edge\left(s\right)}}$ (1)
 > $M≔\mathrm{Matrix}\left(\left[\left[0,2,3\right],\left[2,0,1\right],\left[3,1,0\right]\right]\right)$
 ${M}{≔}\left[\begin{array}{ccc}{0}& {2}& {3}\\ {2}& {0}& {1}\\ {3}& {1}& {0}\end{array}\right]$ (2)
 > $\mathrm{H1}≔\mathrm{MakeWeighted}\left(G,M\right)$
 ${\mathrm{H1}}{≔}{\mathrm{Graph 2: an undirected weighted graph with 3 vertices and 3 edge\left(s\right)}}$ (3)
 > $\mathrm{Edges}\left(\mathrm{H1}\right)$
 $\left\{\left\{{1}{,}{2}\right\}{,}\left\{{1}{,}{3}\right\}{,}\left\{{2}{,}{3}\right\}\right\}$ (4)
 > $\mathrm{WeightMatrix}\left(\mathrm{H1}\right)$
 $\left[\begin{array}{ccc}{0}& {2}& {3}\\ {2}& {0}& {1}\\ {3}& {1}& {0}\end{array}\right]$ (5)
 > $M≔\mathrm{Matrix}\left(M,\mathrm{datatype}=\mathrm{float}\left[8\right],\mathrm{shape}=\mathrm{symmetric}\right)$
 ${M}{≔}\left[\begin{array}{ccc}{0.}& {2.}& {3.}\\ {2.}& {0.}& {1.}\\ {3.}& {1.}& {0.}\end{array}\right]$ (6)
 > $\mathrm{H2}≔\mathrm{MakeWeighted}\left(G,M\right)$
 ${\mathrm{H2}}{≔}{\mathrm{Graph 3: an undirected weighted graph with 3 vertices and 3 edge\left(s\right)}}$ (7)
 > $\mathrm{WeightMatrix}\left(\mathrm{H2}\right)$
 $\left[\begin{array}{ccc}{0.}& {2.}& {3.}\\ {2.}& {0.}& {1.}\\ {3.}& {1.}& {0.}\end{array}\right]$ (8)

 See Also