Пример #1
0
func (n *Node) ToGraphViz() string {
	graphAst, _ := parser.ParseString(`digraph NestedSet {}`)
	graph := gographviz.NewGraph()
	gographviz.Analyse(graphAst, graph)

	n.addToGraphViz(graph, "NestedSet", "")

	output := graph.String()

	return output
}
Пример #2
0
func anal(t *testing.T, input string) Interface {
	fmt.Printf("Input: %v\n", input)
	g, err := parser.ParseString(input)
	check(t, err)
	fmt.Printf("Parsed: %v\n", g)
	ag := NewGraph()
	Analyse(g, ag)
	fmt.Printf("Analysed: %v\n", ag)
	agstr := ag.String()
	fmt.Printf("Written: %v\n", agstr)
	g2, err := parser.ParseString(agstr)
	check(t, err)
	fmt.Printf("Parsed %v\n", g2)
	ag2 := NewEscape()
	Analyse(g2, ag2)
	fmt.Printf("Analysed %v\n", ag2)
	ag2str := ag2.String()
	fmt.Printf("Written: %v\n", ag2str)
	assert(t, "analysed", agstr, ag2str)
	return ag2
}
Пример #3
0
func TestBugSubGraphWorld(t *testing.T) {
	g := analtest(t, "world.gv.txt")
	st, err := parser.ParseString(g.String())
	check(t, err)
	s := &bugSubGraphWorldVisitor{
		t: t,
	}
	st.Walk(s)
	if !s.found {
		t.Fatalf("2 -> SubGraph not found")
	}
}
Пример #4
0
func visualize(data *Data) {
	graphAst, _ := parser.ParseString(`digraph G {}`)
	g := gographviz.NewGraph()

	gographviz.Analyse(graphAst, g)

	// step1 : add nodes
	for node := range data.NodeMap {
		g.AddNode("G", node.ID, nil)
	}

	// step2 : make edge from source node  to target node
	for _, edge := range data.GetEdges() {
		g.AddEdge(edge.Src.ID, edge.Dst.ID, true, nil)
	}
	output := g.String()
	fmt.Println(output)
}
Пример #5
0
func main() {
	pDoGame := flag.Bool("game", false, "start the game")
	flag.Parse()

	rcsv("data/neurons.csv", func(records []string) {
		newEmptyNeuron(records[0], records, 5, BODY)
	})

	rcsv("data/connectome.csv", func(records []string) {
		weight, err := strconv.ParseInt(records[3], 10, 32)
		if err != nil {
			log.Fatal(err)
		}

		ID_TO_NEURON[records[0]].connect(ID_TO_NEURON[records[1]], int32(weight))
	})

	rcsv("data/fake_motor.csv", func(records []string) {
		weight, err := strconv.ParseInt(records[3], 10, 32)
		if err != nil {
			log.Fatal(err)
		}

		if records[1] == "LEFT" {
			ID_TO_NEURON[records[0]].connect(BODY.left, int32(weight))
		} else if records[1] == "RIGHT" {
			ID_TO_NEURON[records[0]].connect(BODY.right, int32(weight))
		}
	})

	for _, v := range ID_TO_NEURON {
		v.ticker()
	}

	http.HandleFunc("/ping", func(w http.ResponseWriter, r *http.Request) {
		q := r.URL.RawQuery
		if n, ok := ID_TO_NEURON[r.URL.RawQuery]; ok {
			n.ping(30)
			fmt.Fprintf(w, "nReceived: %d", n.nReceived)
		} else {
			http.Error(w, fmt.Sprintf("missing neuron: %s", q), 404)
		}
	})

	http.HandleFunc("/debug", func(w http.ResponseWriter, r *http.Request) {
		DEBUG = !DEBUG
		fmt.Fprintf(w, "current: %#v", DEBUG)
	})

	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		graphAst, _ := parser.ParseString(`digraph G {}`)
		graph := gv.NewGraph()
		graph.SetDir(true)
		for _, v := range ID_TO_NEURON {

			if v.activity() > 0 {
				graph.AddNode("G", v.id(), nil)
				for _, c := range v.connections {
					graph.AddNode("G", c.to.id(), nil)
					graph.AddEdge(v.id(), c.to.id(), true, nil)
				}
			}
		}
		gv.Analyse(graphAst, graph)
		output := graph.String()
		fmt.Fprintf(w, output)
	})

	go func() {
		log.Fatal(http.ListenAndServe(":8080", nil))
	}()
	if *pDoGame {
		world()
	} else {
		BODY.ticker()
		for {
			time.Sleep(1 * time.Second)
		}
	}
}