use of net.parostroj.timetable.model.TrainsCycleItem in project grafikon by jub77.
the class TrainsCycleChecker method checkConflicts.
public List<Conflict> checkConflicts(TrainsCycle cycle) {
List<Conflict> conflicts = new LinkedList<>();
Iterator<TrainsCycleItem> i = cycle.getItems().iterator();
TrainsCycleItem last = null;
TrainsCycleItem first = null;
if (i.hasNext()) {
last = i.next();
first = last;
}
while (i.hasNext()) {
TrainsCycleItem current = i.next();
checkItems(conflicts, last, current, false);
last = current;
}
if (first != null) {
if (cycle.isPartOfSequence()) {
checkItems(conflicts, cycle.getPreviousItemCyclic(first), first, true);
checkItems(conflicts, last, cycle.getNextItemCyclic(last), true);
} else {
checkItems(conflicts, last, first, true);
}
}
return conflicts;
}
use of net.parostroj.timetable.model.TrainsCycleItem in project grafikon by jub77.
the class LSTrainsCycleItem method createTrainsCycleItem.
public TrainsCycleItem createTrainsCycleItem(TrainsCycle cycle, TrainDiagram diagram) {
Train modelTrain = diagram.getTrains().getById(train);
TrainsCycleItem item = new TrainsCycleItem(cycle, modelTrain, LocalizedString.fromString(comment), modelTrain.getIntervalById(from), modelTrain.getIntervalById(to));
return item;
}
use of net.parostroj.timetable.model.TrainsCycleItem in project grafikon by jub77.
the class DriverCycleDelegate method getTrainCycleErrors.
@Override
public String getTrainCycleErrors(TrainsCycle cycle) {
TrainDiagram diagram = model.getDiagram();
TimeConverter c = diagram.getTimeConverter();
StringBuilder result = new StringBuilder();
List<TrainsCycleChecker.Conflict> conflicts = checker.checkConflicts(cycle);
for (TrainsCycleChecker.Conflict item : conflicts) {
TrainsCycleItem fromItem = item.getFrom();
TrainsCycleItem toItem = item.getTo();
for (ConflictType conflictType : this.colapseTimeConflictTypes(item.getType())) {
switch(conflictType) {
case NODE:
addNewLineIfNotEmpty(result);
result.append(String.format("%s %s", ResourceLoader.getString("ec.move.nodes"), formatItems(fromItem, toItem, c)));
break;
case TRANSITION_TIME:
addNewLineIfNotEmpty(result);
result.append(String.format("%s %s", ResourceLoader.getString("ec.move.nodes.time.problem"), formatItems(fromItem, toItem, c)));
break;
case TIME:
case SETUP_TIME:
addNewLineIfNotEmpty(result);
result.append(String.format("%s %s", ResourceLoader.getString("ec.problem.time"), formatItems(fromItem, toItem, c)));
break;
}
}
}
return result.toString();
}
use of net.parostroj.timetable.model.TrainsCycleItem in project grafikon by jub77.
the class StationTimetablesExtractor method addEnginesAndTrainUnits.
private void addEnginesAndTrainUnits(TimeInterval interval, TrainsCycleType type, List<CycleFromTo> cycles, BiFunction<TrainsCycle, TrainsCycleItem, TrainsCycleItem> nextItemF, BiFunction<TrainsCycle, TrainsCycleItem, TrainsCycleItem> previousItemF) {
Train train = interval.getTrain();
for (TrainsCycleItem item : train.getCycles(type)) {
CycleFromTo cycleFromTo = null;
if (item.getToInterval() == interval) {
// end
TrainsCycle cycle = item.getCycle();
TrainsCycleItem itemNext = nextItemF.apply(cycle, item);
cycleFromTo = new CycleFromTo(false, false, cycle.getName(), cycle.getDisplayDescription(), itemNext != null ? itemNext.getTrain().getName() : null, itemNext != null ? converter.convertIntToXml(itemNext.getStartTime()) : null);
this.updateAdjacent(cycleFromTo, item, itemNext);
}
if (item.getFromInterval() == interval) {
// start
TrainsCycle cycle = item.getCycle();
TrainsCycleItem itemPrev = previousItemF.apply(cycle, item);
cycleFromTo = new CycleFromTo(itemPrev == null, true, cycle.getName(), cycle.getDisplayDescription(), itemPrev != null ? itemPrev.getTrain().getName() : null, itemPrev != null ? converter.convertIntToXml(itemPrev.getEndTime()) : null);
this.updateAdjacent(cycleFromTo, item, itemPrev);
}
if (cycleFromTo != null) {
if (TrainsCycleType.isEngineType(type) && isHelperEngine(item)) {
cycleFromTo.setHelper(true);
}
cycles.add(cycleFromTo);
}
}
}
use of net.parostroj.timetable.model.TrainsCycleItem in project grafikon by jub77.
the class StationTimetablesExtractor method addOtherData.
private void addOtherData(TimeInterval interval, StationTimetableRow row) {
// technological time handle differently
row.setTechnologicalTime(interval.isTechnological());
if (row.isTechnologicalTime()) {
return;
}
row.setLength(this.getLength(interval));
BiFunction<TrainsCycle, TrainsCycleItem, TrainsCycleItem> nextF = getNextFunction();
BiFunction<TrainsCycle, TrainsCycleItem, TrainsCycleItem> previousF = getPreviousFunction();
this.addEnginesAndTrainUnits(interval, diagram.getEngineCycleType(), row.getEngine(), nextF, previousF);
this.addEnginesAndTrainUnits(interval, diagram.getTrainUnitCycleType(), row.getTrainUnit(), nextF, previousF);
for (TrainsCycleType type : diagram.getCycleTypes()) {
if (!type.isDefaultType()) {
this.addCycles(interval, type, row.getCycle(), nextF, previousF);
}
}
if (interval.isFreight()) {
List<? extends FreightConnection> freightDests = strategy.getFreightToNodes(interval);
if (!freightDests.isEmpty()) {
ArrayList<FreightDestinationInfo> fl = new ArrayList<>(freightDests.size());
for (FreightConnection dst : freightDests) {
fl.add(FreightDestinationInfo.convert(locale, dst));
}
row.setFreightTo(fl);
}
}
if (interval.isFreightConnection()) {
Map<Train, List<FreightConnectionPath>> passedCargoDst = strategy.getFreightPassedInNode(interval);
if (!passedCargoDst.isEmpty()) {
List<FreightToTrain> fttl = new ArrayList<>();
for (Map.Entry<Train, List<FreightConnectionPath>> entry : passedCargoDst.entrySet()) {
FreightToTrain ftt = new FreightToTrain();
ftt.setTrain(entry.getKey().getName());
List<? extends FreightConnection> mList = entry.getValue();
List<FreightDestinationInfo> fl = new ArrayList<>(mList.size());
for (FreightConnection dst : mList) {
fl.add(FreightDestinationInfo.convert(locale, dst));
}
ftt.setFreightTo(fl);
fttl.add(ftt);
}
row.setFreightToTrain(fttl);
}
}
List<FNConnection> trainsFrom = diagram.getFreightNet().getTrainsTo(interval);
if (!trainsFrom.isEmpty()) {
ArrayList<TranslatedString> nt = new ArrayList<>(trainsFrom.size());
for (FNConnection conn : trainsFrom) {
nt.add(conn.getFrom().getTrain().getName());
}
row.setFreightFromTrain(nt);
}
row.setComment(interval.getComment());
row.setOccupied(interval.getAttributes().getBool(TimeInterval.ATTR_OCCUPIED));
}
Aggregations