Skip to content

Commit

Permalink
core: change interface for pathfinding errors on rolling-stock constr…
Browse files Browse the repository at this point in the history
…aints

TODO:
* build real response
* tests
  • Loading branch information
bougue-pe committed Jul 5, 2024
1 parent 1692f8c commit 0e4eb4c
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ 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
Expand Down Expand Up @@ -39,41 +41,21 @@ 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,
val constraints: 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 IncompatibleConstraints(
@Json(name = "incompatible_electrification_ranges")
val incompatibleElectrificationRanges: List<RangeValue<String>>,
@Json(name = "incompatible_gauge_ranges")
val incompatibleGaugeRanges: List<Range<TravelledPath>>,
@Json(name = "incompatible_signaling_system_ranges")
val incompatibleSignalingSystemRanges: List<RangeValue<String>>
)

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)
class RangeValue<T>(val range: Range<TravelledPath>, val value: T)

class PathfindingFailed(
@Json(name = "core_error") val coreError: OSRDError,
Expand All @@ -87,9 +69,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
Original file line number Diff line number Diff line change
Expand Up @@ -155,37 +155,59 @@ private fun computePaths(
.runPathfinding(waypoints)
if (res == null) {
// This way of handling it is suboptimal, but it should be reworked soon
val relaxedPath =
PathfindingBlockSuccess(
listOf(),
listOf(),
listOf(),
Length(0.meters),
listOf()
)

when (currentConstraint::class.java) {
ElectrificationConstraints::class.java -> {
throw NoPathFoundException(
IncompatibleElectrification(
listOf(),
listOf(),
listOf(),
Length(0.meters),
listOf(),
IncompatibleConstraintsPathResponse(
relaxedPath,
IncompatibleConstraints(
listOf(
RangeValue(
Pathfinding.Range(Offset.zero(), Offset.zero()),
"elec"
)
),
listOf(),
listOf()
)
)
)
}
LoadingGaugeConstraints::class.java -> {
throw NoPathFoundException(
IncompatibleLoadingGauge(
listOf(),
listOf(),
listOf(),
Length(0.meters),
listOf(),
IncompatibleConstraintsPathResponse(
relaxedPath,
IncompatibleConstraints(
listOf(),
listOf(Pathfinding.Range(Offset.zero(), Offset.zero())),
listOf()
)
)
)
}
SignalingSystemConstraints::class.java -> {
throw NoPathFoundException(
IncompatibleSignalingSystem(
listOf(),
listOf(),
listOf(),
Length(0.meters),
listOf(),
IncompatibleConstraintsPathResponse(
relaxedPath,
IncompatibleConstraints(
listOf(),
listOf(),
listOf(
RangeValue(
Pathfinding.Range(Offset.zero(), Offset.zero()),
"signal"
)
)
)
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ package fr.sncf.osrd.pathfinding
import fr.sncf.osrd.api.ApiTest
import fr.sncf.osrd.api.api_v2.TrackLocation
import fr.sncf.osrd.api.api_v2.TrackRange
import fr.sncf.osrd.api.api_v2.pathfinding.*
import fr.sncf.osrd.api.api_v2.pathfinding.IncompatibleConstraintsPathResponse
import fr.sncf.osrd.api.api_v2.pathfinding.PathfindingBlockRequest
import fr.sncf.osrd.api.api_v2.pathfinding.PathfindingBlockSuccess
import fr.sncf.osrd.api.api_v2.pathfinding.PathfindingBlocksEndpointV2
import fr.sncf.osrd.api.api_v2.pathfinding.pathfindingRequestAdapter
import fr.sncf.osrd.api.api_v2.pathfinding.pathfindingResponseAdapter
import fr.sncf.osrd.railjson.schema.common.graph.EdgeDirection
import fr.sncf.osrd.railjson.schema.rollingstock.RJSLoadingGaugeType
import fr.sncf.osrd.utils.takes.TakesUtils
Expand Down Expand Up @@ -96,6 +101,7 @@ class PathfindingV2Test : ApiTest() {
.act(RqFake("POST", "/v2/pathfinding/blocks", requestBody))
val response = TakesUtils.readBodyResponse(rawResponse)
val parsed =
(pathfindingResponseAdapter.fromJson(response) as? IncompatibleElectrification)!!
(pathfindingResponseAdapter.fromJson(response)
as? IncompatibleConstraintsPathResponse)!!
}
}

0 comments on commit 0e4eb4c

Please sign in to comment.