2024-12-07 19:23:45 +01:00
|
|
|
package solver
|
|
|
|
|
|
|
|
import (
|
2025-01-21 21:43:27 +01:00
|
|
|
"log"
|
2025-01-25 19:45:31 +01:00
|
|
|
"runtime"
|
|
|
|
"strconv"
|
2024-12-07 19:23:45 +01:00
|
|
|
)
|
|
|
|
|
2025-01-27 18:41:15 +01:00
|
|
|
// The main loop that orchastrates all the logic.
|
2024-12-07 19:23:45 +01:00
|
|
|
func Run() {
|
2025-01-21 21:44:21 +01:00
|
|
|
// Instantiate the Solver interface
|
2024-12-07 19:23:45 +01:00
|
|
|
solver := Solver{}
|
2025-01-21 21:37:53 +01:00
|
|
|
|
2025-01-23 22:39:59 +01:00
|
|
|
// Parse and handle flags
|
|
|
|
solver.parse_flags()
|
2025-01-23 20:26:43 +01:00
|
|
|
|
2025-01-25 19:45:31 +01:00
|
|
|
// 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()) + ")")
|
|
|
|
}
|
|
|
|
|
2025-01-21 21:32:50 +01:00
|
|
|
// Load blocks from CSV file
|
2024-12-07 19:23:45 +01:00
|
|
|
solver.load_blocks()
|
|
|
|
|
|
|
|
// Find rows that fit with the entered rows
|
2025-01-21 21:32:50 +01:00
|
|
|
solver.populate_blocks()
|
2024-12-07 19:23:45 +01:00
|
|
|
|
2025-01-27 00:13:00 +01:00
|
|
|
// If needed, split the workload
|
|
|
|
// May exit and throw an error if the work load isn't viable
|
|
|
|
if solver.split != 1 {
|
|
|
|
solver.select_workload()
|
|
|
|
}
|
|
|
|
|
2025-01-21 21:37:07 +01:00
|
|
|
// Print the total number of solutions to validate
|
2025-01-23 20:26:43 +01:00
|
|
|
log.Println("Number of (potential) solutions:", solver.iter)
|
2024-12-07 19:23:45 +01:00
|
|
|
|
2025-01-21 21:37:53 +01:00
|
|
|
// Check the number of solutions
|
2025-01-23 20:26:43 +01:00
|
|
|
go solver.check_combinations()
|
|
|
|
solver.tracker()
|
2024-12-07 19:23:45 +01:00
|
|
|
|
2025-01-21 21:37:53 +01:00
|
|
|
// Print the valid solutions
|
2025-01-23 20:26:43 +01:00
|
|
|
solver.print_solutions()
|
2024-12-07 19:23:45 +01:00
|
|
|
|
|
|
|
}
|