|
|
@@ -6,23 +6,23 @@ import (
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
-func (solver *Solver) populateBlocks() {
|
|
|
+func (solver *Solver) PopulateBlocks() {
|
|
|
|
|
|
defer solver.timeTrack(time.Now(), "Populated blocks")
|
|
|
log.Println("Populating blocks")
|
|
|
|
|
|
- solver.findBlocks(&solver.row1, &solver.row1s)
|
|
|
- solver.findBlocks(&solver.row2, &solver.row2s)
|
|
|
- solver.findBlocks(&solver.row3, &solver.row3s)
|
|
|
- solver.findBlocks(&solver.row4, &solver.row4s)
|
|
|
- solver.findBlocks(&solver.row5, &solver.row5s)
|
|
|
- solver.findBlocks(&solver.row6, &solver.row6s)
|
|
|
- solver.findBlocks(&solver.row7, &solver.row7s)
|
|
|
- solver.findBlocks(&solver.row8, &solver.row8s)
|
|
|
- solver.findBlocks(&solver.row9, &solver.row9s)
|
|
|
+ solver.findBlocks(&solver.Controller.Row1, &solver.row1s)
|
|
|
+ solver.findBlocks(&solver.Controller.Row2, &solver.row2s)
|
|
|
+ solver.findBlocks(&solver.Controller.Row3, &solver.row3s)
|
|
|
+ solver.findBlocks(&solver.Controller.Row4, &solver.row4s)
|
|
|
+ solver.findBlocks(&solver.Controller.Row5, &solver.row5s)
|
|
|
+ solver.findBlocks(&solver.Controller.Row6, &solver.row6s)
|
|
|
+ solver.findBlocks(&solver.Controller.Row7, &solver.row7s)
|
|
|
+ solver.findBlocks(&solver.Controller.Row8, &solver.row8s)
|
|
|
+ solver.findBlocks(&solver.Controller.Row9, &solver.row9s)
|
|
|
|
|
|
// This calculates and stores the total number of solutions to validate.
|
|
|
- solver.iter = int64(len(solver.row1s)) * int64(len(solver.row2s)) * int64(len(solver.row3s)) * int64(len(solver.row4s)) * int64(len(solver.row5s)) * int64(len(solver.row6s)) * int64(len(solver.row7s)) * int64(len(solver.row8s)) * int64(len(solver.row9s))
|
|
|
+ solver.Iter = int64(len(solver.row1s)) * int64(len(solver.row2s)) * int64(len(solver.row3s)) * int64(len(solver.row4s)) * int64(len(solver.row5s)) * int64(len(solver.row6s)) * int64(len(solver.row7s)) * int64(len(solver.row8s)) * int64(len(solver.row9s))
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -35,7 +35,7 @@ func (solver *Solver) findBlocks(row *string, rows *[]int) {
|
|
|
for letter := range funcRow {
|
|
|
|
|
|
if len(selection) == 0 {
|
|
|
- currBlocks = solver.blocks
|
|
|
+ currBlocks = solver.Controller.Blocks
|
|
|
} else {
|
|
|
currBlocks = selection
|
|
|
selection = nil
|
|
|
@@ -61,7 +61,7 @@ func (solver *Solver) findBlocks(row *string, rows *[]int) {
|
|
|
*rows = selection
|
|
|
}
|
|
|
|
|
|
-func (solver *Solver) checkCombinations() {
|
|
|
+func (solver *Solver) CheckCombinations() {
|
|
|
for rows1Index := range solver.row1s {
|
|
|
for rows2Index := range solver.row2s {
|
|
|
for rows3Index := range solver.row3s {
|
|
|
@@ -71,7 +71,7 @@ func (solver *Solver) checkCombinations() {
|
|
|
for rows7Index := range solver.row7s {
|
|
|
for rows8Index := range solver.row8s {
|
|
|
for rows9Index := range solver.row9s {
|
|
|
- go solver.routineValidator(rows1Index, rows2Index, rows3Index, rows4Index, rows5Index, rows6Index, rows7Index, rows8Index, rows9Index)
|
|
|
+ go solver.validator(rows1Index, rows2Index, rows3Index, rows4Index, rows5Index, rows6Index, rows7Index, rows8Index, rows9Index)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -83,19 +83,19 @@ func (solver *Solver) checkCombinations() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func (solver *Solver) routineValidator(rows1Index int, rows2Index int, rows3Index int, rows4Index int, rows5Index int, rows6Index int, rows7Index int, rows8Index int, rows9Index int) {
|
|
|
+func (solver *Solver) validator(rows1Index int, rows2Index int, rows3Index int, rows4Index int, rows5Index int, rows6Index int, rows7Index int, rows8Index int, rows9Index int) {
|
|
|
|
|
|
- // solver.counter = solver.counter + 1
|
|
|
solver.counter.Add(1)
|
|
|
|
|
|
if solver.validateCombination(solver.row1s[rows1Index], solver.row2s[rows2Index], solver.row3s[rows3Index], solver.row4s[rows4Index], solver.row5s[rows5Index], solver.row6s[rows6Index], solver.row7s[rows7Index], solver.row8s[rows8Index], solver.row9s[rows9Index]) {
|
|
|
- solver.solutions = append(solver.solutions, solver.renderCombination(solver.row1s[rows1Index], solver.row2s[rows2Index], solver.row3s[rows3Index], solver.row4s[rows4Index], solver.row5s[rows5Index], solver.row6s[rows6Index], solver.row7s[rows7Index], solver.row8s[rows8Index], solver.row9s[rows9Index]))
|
|
|
+ solver.Controller.Solutions = append(solver.Controller.Solutions, solver.renderCombination(solver.row1s[rows1Index], solver.row2s[rows2Index], solver.row3s[rows3Index], solver.row4s[rows4Index], solver.row5s[rows5Index], solver.row6s[rows6Index], solver.row7s[rows7Index], solver.row8s[rows8Index], solver.row9s[rows9Index]))
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
-func (solver *Solver) tracker() {
|
|
|
+func (solver *Solver) Tracker() {
|
|
|
|
|
|
+ // Add time tracking
|
|
|
defer solver.timeTrack(time.Now(), "Validated solutions")
|
|
|
log.Println("Validating solutions")
|
|
|
|
|
|
@@ -118,11 +118,14 @@ func (solver *Solver) tracker() {
|
|
|
// Estimation how long it will take
|
|
|
var est_fin string
|
|
|
|
|
|
- // for solver.iter != solver.counter { // Start for-loop
|
|
|
+ // While not needed for rateDiff anymore, it makes estimation calculations more accurate. ☹️
|
|
|
+ time.Sleep(time.Second)
|
|
|
+
|
|
|
+ // for solver.Iter != solver.counter { // Start for-loop
|
|
|
for !done {
|
|
|
|
|
|
// Determine how far we are.
|
|
|
- percentage = (float32(solver.counter.Load()) / (float32(solver.iter) / 100))
|
|
|
+ percentage = (float32(solver.counter.Load()) / (float32(solver.Iter) / 100))
|
|
|
|
|
|
// Reset the loop
|
|
|
rateDiff = solver.counter.Load() - rateStart
|
|
|
@@ -130,9 +133,9 @@ func (solver *Solver) tracker() {
|
|
|
if track <= int(percentage) || rateDiff == 0 { // Start if-statement
|
|
|
|
|
|
// Make sure something happened, making rateStart the only reliable variable
|
|
|
- if solver.iter == solver.counter.Load() {
|
|
|
+ if solver.Iter == solver.counter.Load() {
|
|
|
percentage = 100
|
|
|
- solver.counter.Store(solver.iter)
|
|
|
+ solver.counter.Store(solver.Iter)
|
|
|
done = true
|
|
|
}
|
|
|
|
|
|
@@ -144,17 +147,18 @@ func (solver *Solver) tracker() {
|
|
|
if rateDiff == 0 {
|
|
|
est_fin = "N/A"
|
|
|
} else {
|
|
|
- duration_int := (solver.iter - solver.counter.Load()) / rate_avg
|
|
|
+ duration_int := (solver.Iter - solver.counter.Load()) / rate_avg
|
|
|
duration_string := strconv.Itoa(int(duration_int)) + "s"
|
|
|
est, err := time.ParseDuration(duration_string)
|
|
|
if err != nil {
|
|
|
est_fin = "parse error"
|
|
|
+ } else {
|
|
|
+ est_fin = est.String()
|
|
|
}
|
|
|
- est_fin = est.String()
|
|
|
}
|
|
|
|
|
|
// Printing the progress
|
|
|
- log.Println("Processing: " + strconv.Itoa(int(percentage)) + "% (" + strconv.FormatInt(solver.counter.Load(), 10) + "/" + strconv.Itoa(int(solver.iter)) + "); Rate: " + strconv.FormatInt(rateDiff, 10) + "/sec for " + timer_elapsed.String() + "; Time left (est.): " + est_fin)
|
|
|
+ log.Println("Processing: " + strconv.Itoa(int(percentage)) + "% (" + strconv.FormatInt(solver.counter.Load(), 10) + "/" + strconv.Itoa(int(solver.Iter)) + "); Rate: " + strconv.FormatInt(rateDiff, 10) + "/sec for " + timer_elapsed.String() + "; Time left (est.): " + est_fin)
|
|
|
|
|
|
// After we are done printing, exit this for-loop
|
|
|
if percentage == 100 {
|
|
|
@@ -176,7 +180,7 @@ func (solver *Solver) tracker() {
|
|
|
rateStart = solver.counter.Load()
|
|
|
|
|
|
// Sleep for a second
|
|
|
- if solver.iter != solver.counter.Load() {
|
|
|
+ if solver.Iter != solver.counter.Load() {
|
|
|
time.Sleep(1 * time.Second)
|
|
|
}
|
|
|
} // End for-loop
|