Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add generic TickDataType #53

Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1b3f6db
WIP.
dominikmaeckel Feb 28, 2024
f3e79c8
Fix generic types (missing E1, E2)
tillschallau Feb 28, 2024
43c9377
Fix calculation of until
tillschallau Feb 28, 2024
08be81a
Add equals functions and update toString functions
tillschallau Feb 28, 2024
18ae709
Fixed documentation on CMFTBL operator until.
dominikmaeckel Feb 29, 2024
aa93f83
Fixed detekt warnings.
dominikmaeckel Feb 29, 2024
d6c342d
Fixed wrong generic type in operator next.
dominikmaeckel Feb 29, 2024
fef7f0d
Added missing generics in cmftbl formulas. Added missing documentation.
dominikmaeckel Feb 29, 2024
16b6199
Added missing documentation.
dominikmaeckel Feb 29, 2024
a95366b
Moved TickUnit and TickDifference to separate files. Added missing do…
dominikmaeckel Feb 29, 2024
199a88c
Fixed parameter order in Predicates.
dominikmaeckel Feb 29, 2024
a4604eb
Added "any" multiplicity
dominikmaeckel Feb 29, 2024
bf41972
SpotlessApply
tillschallau Feb 29, 2024
068fe7f
Fix parameter order for AVTSC.kt
tillschallau Feb 29, 2024
5c6ddcf
Fixed logic operators.
dominikmaeckel Mar 4, 2024
7c74d37
Revert "Fixed logic operators."
dominikmaeckel Mar 4, 2024
7ed6de2
Fixed outdated documentation.
dominikmaeckel Mar 4, 2024
14b8934
Clean up and add missing documentation for all classes in the tools.a…
tillschallau Mar 5, 2024
4a98f27
Remove package-info.md globally (closes #54)
tillschallau Mar 5, 2024
d556d73
Re-added TotalSegmentTickDifferenceMetric and TotalSegmentTickDiffere…
dominikmaeckel Mar 5, 2024
966007b
Update and fix documentation throughout the core project
tillschallau Mar 5, 2024
bb3710e
Updated Changelog.
dominikmaeckel Mar 7, 2024
777cdc3
Changed class cast to modern syntax.
dominikmaeckel Mar 7, 2024
0747f3b
Resolved FIXME.
dominikmaeckel Mar 7, 2024
29134db
Update CHANGELOG.md with additional changes
tillschallau Mar 7, 2024
addf45a
Rename DataAvTest.kt to DataAvTSCTest.kt
tillschallau Mar 7, 2024
8a8d584
Add changes to CHANGELOG.md
tillschallau Mar 7, 2024
4d27dfc
Update CHANGELOG.md
tillschallau Mar 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
# Changelog
All notable changes to this project will be documented in this file.

## 0.3 - tba
### Added
- Generic `TickUnit` and `TickDifference` instead of `Double` identifier.

## [0.2.2] - 13.02.2024
### Added
- Add missing documentation
Expand Down
2 changes: 1 addition & 1 deletion HACKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ perform additional quality checks on Kotlin files, but will not fail the build o

### `publish-conventions`

The publish conventions handle publication of artifacts via Maven Central. Most of the process is automated, but each
The publish-conventions handle publication of artifacts via Maven Central. Most of the process is automated, but each
module must provide a name and description for the generated POM file. This is done using the (custom) `MavenMetadata`
extension:

Expand Down
18 changes: 14 additions & 4 deletions stars-core/src/main/kotlin/tools/aqua/stars/core/ListExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,27 @@

package tools.aqua.stars.core

/** Creates TxT cross product. */
/**
* Creates TxT cross product.
*
* @return The TxT cross product of the current [List].
*/
fun <T> List<T>.x2(): List<Pair<T, T>> = this.flatMap { a -> this.map { b -> a to b } }

/** Creates TxTxT cross product. */
/**
* Creates TxTxT cross product.
*
* @return The TxTxT cross product of the current [List].
*/
fun <T> List<T>.x3(): List<Triple<T, T, T>> =
this.flatMap { a -> this.flatMap { b -> this.map { c -> Triple(a, b, c) } } }

/**
* Adaption of com.marcinmoskala.math.powerset for lists while preserving the order of the original
* list, going from small to big subsets see
* https://github.com/MarcinMoskala/KotlinDiscreteMathToolkit/blob/master/src/main/java/com/marcinmoskala/math/PowersetExt.kt
*
* @return The power list of the current [List].
*/
fun <T> List<T>.powerlist(): List<List<T>> =
when {
Expand All @@ -56,6 +66,8 @@ fun <T> List<T>.powerlist(): List<List<T>> =
* listOf(listOf("a", "x", "1"), listOf("a", "x", "2"), /*...*/ listOf("c", "y", "4"))
* )
* ```
*
* @return The cross product of the current [List].
*/
fun <T> List<List<List<T>>>.crossProduct(): List<List<T>> {
require(size >= 2) { "List for cross-product building must at least contain two elements." }
Expand All @@ -70,7 +82,5 @@ fun <T> List<List<List<T>>>.crossProduct(): List<List<T>> {
}
}

// val monitorFunction: (PredicateContext, Segment) -> Boolean = { _, _ -> true }

return if (size == 2) nextLevelList else (listOf(nextLevelList) + subList(2, size)).crossProduct()
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
package tools.aqua.stars.core.evaluation

import kotlin.reflect.KClass
import tools.aqua.stars.core.types.EntityType
import tools.aqua.stars.core.types.SegmentType
import tools.aqua.stars.core.types.TickDataType
import tools.aqua.stars.core.types.*

/**
* Binary predicate.
Expand All @@ -30,39 +28,53 @@
* @param E [EntityType].
* @param T [TickDataType].
* @param S [SegmentType].
* @param U [TickUnit].
* @param D [TickDifference].
* @property kClasses The [KClass]es of the [EntityType]s that are evaluated by this predicate.
* @property eval The evaluation function on the [PredicateContext].
* @property kClasses The actors.
*/
class BinaryPredicate<
E1 : E, E2 : E, E : EntityType<E, T, S>, T : TickDataType<E, T, S>, S : SegmentType<E, T, S>>(
val eval: (PredicateContext<E, T, S>, E1, E2) -> Boolean,
val kClasses: Pair<KClass<E1>, KClass<E2>>
E1 : E,
E2 : E,
E : EntityType<E, T, S, U, D>,
T : TickDataType<E, T, S, U, D>,
S : SegmentType<E, T, S, U, D>,
U : TickUnit<U, D>,
D : TickDifference<D>>(
val kClasses: Pair<KClass<E1>, KClass<E2>>,
val eval: (PredicateContext<E, T, S, U, D>, E1, E2) -> Boolean,
) {

/**
* Checks if this predicate holds (i.e. is true) in the given context.
*
* @param ctx The context this predicate is evaluated in.
* @param tickId The time stamp to evaluate this predicate in. default: first tick in context.
* @param entityId1 The ID of the first entity to evaluate this predicate for. default: ego
* vehicle.
* @param tick The time stamp to evaluate this predicate in. default: first tick in context.
* @param entityId1 The ID of the first entity to evaluate this predicate for. default: primary
* entity.
* @param entityId2 The ID of the second entity to evaluate this predicate for.
*
* @return Whether the predicate holds in the given [PredicateContext] at the given [tick] for the
* given [entityId1] and [entityId2].
*/
fun holds(
ctx: PredicateContext<E, T, S>,
tickId: Double = ctx.segment.firstTickId,
ctx: PredicateContext<E, T, S, U, D>,
tick: U = ctx.segment.ticks.keys.first(),

Check warning on line 62 in stars-core/src/main/kotlin/tools/aqua/stars/core/evaluation/BinaryPredicate.kt

View check run for this annotation

Codecov / codecov/patch

stars-core/src/main/kotlin/tools/aqua/stars/core/evaluation/BinaryPredicate.kt#L62

Added line #L62 was not covered by tests
entityId1: Int = ctx.primaryEntityId,
entityId2: Int
): Boolean = ctx.holds(this, tickId, entityId1, entityId2)
): Boolean = ctx.holds(this, tick, entityId1, entityId2)

Check warning on line 65 in stars-core/src/main/kotlin/tools/aqua/stars/core/evaluation/BinaryPredicate.kt

View check run for this annotation

Codecov / codecov/patch

stars-core/src/main/kotlin/tools/aqua/stars/core/evaluation/BinaryPredicate.kt#L65

Added line #L65 was not covered by tests

/**
* Checks if this predicate holds (i.e. is true) in the given context on current tick.
*
* @param ctx The context this predicate is evaluated in.
* @param entity1 The first entity to evaluate this predicate for. default: ego vehicle.
* @param entity1 The first entity to evaluate this predicate for.
* @param entity2 The second entity to evaluate this predicate for.
*
* @return Whether the predicate holds in the given [PredicateContext] for the given [entity1] and
* [entity2].
*/
fun holds(ctx: PredicateContext<E, T, S>, entity1: E1, entity2: E2): Boolean =
fun holds(ctx: PredicateContext<E, T, S, U, D>, entity1: E1, entity2: E2): Boolean =
holds(
ctx,
entity1.tickData.currentTick.apply {
Expand All @@ -72,15 +84,32 @@
entity2.id)

companion object {
/** Creates a binary tick predicate in this context. */
/**
* Creates a binary tick predicate in this context.
*
* @param E1 [EntityType].
* @param E2 [EntityType].
* @param E [EntityType].
* @param T [TickDataType].
* @param S [SegmentType].
* @param U [TickUnit].
* @param D [TickDifference].
* @param kClasses The [KClass]es of the [EntityType]s that are evaluated by this predicate.
* @param eval The evaluation function on the [PredicateContext].
*
* @return The created [UnaryPredicate] with the given [eval] function and the [KClass]es of the
* entities for which the predicate should be evaluated.
*/
fun <
E1 : E,
E2 : E,
E : EntityType<E, T, S>,
T : TickDataType<E, T, S>,
S : SegmentType<E, T, S>> predicate(
E : EntityType<E, T, S, U, D>,
T : TickDataType<E, T, S, U, D>,
S : SegmentType<E, T, S, U, D>,
U : TickUnit<U, D>,
D : TickDifference<D>> predicate(
Fixed Show fixed Hide fixed
kClasses: Pair<KClass<E1>, KClass<E2>>,
eval: (PredicateContext<E, T, S>, E1, E2) -> Boolean
): BinaryPredicate<E1, E2, E, T, S> = BinaryPredicate(eval, kClasses)
eval: (PredicateContext<E, T, S, U, D>, E1, E2) -> Boolean,
): BinaryPredicate<E1, E2, E, T, S, U, D> = BinaryPredicate(kClasses, eval)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,66 @@

package tools.aqua.stars.core.evaluation

import tools.aqua.stars.core.types.EntityType
import tools.aqua.stars.core.types.SegmentType
import tools.aqua.stars.core.types.TickDataType
import tools.aqua.stars.core.types.*

/**
* Nullary predicate.
*
* @param E [EntityType].
* @param T [TickDataType].
* @param S [SegmentType].
* @param U [TickUnit].
* @param D [TickDifference].
* @property eval The evaluation function on the [PredicateContext].
*/
class NullaryPredicate<
E : EntityType<E, T, S>, T : TickDataType<E, T, S>, S : SegmentType<E, T, S>>(
val eval: (PredicateContext<E, T, S>, T) -> Boolean,
E : EntityType<E, T, S, U, D>,
T : TickDataType<E, T, S, U, D>,
S : SegmentType<E, T, S, U, D>,
U : TickUnit<U, D>,
D : TickDifference<D>>(
val eval: (PredicateContext<E, T, S, U, D>, T) -> Boolean,

Check warning on line 38 in stars-core/src/main/kotlin/tools/aqua/stars/core/evaluation/NullaryPredicate.kt

View check run for this annotation

Codecov / codecov/patch

stars-core/src/main/kotlin/tools/aqua/stars/core/evaluation/NullaryPredicate.kt#L38

Added line #L38 was not covered by tests
) {

/** Evaluates predicate on [PredicateContext]. */
fun evaluate(ctx: PredicateContext<E, T, S>): List<Double> = ctx.evaluate(this)
/**
* Evaluates predicate on the given [PredicateContext].
*
* @param ctx The context this predicate is evaluated in.
*
* @return Whether the predicate holds in the given [PredicateContext].
*/
fun holds(ctx: PredicateContext<E, T, S, U, D>): List<U> = ctx.holds(this)

Check warning on line 48 in stars-core/src/main/kotlin/tools/aqua/stars/core/evaluation/NullaryPredicate.kt

View check run for this annotation

Codecov / codecov/patch

stars-core/src/main/kotlin/tools/aqua/stars/core/evaluation/NullaryPredicate.kt#L48

Added line #L48 was not covered by tests

/**
* Checks if this predicate holds (i.e. is true) in the given context and tick identifier.
*
* @param ctx The context this predicate is evaluated in.
* @param tickId The time stamp to evaluate this predicate in. default: first tick in context.
* @param tick The tick to evaluate this predicate in. default: first tick in context.
*
* @return Whether the predicate holds in the given [PredicateContext] and at the given [tick].
*/
fun holds(ctx: PredicateContext<E, T, S>, tickId: Double): Boolean =
evaluate(ctx).contains(tickId)
fun holds(ctx: PredicateContext<E, T, S, U, D>, tick: U): Boolean = holds(ctx).contains(tick)

Check warning on line 58 in stars-core/src/main/kotlin/tools/aqua/stars/core/evaluation/NullaryPredicate.kt

View check run for this annotation

Codecov / codecov/patch

stars-core/src/main/kotlin/tools/aqua/stars/core/evaluation/NullaryPredicate.kt#L58

Added line #L58 was not covered by tests

companion object {
/** Creates a nullary tick predicate. */
fun <E : EntityType<E, T, S>, T : TickDataType<E, T, S>, S : SegmentType<E, T, S>> predicate(
eval: (PredicateContext<E, T, S>, T) -> Boolean
): NullaryPredicate<E, T, S> = NullaryPredicate(eval)
/**
* Creates a nullary tick predicate.
*
* @param E [EntityType].
* @param T [TickDataType].
* @param S [SegmentType].
* @param U [TickUnit].
* @param D [TickDifference].
* @param eval The evaluation function on the [PredicateContext].
*
* @return The created [NullaryPredicate] with the given [eval] function.
*/
fun <
E : EntityType<E, T, S, U, D>,
T : TickDataType<E, T, S, U, D>,
S : SegmentType<E, T, S, U, D>,
U : TickUnit<U, D>,
D : TickDifference<D>> predicate(
eval: (PredicateContext<E, T, S, U, D>, T) -> Boolean
): NullaryPredicate<E, T, S, U, D> = NullaryPredicate(eval)

Check warning on line 80 in stars-core/src/main/kotlin/tools/aqua/stars/core/evaluation/NullaryPredicate.kt

View check run for this annotation

Codecov / codecov/patch

stars-core/src/main/kotlin/tools/aqua/stars/core/evaluation/NullaryPredicate.kt#L80

Added line #L80 was not covered by tests
}
}
Loading
Loading