ThermostatAgentKt

class ThermostatAgentKt(name: String, coldThreshold: Int, hotThreshold: Int, initialTemperature: Int) : Thread

A self-contained reactive agent whose control loop is written in Prolog but whose sensor/actuator primitives are implemented in Kotlin, demonstrating how to embed a it.unibo.tuprolog.solve.Solver inside a regular JVM Thread to bridge logic programming with imperative, stateful host code.

The agent exposes its simulated temperature to the Prolog program through a custom get_temp/1 primitive (a it.unibo.tuprolog.solve.primitive.UnaryPredicate.Functional, i.e. a function-like predicate computing a single substitution), and lets the Prolog program change it through a custom push/1 primitive (a it.unibo.tuprolog.solve.primitive.UnaryPredicate.Predicative, i.e. a predicate that either succeeds or fails without producing bindings). The control logic itself lives in the bundled thermostat.pl resource, templated with coldThreshold and hotThreshold before being parsed by it.unibo.tuprolog.theory.parsing.ClausesParser: it repeatedly reads the temperature and pushes hot or cold air until it settles within range.

This class is the Kotlin counterpart of the it.unibo.tuprolog.examples.solve.ThermostatAgent Java class in this same module, which implements the identical agent using the Java API surface of :solve instead of its Kotlin DSL/extension conveniences (e.g. mgu as a member rather than via request.getUnificator().mgu(...)).

Parameters

name

the thread name, forwarded to Thread.

coldThreshold

the temperature at or below which the agent pushes hot air.

hotThreshold

the temperature at or above which the agent pushes cold air.

initialTemperature

the starting value of temperature.

Constructors

Link copied to clipboard
constructor(name: String, coldThreshold: Int, hotThreshold: Int, initialTemperature: Int)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
Link copied to clipboard
open val id: Long
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
var name: String?
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open val state: Thread.State?
Link copied to clipboard

The agent's current simulated temperature, read and modified by the Prolog control loop.

Link copied to clipboard

Functions

Link copied to clipboard
Link copied to clipboard
open fun countStackFrames(): Int
Link copied to clipboard
open fun interrupt()
Link copied to clipboard
fun join()
fun join(duration: Duration?): Boolean
fun join(millis: Long)
fun join(millis: Long, nanos: Int)
Link copied to clipboard
fun resume()
Link copied to clipboard
open override fun run()

Parses the templated thermostat.pl program, builds a it.unibo.tuprolog.solve.Solver registering get_temp/1 and push/1 under the libs.agency.thermostat library alias (with it.unibo.tuprolog.solve.flags.TrackVariables turned on so bound variables remain visible in the solution), and runs the start/0 goal once to completion, printing the outcome (reached target temperature, logic failure, or an exception with its Prolog stack trace) to standard output.

Link copied to clipboard
open fun start()
Link copied to clipboard
fun stop()
Link copied to clipboard
fun suspend()
Link copied to clipboard
fun threadId(): Long