Merge remote-tracking branch 'origin/test' into test
This commit is contained in:
commit
dd434fe399
@ -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<JumpStrategy> {
|
||||
|
||||
@Override
|
||||
public List<JumpStrategy> generateStrategy(StrategyCalculateData data) {
|
||||
List<JumpStrategy> list = new ArrayList<>();
|
||||
Stand stand = null;
|
||||
// 暂时按一个站大客流处理
|
||||
List<StandPassenger> standPassengerList = data.getAllStandPassengerList();
|
||||
for (StandPassenger standPassenger : standPassengerList) {
|
||||
if (standPassenger.isLpf()) {
|
||||
stand = standPassenger.getStand();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (stand == null) {
|
||||
return null;
|
||||
}
|
||||
List<Stand> leftStandList = data.getLeftStandList();
|
||||
List<Stand> 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<TrainPassenger> trainPassengerList = data.getTrainPassengerList();
|
||||
Map<String, RealRun> 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<StationPlan> 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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -118,6 +118,22 @@ public class StrategyCalculateData {
|
||||
return new ArrayList<>(this.standPassengerMap.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询大客流站
|
||||
* @return
|
||||
*/
|
||||
public List<StandPassenger> queryLpfList() {
|
||||
List<StandPassenger> lpfList = new ArrayList<>();
|
||||
List<StandPassenger> standPassengerList = this.getAllStandPassengerList();
|
||||
for (StandPassenger standPassenger : standPassengerList) {
|
||||
if (standPassenger.isLpf()) {
|
||||
lpfList.add(standPassenger);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return lpfList;
|
||||
}
|
||||
|
||||
public TripPlan queryTripPlan(String serviceNumber, String tripNumber) {
|
||||
List<TripPlan> tripPlanList = this.planMap.get(serviceNumber);
|
||||
if (CollectionUtils.isEmpty(tripPlanList)) {
|
||||
|
@ -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<JumpStrategy> {
|
||||
|
||||
@Override
|
||||
public List<JumpStrategy> generateStrategy(StrategyCalculateData data) {
|
||||
List<JumpStrategy> list = new ArrayList<>();
|
||||
List<StandPassenger> lpfList = data.queryLpfList();
|
||||
if (CollectionUtils.isEmpty(lpfList)) {
|
||||
return null;
|
||||
}
|
||||
// 暂时按一个站大客流处理
|
||||
StandPassenger standPassenger = lpfList.get(0);
|
||||
Stand stand = standPassenger.getStand();
|
||||
List<Stand> leftStandList = data.getLeftStandList();
|
||||
List<Stand> 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<Stand> jumpableStandList = new ArrayList<>();
|
||||
if (right) {
|
||||
jumpableStandList = rightStandList.subList(0, index);
|
||||
} else {
|
||||
jumpableStandList = leftStandList.subList(0, index);
|
||||
}
|
||||
List<TrainPassenger> 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;
|
||||
}
|
||||
}
|
@ -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<ParkTimeStra
|
||||
@Override
|
||||
public List<ParkTimeStrategy> generateStrategy(StrategyCalculateData data) {
|
||||
List<ParkTimeStrategy> list = new ArrayList<>();
|
||||
Stand stand = null;
|
||||
// 暂时按一个站大客流处理
|
||||
List<StandPassenger> standPassengerList = data.getAllStandPassengerList();
|
||||
for (StandPassenger standPassenger : standPassengerList) {
|
||||
if (standPassenger.isLpf()) {
|
||||
stand = standPassenger.getStand();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (stand == null) {
|
||||
List<StandPassenger> lpfList = data.queryLpfList();
|
||||
if (CollectionUtils.isEmpty(lpfList)) {
|
||||
return null;
|
||||
}
|
||||
// 暂时按一个站大客流处理
|
||||
Stand stand = lpfList.get(0).getStand();
|
||||
Map<String, List<TripPlan>> planMap = data.getPlanMap();
|
||||
int planParkTime = 0; // 计划停站时间
|
||||
for (List<TripPlan> planList : planMap.values()) {
|
@ -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;
|
Loading…
Reference in New Issue
Block a user