Exemplo n.º 1
0
// NewGraphFromPGSolverFile builds a new graph using a file, given as
// argument, that can be generated through PGSolver's generation tools
// or that respects the very same format.
func NewGraphFromPGSolverFile() *Graph {
	fmt.Println("Parsing Graph from .....", flag.Args()[0])
	defer utils.TimeTrack(time.Now(), "Parsed")
	numnodes := -1
	fds, _ := os.Open(flag.Args()[0])
	defer fds.Close()
	file := bufio.NewReader(fds)
	first, err := file.ReadString((byte)('\n'))
	if strings.Contains(first, "parity") {
		first_split := strings.Split(first, " ")
		numnodes, _ = strconv.Atoi(first_split[1][:len(first_split[1])-2])
	} else if err != nil {
		fmt.Fprintln(os.Stderr, "Error when reading from the file:", err)
	}
	G := NewGraph(numnodes + 1)
	wg := &sync.WaitGroup{}
	for {
		line, err := file.ReadString((byte)('\n'))
		if err == io.EOF {
			break
		}
		wg.Add(1)
		go addLineToGraph(G, line, wg)
	}
	wg.Wait()
	return G
}
Exemplo n.º 2
0
// Win is implemented by RecursiveImproved and returns
// the solution for a given game in input
func (c *ConcurrentSolver) Win(G *graphs.Graph) ([]int, []int) {
	defer utils.TimeTrack(time.Now(), "Solved with Concurrent")
	removed := make([]bool, len(G.Nodes))
	res1, res2 := c.win(G, removed)
	return res1, res2
}
Exemplo n.º 3
0
// Win is implemented by RecursiveImproved and returns
// the solution for a given game in input
func (r *RecursiveImproved) Win(G *graphs.Graph) ([]int, []int) {
	defer utils.TimeTrack(time.Now(), "Solve with Recursive")
	removed := make([]bool, len(G.Nodes))
	res1, res2 := r.win(G, removed)
	return res1, res2
}