45 lines
959 B
Go
45 lines
959 B
Go
package solver
|
|
|
|
import (
|
|
"log"
|
|
"runtime"
|
|
"strconv"
|
|
)
|
|
|
|
// The main loop that orchastrates all the logic.
|
|
func Run() {
|
|
// Instantiate the Solver interface
|
|
solver := Solver{}
|
|
|
|
// Parse and handle flags
|
|
solver.parseFlags()
|
|
|
|
// Report number of CPUs being used, if set.
|
|
if runtime.NumCPU() != solver.numCPUs {
|
|
log.Println("Using " + strconv.Itoa(solver.numCPUs) + " CPUs, (was " + strconv.Itoa(runtime.NumCPU()) + ")")
|
|
}
|
|
|
|
// Load blocks from CSV file
|
|
solver.loadBlocks()
|
|
|
|
// Find rows that fit with the entered rows
|
|
solver.populateBlocks()
|
|
|
|
// If needed, split the workload
|
|
// May exit and throw an error if the work load isn't viable
|
|
if solver.split != 1 {
|
|
solver.selectWorkload()
|
|
}
|
|
|
|
// Print the total number of solutions to validate
|
|
log.Println("Number of (potential) solutions:", solver.iter)
|
|
|
|
// Check the number of solutions
|
|
go solver.checkCombinations()
|
|
solver.tracker()
|
|
|
|
// Print the valid solutions
|
|
solver.printSolutions()
|
|
|
|
}
|