Skip to content

Commit

Permalink
improve backtracking
Browse files Browse the repository at this point in the history
  • Loading branch information
gciatto committed Jun 18, 2020
1 parent 2301547 commit 121aecc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ sealed class ChoicePointContext(

protected abstract val typeName: String

abstract fun backtrack(nextStep: Long, startTime: Long): ClassicExecutionContext
abstract fun backtrack(context: ClassicExecutionContext): ClassicExecutionContext

data class Primitives(
override val alternatives: Cursor<out Solve.Response>,
Expand All @@ -72,11 +72,18 @@ sealed class ChoicePointContext(
override val typeName: String
get() = "Primitives"

override fun backtrack(nextStep: Long, startTime: Long): ClassicExecutionContext {
override fun backtrack(context: ClassicExecutionContext): ClassicExecutionContext {
val tempContext = executionContext!!.copy(
primitives = alternatives,
step = nextStep,
startTime = startTime
step = context.step + 1,
startTime = context.startTime,
flags = context.flags,
dynamicKb = context.dynamicKb,
staticKb = context.staticKb,
operators = context.operators,
inputChannels = context.inputChannels,
outputChannels = context.outputChannels,
libraries = context.libraries
)

val nextChoicePointContext = copy(
Expand All @@ -102,11 +109,18 @@ sealed class ChoicePointContext(
override val typeName: String
get() = "Rules"

override fun backtrack(nextStep: Long, startTime: Long): ClassicExecutionContext {
override fun backtrack(context: ClassicExecutionContext): ClassicExecutionContext {
val tempContext = executionContext!!.copy(
rules = alternatives,
step = nextStep,
startTime = startTime
step = context.step + 1,
startTime = context.startTime,
flags = context.flags,
dynamicKb = context.dynamicKb,
staticKb = context.staticKb,
operators = context.operators,
inputChannels = context.inputChannels,
outputChannels = context.outputChannels,
libraries = context.libraries
)

val nextChoicePointContext = copy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal data class StateBacktracking(override val context: ClassicExecutionCont
)
} else {
val choicePointContext = choicePoints!!.pathToRoot.first { it.alternatives.hasNext }
val nextContext = choicePointContext.backtrack(nextStep(), context.startTime)
val nextContext = choicePointContext.backtrack(context)
if (nextContext.primitives.hasNext) {
StatePrimitiveExecution(nextContext)
} else {
Expand Down

0 comments on commit 121aecc

Please sign in to comment.