Skip to content

Commit

Permalink
core :adapt to new node model
Browse files Browse the repository at this point in the history
  • Loading branch information
younesschrifi committed Nov 2, 2023
1 parent e878c17 commit 17ca23c
Show file tree
Hide file tree
Showing 38 changed files with 508 additions and 500 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class RJSInfra {
.build()
.adapter(RJSInfra.class);

public static final transient String CURRENT_VERSION = "3.4.5";
public static final transient String CURRENT_VERSION = "3.4.6";

/** The version of the infra format used */
public String version;
Expand All @@ -45,7 +45,7 @@ public class RJSInfra {
public Collection<RJSRoute> routes;

/** The map of switch types */
@Json(name = "extend_switch_types")
@Json(name = "extended_switch_types")
public List<RJSSwitchType> switchTypes;

public List<RJSSignal> signals;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,48 @@ public SwitchPortConnection(String src, String dst, boolean bidirectional) {
}

public static final RJSSwitchType CLASSIC_TYPE = new RJSSwitchType(
"classic_switch",
List.of("base", "left", "right"),
"point_switch",
List.of("A", "B1", "B2"),
Map.of(
"LEFT", List.of(new SwitchPortConnection("base", "left", true)),
"RIGHT", List.of(new SwitchPortConnection("base", "right", true))
"A_B1", List.of(new SwitchPortConnection("A", "B1", true)),
"A_B2", List.of(new SwitchPortConnection("A", "B2", true))
)
);

public static final RJSSwitchType LINK = new RJSSwitchType("link",
List.of("A", "B"),
Map.of("STATIC", List.of(new SwitchPortConnection("A", "B", true))
)
);

public static final RJSSwitchType CROSSING = new RJSSwitchType("crossing",
List.of("A1", "B1", "A2", "B2"),
Map.of("STATIC", List.of(
new SwitchPortConnection("A1", "B1", true),
new SwitchPortConnection("A2", "B2", true)
)
)
);
public static final RJSSwitchType SINGLE_SLIP_SWITCH = new RJSSwitchType("single_slip_switch",
List.of("A1", "B1", "A2", "B2"),
Map.of("STATIC", List.of(
new SwitchPortConnection("A1", "B1", true),
new SwitchPortConnection("A2", "B2", true)
),
"A1_B2", List.of(new SwitchPortConnection("A1", "B2", true))
)
);

public static final RJSSwitchType DOUBLE_SLIP_SWITCH = new RJSSwitchType("double_slip_switch",
List.of("A1", "B1", "A2", "B2"),
Map.of("A1_B1", List.of(new SwitchPortConnection("A1", "B1", true)),
"A1_B2", List.of(new SwitchPortConnection("A1", "B2", true)),
"A2_B1", List.of(new SwitchPortConnection("A2", "B1", true)),
"A2_B2", List.of(new SwitchPortConnection("A2", "B2", true))
)
);

public static final List<RJSSwitchType> BUILTIN_NODE_TYPES_LIST = List.of(
CLASSIC_TYPE, LINK, CROSSING, SINGLE_SLIP_SWITCH, DOUBLE_SLIP_SWITCH
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@
import static fr.sncf.osrd.railjson.schema.rollingstock.RJSLoadingGaugeType.GB1;
import static fr.sncf.osrd.railjson.schema.rollingstock.RJSLoadingGaugeType.GC;
import static fr.sncf.osrd.railjson.schema.rollingstock.RJSLoadingGaugeType.GLOTT;
import static fr.sncf.osrd.railjson.schema.infra.RJSSwitchType.CLASSIC_TYPE;
import static fr.sncf.osrd.railjson.schema.infra.RJSSwitchType.LINK;
import static fr.sncf.osrd.railjson.schema.infra.RJSSwitchType.CROSSING;
import static fr.sncf.osrd.railjson.schema.infra.RJSSwitchType.SIMPLE_SLIP_SWITCH;
import static fr.sncf.osrd.railjson.schema.infra.RJSSwitchType.DOUBLE_SLIP_SWITCH;
import static fr.sncf.osrd.railjson.schema.infra.RJSSwitchType.BUILTIN_NODE_TYPES_LIST;

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -128,6 +124,17 @@ public static TrackInfra parseInfra(RJSInfra infra, DiagnosticRecorder diagnosti
return new UndirectedInfraBuilder(diagnosticRecorder).parse(infra);
}

/** Retrieve all the switchTypes */
public static List<RJSSwitchType> getswitchTypes(List<RJSSwitchType> switchTypeList) {
if (switchTypeList == null) {
return BUILTIN_NODE_TYPES_LIST;
}

switchTypeList.addAll(BUILTIN_NODE_TYPES_LIST);

return switchTypeList;
}

/** Parse the railjson to build an infra */
private TrackInfra parse(RJSInfra infra) {
// Loads operational points
Expand All @@ -140,7 +147,7 @@ private TrackInfra parse(RJSInfra infra) {

// Creates switches
var switchTypeMap = new HashMap<String, RJSSwitchType>();
for (var rjsSwitchType : infra.switchTypes)
for (var rjsSwitchType : getswitchTypes(infra.switchTypes))
switchTypeMap.put(rjsSwitchType.id, rjsSwitchType);
var switches = new ImmutableMap.Builder<String, Switch>();
for (var s : infra.switches) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class RawInfraAdapterTest {
EdgeDirection.START_TO_STOP,
RJSWaypointRef("det_end_new_route", RJSWaypointRef.RJSWaypointType.DETECTOR),
)
newRoute.switchesDirections["PA0"] = "LEFT"
newRoute.switchesDirections["PA0"] = "A_B1"
rjsInfra.routes = listOf(newRoute)
val oldInfra = Helpers.infraFromRJS(rjsInfra)
adaptRawInfra(oldInfra)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
DELETE FROM infra_object_extended_switch_type;
ALTER TABLE infra_object_extended_switch_type
RENAME TO infra_object_switch_type;
ALTER TABLE infra
ALTER column railjson_version
SET DEFAULT '3.4.5';
UPDATE infra
SET railjson_version = '3.4.5';
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
DELETE FROM infra_object_switch_type;
ALTER TABLE infra_object_switch_type
RENAME TO infra_object_extend_switch_type;
RENAME TO infra_object_extended_switch_type;
ALTER TABLE infra
ALTER column railjson_version
SET DEFAULT '3.4.5';
SET DEFAULT '3.4.6';
UPDATE infra
SET railjson_version = '3.4.5';
SET railjson_version = '3.4.6';
4 changes: 2 additions & 2 deletions editoast/src/converters/generate_routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ impl Graph {

fn edges_from_switches(&mut self, railjson: &RailJson) {
for switch in &railjson.switches {
let switch_type = railjson
.extend_switch_types
let builtin_node_types = builtin_node_types_list();
let switch_type = builtin_node_types
.iter()
.find(|t| t.id == switch.switch_type)
.expect("Switch must have associated type");
Expand Down
41 changes: 19 additions & 22 deletions editoast/src/converters/osm_to_railjson.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub fn parse_osm(osm_pbf_in: PathBuf) -> Result<RailJson, Box<dyn Error + Send +
let nodes_tracks = NodeToTrack::from_edges(&edges);
let signals = signals(&osm_pbf_in, &nodes_tracks, &adjacencies);
let mut railjson = RailJson {
extend_switch_types: default_switch_types(),
extended_switch_types: vec![],
detectors: signals.iter().map(detector).collect(),
signals,
speed_sections: rail_edges.clone().flat_map(speed_sections).collect(),
Expand Down Expand Up @@ -148,7 +148,6 @@ mod tests {
ports.get(&name.into()).unwrap().track.0 == expected
}
let mut railjson = parse_osm("src/tests/switches.osm.pbf".into()).unwrap();
assert_eq!(4, railjson.extend_switch_types.len());
assert_eq!(4, railjson.switches.len());
assert_eq!(18, railjson.buffer_stops.len());

Expand All @@ -162,43 +161,41 @@ mod tests {
assert_eq!(2, switch.ports.len());

let switch = &railjson.switches[3];
assert_eq!("point", switch.switch_type.as_str());
assert_eq!("point_switch", switch.switch_type.as_str());
assert_eq!(3, switch.ports.len());
assert!(port_eq(&switch.ports, "BASE", "-103478-0"));
let a = port_eq(&switch.ports, "LEFT", "-103478-1")
&& port_eq(&switch.ports, "RIGHT", "-103477-0");
let b = port_eq(&switch.ports, "LEFT", "-103477-0")
&& port_eq(&switch.ports, "RIGHT", "-103478-1");
assert!(port_eq(&switch.ports, "A", "-103478-0"));
let a =
port_eq(&switch.ports, "B1", "-103478-1") && port_eq(&switch.ports, "B2", "-103477-0");
let b =
port_eq(&switch.ports, "B1", "-103477-0") && port_eq(&switch.ports, "B2", "-103478-1");
assert!(a || b);

let cross = &railjson.switches[0];
assert_eq!("cross_over", cross.switch_type.as_str());
assert_eq!("crossing", cross.switch_type.as_str());
assert_eq!(4, cross.ports.len());
let a = port_eq(&cross.ports, "NORTH", "-103476-0")
&& port_eq(&cross.ports, "SOUTH", "-103476-1");
let b = port_eq(&cross.ports, "NORTH", "-103476-1")
&& port_eq(&cross.ports, "SOUTH", "-103476-0");
let c = port_eq(&cross.ports, "NORTH", "103475-0")
&& port_eq(&cross.ports, "SOUTH", "103475-1");
let d = port_eq(&cross.ports, "NORTH", "103475-1")
&& port_eq(&cross.ports, "SOUTH", "103475-0");
let a =
port_eq(&cross.ports, "A1", "-103476-0") && port_eq(&cross.ports, "B1", "-103476-1");
let b =
port_eq(&cross.ports, "A1", "-103476-1") && port_eq(&cross.ports, "B1", "-103476-0");
let c = port_eq(&cross.ports, "A1", "103475-0") && port_eq(&cross.ports, "B1", "103475-1");
let d = port_eq(&cross.ports, "A1", "103475-1") && port_eq(&cross.ports, "B1", "103475-0");
assert!(a || b || c || d);

let double = &railjson.switches[1];
assert_eq!("double_slip", double.switch_type.as_str());
assert_eq!("double_slip_switch", double.switch_type.as_str());
assert_eq!(4, double.ports.len());
let a = ["-103474-0", "-103474-1"]
.iter()
.any(|t| port_eq(&double.ports, "NORTH-1", t))
.any(|t| port_eq(&double.ports, "A1", t))
&& ["-103473-0", "-103473-1"]
.iter()
.any(|t| port_eq(&double.ports, "NORTH-2", t));
.any(|t| port_eq(&double.ports, "A2", t));
let b = ["-103473-0", "-103473-1"]
.iter()
.any(|t| port_eq(&double.ports, "NORTH-1", t))
.any(|t| port_eq(&double.ports, "A1", t))
&& ["-103474-0", "-103474-1"]
.iter()
.any(|t| port_eq(&double.ports, "NORTH-2", t));
.any(|t| port_eq(&double.ports, "A2", t));
assert!(a || b);
}

Expand Down
Loading

0 comments on commit 17ca23c

Please sign in to comment.