All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.it.unibo.tuprolog.solve.classic.impl.AbstractSolutionIterator.kt Maven / Gradle / Ivy

Go to download

Stable, state-machine-based implementation of Prolog's SLDNF resolution principle

There is a newer version: 1.0.4
Show newest version
package it.unibo.tuprolog.solve.classic.impl

import it.unibo.tuprolog.solve.Solution
import it.unibo.tuprolog.solve.classic.SolutionIterator
import it.unibo.tuprolog.solve.classic.fsm.State

internal abstract class AbstractSolutionIterator(state: State) : SolutionIterator {
    final override var state: State = state
        private set

    final override var step: Long = 0
        private set

    final override fun hasNext(): Boolean = state.let { !it.isEndState || it.castToEndState().hasOpenAlternatives }

    final override fun next(): Solution {
        do {
            val previousState = state
            state = computeNextState(state, ++step)
            onStateTransition(previousState, state, step)
        } while (!state.isEndState)
        return state.castToEndState().solution.cleanUp()
    }

    protected abstract fun computeNextState(
        state: State,
        step: Long,
    ): State
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy