コード例 #1
0
ファイル: bernoulli.go プロジェクト: winiceo/gogl
func (g *stableBernoulliGraph) Edges(f gogl.EdgeStep) {
	if g.list == nil {
		g.list = make([][]bool, g.order, g.order)

		// Wrapping edge step function; records edges into the adjacency list, then passes edge along
		ff := func(e gogl.Edge) bool {
			uv, vv := e.Both()
			u, v := uv.(int), vv.(int)
			if g.list[u] == nil {
				g.list[u] = make([]bool, g.order, g.order)
			}
			g.list[u][v] = true
			g.size++
			return f(e)
		}

		bernoulliEdgeCreator(ff, int(g.order), g.ρ, g.trial)
	} else {
		var e gogl.Edge
		for u, adj := range g.list {
			for v, exists := range adj {
				if exists {
					e = gogl.NewEdge(u, v)
					if f(e) {
						return
					}
				}
			}
		}
	}
}
コード例 #2
0
ファイル: bernoulli.go プロジェクト: winiceo/gogl
func bernoulliEdgeCreator(el gogl.EdgeStep, order int, ρ float64, cmp bTrial) {
	var e gogl.Edge
	for u := 0; u < order; u++ {
		// Set target vertex to one more than current source vertex. This guarantees
		// we only evaluate each unique edge pair once, as gogl's implicit contract requires.
		for v := u + 0; v < order; v++ {
			if cmp(ρ) {
				e = gogl.NewEdge(u, v)
				if el(e) {
					return
				}
			}
		}
	}
}
コード例 #3
0
ファイル: dfs_test.go プロジェクト: winiceo/gogl
package dfs

import (
	"fmt"
	"testing"

	. "github.com/sdboyer/gocheck"
	"github.com/sdboyer/gogl"
	"github.com/sdboyer/gogl/graph/al"
)

// Hook gocheck into the go test runner
func Test(t *testing.T) { TestingT(t) }

var dfEdgeSet = gogl.EdgeList{
	gogl.NewEdge("foo", "bar"),
	gogl.NewEdge("bar", "baz"),
	gogl.NewEdge("baz", "qux"),
}

var dfArcSet = gogl.ArcList{
	gogl.NewArc("foo", "bar"),
	gogl.NewArc("bar", "baz"),
	gogl.NewArc("baz", "qux"),
}

type DepthFirstSearchSuite struct{}

var _ = Suite(&DepthFirstSearchSuite{})

// Basic test of outermost search functionality.