Skip to content

Commit

Permalink
core: fix distance_range_map.to_range_map
Browse files Browse the repository at this point in the history
  • Loading branch information
Castavo committed Sep 13, 2024
1 parent f6a953b commit 6ea7e56
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ fun getStopPositions(schedule: List<SimulationScheduleItem>): List<Double> {
return schedule.filter { it.stopFor != null }.map { it.pathOffset.distance.meters }
}

// TODO: Get rid of this function, by propagating DistanceRangeMap to the whole codebase
/**
* Converts a DistanceRangeMap<T> into a legacy RangeMap<Double, T>. Distances are converted to
* floats (m).
Expand All @@ -422,7 +423,7 @@ private fun <T> DistanceRangeMap<T>.toRangeMap(): RangeMap<Double, T> {
val res = ImmutableRangeMap.builder<Double, T>()
for (entry in this) {
if (entry.value != null)
res.put(Range.closed(entry.lower.meters, entry.upper.meters), entry.value!!)
res.put(Range.closedOpen(entry.lower.meters, entry.upper.meters), entry.value!!)
}
return res.build()
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,8 @@ import fr.sncf.osrd.railjson.schema.rollingstock.Comfort
import fr.sncf.osrd.railjson.schema.schedule.RJSAllowanceDistribution
import fr.sncf.osrd.sim_infra.api.makePathProperties
import fr.sncf.osrd.train.TestTrains
import fr.sncf.osrd.utils.Helpers
import fr.sncf.osrd.utils.distanceRangeMapOf
import fr.sncf.osrd.utils.pathFromRoutes
import fr.sncf.osrd.utils.toIdxList
import fr.sncf.osrd.utils.units.Distance
import fr.sncf.osrd.utils.units.Offset
import fr.sncf.osrd.utils.units.TimeDelta
import fr.sncf.osrd.utils.units.seconds
import fr.sncf.osrd.utils.*
import fr.sncf.osrd.utils.units.*
import java.util.stream.Stream
import kotlin.test.assertEquals
import org.junit.jupiter.api.Test
Expand Down Expand Up @@ -99,6 +93,7 @@ class StandaloneSimulationTest {
val startSpeed: Double = 0.0,
val margins: RangeValues<MarginValue> = RangeValues(),
val pathLength: Distance,
val powerRestrictions: DistanceRangeMap<String> = distanceRangeMapOf()
)

/**
Expand Down Expand Up @@ -163,27 +158,52 @@ class StandaloneSimulationTest {
)
)

// Power restriction values
val powerRestrictionRangeMaps: List<DistanceRangeMap<String>> =
listOf(
distanceRangeMapOf(),
distanceRangeMapOf(
listOf(
DistanceRangeMap.RangeMapEntry(0.meters, pathLength / 3.0, "Restrict1"),
DistanceRangeMap.RangeMapEntry(
pathLength / 3.0,
pathLength * 2.0 / 3.0,
"Restrict2"
),
DistanceRangeMap.RangeMapEntry(
pathLength * 2.0 / 3.0,
pathLength,
"Restrict1"
)
)
)
)

// List all possible combinations
val res = mutableListOf<TestCase>()
for (schedule in schedules) {
for (margin in margins) {
for (startSpeed in listOf(0.0, 15.0)) {
for (distribution in RJSAllowanceDistribution.entries) {
res.add(
TestCase(
schedule = schedule,
margins = margin,
startSpeed = startSpeed,
allowanceDistribution = distribution,
pathLength = pathLength
for (powerRestrictions in powerRestrictionRangeMaps) {
res.add(
TestCase(
schedule = schedule,
margins = margin,
startSpeed = startSpeed,
allowanceDistribution = distribution,
pathLength = pathLength,
powerRestrictions = powerRestrictions
)
)
)
}
}
}
}
}
return res.map { Arguments.of(it) }.stream()
}

/** Parametrized test, checks the interactions between margins and scheduled points */
@ParameterizedTest
@MethodSource("generateTestCases")
Expand All @@ -199,7 +219,7 @@ class StandaloneSimulationTest {
Comfort.STANDARD,
testCase.allowanceDistribution,
null,
distanceRangeMapOf(),
testCase.powerRestrictions,
false,
2.0,
testCase.schedule,
Expand Down

0 comments on commit 6ea7e56

Please sign in to comment.