-
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 BeliefBase for the 2nd time
- Loading branch information
Showing
5 changed files
with
126 additions
and
134 deletions.
There are no files selected for viewing
95 changes: 53 additions & 42 deletions
95
jakta-api/src/main/kotlin/it/unibo/jakta/beliefs/BeliefBase.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,62 +1,73 @@ | ||
package it.unibo.jakta.beliefs | ||
|
||
/** A BDI Agent's collection of [Belief]s */ | ||
interface BeliefBase<Query : Any, Belief, SelfType: BeliefBase<Query, Belief, SelfType>> : Collection<Belief> { | ||
interface BeliefBase<Query : Any, Belief, SelfType : BeliefBase<Query, Belief, SelfType>> : Collection<Belief> { | ||
|
||
/** | ||
* List of [BeliefUpdate] that populated the current [BeliefBase]. | ||
**/ | ||
val delta: List<Update<Belief>> | ||
|
||
/** | ||
* Resets the [BeliefBase] operations. | ||
* @return a [BeliefBase] where the delta list is empty. | ||
* Performs unification between [B] and values in this [BeliefBase] | ||
*/ | ||
fun resetDelta(): SelfType | ||
fun select(query: Query): SelfType | ||
|
||
/** | ||
* Adds a [Belief] to this [BeliefBase] | ||
* @param belief: the [Belief] to be added | ||
* @return the new [BeliefBase] and the added [Belief] | ||
**/ | ||
operator fun plus(belief: Belief): SelfType | ||
interface MutableBeliefBase<Query, Belief, SelfType> : BeliefBase<Query, Belief, SelfType> where | ||
Query : Any, | ||
SelfType : BeliefBase<Query, Belief, SelfType> { | ||
|
||
/** | ||
* Adds all the given beliefs into this [BeliefBase] | ||
* @param beliefs: beliefs to be added | ||
* @return the new [BeliefBase] and the added [Belief]s | ||
**/ | ||
operator fun plus(beliefs: BeliefBase<Query, Belief>): SelfType | ||
/** | ||
* List of [Update] that populated the current [BeliefBase]. | ||
**/ | ||
var delta: List<Update<Belief>> | ||
|
||
/** | ||
* Removes a [Belief] from the [BeliefBase] | ||
* @param belief: the [Belief] to be removed | ||
* @return the new [BeliefBase] and the removed [Belief] | ||
*/ | ||
operator fun minus(belief: Belief): SelfType | ||
/** | ||
* @return the immutable [BeliefBase] version of this instance. | ||
*/ | ||
fun snapshot(): SelfType | ||
|
||
/** | ||
* Removes all the specified beliefs from this [BeliefBase] | ||
* @param beliefs: beliefs to be removed | ||
* @return the new [BeliefBase] and the removed [Belief]s | ||
*/ | ||
operator fun minus(beliefs: BeliefBase<Query, Belief>): BeliefBase<Query, Belief> | ||
/** | ||
* Adds a [Belief] to this [BeliefBase], if not present. | ||
* @param belief: the [Belief] to be added. | ||
* @return true if the [BeliefBase] was changed as the result of the operation. | ||
**/ | ||
fun add(belief: Belief): Boolean | ||
|
||
/** | ||
* Performs unification between [B] and values in this [BeliefBase] | ||
*/ | ||
fun solve(query: Query): SelfType | ||
/** | ||
* Adds all the given beliefs into this [BeliefBase], if not present. | ||
* @param beliefs: the [BeliefBase] to be added. | ||
* @return true if the [BeliefBase] was changed as the result of the operation. | ||
**/ | ||
fun addAll(beliefs: SelfType): Boolean { | ||
var result = false | ||
for (b in beliefs) { | ||
if (add(b)) result = true | ||
} | ||
return result | ||
} | ||
|
||
/** | ||
* Removes a [Belief] from the [BeliefBase], if present. | ||
* @param belief: the [Belief] to be removed | ||
* @return true if the [BeliefBase] was changed as the result of the operation. | ||
*/ | ||
fun remove(belief: Belief): Boolean | ||
|
||
/** | ||
* Removes all the specified beliefs from this [BeliefBase], if present. | ||
* @param beliefs: beliefs to be removed | ||
* @return true if the [BeliefBase] was changed as the result of the operation. | ||
*/ | ||
fun removeAll(beliefs: SelfType): Boolean { | ||
var result = false | ||
for (b in beliefs) { | ||
if (remove(b)) result = true | ||
} | ||
return result | ||
} | ||
} | ||
|
||
// TODO: this may be a container of multiple updates that happen atomically | ||
sealed interface Update<Belief> { | ||
val diff: Belief | ||
|
||
data class Addition<Belief>(override val diff: Belief) : Update<Belief> | ||
data class Removal<Belief>(override val diff: Belief) : Update<Belief> | ||
// data object NoOp : Update<Nothing> { | ||
// override val diff: Nothing = error("ASSDASDADAS") | ||
// } | ||
} | ||
|
||
interface | ||
} |
15 changes: 0 additions & 15 deletions
15
jakta-api/src/main/kotlin/it/unibo/jakta/beliefs/BeliefUpdate.kt
This file was deleted.
Oops, something went wrong.
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