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: change pathfinding errors on rolling-stock constraints #7953

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 @@ -62,6 +62,10 @@ class MockSigSystemManager(
return parametersSchema
}

override fun getName(sigSystem: SignalingSystemId): String {
return this.sigSystem
}

override val drivers: StaticIdxSpace<SignalDriver>
get() = StaticIdxSpace(1u)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ class SigSystemManagerImpl : SigSystemManager {
return sigSystemPool[sigSystem].parametersSchema
}

override fun getName(sigSystem: SignalingSystemId): String {
return sigSystemPool[sigSystem].id
}

override val drivers
get() = driverPool.space()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import fr.sncf.osrd.reporting.exceptions.OSRDError
import fr.sncf.osrd.sim_infra.impl.SignalParameters
import fr.sncf.osrd.utils.Direction
import fr.sncf.osrd.utils.indexing.*
import fr.sncf.osrd.utils.units.*
import fr.sncf.osrd.utils.units.Length
import fr.sncf.osrd.utils.units.OffsetList

/** A type of signaling system, which is used both for blocks and signals */
sealed interface SignalingSystem
Expand Down Expand Up @@ -45,6 +46,8 @@ interface InfraSigSystemManager {

fun getParametersSchema(sigSystem: SignalingSystemId): SigParametersSchema

fun getName(sigSystem: SignalingSystemId): String

val drivers: StaticIdxSpace<SignalDriver>

fun findDriver(outputSig: SignalingSystemId, inputSig: SignalingSystemId): SignalDriverId
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fr.sncf.osrd.utils

import fr.sncf.osrd.utils.units.*
import fr.sncf.osrd.utils.units.Distance
import fr.sncf.osrd.utils.units.meters
import java.util.function.BiFunction

/**
Expand Down Expand Up @@ -95,3 +96,20 @@ fun <T> mergeDistanceRangeMaps(
// Build the whole map at once to avoid redundant computations.
return distanceRangeMapOf(resEntries)
}

/**
* Filters the 'filtered' map, keeping only ranges also present in 'filter' map (values from
* 'filter' map are not considered)
*/
fun <T, R> filterIntersection(
mapToFilter: DistanceRangeMap<T>,
filter: DistanceRangeMap<R>
): DistanceRangeMap<T> {
val res = distanceRangeMapOf<T>()
for (range in filter) {
val filteredRange = mapToFilter.clone()
filteredRange.truncate(range.lower, range.upper)
res.putMany(filteredRange.asList())
}
return res
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public enum ErrorType {
ErrorCause.USER),
PathfindingTimeoutError(
"no_path_found:timeout", "Pathfinding timed out: no path could be found", ErrorCause.INTERNAL),
PathfindingRelaxedPathTimeoutError(
"no_path_found:relaxed_path_timeout",
"Relaxed pathfinding timed out: no path could be found, then relaxed path search timed out",
ErrorCause.INTERNAL),
InvalidInfraDiscontinuousRoute(
"invalid_infra:discontinuous_route", "Route track path isn't contiguous", ErrorCause.USER),
InvalidInfraMissingDetectorsRoute(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package fr.sncf.osrd.api.api_v2.pathfinding

import com.squareup.moshi.FromJson
import com.squareup.moshi.Json
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.Moshi
import com.squareup.moshi.adapters.PolymorphicJsonAdapterFactory
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
import fr.sncf.osrd.api.api_v2.TrackRange
import fr.sncf.osrd.conflicts.TravelledPath
import fr.sncf.osrd.graph.Pathfinding.Range
import fr.sncf.osrd.reporting.exceptions.OSRDError
import fr.sncf.osrd.sim_infra.api.Path
import fr.sncf.osrd.utils.json.UnitAdapterFactory
import fr.sncf.osrd.utils.units.Length
import fr.sncf.osrd.utils.units.Offset
import java.util.*

interface PathfindingBlockResponse

Expand All @@ -25,7 +29,24 @@ class PathfindingBlockSuccess(

/** Offsets of the waypoints given as input */
@Json(name = "path_item_positions") val pathItemPositions: List<Offset<Path>>
) : PathfindingBlockResponse
) : PathfindingBlockResponse {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is PathfindingBlockSuccess) return false

if (blocks != other.blocks) return false
if (routes != other.routes) return false
if (trackSectionRanges != other.trackSectionRanges) return false
if (length != other.length) return false
if (pathItemPositions != other.pathItemPositions) return false

return true
}

override fun hashCode(): Int {
return Objects.hash(blocks, routes, trackSectionRanges, length, pathItemPositions)
}
}

