示例#1
0
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)
}
示例#2
0
func main() {
	flag.Parse()

	f, err := os.Open(*graphFilename)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error opening graph file: %v\n", err)
		os.Exit(ERR_IO)
	}

	gd, err := ioutil.ReadAll(f)
	def, err := encoding.Unmarshal(gd)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error parsing graph file: %v\n", err)
		os.Exit(ERR_PARSE)
	}

	g := graph.NewGraph(def, graph.MaxCost)

	var clusterList map[graph.ClusterID]*graph.Cluster
	if *clusters == "all" {
		clusterList = g.Clusters()
	} else {
		clusterList = make(map[graph.ClusterID]*graph.Cluster)
		arr := strings.Split(*clusters, ",")
		for _, str := range arr {
			// Allow for "--clusters=all,"
			// (in case there's a cluster
			// called "all")
			if str == "" {
				continue
			}
			cid := graph.ClusterID(str)
			c := g.Cluster(cid)
			if c == nil {
				fmt.Fprintf(os.Stderr, "Nonexistant cluster ID: %v\n", str)
				continue
			}
			clusterList[cid] = c
		}
	}

	printedYet := false
	if *basic {
		fmt.Println("BASIC STATISTICS")
		runBasic(g)
		printedYet = true
	}

	if *advanced {
		if printedYet {
			fmt.Println()
		}
		printedYet = true
		fmt.Println("ADVANCED STATISTICS")
		for _, f := range overallAnalyzers {
			f(g)
		}
	}

	if len(clusterList) > 0 {
		if printedYet {
			fmt.Println()
		}

		fmt.Println("PER-CLUSTER ANALYSIS")
		for cid, c := range clusterList {
			fmt.Printf("  %v:\n", cid)
			for _, f := range clusterAnalyzers {
				f(g, c)
			}
		}
	}
}