-
Notifications
You must be signed in to change notification settings - Fork 3
/
smallgraphs.go
56 lines (49 loc) · 1.03 KB
/
smallgraphs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package graph
import "errors"
// HouseGraph returns an undirected house graph.
func HouseGraph() SimpleGraph {
ss := []uint32{1, 1, 2, 3, 3, 4}
sd := []uint32{2, 3, 4, 4, 5, 5}
g, _ := New(ss, sd)
return g
}
func PathGraph(n int) (SimpleGraph, error) {
ss := make([]uint32, n-1)
sd := make([]uint32, n-1)
for i := u0; i < uint32(n-1); i++ {
ss[i] = i
sd[i] = i + 1
}
return New(ss, sd)
}
func CycleGraph(n int) (SimpleGraph, error) {
ss := make([]uint32, n)
sd := make([]uint32, n)
for i := u0; i < uint32(n-1); i++ {
ss[i] = i
sd[i] = i + 1
}
ss[n-1] = uint32(n - 1)
sd[n-1] = 0
return New(ss, sd)
}
func WheelGraph(n int) (SimpleGraph, error) {
if n < 3 {
return SimpleGraph{}, errors.New("WheelGraph must have at least 3 vertices")
}
ss := make([]uint32, 2*(n-1))
sd := make([]uint32, 2*(n-1))
n32 := uint32(n)
for i := u0; i < uint32(n-1); i++ {
ss[i] = 0
sd[i] = i + 1
if i == 0 {
continue
}
ss[n32-1+i] = i
sd[n32-1+i] = i + 1
}
ss[n-1] = uint32(n - 1)
sd[n-1] = 1
return New(ss, sd)
}