-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: wip on plan implementation
- Loading branch information
Showing
31 changed files
with
280 additions
and
488 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package it.unibo.jakta.beliefs | ||
|
||
interface Belief<B> { | ||
interface Belief<out B> { | ||
val content: B | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1,27 @@ | ||
package it.unibo.jakta.goals | ||
|
||
import it.unibo.jakta.beliefs.Belief | ||
import it.unibo.jakta.goals.impl.AchieveImpl | ||
import it.unibo.jakta.goals.impl.ActExternallyImpl | ||
import it.unibo.jakta.goals.impl.ActImpl | ||
import it.unibo.jakta.goals.impl.ActInternallyImpl | ||
import it.unibo.jakta.goals.impl.AddBeliefImpl | ||
import it.unibo.jakta.goals.impl.RemoveBeliefImpl | ||
import it.unibo.jakta.goals.impl.SpawnImpl | ||
import it.unibo.jakta.goals.impl.TestImpl | ||
import it.unibo.jakta.goals.impl.UpdateBeliefImpl | ||
import it.unibo.tuprolog.core.Struct | ||
import it.unibo.tuprolog.core.Substitution | ||
import it.unibo.tuprolog.core.Truth | ||
|
||
sealed interface Goal { | ||
val value: Struct | ||
|
||
fun applySubstitution(substitution: Substitution): Goal | ||
|
||
fun copy(value: Struct = this.value): Goal | ||
sealed interface Goal<X> { | ||
val value: X | ||
} | ||
|
||
class EmptyGoal(override val value: Struct = Truth.TRUE) : Goal { | ||
override fun applySubstitution(substitution: Substitution): Goal = this | ||
data class EmptyGoal<X>(override val value: X) : Goal<X> | ||
|
||
override fun copy(value: Struct): Goal = EmptyGoal(value) | ||
override fun equals(other: Any?): Boolean { | ||
if (this === other) return true | ||
if (javaClass != other?.javaClass) return false | ||
data class AddBelief<B : Belief<*>> (override val value: B) : Goal<B> | ||
|
||
other as EmptyGoal | ||
data class RemoveBelief<B : Belief<*>> (override val value: B) : Goal<B> | ||
|
||
if (value != other.value) return false | ||
data class UpdateBelief<B : Belief<*>> (override val value: B) : Goal<B> | ||
|
||
return true | ||
} | ||
data class Achieve<X> (override val value: X) : Goal<X> | ||
|
||
override fun hashCode() = value.hashCode() | ||
} | ||
data class Test<X> (override val value: X) : Goal<X> | ||
|
||
sealed interface BeliefGoal : Goal { | ||
val belief: Struct | ||
get() = value | ||
} | ||
data class Spawn<X> (override val value: X) : Goal<X> | ||
|
||
interface AddBelief : BeliefGoal { | ||
companion object { | ||
fun of(belief: Belief): AddBelief = AddBeliefImpl(belief) | ||
} | ||
} | ||
data class Act<X> (override val value: X) : Goal<X> | ||
|
||
interface RemoveBelief : BeliefGoal { | ||
companion object { | ||
fun of(belief: Belief): RemoveBelief = RemoveBeliefImpl(belief) | ||
} | ||
} | ||
data class ActInternally<X> (override val value: X) : Goal<X> | ||
|
||
interface UpdateBelief : BeliefGoal { | ||
companion object { | ||
fun of(belief: Belief): UpdateBelief = UpdateBeliefImpl(belief) | ||
} | ||
} | ||
|
||
interface Achieve : Goal { | ||
companion object { | ||
fun of(value: Struct): Achieve = AchieveImpl(value) | ||
} | ||
} | ||
|
||
interface Test : Goal { | ||
companion object { | ||
fun of(belief: Belief): Test = TestImpl(belief) | ||
} | ||
} | ||
|
||
interface Spawn : Goal { | ||
companion object { | ||
fun of(value: Struct): Spawn = SpawnImpl(value) | ||
} | ||
} | ||
|
||
sealed interface ActionGoal : Goal { | ||
val action: Struct | ||
get() = value | ||
} | ||
|
||
interface Act : ActionGoal { | ||
companion object { | ||
fun of(value: Struct): Act = ActImpl(value) | ||
} | ||
} | ||
|
||
interface ActInternally : ActionGoal { | ||
companion object { | ||
fun of(value: Struct): ActInternally = ActInternallyImpl(value) | ||
} | ||
} | ||
|
||
interface ActExternally : ActionGoal { | ||
companion object { | ||
fun of(value: Struct): ActExternally = ActExternallyImpl(value) | ||
} | ||
} | ||
data class ActExternally<X> (override val value: X) : Goal<X> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 15 additions & 17 deletions
32
jakta-api/src/main/kotlin/it/unibo/jakta/plans/PlanLibrary.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,31 @@ | ||
package it.unibo.jakta.plans | ||
|
||
import it.unibo.jakta.beliefs.PrologBeliefBase | ||
import it.unibo.jakta.beliefs.Belief | ||
import it.unibo.jakta.beliefs.BeliefBase | ||
import it.unibo.jakta.events.Event | ||
import it.unibo.jakta.events.Trigger | ||
import it.unibo.jakta.plans.impl.PlanLibraryImpl | ||
import it.unibo.jakta.goals.Goal | ||
|
||
interface PlanLibrary<T, G, P> where | ||
interface PlanLibrary<T, Gu, Go, P> where | ||
T : Trigger<*>, | ||
G : Guard<*>, | ||
P : Plan<T, G> { | ||
Gu : Guard<*>, | ||
Go : Goal<*>, | ||
P : Plan<T, Gu, Go> { | ||
/** | ||
* Like a standard practice in prolog, plans are ordered to let programmers know when the end of an eventual recursion happens. | ||
*/ | ||
val plans: List<P> | ||
|
||
/** @return all the relevant [Plan]s from a given [Event] */ | ||
fun relevantPlans(event: Event<T>): PlanLibrary<T, G, P> | ||
fun relevantPlans(event: Event<T>): PlanLibrary<T, Gu, Go, P> | ||
|
||
/** @return all the applicable [Plan]s in the agent with the specified [PrologBeliefBase] */ | ||
fun applicablePlans(event: Event<T>, beliefBase: PrologBeliefBase): PlanLibrary | ||
/** @return all the applicable [Plan]s in the agent with the specified [BeliefBase] */ | ||
fun <B : Belief<*>, BB : BeliefBase<B, BB>> applicablePlans( | ||
event: Event<T>, | ||
beliefBase: BB, | ||
): PlanLibrary<T, Gu, Go, P> | ||
|
||
fun addPlan(plan: Plan): PlanLibrary | ||
fun addPlan(plan: P): PlanLibrary<T, Gu, Go, P> | ||
|
||
fun removePlan(plan: Plan): PlanLibrary | ||
|
||
companion object { | ||
fun of(plans: List<Plan>): PlanLibrary = PlanLibraryImpl(plans) | ||
fun of(vararg plans: Plan): PlanLibrary = of(plans.asList()) | ||
|
||
fun empty(): PlanLibrary = PlanLibraryImpl(emptyList()) | ||
} | ||
fun removePlan(plan: P): PlanLibrary<T, Gu, Go, P> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.