solver.go 959 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package solver
  2. import (
  3. "log"
  4. "runtime"
  5. "strconv"
  6. )
  7. // The main loop that orchastrates all the logic.
  8. func Run() {
  9. // Instantiate the Solver interface
  10. solver := Solver{}
  11. // Parse and handle flags
  12. solver.parseFlags()
  13. // Report number of CPUs being used, if set.
  14. if runtime.NumCPU() != solver.numCPUs {
  15. log.Println("Using " + strconv.Itoa(solver.numCPUs) + " CPUs, (was " + strconv.Itoa(runtime.NumCPU()) + ")")
  16. }
  17. // Load blocks from CSV file
  18. solver.loadBlocks()
  19. // Find rows that fit with the entered rows
  20. solver.populateBlocks()
  21. // If needed, split the workload
  22. // May exit and throw an error if the work load isn't viable
  23. if solver.split != 1 {
  24. solver.selectWorkload()
  25. }
  26. // Print the total number of solutions to validate
  27. log.Println("Number of (potential) solutions:", solver.iter)
  28. // Check the number of solutions
  29. go solver.checkCombinations()
  30. solver.tracker()
  31. // Print the valid solutions
  32. solver.printSolutions()
  33. }