Merge remote-tracking branch 'origin/ats-restruct' into ats-restruct

This commit is contained in:
joylink_zhangsai 2021-07-23 11:09:12 +08:00
commit 02924c0cb5
5 changed files with 216 additions and 51 deletions

View File

@ -10,6 +10,7 @@ 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.StationTurnBackStrategyOption;
import club.joylink.rtss.simulation.cbtc.data.vo.TrainInfo;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@ -74,10 +75,10 @@ public class AtsPlanTrainRouteSelectServiceImpl extends AtsRouteSelectService {
}
log.debug(String.format("列车[%s]筛选出的进路为:[%s]", trainInfo.getGroupNumber(), route.getName()));
if (route.isCheckConflict() && route.getConflictAlarm() == null) {
Object[] conflictInfos = this.checkConflict(repository, trainInfo, tripPlan, route, turnBack);
if (conflictInfos != null) {
Section startSection = (Section) conflictInfos[0];
StationPlan stationPlan = (StationPlan) conflictInfos[1];
ConflictInfo conflictInfo = this.checkConflict(repository, trainInfo, tripPlan, route);
if (conflictInfo != null) {
Section startSection = conflictInfo.section;
StationPlan stationPlan = conflictInfo.stationPlan;
String conflictDesc = String.format("计划车(%s(%s)触发的进路[%s]与计划(%s)从节点(%s_%s)到节点(%s_%s)的计划冲突,无法选排",
tripPlan.getStNumber(), trainInfo.getGroupNumber(), route.getName(),
stationPlan.getPlan().getStNumber(),
@ -94,37 +95,46 @@ public class AtsPlanTrainRouteSelectServiceImpl extends AtsRouteSelectService {
return route;
}
@Getter
public static class ConflictInfo {
Section section;
StationPlan stationPlan;
public ConflictInfo(Section section, StationPlan stationPlan) {
this.section = section;
this.stationPlan = stationPlan;
}
}
/**
* 检查进路是否和未完成的计划冲突
* @param repository
* @param trainInfo
* @param tripPlan
* @param route
* @return
*/
private Object[] checkConflict(SimulationDataRepository repository, TrainInfo trainInfo,
TripPlan tripPlan, Route route, boolean turnBack) {
public ConflictInfo checkConflict(SimulationDataRepository repository, TrainInfo trainInfo,
TripPlan tripPlan, Route route) {
Section section = repository.getByCode(trainInfo.getPlanStandTrack(), Section.class);
StationPlan stationPlan;
TripPlan nextTripPlan = null;
if (turnBack) { // 站后折返
nextTripPlan = repository.queryNextTripPlanOf(tripPlan);
stationPlan = nextTripPlan.getFirstStationPlan();
} else {
stationPlan = tripPlan.queryStationPlan(section);
LocalTime arriveTime = this.queryRouteArriveTime(repository, route, trainInfo, tripPlan, section);
if (arriveTime == null) {
log.debug(String.format("计划车[%s]未找到进路[%s]下一计划到达时间", trainInfo.getGroupNumber(), route.getName()));
return null;
}
TripPlan nextTripPlan = repository.queryNextTripPlanOf(tripPlan);
Section start = null;
StationPlan conflictStationPlan = null;
LocalTime arriveTime = stationPlan.getArriveTime();
Map<String, List<TripPlan>> serviceTripsMap = repository.getServiceTripsMap();
for (List<TripPlan> planList : serviceTripsMap.values()) {
for (TripPlan plan : planList) {
if (turnBack && plan.isRight() == tripPlan.isRight()) {
continue;
}
if (plan.equals(tripPlan)) {
continue;
}
if (turnBack && plan.equals(nextTripPlan)) {
if (plan.equals(nextTripPlan)) {
continue;
}
if (!plan.getStartTime().isBefore(arriveTime)) {
if (plan.getStartTime().isAfter(arriveTime)) {
break;
}
List<StationPlan> stationPlanList = plan.getPlanList();
@ -147,12 +157,6 @@ public class AtsPlanTrainRouteSelectServiceImpl extends AtsRouteSelectService {
}
start = temp.getSection();
}
// if (aheadTrain != null && plan.isLastPlanStationSection(start)) {
// if (this.isConflict(repository, route, aheadTrain, start, plan.getEndSection())) {
// conflictStationPlan = plan.getLastStationPlan();
// break;
// }
// }
if (conflictStationPlan != null) {
break;
}
@ -165,12 +169,137 @@ public class AtsPlanTrainRouteSelectServiceImpl extends AtsRouteSelectService {
log.debug(String.format("列车[%s]的进路[%s]和未完成车站计划[%s]冲突",
trainInfo.getGroupNumber(), route.getName(),
String.format("%s{%s}", conflictStationPlan.getPlan().getStNumber(), conflictStationPlan.debugStr())));
return new Object[] {start, conflictStationPlan};
return new ConflictInfo(start, conflictStationPlan);
}
return null;
}
private boolean isConflict(SimulationDataRepository repository, Route route, TrainInfo aheadTrain, Section start, Section end) {
/**
* 查询所需办理进路所需到达的计划时间
* @param repository
* @param route
* @param trainInfo
* @param tripPlan
* @param nextPlanSection
* @return
*/
private LocalTime queryRouteArriveTime(SimulationDataRepository repository, Route route,
TrainInfo trainInfo, TripPlan tripPlan, Section nextPlanSection) {
boolean start = false;
List<StationPlan> planList = tripPlan.getPlanList();
for (int i = 0; i < planList.size(); i++) {
StationPlan stationPlan = planList.get(i);
if (stationPlan.getSection().equals(nextPlanSection)) {
start = true;
}
if (start) {
List<RoutePath> routePathList = repository.queryRoutePathsByEnd(stationPlan.getSection());
for (RoutePath routePath : routePathList) {
if (routePath.isPathRoute(route)) {
return stationPlan.getArriveTime();
}
}
if (i == planList.size() - 1) { // 最后一站,判断是否站后折返
if (tripPlan.isBehindTurnBack()) {
routePathList = repository.queryRoutePathsByStart(stationPlan.getSection());
for (RoutePath routePath : routePathList) {
if (routePath.isPathRoute(route)) {
TripPlan nextTripPlan = repository.queryNextTripPlanOf(tripPlan);
return nextTripPlan.getFirstStationPlan().getArriveTime();
}
}
} else if (!Objects.equals(tripPlan.getEndSection(), stationPlan.getSection())) {
routePathList = repository.getRoutePaths(stationPlan.getSection(), tripPlan.getEndSection());
for (RoutePath routePath : routePathList) {
if (routePath.isPathRoute(route)) {
return tripPlan.getEndTime();
}
}
}
}
}
}
return null;
}
//
// /**
// * 检查进路是否和未完成的计划冲突
// * @return
// */
// public Object[] checkConflict(SimulationDataRepository repository, TrainInfo trainInfo,
// TripPlan tripPlan, Route route, boolean turnBack) {
// Section section = repository.getByCode(trainInfo.getPlanStandTrack(), Section.class);
// StationPlan stationPlan;
// TripPlan nextTripPlan = null;
// if (turnBack) { // 站后折返
// nextTripPlan = repository.queryNextTripPlanOf(tripPlan);
// stationPlan = nextTripPlan.getFirstStationPlan();
// } else {
// stationPlan = tripPlan.queryStationPlan(section);
// }
// Section start = null;
// StationPlan conflictStationPlan = null;
// LocalTime arriveTime = stationPlan.getArriveTime();
// Map<String, List<TripPlan>> serviceTripsMap = repository.getServiceTripsMap();
// for (List<TripPlan> planList : serviceTripsMap.values()) {
// for (TripPlan plan : planList) {
// if (turnBack && plan.isRight() == tripPlan.isRight()) {
// continue;
// }
// if (plan.equals(tripPlan)) {
// continue;
// }
// if (turnBack && plan.equals(nextTripPlan)) {
// continue;
// }
// if (!plan.getStartTime().isBefore(arriveTime)) {
// break;
// }
// List<StationPlan> stationPlanList = plan.getPlanList();
// TrainInfo aheadTrain = repository.queryAtsTrainInfoOfTripPlan(plan);
// start = plan.getStartSection();
// for (StationPlan temp : stationPlanList) {
// if (temp.getArriveTime().isAfter(arriveTime)) {
// break;
// }
// if (!temp.isFinished()) {
// if (!start.equals(temp.getSection())) {
// if(this.isConflict(repository, route, aheadTrain, start, temp.getSection())){
// conflictStationPlan = temp;
// break;
// }
// }
// }
// if (conflictStationPlan != null) {
// break;
// }
// start = temp.getSection();
// }
//// if (aheadTrain != null && plan.isLastPlanStationSection(start)) {
//// if (this.isConflict(repository, route, aheadTrain, start, plan.getEndSection())) {
//// conflictStationPlan = plan.getLastStationPlan();
//// break;
//// }
//// }
// if (conflictStationPlan != null) {
// break;
// }
// }
// if (conflictStationPlan != null) {
// break;
// }
// }
// if (conflictStationPlan != null) {
// log.debug(String.format("列车[%s]的进路[%s]和未完成车站计划[%s]冲突",
// trainInfo.getGroupNumber(), route.getName(),
// String.format("%s{%s}", conflictStationPlan.getPlan().getStNumber(), conflictStationPlan.debugStr())));
// return new Object[] {start, conflictStationPlan};
// }
// return null;
// }
private boolean isConflict(SimulationDataRepository repository, Route route,
TrainInfo aheadTrain, Section start, Section end) {
if (start.equals(end)) {
return false;
}
@ -181,6 +310,14 @@ public class AtsPlanTrainRouteSelectServiceImpl extends AtsRouteSelectService {
conflict = true;
if (aheadTrain != null) {
if (routePath.containsSection(aheadTrain.getPhysicalSection())) {//前车在此计划路径中
Map<String, Route> atsTriggerRouteMap = aheadTrain.getAtsTriggerRouteMap();
if (!atsTriggerRouteMap.isEmpty()) {
for (Route triggerRoute : atsTriggerRouteMap.values()) {
if (triggerRoute.isConflictWith(route) && (triggerRoute.isSetting() || triggerRoute.isOpen())) {
return false;
}
}
}
if (routePath.isRight() == route.isRight()) {
if (routePath.containsSection(route.getFirstRouteSection()) &&
routePath.getSectionSort(route.getFirstRouteSection()) <= routePath.getSectionSort(aheadTrain.getPhysicalSection())) {
@ -191,7 +328,7 @@ public class AtsPlanTrainRouteSelectServiceImpl extends AtsRouteSelectService {
// 前车已经走过区段非冲突
return false;
}
} else if(routePath.isRight() != route.isRight()) { // 相反方向
} else if (routePath.isRight() != route.isRight()) { // 相反方向
// 列车是否已经经过敌对进路
if (routePath.containsSection(route.getLastRouteSection()) &&
routePath.getSectionSort(route.getLastRouteSection()) <= routePath.getSectionSort(aheadTrain.getPhysicalSection())) {

View File

@ -40,10 +40,25 @@ public class AtsTriggerRouteService {
if (route.isSetting()) {
return;
}
if (route.getConflictAlarm() != null && route.isOpen()) {
if (route.getConflictAlarm() != null) {
if (route.isOpen()) {
route.getConflictAlarm().recover(simulation.getCorrectSystemTime());
route.setConflictAlarm(null);
continue;
} else if (route.isConflictHandleRunAsPlan()) {
if (trainInfo.isPlanTrain()) {
SimulationDataRepository repository = simulation.getRepository();
TripPlan tripPlan = repository.getTripPlan(trainInfo.getServiceNumber(), trainInfo.getTripNumber());
AtsPlanTrainRouteSelectServiceImpl.ConflictInfo conflictInfo = this.planTrainRouteSelectService.checkConflict(repository, trainInfo, tripPlan, route);
if (conflictInfo != null) {
return;
} else {
route.getConflictAlarm().recover(simulation.getCorrectSystemTime());
route.setConflictAlarm(null);
this.trySetRoute(simulation, trainInfo, route);
}
}
}
}
if (!route.isOpen()) { // 存在未开放的进路直接返回
if(!route.isSetting()){ // 进路未办理继续尝试办理
@ -74,8 +89,8 @@ public class AtsTriggerRouteService {
}
if (route.isCheckConflict() && route.getConflictAlarm() != null) {
if (!route.isConflictConfirmed() ||
(route.isConflictConfirmed() && Route.Conflict_Handle_Way_1 == route.getConflictAlarm().getConfirmParam())) {
// 进路冲突且进路检查冲突且用户确认按计划执行不办理返回
route.isConflictHandleRunAsPlan()) {
// 进路冲突且进路检查冲突且用户未确认或确认按计划执行不办理返回
return;
}
}

View File

@ -400,6 +400,14 @@ public class Route extends MapNamedElement {
if (this.containConflictSwitch(route2.getSwitchList())) {
return true;
}
if (route2.getOverlap() != null && route2.getOverlap().isOnlyOnePath() &&
this.containConflictSwitch(route2.getOverlap().getFirstPath().getSwitchList())) {
return true;
}
if (this.getOverlap() != null && this.getOverlap().isOnlyOnePath() &&
route2.containConflictSwitch(this.getOverlap().getFirstPath().getSwitchList())) {
return true;
}
return false;
}
@ -596,6 +604,10 @@ public class Route extends MapNamedElement {
return this.conflictAlarm!=null && this.conflictAlarm.isConfirmed();
}
public boolean isConflictHandleRunAsPlan() {
return this.conflictAlarm!=null && Route.Conflict_Handle_Way_1 == this.conflictAlarm.getConfirmParam();
}
/**
* 进路检查失败原因
*/

View File

@ -88,6 +88,23 @@ public class RouteStatus extends DeviceStatus {
this.checkConflict = route.isCheckConflict();
}
@Override
public DeviceStatusVO convert2VO(MapElement device) {
RouteStatusVO statusVO = new RouteStatusVO((Route) device);
statusVO.setCbtcMode(cbtcMode);
statusVO.setAtsControl(atsControl);
statusVO.setFleetMode(fleetMode);
statusVO.setCiControl(ciControl);
statusVO.setSettable(settable);
statusVO.setSetting(setting);
statusVO.setSettingGuide(settingGuide);
statusVO.setLock(lock);
statusVO.setCanceling(canceling);
statusVO.setNormalUnlock(normalUnlock);
statusVO.setCheckConflict(checkConflict);
return statusVO;
}
@Override
public boolean compareAndChange(MapElement device, DeviceStatusVO statusVO) {
Route route = (Route) device;
@ -158,20 +175,4 @@ public class RouteStatus extends DeviceStatus {
return change;
}
@Override
public DeviceStatusVO convert2VO(MapElement device) {
RouteStatusVO statusVO = new RouteStatusVO((Route) device);
statusVO.setNormalUnlock(normalUnlock);
statusVO.setCanceling(canceling);
statusVO.setLock(lock);
statusVO.setSettingGuide(settingGuide);
statusVO.setSettable(settable);
statusVO.setSetting(setting);
statusVO.setCiControl(ciControl);
statusVO.setFleetMode(fleetMode);
statusVO.setAtsControl(atsControl);
statusVO.setCbtcMode(cbtcMode);
return statusVO;
}
}

View File

@ -55,7 +55,7 @@ public class RouteStatusVO extends DeviceStatusVO {
/** 检查冲突功能是否开启 */
@JsonSerialize(using = Boolean2NumSerializer.class)
private boolean checkConflict;
private Boolean checkConflict;
public RouteStatusVO(Route route) {
super(route.getCode(), route.getDeviceType());