commonMain.it.unibo.tuprolog.solve.problog.MutableProblogSolver.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of solve-problog-jvm Show documentation
Show all versions of solve-problog-jvm Show documentation
State-machine-based implementation of ProbLog
package it.unibo.tuprolog.solve.problog
import it.unibo.tuprolog.core.Clause
import it.unibo.tuprolog.core.Fact
import it.unibo.tuprolog.core.Struct
import it.unibo.tuprolog.core.Term
import it.unibo.tuprolog.solve.MutableSolver
import it.unibo.tuprolog.solve.channel.InputChannel
import it.unibo.tuprolog.solve.channel.OutputChannel
import it.unibo.tuprolog.solve.exception.Warning
import it.unibo.tuprolog.solve.flags.FlagStore
import it.unibo.tuprolog.solve.flags.NotableFlag
import it.unibo.tuprolog.solve.library.Library
import it.unibo.tuprolog.solve.library.Runtime
import it.unibo.tuprolog.solve.problog.lib.knowledge.ProblogTheory
import it.unibo.tuprolog.theory.RetractResult
import it.unibo.tuprolog.theory.Theory
import it.unibo.tuprolog.unify.Unificator
internal class MutableProblogSolver(
private val solver: MutableSolver
) : ProblogSolver(solver), MutableSolver {
override fun loadLibrary(library: Library) {
solver.loadLibrary(library)
}
override fun unloadLibrary(library: Library) {
solver.unloadLibrary(library)
}
override fun setRuntime(libraries: Runtime) {
solver.setRuntime(libraries)
}
override fun loadStaticKb(theory: Theory) {
solver.loadStaticKb(ProblogTheory.of(solver.unificator, theory))
}
override fun appendStaticKb(theory: Theory) {
solver.appendStaticKb(ProblogTheory.of(solver.unificator, theory))
}
override fun resetStaticKb() {
solver.resetStaticKb()
}
override fun loadDynamicKb(theory: Theory) {
solver.loadDynamicKb(ProblogTheory.of(solver.unificator, theory))
}
override fun appendDynamicKb(theory: Theory) {
solver.appendDynamicKb(ProblogTheory.of(solver.unificator, theory))
}
override fun resetDynamicKb() {
solver.resetDynamicKb()
}
override fun assertA(clause: Clause) {
solver.assertA(ProblogTheory.of(solver.unificator, clause).clauses.first())
}
override fun assertA(fact: Struct) {
solver.assertA(ProblogTheory.of(solver.unificator, Fact.of(fact)).clauses.first())
}
override fun assertZ(clause: Clause) {
solver.assertZ(ProblogTheory.of(solver.unificator, clause).clauses.first())
}
override fun assertZ(fact: Struct) {
solver.assertA(ProblogTheory.of(solver.unificator, Fact.of(fact)).clauses.first())
}
override fun retract(clause: Clause): RetractResult {
return solver.retract(ProblogTheory.of(solver.unificator, clause).clauses.first())
}
override fun retract(fact: Struct): RetractResult {
return solver.retract(ProblogTheory.of(solver.unificator, Fact.of(fact)).clauses.first())
}
override fun retractAll(clause: Clause): RetractResult {
return solver.retractAll(ProblogTheory.of(solver.unificator, clause).clauses.first())
}
override fun retractAll(fact: Struct): RetractResult {
return solver.retractAll(ProblogTheory.of(solver.unificator, Fact.of(fact)).clauses.first())
}
override fun setFlag(name: String, value: Term) {
solver.setFlag(name, value)
}
override fun setFlag(flag: Pair) {
solver.setFlag(flag)
}
override fun setFlag(flag: NotableFlag) {
solver.setFlag(flag)
}
override fun setStandardInput(stdIn: InputChannel) {
solver.setStandardInput(stdIn)
}
override fun setStandardError(stdErr: OutputChannel) {
solver.setStandardError(stdErr)
}
override fun setStandardOutput(stdOut: OutputChannel) {
solver.setStandardOutput(stdOut)
}
override fun setWarnings(warnings: OutputChannel) {
solver.setWarnings(warnings)
}
override fun copy(
unificator: Unificator,
libraries: Runtime,
flags: FlagStore,
staticKb: Theory,
dynamicKb: Theory,
stdIn: InputChannel,
stdOut: OutputChannel,
stdErr: OutputChannel,
warnings: OutputChannel
): MutableSolver {
return MutableProblogSolver(
solver.copy(unificator, libraries, flags, staticKb, dynamicKb, stdIn, stdOut, stdErr, warnings)
)
}
override fun clone(): MutableSolver {
return MutableProblogSolver(solver.clone())
}
}