class NotFoundInBlocks(
@Json(name = "track_section_ranges") val trackSectionRanges: List<TrackRange>,
Expand All @@ -39,41 +60,25 @@ class NotFoundInRoutes(

class NotFoundInTracks : PathfindingBlockResponse

open class IncompatibleConstraint(
val blocks: List<String>,
val routes: List<String>,
@Json(name = "track_section_ranges") val trackSectionRanges: List<TrackRange>,
val length: Length<Path>,
@Json(name = "incompatible_ranges")
val incompatibleRanges: List<List<Offset<Path>>>, // List of pairs
class IncompatibleConstraintsPathResponse(
@Json(name = "relaxed_constraints_path") val relaxedConstraintsPath: PathfindingBlockSuccess,
@Json(name = "incompatible_constraints") val incompatibleConstraints: IncompatibleConstraints
) : PathfindingBlockResponse

class IncompatibleElectrification(
blocks: List<String>,
routes: List<String>,
@Json(name = "track_section_ranges") trackSectionRanges: List<TrackRange>,
length: Length<Path>,
@Json(name = "incompatible_ranges")
incompatibleRanges: List<List<Offset<Path>>> // List of pairs
) : IncompatibleConstraint(blocks, routes, trackSectionRanges, length, incompatibleRanges)

class IncompatibleLoadingGauge(
blocks: List<String>,
routes: List<String>,
@Json(name = "track_section_ranges") trackSectionRanges: List<TrackRange>,
length: Length<Path>,
@Json(name = "incompatible_ranges")
incompatibleRanges: List<List<Offset<Path>>> // List of pairs
) : IncompatibleConstraint(blocks, routes, trackSectionRanges, length, incompatibleRanges)

class IncompatibleSignalingSystem(
blocks: List<String>,
routes: List<String>,
@Json(name = "track_section_ranges") trackSectionRanges: List<TrackRange>,
length: Length<Path>,
@Json(name = "incompatible_ranges")
incompatibleRanges: List<List<Offset<Path>>> // List of pairs
) : IncompatibleConstraint(blocks, routes, trackSectionRanges, length, incompatibleRanges)
data class IncompatibleConstraints(
@Json(name = "incompatible_electrification_ranges")
val incompatibleElectrificationRanges: List<RangeValue<String>>,
@Json(name = "incompatible_gauge_ranges") val incompatibleGaugeRanges: List<RangeValue<String>>,
@Json(name = "incompatible_signaling_system_ranges")
val incompatibleSignalingSystemRanges: List<RangeValue<String>>
)

data class RangeValue<T>(val range: Range<TravelledPath>, val value: T?) {
@FromJson
fun fromJson(range: Range<TravelledPath>): RangeValue<T> {
return RangeValue(range, null)
}
}

class PathfindingFailed(
@Json(name = "core_error") val coreError: OSRDError,
Expand All @@ -87,9 +92,7 @@ val polymorphicPathfindingResponseAdapter: PolymorphicJsonAdapterFactory<Pathfin
.withSubtype(NotFoundInBlocks::class.java, "not_found_in_blocks")
.withSubtype(NotFoundInRoutes::class.java, "not_found_in_routes")
.withSubtype(NotFoundInTracks::class.java, "not_found_in_tracks")
.withSubtype(IncompatibleElectrification::class.java, "incompatible_electrification")
.withSubtype(IncompatibleLoadingGauge::class.java, "incompatible_loading_gauge")
.withSubtype(IncompatibleSignalingSystem::class.java, "incompatible_signaling_system")
.withSubtype(IncompatibleConstraintsPathResponse::class.java, "incompatible_constraints")
.withSubtype(NotEnoughPathItems::class.java, "not_enough_path_items")
.withSubtype(PathfindingFailed::class.java, "pathfinding_failed")

Expand Down
Loading
Loading