commonMain.it.unibo.tuprolog.solve.SolverStrategies.kt Maven / Gradle / Ivy
Show all versions of solve-streams-jvm Show documentation
package it.unibo.tuprolog.solve
import it.unibo.tuprolog.core.Clause
import it.unibo.tuprolog.core.Term
/**
* Interface representing internal strategies used by the [Solver]
*
* @author Enrico
*/
interface SolverStrategies {
/** Selects the predication to be solved first, from provided sequence */
fun predicationChoiceStrategy(predicationSequence: Sequence
, context: ExecutionContext): P
/** Selects the clause to be expanded in place of unifying predication, from provided sequence */
fun clauseChoiceStrategy(unifiableClauses: Sequence, context: ExecutionContext): C
/** Determines "when and what" is considered successfully demonstrated, during solution process */
fun successCheckStrategy(term: Term, context: ExecutionContext): Boolean
companion object {
/** Returns a strategy object containing the key solution strategies used by a Standard Prolog solver */
val prologStandard = object : SolverStrategies {
/** The default implementation, following the Prolog Standard, selects the first predication found */
override fun predicationChoiceStrategy(
predicationSequence: Sequence
,
context: ExecutionContext
): P = predicationSequence.first()
/** The default implementation, following the Prolog Standard, selects the first clause found */
override fun clauseChoiceStrategy(
unifiableClauses: Sequence,
context: ExecutionContext
): C = unifiableClauses.first()
override fun successCheckStrategy(term: Term, context: ExecutionContext): Boolean = term.isTrue
}
}
}