From e9976772de07e6d8ddae88b1c581204095ea6002 Mon Sep 17 00:00:00 2001 From: walker-sheng Date: Fri, 29 Jan 2021 18:04:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=A2=E6=B5=81=E7=AD=96=E7=95=A5=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../strategy/JumpStrategyServiceImpl.java | 163 ------------------ .../StrategyCalculateAndRecommendService.java | 1 + .../passenger/strategy/data/JumpStrategy.java | 5 + .../strategy/data/StrategyCalculateData.java | 16 ++ .../service/JumpStrategyServiceImpl.java | 87 ++++++++++ .../ParkTimeStrategyServiceImpl.java | 18 +- .../{ => service}/StrategyService.java | 2 +- 7 files changed, 117 insertions(+), 175 deletions(-) delete mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/passenger/strategy/JumpStrategyServiceImpl.java create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/passenger/strategy/service/JumpStrategyServiceImpl.java rename src/main/java/club/joylink/rtss/simulation/cbtc/passenger/strategy/{ => service}/ParkTimeStrategyServiceImpl.java (95%) rename src/main/java/club/joylink/rtss/simulation/cbtc/passenger/strategy/{ => service}/StrategyService.java (95%) diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/passenger/strategy/JumpStrategyServiceImpl.java b/src/main/java/club/joylink/rtss/simulation/cbtc/passenger/strategy/JumpStrategyServiceImpl.java deleted file mode 100644 index 2a7301368..000000000 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/passenger/strategy/JumpStrategyServiceImpl.java +++ /dev/null @@ -1,163 +0,0 @@ -package club.joylink.rtss.simulation.cbtc.passenger.strategy; - -import club.joylink.rtss.exception.BusinessExceptionAssertEnum; -import club.joylink.rtss.simulation.cbtc.data.map.Stand; -import club.joylink.rtss.simulation.cbtc.data.plan.RealRun; -import club.joylink.rtss.simulation.cbtc.data.plan.StationPlan; -import club.joylink.rtss.simulation.cbtc.data.plan.TripPlan; -import club.joylink.rtss.simulation.cbtc.passenger.strategy.data.JumpStrategy; -import club.joylink.rtss.simulation.cbtc.passenger.strategy.data.StandPassenger; -import club.joylink.rtss.simulation.cbtc.passenger.strategy.data.StrategyCalculateData; -import club.joylink.rtss.simulation.cbtc.passenger.strategy.data.TrainPassenger; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Component; - -import java.time.LocalTime; -import java.util.*; - -@Slf4j -@Component -public class JumpStrategyServiceImpl implements StrategyService { - - @Override - public List generateStrategy(StrategyCalculateData data) { - List list = new ArrayList<>(); - Stand stand = null; - // 暂时按一个站大客流处理 - List standPassengerList = data.getAllStandPassengerList(); - for (StandPassenger standPassenger : standPassengerList) { - if (standPassenger.isLpf()) { - stand = standPassenger.getStand(); - break; - } - } - if (stand == null) { - return null; - } - List leftStandList = data.getLeftStandList(); - List rightStandList = data.getRightStandList(); - boolean right = false; - int index = leftStandList.indexOf(stand); - if (index < 0) { - // 不是左向站台 - right = true; - index = rightStandList.indexOf(stand); - } - BusinessExceptionAssertEnum.DATA_ERROR.assertTrue(index >= 0, String.format("未找到站台[%s]", stand.debugStr())); - - log.debug(String.format("生成跳停策略[%s]个", list.size())); - return list; - } - - @Override - public void calculate(StrategyCalculateData data, JumpStrategy strategy) { - // 系统时间 - LocalTime systemTime = data.getSystemTime().toLocalTime();// 系统当前时间 - LocalTime endTime = systemTime.plusMinutes(Config.STRATEGY_CAL_TIME);// 预测计算终点 - List trainPassengerList = data.getTrainPassengerList(); - Map trainPreviousMap = new HashMap<>(); // 列车上一个到站/发车数据 - int i = 0; - while (systemTime.isBefore(endTime) && i<1000) { // 在计算时间内 - ++i; - if (i > 999) { - log.error("死循环--------------------------"); - } - LocalTime nextTime = null; - for (TrainPassenger trainPassenger : trainPassengerList) { - String groupNumber = trainPassenger.getGroupNumber(); - TripPlan tripPlan = data.queryTripPlan(trainPassenger.getServiceNumber(), trainPassenger.getTripNumber()); - if (tripPlan == null) { // 未找到计划,跳过 - log.warn(String.format("列车[%s-%s|%s]没有找到车次计划", - groupNumber, trainPassenger.getServiceNumber(), trainPassenger.getTripNumber())); - continue; - } - if (tripPlan.isBackup()) { - continue; - } - // 上一实际到发 - RealRun realRun = trainPreviousMap.get(groupNumber); - if (realRun == null) { - realRun = data.queryPreviousRealRunData(groupNumber); - if (realRun != null) { - trainPreviousMap.put(groupNumber, realRun); - } - } - List planList = tripPlan.getPlanList(); - int offsetTime = 0; - StationPlan nextStationPlan = null; - if (realRun != null && - Objects.equals(tripPlan.getServiceNumber(), realRun.getServiceNumber()) && - Objects.equals(tripPlan.getTripNumber(), realRun.getTripNumber())) { - // 上一实际运行数据存在且在当前计划中 - // 查询实际运行到的车站计划 - StationPlan stationPlan = tripPlan.queryStationPlanByStationCode(realRun.getStationCode()); - BusinessExceptionAssertEnum.DATA_ERROR.assertNotNull(stationPlan); - LocalTime leaveTime = stationPlan.getLeaveTime(); - if (realRun.isArrive()) { - // 是到达车站的计划,预测离站 - LocalTime arriveTime = stationPlan.getArriveTime(); - if (!tripPlan.isFirstPlan(stationPlan)) { - offsetTime = realRun.getTime().toLocalTime().toSecondOfDay() - arriveTime.toSecondOfDay(); - } - RealRun leave = this.handleTrainLeave(data, strategy, trainPassenger, tripPlan, stationPlan, offsetTime); - - trainPreviousMap.put(groupNumber, leave); - } else { - offsetTime = realRun.getTime().toLocalTime().toSecondOfDay() - leaveTime.toSecondOfDay(); - } - if (tripPlan.isLastPlan(stationPlan)) { - // 最后一个到发计划,获取下一个折返后车次计划 - TripPlan nextTripPlan = data.queryNextTripPlan(tripPlan); - if (nextTripPlan != null) { - tripPlan = nextTripPlan; - nextStationPlan = nextTripPlan.getFirstStationPlan(); - } - } else { - nextStationPlan = tripPlan.queryNextStationPlanByStationCode(realRun.getStationCode()); - } - } else { - for (StationPlan stationPlan : planList) { - if (stationPlan.getArriveTime().compareTo(systemTime) >= 0) { - nextStationPlan = stationPlan; - break; - } - } - } - if (nextStationPlan != null) { - LocalTime arriveTime = nextStationPlan.getArriveTime(); - RealRun arrive = this.buildRealRun(groupNumber, tripPlan, nextStationPlan, true, arriveTime, offsetTime, data.getSystemTime()); - data.addRealRun(arrive); - RealRun leave = this.handleTrainLeave(data, strategy, trainPassenger, tripPlan, nextStationPlan, offsetTime); - data.addRealRun(leave); - trainPreviousMap.put(groupNumber, leave); - if (nextTime == null || leave.getTime().toLocalTime().isBefore(nextTime)) { - nextTime = leave.getTime().toLocalTime(); - } - } - } - BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(nextTime); - systemTime = nextTime; - } - strategy.setCoTarget(strategy.getTarget1()*strategy.getW1()+strategy.getTarget2()*strategy.getW2()); - } - - @Override - public String getName() { - return "跳停策略服务"; - } - - private RealRun handleTrainLeave(StrategyCalculateData data, JumpStrategy strategy, TrainPassenger trainPassenger, - TripPlan tripPlan, StationPlan stationPlan, int offsetTime) { - Stand stand = strategy.getStand(); - LocalTime arriveTime = stationPlan.getArriveTime(); - LocalTime leaveTime = stationPlan.getLeaveTime(); - // 生成预测实际运行图 - RealRun leave = this.buildRealRun(trainPassenger.getGroupNumber(), tripPlan, stationPlan, false, leaveTime, offsetTime, data.getSystemTime()); - data.addRealRun(leave); - // 大客流站计算指标 - if (Objects.equals(stationPlan.getSection(), stand.getSection())) { - - } - return leave; - } -} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/passenger/strategy/StrategyCalculateAndRecommendService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/passenger/strategy/StrategyCalculateAndRecommendService.java index d60f9e212..042b1c422 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/passenger/strategy/StrategyCalculateAndRecommendService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/passenger/strategy/StrategyCalculateAndRecommendService.java @@ -2,6 +2,7 @@ package club.joylink.rtss.simulation.cbtc.passenger.strategy; import club.joylink.rtss.simulation.cbtc.passenger.strategy.data.Strategy; import club.joylink.rtss.simulation.cbtc.passenger.strategy.data.StrategyCalculateData; +import club.joylink.rtss.simulation.cbtc.passenger.strategy.service.StrategyService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/passenger/strategy/data/JumpStrategy.java b/src/main/java/club/joylink/rtss/simulation/cbtc/passenger/strategy/data/JumpStrategy.java index 7eafbd335..4e424b8ad 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/passenger/strategy/data/JumpStrategy.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/passenger/strategy/data/JumpStrategy.java @@ -11,6 +11,11 @@ public class JumpStrategy extends Strategy { */ @JsonIgnore Stand stand; + private String groupNumber; + /** 服务号 */ + String serviceNumber; + /** 车次号 */ + String tripNumber; public JumpStrategy(Stand stand) { super(Type.JUMP); diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/passenger/strategy/data/StrategyCalculateData.java b/src/main/java/club/joylink/rtss/simulation/cbtc/passenger/strategy/data/StrategyCalculateData.java index 6f57c32ff..330cc0fdf 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/passenger/strategy/data/StrategyCalculateData.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/passenger/strategy/data/StrategyCalculateData.java @@ -118,6 +118,22 @@ public class StrategyCalculateData { return new ArrayList<>(this.standPassengerMap.values()); } + /** + * 查询大客流站 + * @return + */ + public List queryLpfList() { + List lpfList = new ArrayList<>(); + List standPassengerList = this.getAllStandPassengerList(); + for (StandPassenger standPassenger : standPassengerList) { + if (standPassenger.isLpf()) { + lpfList.add(standPassenger); + break; + } + } + return lpfList; + } + public TripPlan queryTripPlan(String serviceNumber, String tripNumber) { List tripPlanList = this.planMap.get(serviceNumber); if (CollectionUtils.isEmpty(tripPlanList)) { diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/passenger/strategy/service/JumpStrategyServiceImpl.java b/src/main/java/club/joylink/rtss/simulation/cbtc/passenger/strategy/service/JumpStrategyServiceImpl.java new file mode 100644 index 000000000..291a86f79 --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/passenger/strategy/service/JumpStrategyServiceImpl.java @@ -0,0 +1,87 @@ +package club.joylink.rtss.simulation.cbtc.passenger.strategy.service; + +import club.joylink.rtss.exception.BusinessExceptionAssertEnum; +import club.joylink.rtss.simulation.cbtc.data.map.Stand; +import club.joylink.rtss.simulation.cbtc.data.plan.RealRun; +import club.joylink.rtss.simulation.cbtc.data.plan.StationPlan; +import club.joylink.rtss.simulation.cbtc.data.plan.TripPlan; +import club.joylink.rtss.simulation.cbtc.passenger.strategy.data.JumpStrategy; +import club.joylink.rtss.simulation.cbtc.passenger.strategy.data.StandPassenger; +import club.joylink.rtss.simulation.cbtc.passenger.strategy.data.StrategyCalculateData; +import club.joylink.rtss.simulation.cbtc.passenger.strategy.data.TrainPassenger; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; + +import java.time.LocalTime; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +@Slf4j +@Component +public class JumpStrategyServiceImpl implements StrategyService { + + @Override + public List generateStrategy(StrategyCalculateData data) { + List list = new ArrayList<>(); + List lpfList = data.queryLpfList(); + if (CollectionUtils.isEmpty(lpfList)) { + return null; + } + // 暂时按一个站大客流处理 + StandPassenger standPassenger = lpfList.get(0); + Stand stand = standPassenger.getStand(); + List leftStandList = data.getLeftStandList(); + List rightStandList = data.getRightStandList(); + boolean right = false; + int index = leftStandList.indexOf(stand); + if (index < 0) { + // 不是左向站台 + right = true; + index = rightStandList.indexOf(stand); + } + BusinessExceptionAssertEnum.DATA_ERROR.assertTrue(index >= 0, String.format("未找到站台[%s]", stand.debugStr())); + log.debug(String.format("[%s]第[%s]个站台大客流", right?"右向":"左向", (index+1))); + + if (index == 0) { + // 第一站,不生成跳停策略 + log.debug(String.format("第一个站,不生成跳停策略")); + return null; + } + List jumpableStandList = new ArrayList<>(); + if (right) { + jumpableStandList = rightStandList.subList(0, index); + } else { + jumpableStandList = leftStandList.subList(0, index); + } + List trainPassengerList = data.getTrainPassengerList(); + + log.debug(String.format("生成跳停策略[%s]个", list.size())); + return list; + } + + @Override + public void calculate(StrategyCalculateData data, JumpStrategy strategy) { + } + + @Override + public String getName() { + return "跳停策略服务"; + } + + private RealRun handleTrainLeave(StrategyCalculateData data, JumpStrategy strategy, TrainPassenger trainPassenger, + TripPlan tripPlan, StationPlan stationPlan, int offsetTime) { + Stand stand = strategy.getStand(); + LocalTime arriveTime = stationPlan.getArriveTime(); + LocalTime leaveTime = stationPlan.getLeaveTime(); + // 生成预测实际运行图 + RealRun leave = this.buildRealRun(trainPassenger.getGroupNumber(), tripPlan, stationPlan, false, leaveTime, offsetTime, data.getSystemTime()); + data.addRealRun(leave); + // 大客流站计算指标 + if (Objects.equals(stationPlan.getSection(), stand.getSection())) { + + } + return leave; + } +} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/passenger/strategy/ParkTimeStrategyServiceImpl.java b/src/main/java/club/joylink/rtss/simulation/cbtc/passenger/strategy/service/ParkTimeStrategyServiceImpl.java similarity index 95% rename from src/main/java/club/joylink/rtss/simulation/cbtc/passenger/strategy/ParkTimeStrategyServiceImpl.java rename to src/main/java/club/joylink/rtss/simulation/cbtc/passenger/strategy/service/ParkTimeStrategyServiceImpl.java index f33730c9c..0fe232ce0 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/passenger/strategy/ParkTimeStrategyServiceImpl.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/passenger/strategy/service/ParkTimeStrategyServiceImpl.java @@ -1,16 +1,18 @@ -package club.joylink.rtss.simulation.cbtc.passenger.strategy; +package club.joylink.rtss.simulation.cbtc.passenger.strategy.service; import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.simulation.cbtc.data.map.Stand; import club.joylink.rtss.simulation.cbtc.data.plan.RealRun; import club.joylink.rtss.simulation.cbtc.data.plan.StationPlan; import club.joylink.rtss.simulation.cbtc.data.plan.TripPlan; +import club.joylink.rtss.simulation.cbtc.passenger.strategy.Config; import club.joylink.rtss.simulation.cbtc.passenger.strategy.data.ParkTimeStrategy; import club.joylink.rtss.simulation.cbtc.passenger.strategy.data.StandPassenger; import club.joylink.rtss.simulation.cbtc.passenger.strategy.data.StrategyCalculateData; import club.joylink.rtss.simulation.cbtc.passenger.strategy.data.TrainPassenger; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; import java.time.LocalTime; import java.util.*; @@ -22,18 +24,12 @@ public class ParkTimeStrategyServiceImpl implements StrategyService generateStrategy(StrategyCalculateData data) { List list = new ArrayList<>(); - Stand stand = null; - // 暂时按一个站大客流处理 - List standPassengerList = data.getAllStandPassengerList(); - for (StandPassenger standPassenger : standPassengerList) { - if (standPassenger.isLpf()) { - stand = standPassenger.getStand(); - break; - } - } - if (stand == null) { + List lpfList = data.queryLpfList(); + if (CollectionUtils.isEmpty(lpfList)) { return null; } + // 暂时按一个站大客流处理 + Stand stand = lpfList.get(0).getStand(); Map> planMap = data.getPlanMap(); int planParkTime = 0; // 计划停站时间 for (List planList : planMap.values()) { diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/passenger/strategy/StrategyService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/passenger/strategy/service/StrategyService.java similarity index 95% rename from src/main/java/club/joylink/rtss/simulation/cbtc/passenger/strategy/StrategyService.java rename to src/main/java/club/joylink/rtss/simulation/cbtc/passenger/strategy/service/StrategyService.java index 616de3247..35cb0c6e4 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/passenger/strategy/StrategyService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/passenger/strategy/service/StrategyService.java @@ -1,4 +1,4 @@ -package club.joylink.rtss.simulation.cbtc.passenger.strategy; +package club.joylink.rtss.simulation.cbtc.passenger.strategy.service; import club.joylink.rtss.simulation.cbtc.data.plan.RealRun; import club.joylink.rtss.simulation.cbtc.data.plan.StationPlan;