예제 #1
0
파일: ghs_test.go 프로젝트: tcolgate/radia
func TestGHS3(t *testing.T) {
	wg := sync.WaitGroup{}

	// We'll only ever get halt messages from the core edge, so only
	// two nodes halt
	wg.Add(3)
	n1 := graphalg.Node{
		ID: graphalg.NodeID("n1"),
	}
	n2 := graphalg.Node{
		ID: graphalg.NodeID("n2"),
	}
	n3 := graphalg.Node{
		ID: graphalg.NodeID("n3"),
	}

	n1.Join(&n2, 1.0, graphalg.MakeChanPair)
	n2.Join(&n3, 2.0, graphalg.MakeChanPair)
	n3.Join(&n1, 3.0, graphalg.MakeChanPair)

	ghs1 := State{Node: &n1}
	ghs2 := State{Node: &n2}
	ghs3 := State{Node: &n3}

	go graphalg.Run(&ghs1, wg.Done)
	go graphalg.Run(&ghs2, wg.Done)
	go graphalg.Run(&ghs3, wg.Done)

	ghs1.WakeUp()

	wg.Wait()
}
예제 #2
0
파일: ghs_test.go 프로젝트: tcolgate/radia
func TestGHS1(t *testing.T) {
	wg := sync.WaitGroup{}

	wg.Add(2)
	n1 := graphalg.Node{
		ID: graphalg.NodeID("n1"),
	}
	n2 := graphalg.Node{
		ID: graphalg.NodeID("n2"),
	}

	n1.Join(&n2, 1.0, graphalg.MakeChanPair)

	ghs1 := State{Node: &n1}
	ghs2 := State{Node: &n2}

	go graphalg.Run(&ghs1, wg.Done)
	go graphalg.Run(&ghs2, wg.Done)

	ghs1.WakeUp()

	wg.Wait()
}
예제 #3
0
파일: ghs_test.go 프로젝트: tcolgate/radia
func TestGHS6(t *testing.T) {
	wg := sync.WaitGroup{}

	// We'll only ever get halt messages from the core edge, so only
	// two nodes halt
	wg.Add(6)
	n1 := graphalg.Node{
		ID: graphalg.NodeID("n1"),
	}
	n2 := graphalg.Node{
		ID: graphalg.NodeID("n2"),
	}
	n3 := graphalg.Node{
		ID: graphalg.NodeID("n3"),
	}
	n4 := graphalg.Node{
		ID: graphalg.NodeID("n4"),
	}
	n5 := graphalg.Node{
		ID: graphalg.NodeID("n5"),
	}
	n6 := graphalg.Node{
		ID: graphalg.NodeID("n6"),
	}

	n1.Join(&n2, 1.1, graphalg.MakeChanPair)
	n2.Join(&n4, 3.1, graphalg.MakeChanPair)
	n4.Join(&n6, 3.7, graphalg.MakeChanPair)
	n6.Join(&n5, 2.1, graphalg.MakeChanPair)
	n5.Join(&n3, 3.8, graphalg.MakeChanPair)
	n5.Join(&n1, 2.6, graphalg.MakeChanPair)
	n3.Join(&n1, 1.7, graphalg.MakeChanPair)

	ghs1 := State{Node: &n1}
	ghs2 := State{Node: &n2}
	ghs3 := State{Node: &n3}
	ghs4 := State{Node: &n4}
	ghs5 := State{Node: &n5}
	ghs6 := State{Node: &n6}

	go graphalg.Run(&ghs1, wg.Done)
	go graphalg.Run(&ghs2, wg.Done)
	go graphalg.Run(&ghs3, wg.Done)
	go graphalg.Run(&ghs4, wg.Done)
	go graphalg.Run(&ghs5, wg.Done)
	go graphalg.Run(&ghs6, wg.Done)

	ghs1.WakeUp()

	wg.Wait()
}
예제 #4
0
파일: main.go 프로젝트: tcolgate/radia
func setupGHS(mux *http.ServeMux) {
	s := state{}

	t := tracer.NewHTTPDisplay(mux, s.OnRun)

	s.wg = &sync.WaitGroup{}

	count := 25
	s.wg.Add(count)
	nodes := make([]*graphalg.Node, 0)
	s.ghs = make([]*ghs.State, 0)

	for i := 0; i < count; i++ {
		n := &graphalg.Node{
			ID:     graphalg.NodeID(fmt.Sprintf("n%v", i+1)),
			Tracer: t,
		}
		nodes = append(nodes, n)
		s.ghs = append(s.ghs, &ghs.State{Node: n})
	}

	for i := 0; i < count; i++ {
		for j := i + 1; j < count; j++ {
			log.Println("join", i, j)
			w := rand.NormFloat64()*1.0 + 4.0
			nodes[i].Join(nodes[j], w, graphalg.MakeChanPair)
		}
	}

	for _, g := range s.ghs {
		go func(g *ghs.State) {
			n := g.Node
			n.NodeUpdate("from node")
			for _, e := range n.Edges() {
				e.EdgeUpdate()
			}

			graphalg.Run(g, s.wg.Done)
		}(g)
	}

	log.Println("running")
}