This commit is contained in:
DU 2021-01-27 18:17:43 +08:00
commit 62edf56871
9 changed files with 237 additions and 20 deletions

View File

@ -157,6 +157,10 @@ public class AtsPlanService {
hold = this.atsStandService.isHoldTrain(target);
}
// 更新跳停状态
if (jump && Objects.equals(tripPlan.getLastStationPlan().getStation(), target.getStation())) {
// 最后一站不跳停
jump = false;
}
if (!Objects.equals(train.isJump(), jump)) {
if (jump) {
this.onboardAtpApiService.setJump(simulation, train.getGroupNumber());
@ -365,7 +369,8 @@ public class AtsPlanService {
}
LocalTime arriveTime = systemTime.plusSeconds(intervalRunTime);
train.updateEstimatedArriveInfo(nextStationPlan.getSection(), arriveTime);
if (this.atsStandService.isJump(nextStationPlan.getSection(), train.getGroupNumber())) {
if (!tripPlan.isLastPlan(nextStationPlan) &&
this.atsStandService.isJump(nextStationPlan.getSection(), train.getGroupNumber())) {
this.onboardAtpApiService.setJump(simulation, train.getGroupNumber());
}
} else {

View File

@ -296,7 +296,6 @@ public class PassengerFlowSimulateService {
StandTimePassengerFlowData flowData = standTimePassengerFlowDataMap.get(stand.getCode());
StandTimePassengerFlowData preData = preTimePassengerFlowDataMap.get(stand.getCode());
int add = flowData.getNum() - preData.getNum();
log.debug(String.format("站台[%s]增加乘客: %s", stand.debugStr(), add));
if (add < 0) {
// 列车拉走了站台上的人
if (flowData.getNum() != 0 && preData.getNum() > 1000) {
@ -305,6 +304,7 @@ public class PassengerFlowSimulateService {
add = flowData.getNum();
}
}
log.debug(String.format("站台[%s]增加乘客: %s", stand.debugStr(), add));
int total = standPassengerFlow.plus(add);
sendData.put("standCode", stand.getCode());
sendData.put("num", total);
@ -392,7 +392,7 @@ public class PassengerFlowSimulateService {
// 如果没有数据默认下车5%的人
down = (int) (trainPassengerFlow.getPassengerQuantity() * 0.05);
}
trainPassengerFlow.minus(down);
down = trainPassengerFlow.minus(down);
}
sendData.put("out", down);
// 上车
@ -406,6 +406,7 @@ public class PassengerFlowSimulateService {
}
trainPassengerFlow.plus(up);
sendData.put("in", up);
sendData.put("remain", trainPassengerFlow.getPassengerQuantity());
String json = JsonUtils.writeValueNullableFieldAsString(sendData);
SocketMessageVO<String> message = SocketMessageFactory.build(

View File

@ -24,13 +24,15 @@ public class TrainPassengerFlow {
this.off = false;
}
public void minus(int num) {
public int minus(int num) {
this.off = true;
if (this.passengerQuantity < num) {
num = this.passengerQuantity;
this.passengerQuantity = 0;
} else {
this.passengerQuantity -= num;
}
this.off = true;
return num;
}
public void plus(int up) {

View File

@ -0,0 +1,158 @@
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());
}
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;
}
}

View File

@ -58,6 +58,7 @@ public class LargePassengerFlowStrategyService {
for (ParkTimeStrategy parkTimeStrategy : parkTimeStrategies) {
this.parkTimeStrategyService.calculate(strategyCalculateData.clone(), parkTimeStrategy);
parkTimeStrategy.buildDescription();
parkTimeStrategy.handleTarget();
log.info(String.format("停站时间策略[%s]计算指标为:%s", parkTimeStrategy.getDescription(),
parkTimeStrategy.targetDebugStr()));
}

View File

@ -79,15 +79,6 @@ public class ParkTimeStrategyServiceImpl implements StrategyService<ParkTimeStra
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) {
@ -96,6 +87,20 @@ public class ParkTimeStrategyServiceImpl implements StrategyService<ParkTimeStra
trainPreviousMap.put(groupNumber, realRun);
}
}
TripPlan tripPlan;
if (realRun != null) {
tripPlan = data.queryTripPlan(realRun.getServiceNumber(), realRun.getTripNumber());
} else {
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;
}
List<StationPlan> planList = tripPlan.getPlanList();
int offsetTime = 0;
StationPlan nextStationPlan = null;
@ -114,7 +119,6 @@ public class ParkTimeStrategyServiceImpl implements StrategyService<ParkTimeStra
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();
@ -152,7 +156,6 @@ public class ParkTimeStrategyServiceImpl implements StrategyService<ParkTimeStra
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(nextTime);
systemTime = nextTime;
}
strategy.setCoTarget(strategy.getTarget1()*strategy.getW1()+strategy.getTarget2()*strategy.getW2());
}
private RealRun handleTrainLeave(StrategyCalculateData data, ParkTimeStrategy strategy, TrainPassenger trainPassenger,
@ -169,9 +172,6 @@ public class ParkTimeStrategyServiceImpl implements StrategyService<ParkTimeStra
float min = Math.min(Math.min(wait, predict), remain); // 实际上车人数
standPassenger.minus(min);
trainPassenger.plus(min);
// 生成预测实际运行图
RealRun leave = this.buildRealRun(trainPassenger.getGroupNumber(), tripPlan, stationPlan, false, leaveTime, offsetTime, data.getSystemTime());
data.addRealRun(leave);
// 大客流站计算指标
if (Objects.equals(stationPlan.getSection(), stand.getSection())) {
// 时刻表偏差
@ -181,6 +181,9 @@ public class ParkTimeStrategyServiceImpl implements StrategyService<ParkTimeStra
// 乘客等待时间(按人数统计不考虑时间)
strategy.addTarget2(standPassenger.getWait());
}
// 生成预测实际运行图
RealRun leave = this.buildRealRun(trainPassenger.getGroupNumber(), tripPlan, stationPlan, false, leaveTime, offsetTime, data.getSystemTime());
data.addRealRun(leave);
return leave;
}
}

