SimulationBuilder.build中实现加载车辆段route path

This commit is contained in:
xiazengbin 2021-12-06 18:06:01 +08:00
parent 05e0eedb34
commit eb56128954

View File

@ -1,416 +1,477 @@
package club.joylink.rtss.simulation.cbtc.build; package club.joylink.rtss.simulation.cbtc.build;
import club.joylink.rtss.entity.Ibp; import club.joylink.rtss.entity.Ibp;
import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.data.CalculateService; import club.joylink.rtss.simulation.cbtc.data.CalculateService;
import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository; import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository;
import club.joylink.rtss.simulation.cbtc.data.map.*; import club.joylink.rtss.simulation.cbtc.data.map.*;
import club.joylink.rtss.simulation.cbtc.data.plan.TerminalDeparturePlan; import club.joylink.rtss.simulation.cbtc.data.plan.TerminalDeparturePlan;
import club.joylink.rtss.simulation.cbtc.data.plan.TripPlan; import club.joylink.rtss.simulation.cbtc.data.plan.TripPlan;
import club.joylink.rtss.simulation.cbtc.data.support.RoutePath; import club.joylink.rtss.simulation.cbtc.data.support.RoutePath;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityDevice; import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityDevice;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityIbp; import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityIbp;
import club.joylink.rtss.util.JsonUtils; import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.client.ibp.IbpData; import club.joylink.rtss.vo.client.ibp.IbpData;
import club.joylink.rtss.vo.client.runplan.RunPlanVO; import club.joylink.rtss.vo.client.runplan.RunPlanVO;
import club.joylink.rtss.vo.client.schedulingNew.SchedulingPlanNewVO; import club.joylink.rtss.vo.client.schedulingNew.SchedulingPlanNewVO;
import club.joylink.rtss.vo.map.logic.MapStationParkingTimeVO; import club.joylink.rtss.vo.map.logic.MapStationParkingTimeVO;
import club.joylink.rtss.vo.map.MapVO; import club.joylink.rtss.vo.map.MapVO;
import club.joylink.rtss.vo.map.RealLineConfigVO; import club.joylink.rtss.vo.map.RealLineConfigVO;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import javax.swing.text.Element; import javax.swing.text.Element;
import java.util.*; import java.util.*;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@Slf4j @Slf4j
public class SimulationBuilder { public class SimulationBuilder {
/** /**
* 构造仿真对象 * 构造仿真对象
*/ */
public static Simulation build(String group, SimulationBuildParams buildParams) { public static Simulation build(String group, SimulationBuildParams buildParams) {
Simulation simulation = new Simulation(group); Simulation simulation = new Simulation(group);
simulation.setBuildParams(buildParams); simulation.setBuildParams(buildParams);
if (Objects.nonNull(buildParams.getLoginUserInfo())) { if (Objects.nonNull(buildParams.getLoginUserInfo())) {
simulation.setProject(buildParams.getLoginUserInfo().getProject()); simulation.setProject(buildParams.getLoginUserInfo().getProject());
} }
// 线路配置参数 // 线路配置参数
simulation.getRepository().setConfig(buildConfig(buildParams.getMap().getConfigVO())); simulation.getRepository().setConfig(buildConfig(buildParams.getMap().getConfigVO()));
simulation.getRepository().getConfig() simulation.getRepository().getConfig()
.setRouteLikeHa1(buildParams.getMap().getGraphDataNew().getGenerateConfig().isLikeHa1()); .setRouteLikeHa1(buildParams.getMap().getGraphDataNew().getGenerateConfig().isLikeHa1());
simulation.getRepository().getConfig() simulation.getRepository().getConfig()
.setOverlapSettingByTrigger(buildParams.getMap().getGraphDataNew().getGenerateConfig().isOverlapSettingByTrigger()); .setOverlapSettingByTrigger(buildParams.getMap().getGraphDataNew().getGenerateConfig().isOverlapSettingByTrigger());
simulation.getRepository().getConfig() simulation.getRepository().getConfig()
.setSharingECStations(buildParams.getMap().getGraphDataNew().getGenerateConfig().getSharingECStations()); .setSharingECStations(buildParams.getMap().getGraphDataNew().getGenerateConfig().getSharingECStations());
simulation.getRepository().getConfig() simulation.getRepository().getConfig()
.setHandleDepot(buildParams.getMap().getGraphDataNew().getGenerateConfig().isHandleDepot()); .setHandleDepot(buildParams.getMap().getGraphDataNew().getGenerateConfig().isHandleDepot());
// 地图数据构建 // 地图数据构建
SimulationDeviceBuildResult mapDataBuildResult = checkAndBuildMapData(buildParams.getMap()); SimulationDeviceBuildResult mapDataBuildResult = checkAndBuildMapData(buildParams.getMap());
// ibp数据构建 // ibp数据构建
buildIbpData(mapDataBuildResult, buildParams.getMap().getIbpList()); buildIbpData(mapDataBuildResult, buildParams.getMap().getIbpList());
simulation.getRepository().setDeviceMap(mapDataBuildResult.getDeviceMap()); simulation.getRepository().setDeviceMap(mapDataBuildResult.getDeviceMap());
simulation.getRepository().setSectionArriveNearMap(mapDataBuildResult.sectionArriveNearMap); simulation.getRepository().setSectionArriveNearMap(mapDataBuildResult.sectionArriveNearMap);
simulation.getRepository().setVrDeviceMap(mapDataBuildResult.getVrDeviceMap()); simulation.getRepository().setVrDeviceMap(mapDataBuildResult.getVrDeviceMap());
// simulation.getRepository().setRouteUnitMap(mapDataBuildResult.getRouteUnitMap()); // simulation.getRepository().setRouteUnitMap(mapDataBuildResult.getRouteUnitMap());
simulation.getRepository().setRoutePathMap(mapDataBuildResult.getRoutePathMap()); simulation.getRepository().setRoutePathMap(mapDataBuildResult.getRoutePathMap());
simulation.getRepository().setDestinationMap(mapDataBuildResult.getDestinationMap()); simulation.getRepository().setDestinationMap(mapDataBuildResult.getDestinationMap());
simulation.getRepository().setRoutingList(mapDataBuildResult.getRoutingList()); simulation.getRepository().setRoutingList(mapDataBuildResult.getRoutingList());
// simulation.getRepository().setRunLevelList(mapDataBuildResult.getRunLevelList()); // simulation.getRepository().setRunLevelList(mapDataBuildResult.getRunLevelList());
simulation.getRepository().getCatenaryMap().putAll(mapDataBuildResult.getCatenaryMap()); simulation.getRepository().getCatenaryMap().putAll(mapDataBuildResult.getCatenaryMap());
simulation.getRepository().getSectionRespondersMap().putAll(mapDataBuildResult.getSectionRespondersMap()); simulation.getRepository().getSectionRespondersMap().putAll(mapDataBuildResult.getSectionRespondersMap());
simulation.getRepository().setParkingTracksMap(mapDataBuildResult.getParkingTracksMap()); simulation.getRepository().setParkingTracksMap(mapDataBuildResult.getParkingTracksMap());
// simulation.getRepository().setParkTimeMap(mapDataBuildResult.getParkTimeMap()); // simulation.getRepository().setParkTimeMap(mapDataBuildResult.getParkTimeMap());
UserConfigDataBuilder.buildRunLevel(simulation.getRepository(), buildParams.getUserRunLevelList(), UserConfigDataBuilder.buildRunLevel(simulation.getRepository(), buildParams.getUserRunLevelList(),
buildParams.getMap(), mapDataBuildResult.getErrMsgList()); buildParams.getMap(), mapDataBuildResult.getErrMsgList());
UserConfigDataBuilder.buildParkTime(simulation.getRepository(), buildParams.getUserParkTimeList(), UserConfigDataBuilder.buildParkTime(simulation.getRepository(), buildParams.getUserParkTimeList(),
buildParams.getMap(), mapDataBuildResult.getErrMsgList()); buildParams.getMap(), mapDataBuildResult.getErrMsgList());
if (!CollectionUtils.isEmpty(mapDataBuildResult.getErrMsgList())) { // 存在数据异常 if (!CollectionUtils.isEmpty(mapDataBuildResult.getErrMsgList())) { // 存在数据异常
mapDataBuildResult.getErrMsgList().forEach(errMsg -> log.warn(String.format("地图数据异常:%s", errMsg))); mapDataBuildResult.getErrMsgList().forEach(errMsg -> log.warn(String.format("地图数据异常:%s", errMsg)));
simulation.setMapDataError(true); simulation.setMapDataError(true);
simulation.addDataErrMsgs(mapDataBuildResult.getErrMsgList()); simulation.addDataErrMsgs(mapDataBuildResult.getErrMsgList());
} }
// 加载运行图 // 加载运行图
checkAndLoadRunPlan(simulation, buildParams.getRunPlan()); checkAndLoadRunPlan(simulation, buildParams.getRunPlan());
// 加载派班计划 // 加载派班计划
checkAndLoadSchedulingPlan(simulation, buildParams.getSchedulingPlan()); checkAndLoadSchedulingPlan(simulation, buildParams.getSchedulingPlan());
return simulation; // 加载车辆段route path
} loadDepotInOutRoutePath(simulation);
return simulation;
private static void buildIbpData(SimulationDeviceBuildResult mapDataBuildResult, List<Ibp> ibpList) { }
if (CollectionUtils.isEmpty(ibpList))
return; /**
Map<String, MapElement> deviceMap = mapDataBuildResult.getDeviceMap(); * 加载进出depot的route path
Map<String, VirtualRealityDevice> vrDeviceMap = mapDataBuildResult.getVrDeviceMap(); */
Map<String, Ibp> ibpMap = ibpList.stream().collect(Collectors.toMap(Ibp::getStationCode, Function.identity())); private static void loadDepotInOutRoutePath(Simulation simulation) {
List<Station> collect = deviceMap.values().stream() final Map<String, List<RoutePath>> srps = simulation.getRepository().getRoutePathMap();
.filter(element -> MapElement.DeviceType.STATION.equals(element.getDeviceType())) // 仿真车辆段站台停车轨列表
.map(element -> (Station) element).collect(Collectors.toList()); Map<Station, List<Section>> parkingTracksMap = simulation.getRepository().getParkingTracksMap();
collect.forEach(station -> { if (CollectionUtils.isEmpty(parkingTracksMap)) {
//构建添加IBP return;
Ibp ibp = ibpMap.get(station.getCode()); }
if (ibp == null) parkingTracksMap.forEach((station, secs) -> {
ibp = ibpMap.get(null); if (station.isDepot()) {// 车站为车辆段
if (ibp != null) { List<Section> transferList = station.getTransferList();// 转换轨列表
IbpData ibpData = JsonUtils.read(ibp.getData(), IbpData.class); if(!CollectionUtils.isEmpty(transferList)) {
VirtualRealityIbp vrIbp = new VirtualRealityIbp(station.getCode() + "_IBP", station.getName() + "_IBP", ibpData, station); transferList.forEach(transSec->{
station.setVrIbp(vrIbp); //停车轨到转换轨
deviceMap.put(vrIbp.getCode(), vrIbp); secs.forEach(parkSec->{
vrDeviceMap.put(vrIbp.getCode(), vrIbp); final String rpKey=RoutePath.buildKey(parkSec, transSec);
} List<RoutePath> nrp=tryFindRoutePathByDirection(parkSec, transSec,10);
}); List<RoutePath> srp=srps.get(rpKey);
} if(null==srp) {
srp=new ArrayList<RoutePath>();
private static boolean isOverlapSettingByTrigger(Map<String, MapElement> deviceMap) { srps.put(rpKey, srp);
for (MapElement mapElement : deviceMap.values()) { }
if (mapElement.getDeviceType().equals(MapElement.DeviceType.OVERLAP)) { if(!CollectionUtils.isEmpty(nrp)) {
if (!CollectionUtils.isEmpty(((RouteOverlap) mapElement).getTriggerPathList())) { srp.addAll(nrp);
return true; }
} else { });
return false; //转换轨到停车轨
} secs.forEach(parkSec->{
} final String rpKey=RoutePath.buildKey(transSec, parkSec);
} List<RoutePath> nrp=tryFindRoutePathByDirection(transSec, parkSec,10);
return false; List<RoutePath> srp=srps.get(rpKey);
} if(null==srp) {
srp=new ArrayList<RoutePath>();
/** srps.put(rpKey, srp);
* 检查并加载派班计划 }
* @param simulation if(!CollectionUtils.isEmpty(nrp)) {
* @param schedulingPlan srp.addAll(nrp);
*/ }
public static void checkAndLoadSchedulingPlan(Simulation simulation, SchedulingPlanNewVO schedulingPlan) { });
if (simulation.isMapDataError() || simulation.isPlanDataError()) { });
return; }else {
} log.info("仿真数据有问题,车辆段[{}]没有转换轨",station.getName());
if (Objects.isNull(schedulingPlan)) { }
// 如果没有加载计划生成默认的加载计划 }
if (!simulation.isMapDataError() && simulation.isPlanLoaded() && !simulation.isPlanDataError()) { // 地图数据和运行计划加载成功的情况下 });
log.info(String.format("地图[%s(%s)]没有派班计划,生成默认派班计划使用", }
simulation.getBuildParams().getMap().getName(), /**
simulation.getBuildParams().getMap().getId())); *当方向未知时起点终点不变不同方向搜索route path
SchedulingBuilder.generateSchedulingPlan(simulation); */
} private static List<RoutePath> tryFindRoutePathByDirection(Section start, Section end,int iterTimes) {
} else { List<RoutePath> r= CalculateService.queryRoutePathsOnDirection(start, end,true, iterTimes);
SchedulingBuilder.loadSchedulingPlan(simulation, schedulingPlan); if(!CollectionUtils.isEmpty(r)) {
} return r;
} }else {
return CalculateService.queryRoutePathsOnDirection(start, end,false, iterTimes);
/** }
* 检查并加载运行计划 }
* @param simulation private static void buildIbpData(SimulationDeviceBuildResult mapDataBuildResult, List<Ibp> ibpList) {
* @param runPlan if (CollectionUtils.isEmpty(ibpList))
* @return return;
*/ Map<String, MapElement> deviceMap = mapDataBuildResult.getDeviceMap();
public static void checkAndLoadRunPlan(Simulation simulation, RunPlanVO runPlan) { Map<String, VirtualRealityDevice> vrDeviceMap = mapDataBuildResult.getVrDeviceMap();
if (simulation.isMapDataError()) { Map<String, Ibp> ibpMap = ibpList.stream().collect(Collectors.toMap(Ibp::getStationCode, Function.identity()));
// 地图逻辑数据有问题不加载 List<Station> collect = deviceMap.values().stream()
log.info(String.format("仿真地图[%s(%s)]数据有问题,不执行运行计划加载", .filter(element -> MapElement.DeviceType.STATION.equals(element.getDeviceType()))
simulation.getBuildParams().getMap().getName(), .map(element -> (Station) element).collect(Collectors.toList());
simulation.getBuildParams().getMap().getId())); collect.forEach(station -> {
return; //构建添加IBP
} Ibp ibp = ibpMap.get(station.getCode());
if (Objects.nonNull(runPlan)) { if (ibp == null)
RunPlanBuilder.RunPlanBuildResult runPlanBuildResult = ibp = ibpMap.get(null);
RunPlanBuilder.buildRunDiagram(simulation.getRepository().getDeviceMap(), runPlan); if (ibp != null) {
simulation.setPlanLoaded(true); IbpData ibpData = JsonUtils.read(ibp.getData(), IbpData.class);
if (!CollectionUtils.isEmpty(runPlanBuildResult.getErrMsgList())) { // 数据异常 VirtualRealityIbp vrIbp = new VirtualRealityIbp(station.getCode() + "_IBP", station.getName() + "_IBP", ibpData, station);
runPlanBuildResult.getErrMsgList().forEach(errMsg -> log.warn(String.format("运行图数据异常:%s", errMsg))); station.setVrIbp(vrIbp);
simulation.setPlanDataError(true); deviceMap.put(vrIbp.getCode(), vrIbp);
simulation.addDataErrMsgs(runPlanBuildResult.getErrMsgList()); vrDeviceMap.put(vrIbp.getCode(), vrIbp);
} else { }
simulation.getRepository().setServiceTripsMap(runPlanBuildResult.getServerTripMap()); });
simulation.getRepository().setStandTripMap(runPlanBuildResult.getStandTripMap()); }
simulation.getRepository().setEndTripMap(runPlanBuildResult.getEndTripMap());
// 校验运行计划和路径单元 private static boolean isOverlapSettingByTrigger(Map<String, MapElement> deviceMap) {
List<String> errMsgList = checkRunPlanAndBuildLostRoutePaths(runPlanBuildResult.getServerTripMap(), for (MapElement mapElement : deviceMap.values()) {
simulation.getRepository().getRoutePathMap()); if (mapElement.getDeviceType().equals(MapElement.DeviceType.OVERLAP)) {
if (!errMsgList.isEmpty()) { if (!CollectionUtils.isEmpty(((RouteOverlap) mapElement).getTriggerPathList())) {
simulation.setMapDataError(true); return true;
simulation.addDataErrMsgs(errMsgList); } else {
} return false;
// // 构建终端发车计划 }
// TerminalPlanBuildResult terminalPlanBuildResult = buildTerminalPlan(simulation.getRepository(), runPlanBuildResult.getServerTripMap()); }
// if (!CollectionUtils.isEmpty(terminalPlanBuildResult.getErrMsgList())) { }
// simulation.setMapDataError(true); return false;
// simulation.addDataErrMsgs(terminalPlanBuildResult.getErrMsgList()); }
// } else {
// simulation.getRepository().setTerminalDeparturePlanMap(terminalPlanBuildResult.getTerminalPlanMap()); /**
// } * 检查并加载派班计划
} * @param simulation
} else { * @param schedulingPlan
simulation.addDataErrMsg("运行图为空"); */
} public static void checkAndLoadSchedulingPlan(Simulation simulation, SchedulingPlanNewVO schedulingPlan) {
} if (simulation.isMapDataError() || simulation.isPlanDataError()) {
return;
public static List<String> checkRunPlanAndBuildLostRoutePaths(Map<String, List<TripPlan>> serverTripMap, }
Map<String, List<RoutePath>> routePathMap) { if (Objects.isNull(schedulingPlan)) {
Map<String, String> errMsgMap = new HashMap<>(); // 如果没有加载计划生成默认的加载计划
for (List<TripPlan> tripPlanList : serverTripMap.values()) { if (!simulation.isMapDataError() && simulation.isPlanLoaded() && !simulation.isPlanDataError()) { // 地图数据和运行计划加载成功的情况下
for (TripPlan tripPlan : tripPlanList) { log.info(String.format("地图[%s(%s)]没有派班计划,生成默认派班计划使用",
List<Section> allViaSectionList = tripPlan.getAllViaStoppedSectionList(); simulation.getBuildParams().getMap().getName(),
for (int i = 1; i < allViaSectionList.size(); i++) { simulation.getBuildParams().getMap().getId()));
Section start = allViaSectionList.get(i - 1); SchedulingBuilder.generateSchedulingPlan(simulation);
Section end = allViaSectionList.get(i); }
String key = RoutePath.buildKey(start, end); } else {
if (!routePathMap.containsKey(key)) { SchedulingBuilder.loadSchedulingPlan(simulation, schedulingPlan);
// 路径不存在尝试构建 }
List<RoutePath> routePaths = CalculateService.queryRoutePathsOnDirection(start, end, tripPlan.isRight(), 10); }
if (CollectionUtils.isEmpty(routePaths)) {
// 计划方向路径未找到反向尝试 /**
routePaths = CalculateService.queryRoutePathsOnDirection(start, end, !tripPlan.isRight(), 10); * 检查并加载运行计划
} * @param simulation
if (CollectionUtils.isEmpty(routePaths)) { * @param runPlan
// 依然未找到 * @return
errMsgMap.put(key, String.format("从[%s]->[%s]无法到达,请检查运行图和联锁数据是否正确", */
start.debugStr(), end.debugStr())); public static void checkAndLoadRunPlan(Simulation simulation, RunPlanVO runPlan) {
} else { if (simulation.isMapDataError()) {
// 找到保存 // 地图逻辑数据有问题不加载
log.info(String.format("运行图从[%s]->[%s]没有站间运行数据,根据路径查询找到并生成默认的路径单元", log.info(String.format("仿真地图[%s(%s)]数据有问题,不执行运行计划加载",
start.debugStr(), end.debugStr())); simulation.getBuildParams().getMap().getName(),
for (RoutePath routePath : routePaths) { simulation.getBuildParams().getMap().getId()));
routePath.calculateDistance(); return;
} }
routePathMap.put(key, routePaths); if (Objects.nonNull(runPlan)) {
} RunPlanBuilder.RunPlanBuildResult runPlanBuildResult =
} RunPlanBuilder.buildRunDiagram(simulation.getRepository().getDeviceMap(), runPlan);
} simulation.setPlanLoaded(true);
} if (!CollectionUtils.isEmpty(runPlanBuildResult.getErrMsgList())) { // 数据异常
} runPlanBuildResult.getErrMsgList().forEach(errMsg -> log.warn(String.format("运行图数据异常:%s", errMsg)));
return new ArrayList<>(errMsgMap.values()); simulation.setPlanDataError(true);
} simulation.addDataErrMsgs(runPlanBuildResult.getErrMsgList());
} else {
// private static List<String> checkRunPlanAndBuildLostRouteUnit(Map<String, List<TripPlan>> serverTripMap, simulation.getRepository().setServiceTripsMap(runPlanBuildResult.getServerTripMap());
// Map<String, RouteUnit> routeUnitMap) { simulation.getRepository().setStandTripMap(runPlanBuildResult.getStandTripMap());
// Map<String, String> errMsgMap = new HashMap<>(); simulation.getRepository().setEndTripMap(runPlanBuildResult.getEndTripMap());
// for (List<TripPlan> tripPlanList : serverTripMap.values()) { // 校验运行计划和路径单元
// for (TripPlan tripPlan : tripPlanList) { List<String> errMsgList = checkRunPlanAndBuildLostRoutePaths(runPlanBuildResult.getServerTripMap(),
// List<Section> allViaSectionList = tripPlan.getAllViaSectionList(); simulation.getRepository().getRoutePathMap());
// for (int i = 1; i < allViaSectionList.size(); i++) { if (!errMsgList.isEmpty()) {
// Section start = allViaSectionList.get(i - 1); simulation.setMapDataError(true);
// Section end = allViaSectionList.get(i); simulation.addDataErrMsgs(errMsgList);
// String key = RouteUnit.buildKey(start, end); }
// if (!routeUnitMap.containsKey(key)) { // // 构建终端发车计划
// // 尝试构建 // TerminalPlanBuildResult terminalPlanBuildResult = buildTerminalPlan(simulation.getRepository(), runPlanBuildResult.getServerTripMap());
// List<String> errList = new ArrayList<>(); // if (!CollectionUtils.isEmpty(terminalPlanBuildResult.getErrMsgList())) {
// RouteUnit routeUnit = InterlockBuilder2.findAndBuildRouteUnit(start, end, tripPlan.isRight(), errList); // simulation.setMapDataError(true);
// if (Objects.isNull(routeUnit)) { // simulation.addDataErrMsgs(terminalPlanBuildResult.getErrMsgList());
// // 反向再尝试 // } else {
// routeUnit = InterlockBuilder2.findAndBuildRouteUnit(start, end, !tripPlan.isRight(), errList); // simulation.getRepository().setTerminalDeparturePlanMap(terminalPlanBuildResult.getTerminalPlanMap());
// } // }
// if (Objects.nonNull(routeUnit)) { }
// log.warn(String.format("运行图从[%s(%s)]到[%s(%s)]没有站间运行数据,根据路径查询找到并生成默认的路径单元", } else {
// start.getName(), start.getCode(), end.getName(), end.getCode())); simulation.addDataErrMsg("运行图为空");
// routeUnitMap.put(key, routeUnit); }
// } else { }
// errMsgMap.put(key, String.format("从[%s(%s)]到[%s(%s)]无法到达,请检查运行图和联锁数据是否正确",
// start.getName(), start.getCode(), end.getName(), end.getCode())); public static List<String> checkRunPlanAndBuildLostRoutePaths(Map<String, List<TripPlan>> serverTripMap,
// } Map<String, List<RoutePath>> routePathMap) {
// } Map<String, String> errMsgMap = new HashMap<>();
// } for (List<TripPlan> tripPlanList : serverTripMap.values()) {
// } for (TripPlan tripPlan : tripPlanList) {
// } List<Section> allViaSectionList = tripPlan.getAllViaStoppedSectionList();
// return new ArrayList<>(errMsgMap.values()); for (int i = 1; i < allViaSectionList.size(); i++) {
// } Section start = allViaSectionList.get(i - 1);
Section end = allViaSectionList.get(i);
private static TerminalPlanBuildResult buildTerminalPlan(SimulationDataRepository repository, Map<String, List<TripPlan>> serverTripMap) { String key = RoutePath.buildKey(start, end);
TerminalPlanBuildResult result = new TerminalPlanBuildResult(); if (!routePathMap.containsKey(key)) {
List<String> errMsgList = result.getErrMsgList(); // 路径不存在尝试构建
Map<String, TerminalDeparturePlan> terminalPlanMap = result.getTerminalPlanMap(); List<RoutePath> routePaths = CalculateService.queryRoutePathsOnDirection(start, end, tripPlan.isRight(), 10);
serverTripMap.values().forEach(tripPlanList -> if (CollectionUtils.isEmpty(routePaths)) {
tripPlanList.forEach(tripPlan -> { // 计划方向路径未找到反向尝试
Section startSection = tripPlan.getStartSection(); routePaths = CalculateService.queryRoutePathsOnDirection(start, end, !tripPlan.isRight(), 10);
TerminalDeparturePlan terminalPlan = terminalPlanMap.get(startSection.getCode()); }
if (Objects.isNull(terminalPlan)) { if (CollectionUtils.isEmpty(routePaths)) {
terminalPlan = new TerminalDeparturePlan(startSection.getCode()); // 依然未找到
terminalPlanMap.put(startSection.getCode(), terminalPlan); errMsgMap.put(key, String.format("从[%s]->[%s]无法到达,请检查运行图和联锁数据是否正确",
} start.debugStr(), end.debugStr()));
terminalPlan.addTripPlan(tripPlan); } else {
})); // 找到保存
terminalPlanMap.values().forEach(terminalDeparturePlan -> log.info(String.format("运行图从[%s]->[%s]没有站间运行数据,根据路径查询找到并生成默认的路径单元",
terminalDeparturePlan.getPlanList().sort((plan1, plan2) -> { start.debugStr(), end.debugStr()));
return plan1.getStartTime().compareTo(plan2.getStartTime()); for (RoutePath routePath : routePaths) {
})); routePath.calculateDistance();
return result; }
} routePathMap.put(key, routePaths);
}
public static MapConfig buildConfig(RealLineConfigVO configVO) { }
MapConfig mapConfig = new MapConfig(); }
if (Objects.nonNull(configVO)) { }
mapConfig.copyConfigBy(configVO); }
} return new ArrayList<>(errMsgMap.values());
return mapConfig; }
}
// private static List<String> checkRunPlanAndBuildLostRouteUnit(Map<String, List<TripPlan>> serverTripMap,
/** // Map<String, RouteUnit> routeUnitMap) {
* 地图基础数据检查和构建 // Map<String, String> errMsgMap = new HashMap<>();
* @param map // for (List<TripPlan> tripPlanList : serverTripMap.values()) {
* @return // for (TripPlan tripPlan : tripPlanList) {
*/ // List<Section> allViaSectionList = tripPlan.getAllViaSectionList();
public static SimulationDeviceBuildResult checkAndBuildBasicMapData(MapVO map) { // for (int i = 1; i < allViaSectionList.size(); i++) {
SimulationDeviceBuildResult mapDataBuildResult = new SimulationDeviceBuildResult(); // Section start = allViaSectionList.get(i - 1);
MapDeviceBuilder.checkAndBuildMapDeviceData(map.getGraphDataNew(), mapDataBuildResult); // Section end = allViaSectionList.get(i);
return mapDataBuildResult; // String key = RouteUnit.buildKey(start, end);
} // if (!routeUnitMap.containsKey(key)) {
// // 尝试构建
/** // List<String> errList = new ArrayList<>();
* 地图数据逻辑检查和构建 // RouteUnit routeUnit = InterlockBuilder2.findAndBuildRouteUnit(start, end, tripPlan.isRight(), errList);
* // if (Objects.isNull(routeUnit)) {
* @param map // // 反向再尝试
* @return // routeUnit = InterlockBuilder2.findAndBuildRouteUnit(start, end, !tripPlan.isRight(), errList);
*/ // }
public static SimulationDeviceBuildResult checkAndBuildMapData(MapVO map) { // if (Objects.nonNull(routeUnit)) {
SimulationDeviceBuildResult mapDataBuildResult = new SimulationDeviceBuildResult(); // log.warn(String.format("运行图从[%s(%s)]到[%s(%s)]没有站间运行数据,根据路径查询找到并生成默认的路径单元",
MapDeviceBuilder.checkAndBuildMapDeviceData(map.getGraphDataNew(), mapDataBuildResult); // start.getName(), start.getCode(), end.getName(), end.getCode()));
if (CollectionUtils.isEmpty(mapDataBuildResult.getErrMsgList())) { // 基础数据没有问题再构建逻辑数据 // routeUnitMap.put(key, routeUnit);
// InterlockBuilder.checkAndBuildMapCILogicData(map.getLogicDataNew(), mapDataBuildResult); // } else {
InterlockBuilder2.checkAndBuildMapCILogicData(map.getLogicDataNew(), mapDataBuildResult); // errMsgMap.put(key, String.format("从[%s(%s)]到[%s(%s)]无法到达,请检查运行图和联锁数据是否正确",
List<MapStationParkingTimeVO> parkingTimeList = map.getLogicDataNew().getParkingTimeList(); // start.getName(), start.getCode(), end.getName(), end.getCode()));
if (CollectionUtils.isEmpty(parkingTimeList)) { // }
mapDataBuildResult.errMsgList.add("无停站时间数据"); // }
} // }
} // }
return mapDataBuildResult; // }
} // return new ArrayList<>(errMsgMap.values());
// }
public static SimulationDeviceBuildResult checkAndBuildMapDeviceData(MapVO map) {
SimulationDeviceBuildResult mapDataBuildResult = new SimulationDeviceBuildResult(); private static TerminalPlanBuildResult buildTerminalPlan(SimulationDataRepository repository, Map<String, List<TripPlan>> serverTripMap) {
MapDeviceBuilder.checkAndBuildMapDeviceData(map.getGraphDataNew(), mapDataBuildResult); TerminalPlanBuildResult result = new TerminalPlanBuildResult();
return mapDataBuildResult; List<String> errMsgList = result.getErrMsgList();
} Map<String, TerminalDeparturePlan> terminalPlanMap = result.getTerminalPlanMap();
serverTripMap.values().forEach(tripPlanList ->
@Getter tripPlanList.forEach(tripPlan -> {
public static class TerminalPlanBuildResult { Section startSection = tripPlan.getStartSection();
private Map<String, TerminalDeparturePlan> terminalPlanMap; TerminalDeparturePlan terminalPlan = terminalPlanMap.get(startSection.getCode());
if (Objects.isNull(terminalPlan)) {
private List<String> errMsgList; terminalPlan = new TerminalDeparturePlan(startSection.getCode());
terminalPlanMap.put(startSection.getCode(), terminalPlan);
public TerminalPlanBuildResult() { }
this.terminalPlanMap = new HashMap<>(); terminalPlan.addTripPlan(tripPlan);
this.errMsgList = new ArrayList<>(); }));
} terminalPlanMap.values().forEach(terminalDeparturePlan ->
} terminalDeparturePlan.getPlanList().sort((plan1, plan2) -> {
return plan1.getStartTime().compareTo(plan2.getStartTime());
/** }));
* 地图数据构建结果 return result;
*/ }
@Getter
public static class SimulationDeviceBuildResult { public static MapConfig buildConfig(RealLineConfigVO configVO) {
/** MapConfig mapConfig = new MapConfig();
* 地图设备map if (Objects.nonNull(configVO)) {
* key-设备code mapConfig.copyConfigBy(configVO);
* val-设备对象 }
*/ return mapConfig;
private Map<String, MapElement> deviceMap; }
/** /**
* 虚拟真实设备map * 地图基础数据检查和构建
* key-设备code * @param map
* val-虚拟真实设备对象 * @return
*/ */
private Map<String, VirtualRealityDevice> vrDeviceMap; public static SimulationDeviceBuildResult checkAndBuildBasicMapData(MapVO map) {
SimulationDeviceBuildResult mapDataBuildResult = new SimulationDeviceBuildResult();
/** MapDeviceBuilder.checkAndBuildMapDeviceData(map.getGraphDataNew(), mapDataBuildResult);
* 目的地码定义map return mapDataBuildResult;
* key-目的地码code }
*/
private Map<String, DestinationCodeDefinition> destinationMap = new HashMap<>(); /**
* 地图数据逻辑检查和构建
/** *
* 交路列表 * @param map
*/ * @return
@Setter */
private List<Routing> routingList; public static SimulationDeviceBuildResult checkAndBuildMapData(MapVO map) {
SimulationDeviceBuildResult mapDataBuildResult = new SimulationDeviceBuildResult();
/** MapDeviceBuilder.checkAndBuildMapDeviceData(map.getGraphDataNew(), mapDataBuildResult);
* 站间运行等级列表 if (CollectionUtils.isEmpty(mapDataBuildResult.getErrMsgList())) { // 基础数据没有问题再构建逻辑数据
*/ // InterlockBuilder.checkAndBuildMapCILogicData(map.getLogicDataNew(), mapDataBuildResult);
@Setter InterlockBuilder2.checkAndBuildMapCILogicData(map.getLogicDataNew(), mapDataBuildResult);
private List<StationRunLevel> runLevelList; List<MapStationParkingTimeVO> parkingTimeList = map.getLogicDataNew().getParkingTimeList();
if (CollectionUtils.isEmpty(parkingTimeList)) {
// /** mapDataBuildResult.errMsgList.add("无停站时间数据");
// * 路径单元map }
// */ }
// private Map<String, RouteUnit> routeUnitMap; return mapDataBuildResult;
}
/**
* 路径map public static SimulationDeviceBuildResult checkAndBuildMapDeviceData(MapVO map) {
*/ SimulationDeviceBuildResult mapDataBuildResult = new SimulationDeviceBuildResult();
private Map<String, List<RoutePath>> routePathMap; MapDeviceBuilder.checkAndBuildMapDeviceData(map.getGraphDataNew(), mapDataBuildResult);
return mapDataBuildResult;
/** }
* 接触网map
* key-sectionCode @Getter
*/ public static class TerminalPlanBuildResult {
private Map<String, Set<Catenary>> catenaryMap = new HashMap<>(); private Map<String, TerminalDeparturePlan> terminalPlanMap;
private Map<Section,List<Responder>> sectionRespondersMap; private List<String> errMsgList;
/** 默认停站时间map */ public TerminalPlanBuildResult() {
private Map<String, StationParkTime> parkTimeMap = new HashMap<>(); this.terminalPlanMap = new HashMap<>();
this.errMsgList = new ArrayList<>();
@Setter }
Map<String, Set<Section>> sectionArriveNearMap; }
Map<Station, List<Section>> parkingTracksMap = new HashMap<>(); /**
* 地图数据构建结果
/** */
* 数据错误信息列表 @Getter
*/ public static class SimulationDeviceBuildResult {
private List<String> errMsgList; /**
* 地图设备map
public SimulationDeviceBuildResult() { * key-设备code
this.deviceMap = new HashMap<>(); * val-设备对象
this.vrDeviceMap = new HashMap<>(); */
// this.routeUnitMap = new HashMap<>(); private Map<String, MapElement> deviceMap;
this.routePathMap = new HashMap<>();
this.sectionRespondersMap = new HashMap<>(); /**
this.errMsgList = new ArrayList<>(); * 虚拟真实设备map
} * key-设备code
} * val-虚拟真实设备对象
} */
private Map<String, VirtualRealityDevice> vrDeviceMap;
/**
* 目的地码定义map
* key-目的地码code
*/
private Map<String, DestinationCodeDefinition> destinationMap = new HashMap<>();
/**
* 交路列表
*/
@Setter
private List<Routing> routingList;
/**
* 站间运行等级列表
*/
@Setter
private List<StationRunLevel> runLevelList;
// /**
// * 路径单元map
// */
// private Map<String, RouteUnit> routeUnitMap;
/**
* 路径map
*/
private Map<String, List<RoutePath>> routePathMap;
/**
* 接触网map
* key-sectionCode
*/
private Map<String, Set<Catenary>> catenaryMap = new HashMap<>();
private Map<Section,List<Responder>> sectionRespondersMap;
/** 默认停站时间map */
private Map<String, StationParkTime> parkTimeMap = new HashMap<>();
@Setter
Map<String, Set<Section>> sectionArriveNearMap;
Map<Station, List<Section>> parkingTracksMap = new HashMap<>();
/**
* 数据错误信息列表
*/
private List<String> errMsgList;
public SimulationDeviceBuildResult() {
this.deviceMap = new HashMap<>();
this.vrDeviceMap = new HashMap<>();
// this.routeUnitMap = new HashMap<>();
this.routePathMap = new HashMap<>();
this.sectionRespondersMap = new HashMap<>();
this.errMsgList = new ArrayList<>();
}
}
}