func writeLogfile(g *graph.Graph, round int) error { logfile := filepath.Join(*outputDir, fmt.Sprintf("%04d.def", round)) f, err := os.Create(logfile) if err != nil { return fmt.Errorf("Error creating logfile: %v", err) } def := g.GraphDef() data, err := encoding.Marshal(def) if err != nil { return fmt.Errorf("Error marshalling graph def: %v", err) } _, err = f.Write(data) return err }
func runOverallMaxCost(g *graph.Graph) { if !*maxCost { return } cost := 0 highest, hcost := graph.ClusterID(""), 0 lowest, lcost := graph.ClusterID(""), maxInt for _, c := range g.Clusters() { tmpcost := graph.MaxCost(g, c.ClusterID()) cost += tmpcost if tmpcost > hcost { highest, hcost = c.ClusterID(), tmpcost } if tmpcost < lcost { lowest, lcost = c.ClusterID(), tmpcost } } fmt.Printf(" Average MaxCost: %v\n", float64(cost)/float64(g.NumClusters())) fmt.Printf(" Total MaxCost: %v\n", cost) fmt.Printf(" Cluster with highest MaxCost: %v (%v)\n", highest, hcost) fmt.Printf(" Cluster with lowest MaxCost: %v (%v)\n", lowest, lcost) }
func runBasic(g *graph.Graph) { fmt.Printf(" Number of nodes: %v\n", g.NumNodes()) fmt.Printf(" Number of clusters: %v\n", g.NumClusters()) fmt.Printf(" Average nodes per cluster: %.2f\n", float64(g.NumNodes())/float64(g.NumClusters())) borderNodes := 0 for _, n := range g.Nodes() { if n.IsBorderNode() { borderNodes++ } } fmt.Printf(" Number of border nodes: %v\n", borderNodes) fmt.Printf(" Average border nodes per cluster: %.2f\n", float64(borderNodes)/float64(g.NumClusters())) edges := 0 for _, n := range g.Nodes() { edges += n.NumEdges() } edges /= 2 fmt.Printf(" Number of edges: %v\n", edges) fmt.Printf(" Average edges per node: %.2f\n", float64(2*edges)/float64(g.NumNodes())) borderEdges := 0 for _, n := range g.Nodes() { borderEdges += n.NumEdgesOutCluster() } borderEdges /= 2 fmt.Printf(" Number of border edges: %v\n", borderEdges) fmt.Printf(" Average border edges per cluster: %.2f\n", float64(2*borderEdges)/float64(g.NumClusters())) fmt.Println() biggest, bsize := "", 0 smallest, ssize := "", maxInt borderBiggest, borderBsize := "", 0 borderSmallest, borderSsize := "", maxInt for _, c := range g.Clusters() { cid := string(c.ClusterID()) n := c.NumNodes() if n > bsize { biggest, bsize = cid, n } if n < ssize { smallest, ssize = cid, n } n = c.NumBorderNodes() if n > borderBsize { borderBiggest, borderBsize = cid, n } if n < borderSsize { borderSmallest, borderSsize = cid, n } } fmt.Printf(" Cluster with most nodes: %v (%v)\n", biggest, bsize) fmt.Printf(" Cluster with fewest nodes: %v (%v)\n", smallest, ssize) fmt.Printf(" Cluster with most border nodes: %v (%v)\n", borderBiggest, borderBsize) fmt.Printf(" Cluster with fewest border nodes: %v (%v)\n", borderSmallest, borderSsize) }