Interface SolutionManager
- All Known Implementing Classes:
SimpleSolutionManager
public interface SolutionManager
SolutionManager
Abstraction that stores the partial substitutions produced by a back‑tracking evaluation engine. For each depth of the search tree (level) it keeps:
- the
Spliteratorenumerating the candidate substitutions of that sub‑query, - the set of variables that will be newly bound when a candidate wins.
The interface lets the engine:
- read the current (live) substitution
getCurrentSolution(), - obtain a defensive snapshot via
copyCurrentSolution(), - advance or register choice‑points (
next(int),add(int, Spliterator, Collection)), - expose internal spliterators for work‑stealing / splitting,
- clone the whole structure so each branch explores independently.
Concurrency and mutability: the object returned by
getCurrentSolution() is a live view; it changes as soon as
next(int) succeeds. Never cache or publish it outside the evaluation loop.
Use copyCurrentSolution() when you need an immutable snapshot.
- Author:
- Guillaume Perution-Kihli
-
Method Summary
Modifier and TypeMethodDescriptionvoidadd(int level, Spliterator<Substitution> substitutions, Collection<Variable> newVariables) Register the spliterator that will supply substitutions forleveltogether with the
list of variables that those substitutions can bind for the first time.Returns a stable snapshot of the current solution.deepCopy()Creates an independent copy of this solution manager.Returns the substitution that is currently valid at all explored levels.getSpliterator(int level) Returns the spliterator registered for a level.booleannext(int level) Advance the iterator atlevelso the next candidate substitution (if any) is merged into the global solution.voidpruneOtherIterators(int level) Prunes every stored iterator except the selected level.voidreplaceSpliterator(int level, Spliterator<Substitution> newSpliterator) Replaces the spliterator registered for a level.
-
Method Details
-
getCurrentSolution
Substitution getCurrentSolution()Returns the substitution that is currently valid at all explored levels.Live view: subsequent calls to
next(int)may mutate and/or invalidate the content. Clone it withcopyCurrentSolution()if you need to keep a stable version.- Returns:
- the current live substitution
-
copyCurrentSolution
Substitution copyCurrentSolution()Returns a stable snapshot of the current solution.- Returns:
- a defensive copy of the current solution (safe to keep).
-
next
boolean next(int level) Advance the iterator atlevelso the next candidate substitution (if any) is merged into the global solution.- Parameters:
level- depth in the search tree (0‑based)- Returns:
trueif a compatible substitution exists,falseotherwise.
-
add
Register the spliterator that will supply substitutions forleveltogether with the
list of variables that those substitutions can bind for the first time.- Parameters:
level- depth in the search tree (0-based)substitutions- the substitutions available at that levelnewVariables- the variables that may become bound at that level
-
getSpliterator
Returns the spliterator registered for a level.- Parameters:
level- depth in the search tree (0-based)- Returns:
- the spliterator associated with
level, ornull.
-
replaceSpliterator
Replaces the spliterator registered for a level. Replace the spliterator stored forlevel.- Parameters:
level- depth in the search tree (0-based)newSpliterator- the replacement spliterator
-
pruneOtherIterators
void pruneOtherIterators(int level) Prunes every stored iterator except the selected level. Remove (or empty) every level that is not equal tolevel.- Parameters:
level- the level to keep
-
deepCopy
SolutionManager deepCopy()Creates an independent copy of this solution manager.- Returns:
- an independent copy of this manager so that another branch can evolve in parallel without interference.
-