RandomRegularGraph - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Mozilla Firefox.

Online Help

All Products    Maple    MapleSim


GraphTheory[RandomGraphs]

  

RandomRegularGraph

  

generate a random regular graph

 

Calling Sequence

Parameters

Options

Description

Examples

Calling Sequence

RandomRegularGraph(n,d,options)

Parameters

n

-

positive integer or list of vertices

d

-

nonnegative integer

options

-

(optional) equation(s) of the form option=value where option is one of connected or seed

Options

• 

connected = truefalse

  

If specified, indicates that the generated graph should be connected.

• 

seed = integer or none

  

Seed for the random number generator. When an integer is specified, this is equivalent to calling randomize(seed).

Description

• 

RandomRegularGraph(n,d) creates a d-regular undirected unweighted graph on n vertices. n and d cannot both be odd and d must satisfy d<n.

• 

If the option connected is specified, the graph created will be connected. n and d must then satisfy n = 1 and d = 0, or n = 2 and d = 1, or n&gt;2 and d&gt;1 as well as the above.

• 

For RandomRegularGraph(n,d,connected), a random tree with maximum degree≤d is first created.

• 

For generating weighted graphs use weights = f and see AssignEdgeWeights for details about f.

• 

The random number generator used can be seeded using the seed option or the randomize function.

Examples

> 

with⁡GraphTheory&colon;

> 

with⁡RandomGraphs&colon;

> 

R≔RandomRegularGraph⁡100&comma;80&comma;connected

R≔Graph 1: an undirected graph with 100 vertices and 4000 edges

(1)
> 

IsRegular⁡R

true

(2)
> 

IsConnected⁡R

true

(3)
> 

R≔RandomRegularGraph⁡seq⁡a..j&comma;3&comma;weights=−10..10

R≔Graph 2: an undirected weighted graph with 10 vertices and 15 edges

(4)
> 

WeightMatrix⁡R

0−100030900−10090000−700000007−100609008000−7000080−10−60003000−10000−200070−60000−790−10000000−60−70−70−20000006000−7−600

(5)
> 

f≔RandomTools:-Generate⁡float⁡range=0.1..1&comma;digits=2&comma;makeproc=true&colon;

> 

R≔RandomRegularGraph⁡10&comma;3&comma;weights=f

R≔Graph 3: an undirected weighted graph with 10 vertices and 15 edges

(6)
> 

WeightMatrix⁡R

000.330000.42000.95000.33000000.270.250.330.3300000.6400000000000.540.740.83000000.400.540.740000000.40000.700.4700.4200.6400.54000000000.540.740.70000000.2700.7400.4700000.950.2500.83000000

(7)
> 

U≔rand⁡1..4&colon;

> 

f := proc() local x; x := U(); if x=1 then 1 else 2 end if; end proc:

> 

H≔RandomRegularGraph⁡10&comma;3&comma;connected&comma;weights=f

H≔Graph 4: an undirected weighted graph with 10 vertices and 15 edges

(8)
> 

WeightMatrix⁡H

0022100000002100100022000000202100001000100000022000000002220101000002000022000200202200000000022200

(9)

See Also

AssignEdgeWeights

GraphTheory:-IsConnected

GraphTheory:-WeightMatrix

RandomBipartiteGraph

RandomDigraph

RandomGraph

RandomNetwork

RandomTournament

RandomTree