Exemplo n.º 1
0
func main() {
	if len(os.Args) != 2 {
		fmt.Fprintf(os.Stderr, "Proper usage: %s <probability>\n")
		os.Exit(1)
	}

	prob, err := strconv.ParseFloat(os.Args[1], 64)
	if err != nil {
		fmt.Fprintf(os.Stderr, err.Error())
		os.Exit(1)
	} else if prob > 1 {
		prob = 1
	} else if prob < 0 {
		prob = 0
	}

	us, vs := potts.GenerateEdges(potts.Grid2D, prob, gridWidth)

	fmt.Printf("For a grid of width %d with %d nodes the following edges "+
		"were generated:\n", gridWidth, gridWidth*gridWidth)

	for i := 0; i < len(us); i++ {
		fmt.Printf("  (%d, %d)\n", us[i], vs[i])
	}

	if len(us) == 0 {
		fmt.Println("nil")
	}
}
Exemplo n.º 2
0
func main() {
	if len(os.Args) != 3 {
		fmt.Fprintf(os.Stderr, "Usage: %s <grid width> <out-file>\n")
		os.Exit(1)
	}

	width, err := strconv.ParseInt(os.Args[1], 10, 64)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error with first argument: %s", err.Error())
		os.Exit(1)
	}

	timeTable := table.NewOutTable("Generate Edges", "Create Graph", "Union")
	dataTable := table.NewOutTable("Edge Frequency", "Largest Group Frac")
	dataTable.SetHeader(fmt.Sprintf(
		"Grid has continuous boundary conditions and %d x %d nodes.",
		width, width))

	for step := 0; step <= steps; step++ {
		prob := float64(step) / float64(steps)

		t0 := time.Now()
		us, vs := potts.GenerateEdges(potts.Grid2D, prob, int(width))

		t1 := time.Now()
		g := graph.New(uint32(width*width), us, vs)

		t2 := time.Now()
		g.Union()

		t3 := time.Now()

		largestGroup := g.Query(graph.Size, g.LargestGroup())
		dataTable.AddRow(prob, float64(largestGroup)/float64(width*width))
		timeTable.AddRow(sec(t0, t1), sec(t1, t2), sec(t2, t3))
	}

	timeTable.Print(table.KeepHeader)
	if err := dataTable.Write(table.KeepHeader, os.Args[2]); err != nil {
		fmt.Fprintf(os.Stderr, "I/O Error: %s\n", err.Error())
		os.Exit(1)
	}
}