#6 Improved estimation algorithm

This commit is contained in:
Sacha Ligthert 2025-01-25 14:34:51 +01:00
parent 582e268d56
commit 26b78420a2
2 changed files with 25 additions and 6 deletions

View File

@ -125,24 +125,25 @@ func (solver *Solver) tracker() {
rate_diff = rate_stop - rate_start
// Make sure something happened, making rate_start the only reliable variable
if rate_diff == 0 && rate_start > 1 {
if rate_diff == 0 && int(percentage) > 1 {
percentage = 100
solver.counter = solver.iter
}
timer_elapsed := time.Since(timer_start)
rate := int64(rate_diff) / int64(timer_elapsed.Seconds())
solver.rates = append(solver.rates, rate)
rate_avg := solver.calc_avg()
// Estimate when this is finished:
// TODO: Make this Bayesian
// Estimate when this is finished
if rate_diff == 0 {
est_fin = "N/A"
} else {
est_fin = solver.secondsToHuman((int(solver.iter) - int(solver.counter)) / int(rate))
est_fin = solver.secondsToHuman((int(solver.iter) - int(solver.counter)) / int(rate_avg))
}
// Printing the meat
log.Println("Processing: " + strconv.Itoa(int(percentage)) + "% (" + strconv.Itoa(int(solver.counter)) + "/" + strconv.Itoa(int(solver.iter)) + "); Rate (avg): " + strconv.Itoa(int(rate)) + "/sec for " + timer_elapsed.String() + "; Time left (est.): " + est_fin)
log.Println("Processing: " + strconv.Itoa(int(percentage)) + "% (" + strconv.Itoa(int(solver.counter)) + "/" + strconv.Itoa(int(solver.iter)) + "); Rate: " + strconv.Itoa(int(rate)) + "/sec for " + timer_elapsed.String() + "; Time left (est.): " + est_fin)
// Wrap up the loop or break
if int(percentage) > track {
@ -153,10 +154,14 @@ func (solver *Solver) tracker() {
rate_start = rate_stop
timer_start = time.Now()
if rate_diff == 0 && rate_start > 100 {
if percentage == 100 {
break
}
} else {
log.Println(percentage)
log.Println(solver.counter)
log.Println(rate_diff)
}
time.Sleep(1 * time.Second)
@ -219,3 +224,16 @@ func (solver *Solver) validate_combination(row1 int, row2 int, row3 int, row4 in
return retval
}
func (solver *Solver) calc_avg() int {
var avg_sum int64
var avg int
for _, value := range solver.rates {
avg_sum += value
}
avg = int(avg_sum) / len(solver.rates)
return avg
}

View File

@ -23,4 +23,5 @@ type Solver struct {
iter int64
counter int64
solutions []string
rates []int64
}