View File

@ -0,0 +1,22 @@
package club.joylink.rtss.simulation.cbtc.passenger.strategy.data;
import club.joylink.rtss.simulation.cbtc.data.map.Stand;
import lombok.Getter;
@Getter
public class JumpStrategy extends Strategy {
/**
* 站台
*/
Stand stand;
public JumpStrategy(Stand stand) {
this.stand = stand;
}
@Override
public String buildDescription() {
this.description = String.format("站台%s设置跳停", stand.debugStr());
return this.description;
}
}

View File

@ -47,4 +47,8 @@ public abstract class Strategy {
public String targetDebugStr() {
return String.format("指标1-时刻表偏差为:[%s],指标2-等待乘客数为:[%s],综合指标为:[%s]",this.target1, this.target2, this.coTarget);
}
}
public void handleTarget() {
this.coTarget = this.target1 * this.w1 + this.target2 * this.w2;
}
}

View File

@ -30,6 +30,10 @@ public class StrategyCalculateData {
Map<String, StandPassenger> standPassengerMap = new ConcurrentHashMap<>();
List<Stand> leftStandList;
List<Stand> rightStandList;
List<TrainPassenger> trainPassengerList;
private StrategyCalculateData() {
@ -56,6 +60,21 @@ public class StrategyCalculateData {
StandPassenger standPassenger = new StandPassenger(standPassengerFlow);
this.standPassengerMap.put(standPassenger.getStand().getCode(), standPassenger);
}
List<Stand> leftList = new ArrayList<>();
List<Stand> rightList = new ArrayList<>();
for (StandPassengerFlow standPassengerFlow : allStandPassengerFlow) {
Stand stand = standPassengerFlow.getStand();
if (stand.isRight()) {
rightList.add(stand);
} else {
leftList.add(stand);
}
}
leftList.sort(Comparator.comparing((stand) -> stand.getStation().getSn()));
rightList.sort(Comparator.comparing((stand) -> stand.getStation().getSn()));
Collections.reverse(leftList);
this.leftStandList = leftList;
this.rightStandList = rightList;
List<TrainPassenger> tpList = new ArrayList<>();
for (TrainPassengerFlow trainPassengerFlow : allTrainPassengerFlow) {
if (!StringUtils.hasText(trainPassengerFlow.getTrain().getServiceNumber())) {
@ -85,6 +104,8 @@ public class StrategyCalculateData {
standPassengerMap.put(code, standPassenger.clone());
});
obj.standPassengerMap = standPassengerMap;
obj.leftStandList = this.leftStandList;
obj.rightStandList = this.rightStandList;
List<TrainPassenger> tpList = new ArrayList<>();
for (TrainPassenger trainPassenger : this.trainPassengerList) {
tpList.add(trainPassenger.clone());