func TestColorMap(t *testing.T) { Heuristic.MRV = true Heuristic.FC = true Heuristic.Degree = false Heuristic.LCV = false file, err := os.Open("input/brasil.in") if err != nil { t.Error(err) } descs, _ := parseInputFile(file) g := graph.NewGraph(len(descs)) populateGraph(&g, descs) if colorMap(g) { for _, node := range g { for _, adj := range node.Adj { if node.Color == adj.Color { t.Error("Adjacent nodes have the same color:", node, adj) } } } } else { t.Error("Graph coloring for should be possible") } }
func main() { // Heuristic level flag heuristicString := flag.String("heuristic", "a", "a, b, c or d") // Input file flag inputFile := flag.String("file", "input/usa.in", "filename of input file, standard input for default") flag.Parse() // Open file if specified, use stdin otherwise var file *os.File if *inputFile != "" { var err error file, err = os.Open(*inputFile) if err != nil { panic(err) } } else { file = os.Stdin } //parse input file graphDescription, fileHeuristic := parseInputFile(file) file.Close() if len(fileHeuristic) > 0 { heuristicString = &fileHeuristic } // Initialize Heuristic global parseHeuristic(*heuristicString) // Populate graph g := graph.NewGraph(len(graphDescription)) populateGraph(&g, graphDescription) // start := time.Now() if colorMap(g) { // elapsed := time.Now().Sub(start) // fmt.Println(elapsed) for _, node := range g { fmt.Println(node.Name()+":", node.Color.String()+".") } } else { fmt.Println("Impossível") } }