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

core: fix distance_range_map.to_range_map #8831

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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!!)
bougue-pe marked this conversation as resolved.
Show resolved Hide resolved
}
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
Loading