#9 Make use of the Atomic package to keep track of solver.counter
.
This commit is contained in:
parent
53953cf47c
commit
6d6db0ed28
@ -85,7 +85,8 @@ func (solver *Solver) check_combinations() {
|
|||||||
|
|
||||||
func (solver *Solver) routine_validator(rows1_index int, rows2_index int, rows3_index int, rows4_index int, rows5_index int, rows6_index int, rows7_index int, rows8_index int, rows9_index int) {
|
func (solver *Solver) routine_validator(rows1_index int, rows2_index int, rows3_index int, rows4_index int, rows5_index int, rows6_index int, rows7_index int, rows8_index int, rows9_index int) {
|
||||||
|
|
||||||
solver.counter = solver.counter + 1
|
// solver.counter = solver.counter + 1
|
||||||
|
solver.counter.Add(1)
|
||||||
|
|
||||||
if solver.validate_combination(solver.row1s[rows1_index], solver.row2s[rows2_index], solver.row3s[rows3_index], solver.row4s[rows4_index], solver.row5s[rows5_index], solver.row6s[rows6_index], solver.row7s[rows7_index], solver.row8s[rows8_index], solver.row9s[rows9_index]) {
|
if solver.validate_combination(solver.row1s[rows1_index], solver.row2s[rows2_index], solver.row3s[rows3_index], solver.row4s[rows4_index], solver.row5s[rows5_index], solver.row6s[rows6_index], solver.row7s[rows7_index], solver.row8s[rows8_index], solver.row9s[rows9_index]) {
|
||||||
solver.solutions = append(solver.solutions, solver.render_combination(solver.row1s[rows1_index], solver.row2s[rows2_index], solver.row3s[rows3_index], solver.row4s[rows4_index], solver.row5s[rows5_index], solver.row6s[rows6_index], solver.row7s[rows7_index], solver.row8s[rows8_index], solver.row9s[rows9_index]))
|
solver.solutions = append(solver.solutions, solver.render_combination(solver.row1s[rows1_index], solver.row2s[rows2_index], solver.row3s[rows3_index], solver.row4s[rows4_index], solver.row5s[rows5_index], solver.row6s[rows6_index], solver.row7s[rows7_index], solver.row8s[rows8_index], solver.row9s[rows9_index]))
|
||||||
@ -123,17 +124,17 @@ func (solver *Solver) tracker() {
|
|||||||
for !done {
|
for !done {
|
||||||
|
|
||||||
// Determine how far we are.
|
// Determine how far we are.
|
||||||
percentage = (float32(solver.counter) / (float32(solver.iter) / 100))
|
percentage = (float32(solver.counter.Load()) / (float32(solver.iter) / 100))
|
||||||
|
|
||||||
// Reset the loop
|
// Reset the loop
|
||||||
rate_diff = solver.counter - rate_start
|
rate_diff = solver.counter.Load() - rate_start
|
||||||
|
|
||||||
if track <= int(percentage) || rate_diff == 0 { // Start if-statement
|
if track <= int(percentage) || rate_diff == 0 { // Start if-statement
|
||||||
|
|
||||||
// Make sure something happened, making rate_start the only reliable variable
|
// Make sure something happened, making rate_start the only reliable variable
|
||||||
if rate_diff == 0 {
|
if rate_diff == 0 {
|
||||||
percentage = 100
|
percentage = 100
|
||||||
solver.counter = solver.iter
|
solver.counter.Store(solver.iter)
|
||||||
done = true
|
done = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,11 +146,11 @@ func (solver *Solver) tracker() {
|
|||||||
if rate_diff == 0 {
|
if rate_diff == 0 {
|
||||||
est_fin = "N/A"
|
est_fin = "N/A"
|
||||||
} else {
|
} else {
|
||||||
est_fin = solver.secondsToHuman((solver.iter - solver.counter) / rate_avg)
|
est_fin = solver.secondsToHuman((solver.iter - solver.counter.Load()) / rate_avg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Printing the progress
|
// Printing the progress
|
||||||
log.Println("Processing: " + strconv.Itoa(int(percentage)) + "% (" + strconv.Itoa(int(solver.counter)) + "/" + strconv.Itoa(int(solver.iter)) + "); Rate: " + strconv.FormatInt(rate_diff, 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(rate_diff, 10) + "/sec for " + timer_elapsed.String() + "; Time left (est.): " + est_fin)
|
||||||
|
|
||||||
// After we are done printing, exit this for-loop
|
// After we are done printing, exit this for-loop
|
||||||
if percentage == 100 {
|
if percentage == 100 {
|
||||||
@ -168,7 +169,7 @@ func (solver *Solver) tracker() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Resert the rate counter
|
// Resert the rate counter
|
||||||
rate_start = solver.counter
|
rate_start = solver.counter.Load()
|
||||||
|
|
||||||
// Sleep for a second
|
// Sleep for a second
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package solver
|
package solver
|
||||||
|
|
||||||
|
import "sync/atomic"
|
||||||
|
|
||||||
type Solver struct {
|
type Solver struct {
|
||||||
blocks []int
|
blocks []int
|
||||||
row1 string
|
row1 string
|
||||||
@ -21,7 +23,7 @@ type Solver struct {
|
|||||||
row8s []int
|
row8s []int
|
||||||
row9s []int
|
row9s []int
|
||||||
iter int64
|
iter int64
|
||||||
counter int64
|
counter atomic.Int64
|
||||||
solutions []string
|
solutions []string
|
||||||
rates []int64
|
rates []int64
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user