This functor provides constraint solvers which support timeout, and are thus fit for realtime constraint programming. A solver with timeout is very similar to a normal constraint solver. It expects a constraint script, and returns a solution. Additionally, however, a default solution and a maximum search time are specified as input arguments. In case the solver found no solution in the specified maximum search time, or in case the search failed, then the default solution is returned.
In a real-time situation, a solver with timeout can be called repeatedly, for example with new real-time input arriving. Examples are provided in the folder ../examples. Please refer to the file ../testing/RealTime-test.oz for further examples.
Functor
Import
- Search
- System
- GUtils at "x-ozlib://anders/strasheela/source/GeneralUtils.ozf"
- SDistro at "x-ozlib://anders/strasheela/source/ScoreDistribution.ozf"
Export
Define
proc{SearchWithTimeout MyScript Args Result}
SearchWithTimeout is a 'meta search engine' with a timeout: in case a user-specified maximum search time is elapsed, a user-specified default solution is returned (defaults to nil).
MyScript is a unary procedure defining the CSP plus a distribution strategy. Args is a record of the following optional arguments (feature-value pairs). The argument 'maxSearchTime' specifies the maximum search time in msecs (default: 1000). The default solution is given at the argument 'defaultSolution'. The argument 'solver' specifies the solver to use. The solver must be a procedure with the following interface {MySolver MyScript KillP MyScore}, and it must return a list with solution(s), or nil in case of no solution (only the first solution is ever used). The default solver is the following (KillP is a nullary procedure with stops the search when called, cf. the documentation of Search.one.depth).
proc {$ MyScript KillP ?MyScore}
{GUtils.setRandomGeneratorSeed 0} % reset seed for random value ordering
MyScore = {Search.one.depth MyScript 1 KillP}
end
In case of a timeout or a fail, a warning is printed at stdout, together with Args (e.g., additional Arg features can be handed over for a more informative warning).
NB: only searching is terminated after timeout: a script with keeps computing forever without search (e.g., because it contains an infinite loop) can not be killed.
ScoreSearcherWithTimeout provides a 'meta-search object' with a timeout, specialised in searching for Strasheela score objects. Create a search object with the method init, and obtain new solutions with the method next. The next method supports a number of arguments. For example, input data (including real-time input) can be handed over and previous output is accessible. See ../testing/Realtime-test.oz for simple examples.
class ScoreSearcherWithTimeout
feat initArgs extendedScript inputLength outputLength
- init(MyExtendedScript distroArgs:DArgs inputLength:InLength inputScores:InScores outputLength:OutLength outputScores:OutScores ...)
- next(Result inputScore:InScore ...)
- reset()
end
End