mirror of
https://github.com/mudler/luet.git
synced 2025-08-28 11:50:37 +00:00
Consume internal attempts in QLearn so resolver can be re-used
This commit is contained in:
parent
54b0dce54b
commit
4f33eca263
@ -68,6 +68,9 @@ type QLearningResolver struct {
|
|||||||
Attempts int
|
Attempts int
|
||||||
|
|
||||||
ToAttempt int
|
ToAttempt int
|
||||||
|
|
||||||
|
attempts int
|
||||||
|
|
||||||
Attempted map[string]bool
|
Attempted map[string]bool
|
||||||
|
|
||||||
Solver PackageSolver
|
Solver PackageSolver
|
||||||
@ -114,6 +117,8 @@ func (resolver *QLearningResolver) Solve(f bf.Formula, s PackageSolver) (Package
|
|||||||
Debug("Attempts:", resolver.ToAttempt)
|
Debug("Attempts:", resolver.ToAttempt)
|
||||||
resolver.Targets = resolver.Solver.(*Solver).Wanted
|
resolver.Targets = resolver.Solver.(*Solver).Wanted
|
||||||
|
|
||||||
|
resolver.attempts = resolver.Attempts
|
||||||
|
|
||||||
resolver.Attempted = make(map[string]bool, len(resolver.Targets))
|
resolver.Attempted = make(map[string]bool, len(resolver.Targets))
|
||||||
|
|
||||||
for resolver.IsComplete() == Going {
|
for resolver.IsComplete() == Going {
|
||||||
@ -159,7 +164,7 @@ func (resolver *QLearningResolver) Solve(f bf.Formula, s PackageSolver) (Package
|
|||||||
|
|
||||||
// Returns the current state.
|
// Returns the current state.
|
||||||
func (resolver *QLearningResolver) IsComplete() int {
|
func (resolver *QLearningResolver) IsComplete() int {
|
||||||
if resolver.Attempts < 1 {
|
if resolver.attempts < 1 {
|
||||||
resolver.Log("Attempts finished!")
|
resolver.Log("Attempts finished!")
|
||||||
return NoSolution
|
return NoSolution
|
||||||
}
|
}
|
||||||
@ -231,10 +236,9 @@ func (resolver *QLearningResolver) Choose(c Choice) bool {
|
|||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
resolver.ToAttempt--
|
resolver.ToAttempt--
|
||||||
resolver.Attempts-- // Decrease attempts - it's a barrier
|
resolver.attempts-- // Decrease attempts - it's a barrier. We could also do not decrease it here, allowing more attempts to be made
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
resolver.Attempts--
|
resolver.attempts--
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -314,7 +318,7 @@ TARGETS:
|
|||||||
// Log is a wrapper of fmt.Printf. If Game.debug is true, Log will print
|
// Log is a wrapper of fmt.Printf. If Game.debug is true, Log will print
|
||||||
// to stdout.
|
// to stdout.
|
||||||
func (resolver *QLearningResolver) Log(msg string, args ...interface{}) {
|
func (resolver *QLearningResolver) Log(msg string, args ...interface{}) {
|
||||||
logMsg := fmt.Sprintf("(%d moves, %d remaining attempts) %s\n", len(resolver.Attempted), resolver.Attempts, msg)
|
logMsg := fmt.Sprintf("(%d moves, %d remaining attempts) %s\n", len(resolver.Attempted), resolver.attempts, msg)
|
||||||
Debug(fmt.Sprintf(logMsg, args...))
|
Debug(fmt.Sprintf(logMsg, args...))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user