Search in sources :

Example 1 with TrainsCycleItem

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;
}
Also used : TrainsCycleItem(net.parostroj.timetable.model.TrainsCycleItem) LinkedList(java.util.LinkedList)

Example 2 with TrainsCycleItem

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;
}
Also used : TrainsCycleItem(net.parostroj.timetable.model.TrainsCycleItem) Train(net.parostroj.timetable.model.Train)

Example 3 with TrainsCycleItem

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();
}
Also used : TrainsCycleChecker(net.parostroj.timetable.actions.TrainsCycleChecker) TrainsCycleItem(net.parostroj.timetable.model.TrainsCycleItem) TimeConverter(net.parostroj.timetable.model.TimeConverter) ConflictType(net.parostroj.timetable.actions.TrainsCycleChecker.ConflictType) TrainDiagram(net.parostroj.timetable.model.TrainDiagram)

Example 4 with TrainsCycleItem

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);
        }
    }
}
Also used : TrainsCycle(net.parostroj.timetable.model.TrainsCycle) TrainsCycleItem(net.parostroj.timetable.model.TrainsCycleItem) Train(net.parostroj.timetable.model.Train)

Example 5 with TrainsCycleItem

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));
}
Also used : TrainsCycle(net.parostroj.timetable.model.TrainsCycle) TranslatedString(net.parostroj.timetable.model.TranslatedString) ArrayList(java.util.ArrayList) TrainsCycleItem(net.parostroj.timetable.model.TrainsCycleItem) FreightConnection(net.parostroj.timetable.model.freight.FreightConnection) ArrayList(java.util.ArrayList) TimeIntervalList(net.parostroj.timetable.model.TimeIntervalList) LinkedList(java.util.LinkedList) List(java.util.List) Train(net.parostroj.timetable.model.Train) Map(java.util.Map) FNConnection(net.parostroj.timetable.model.FNConnection) TrainsCycleType(net.parostroj.timetable.model.TrainsCycleType)

Aggregations

TrainsCycleItem (net.parostroj.timetable.model.TrainsCycleItem)12 TrainsCycle (net.parostroj.timetable.model.TrainsCycle)6 Train (net.parostroj.timetable.model.Train)5 LinkedList (java.util.LinkedList)4 ArrayList (java.util.ArrayList)2 ConflictType (net.parostroj.timetable.actions.TrainsCycleChecker.ConflictType)2 TimeConverter (net.parostroj.timetable.model.TimeConverter)2 TimeInterval (net.parostroj.timetable.model.TimeInterval)2 List (java.util.List)1 Map (java.util.Map)1 TrainsCycleChecker (net.parostroj.timetable.actions.TrainsCycleChecker)1 Conflict (net.parostroj.timetable.actions.TrainsCycleChecker.Conflict)1 ModelPredicates (net.parostroj.timetable.filters.ModelPredicates)1 FNConnection (net.parostroj.timetable.model.FNConnection)1 Interval (net.parostroj.timetable.model.Interval)1 LocalizedString (net.parostroj.timetable.model.LocalizedString)1 TimeIntervalList (net.parostroj.timetable.model.TimeIntervalList)1 TrainDiagram (net.parostroj.timetable.model.TrainDiagram)1 TrainsCycleType (net.parostroj.timetable.model.TrainsCycleType)1 TranslatedString (net.parostroj.timetable.model.TranslatedString)1