From 30b37ac6f286fd9f25ccbd7686cd6fcbdf7bb609 Mon Sep 17 00:00:00 2001 From: Kenzotong <709567093@qq.com> Date: Tue, 5 Sep 2023 12:26:10 +0200 Subject: [PATCH 1/6] 9.5 add number of rejection by time bin --- .../DrtAnalysisControlerListener.java | 64 +++++++++++++++---- 1 file changed, 50 insertions(+), 14 deletions(-) diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/DrtAnalysisControlerListener.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/DrtAnalysisControlerListener.java index c9199656800..42088502231 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/DrtAnalysisControlerListener.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/DrtAnalysisControlerListener.java @@ -30,17 +30,7 @@ import java.text.DecimalFormatSymbols; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Comparator; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Optional; -import java.util.TreeMap; +import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; @@ -251,7 +241,7 @@ public void notifyIterationEnds(IterationEndsEvent event) { } writeVehicleDistances(drtVehicleStats.getVehicleStates(), filename(event, "vehicleDistanceStats", ".csv"), delimiter); analyseDetours(network, legs, drtVehicleStats.getTravelDistances(), drtCfg, filename(event, "drt_detours"), createGraphs, delimiter); - analyseWaitTimes(filename(event, "waitStats"), legs, 1800, createGraphs, delimiter); + analyseWaitTimes(filename(event, "waitStats"), legs, drtEventSequenceCollector, 1800, createGraphs, delimiter); analyseConstraints(filename(event, "constraints"), legs, createGraphs); double endTime = qSimCfg.getEndTime() @@ -453,6 +443,37 @@ private static Map> splitLegsIntoBins(Collection le return splitLegs; } + private static Map> splitEventsIntoBins(DrtEventSequenceCollector drtEventSequenceCollector, int startTime, int endTime, int binSize_s) { + // get all events + Map, EventSequence> rejectionSeq = drtEventSequenceCollector.getRejectedRequestSequences(); + // get all rejection events + Collection rejectionEvents = rejectionSeq.values(); + + Map> rejections = new TreeMap<>(); + + for (int time = startTime; time < endTime; time = time + binSize_s) { + + // rejection list in this timebin + List rejectionList = new ArrayList<>(); + rejections.put((double)time, rejectionList); + + //Iterate through each rejection + for (EventSequence seq : rejectionEvents){ + //get rejection time + DrtRequestSubmittedEvent submission = seq.getSubmitted(); + double rejectionTime = submission.getTime(); + if (rejectionTime > endTime || rejectionTime legs, String delimiter, double startTime, double endTime, double timeBinSize, String boardingsFile, String deboardingsFile, Network network) { if (endTime < startTime) { @@ -615,12 +636,13 @@ private static void analyseDetours(Network network, List legs, Map legs, int binsize_s, boolean createGraphs, String delimiter) { + private static void analyseWaitTimes(String fileName, List legs, DrtEventSequenceCollector drtEventSequenceCollector, int binsize_s, boolean createGraphs, String delimiter) { if (legs.size() == 0) return; int startTime = ((int)(legs.get(0).departureTime / binsize_s)) * binsize_s; int endTime = ((int)(legs.get(legs.size() - 1).departureTime / binsize_s) + binsize_s) * binsize_s; Map> splitLegs = splitLegsIntoBins(legs, startTime, endTime, binsize_s); + Map> splitEvents = splitEventsIntoBins(drtEventSequenceCollector,startTime, endTime, binsize_s); DecimalFormat format = new DecimalFormat(); format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US)); @@ -633,6 +655,7 @@ private static void analyseWaitTimes(String fileName, List legs, int bin BufferedWriter bw = IOUtils.getBufferedWriter(fileName + ".csv"); TimeSeriesCollection dataset = new TimeSeriesCollection(); TimeSeriesCollection datasetrequ = new TimeSeriesCollection(); + TimeSeries rejections = new TimeSeries("number of rejections"); TimeSeries averageWaitC = new TimeSeries("average"); TimeSeries medianWait = new TimeSeries("median"); TimeSeries p_5Wait = new TimeSeries("5th percentile"); @@ -640,7 +663,7 @@ private static void analyseWaitTimes(String fileName, List legs, int bin TimeSeries requests = new TimeSeries("Ride requests"); try { - bw.write(String.join(delimiter, "timebin", "legs", "average_wait", "min", "p_5", "p_25", "median", "p_75", "p_95", "max")); + bw.write(String.join(delimiter, "timebin", "legs", "rejections", "average_wait", "min", "p_5", "p_25", "median", "p_75", "p_95", "max")); for (Map.Entry> e : splitLegs.entrySet()) { long rides = 0; double averageWait = 0; @@ -687,6 +710,19 @@ private static void analyseWaitTimes(String fileName, List legs, int bin format.format(max) + "")); } + for(Map.Entry> e : splitEvents.entrySet()){ + int rejectionNum = 0; + if (!e.getValue().isEmpty()) { + rejectionNum = e.getValue().size(); + } + + Minute h = new Minute(sdf2.parse(Time.writeTime(e.getKey()))); + + rejections.addOrUpdate(h, Double.valueOf(rejectionNum)); + bw.newLine(); + bw.write(String.join(delimiter, "" + format.format(rejectionNum))); + } + bw.flush(); bw.close(); if (createGraphs) { From f96ebf5983405a5cb3b04ace8d059f5bfea8578c Mon Sep 17 00:00:00 2001 From: Kenzotong <709567093@qq.com> Date: Thu, 7 Sep 2023 12:21:22 +0200 Subject: [PATCH 2/6] 9.7 wrote two methods -> splitEventIntoBins and analyseRejections --- .../DrtAnalysisControlerListener.java | 79 +++++++++++++------ 1 file changed, 57 insertions(+), 22 deletions(-) diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/DrtAnalysisControlerListener.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/DrtAnalysisControlerListener.java index 42088502231..e06ebd2e5a9 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/DrtAnalysisControlerListener.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/DrtAnalysisControlerListener.java @@ -241,7 +241,8 @@ public void notifyIterationEnds(IterationEndsEvent event) { } writeVehicleDistances(drtVehicleStats.getVehicleStates(), filename(event, "vehicleDistanceStats", ".csv"), delimiter); analyseDetours(network, legs, drtVehicleStats.getTravelDistances(), drtCfg, filename(event, "drt_detours"), createGraphs, delimiter); - analyseWaitTimes(filename(event, "waitStats"), legs, drtEventSequenceCollector, 1800, createGraphs, delimiter); + analyseWaitTimes(filename(event, "waitStats"), legs, 1800, createGraphs, delimiter); + analyseRejections(filename(event,"drt_numOfRejection"), drtEventSequenceCollector,1800, createGraphs, delimiter); analyseConstraints(filename(event, "constraints"), legs, createGraphs); double endTime = qSimCfg.getEndTime() @@ -389,6 +390,7 @@ public void notifyShutdown(ShutdownEvent event) { dumpOutput(event.getIteration(), "waitTimeComparison", ".png"); dumpOutput(event.getIteration(), "waitTimeComparison", ".csv"); dumpOutput(event.getIteration(), "drt_rejections", ".csv"); + dumpOutput(event.getIteration(), "drt_numOfRejection", ".csv"); dumpOutput(event.getIteration(), "drt_legs", ".csv"); dumpOutput(event.getIteration(), "vehicleDistanceStats", ".csv"); dumpOutput(event.getIteration(), "drt_detours", ".csv"); @@ -444,10 +446,8 @@ private static Map> splitLegsIntoBins(Collection le } private static Map> splitEventsIntoBins(DrtEventSequenceCollector drtEventSequenceCollector, int startTime, int endTime, int binSize_s) { - // get all events - Map, EventSequence> rejectionSeq = drtEventSequenceCollector.getRejectedRequestSequences(); // get all rejection events - Collection rejectionEvents = rejectionSeq.values(); + Collection rejectionEvents = drtEventSequenceCollector.getRejectedRequestSequences().values(); Map> rejections = new TreeMap<>(); @@ -455,7 +455,6 @@ private static Map> splitEventsIntoBins(DrtEventSequ // rejection list in this timebin List rejectionList = new ArrayList<>(); - rejections.put((double)time, rejectionList); //Iterate through each rejection for (EventSequence seq : rejectionEvents){ @@ -466,10 +465,11 @@ private static Map> splitEventsIntoBins(DrtEventSequ LogManager.getLogger(DrtAnalysisControlerListener.class).error("wrong end / start Times for analysis"); } - if (rejectionTime < time + binSize_s) { + if (rejectionTime > time && rejectionTime < time + binSize_s) { rejectionList.add(seq); } } + rejections.put((double)time, rejectionList); } return rejections; } @@ -636,13 +636,12 @@ private static void analyseDetours(Network network, List legs, Map legs, DrtEventSequenceCollector drtEventSequenceCollector, int binsize_s, boolean createGraphs, String delimiter) { + private static void analyseWaitTimes(String fileName, List legs, int binsize_s, boolean createGraphs, String delimiter) { if (legs.size() == 0) return; int startTime = ((int)(legs.get(0).departureTime / binsize_s)) * binsize_s; int endTime = ((int)(legs.get(legs.size() - 1).departureTime / binsize_s) + binsize_s) * binsize_s; Map> splitLegs = splitLegsIntoBins(legs, startTime, endTime, binsize_s); - Map> splitEvents = splitEventsIntoBins(drtEventSequenceCollector,startTime, endTime, binsize_s); DecimalFormat format = new DecimalFormat(); format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US)); @@ -655,7 +654,6 @@ private static void analyseWaitTimes(String fileName, List legs, DrtEven BufferedWriter bw = IOUtils.getBufferedWriter(fileName + ".csv"); TimeSeriesCollection dataset = new TimeSeriesCollection(); TimeSeriesCollection datasetrequ = new TimeSeriesCollection(); - TimeSeries rejections = new TimeSeries("number of rejections"); TimeSeries averageWaitC = new TimeSeries("average"); TimeSeries medianWait = new TimeSeries("median"); TimeSeries p_5Wait = new TimeSeries("5th percentile"); @@ -663,7 +661,7 @@ private static void analyseWaitTimes(String fileName, List legs, DrtEven TimeSeries requests = new TimeSeries("Ride requests"); try { - bw.write(String.join(delimiter, "timebin", "legs", "rejections", "average_wait", "min", "p_5", "p_25", "median", "p_75", "p_95", "max")); + bw.write(String.join(delimiter, "timebin", "legs", "average_wait", "min", "p_5", "p_25", "median", "p_75", "p_95", "max")); for (Map.Entry> e : splitLegs.entrySet()) { long rides = 0; double averageWait = 0; @@ -710,18 +708,6 @@ private static void analyseWaitTimes(String fileName, List legs, DrtEven format.format(max) + "")); } - for(Map.Entry> e : splitEvents.entrySet()){ - int rejectionNum = 0; - if (!e.getValue().isEmpty()) { - rejectionNum = e.getValue().size(); - } - - Minute h = new Minute(sdf2.parse(Time.writeTime(e.getKey()))); - - rejections.addOrUpdate(h, Double.valueOf(rejectionNum)); - bw.newLine(); - bw.write(String.join(delimiter, "" + format.format(rejectionNum))); - } bw.flush(); bw.close(); @@ -744,6 +730,55 @@ private static void analyseWaitTimes(String fileName, List legs, DrtEven } + private static void analyseRejections(String fileName, DrtEventSequenceCollector drtEventSequenceCollector, int binsize_s, boolean createGraphs, String delimiter) { + + int startTime = 0; + int endTime = 86400; + Map> splitEvents = splitEventsIntoBins(drtEventSequenceCollector,startTime, endTime, binsize_s); + + DecimalFormat format = new DecimalFormat(); + format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US)); + format.setMinimumIntegerDigits(1); + format.setMaximumFractionDigits(2); + format.setGroupingUsed(false); + + SimpleDateFormat sdf2 = new SimpleDateFormat("HH:mm:ss"); + + BufferedWriter bw = IOUtils.getBufferedWriter(fileName + ".csv"); + TimeSeriesCollection dataset = new TimeSeriesCollection(); + TimeSeries rejections = new TimeSeries("number of rejections"); + + try { + bw.write(String.join(delimiter, "timebin", "rejections")); + + for(Map.Entry> e : splitEvents.entrySet()){ + int drt_numOfRejection = 0; + if (!e.getValue().isEmpty()) { + drt_numOfRejection = e.getValue().size(); + } + + Minute h = new Minute(sdf2.parse(Time.writeTime(e.getKey()))); + + rejections.addOrUpdate(h, Double.valueOf(drt_numOfRejection)); + bw.newLine(); + bw.write(String.join(delimiter, Time.writeTime(e.getKey()) + "",// + format.format(drt_numOfRejection) +"")); + } + + bw.flush(); + bw.close(); + if (createGraphs) { + dataset.addSeries(rejections); + JFreeChart chart = chartProfile(splitEvents.size(), dataset, "Number of rejections", "Number"); + ChartSaveUtils.saveAsPNG(chart, fileName, 1500, 1000); + } + + } catch (IOException | ParseException e) { + + e.printStackTrace(); + } + } + private static JFreeChart chartProfile(int length, TimeSeriesCollection dataset, String descriptor, String yax) { JFreeChart chart = ChartFactory.createTimeSeriesChart(descriptor, "Time", yax, dataset); From 864301731f525ef15c052f28aa343f0bbf03a77f Mon Sep 17 00:00:00 2001 From: Kezhou Tong <709567093@qq.com> Date: Fri, 8 Sep 2023 18:36:24 +0200 Subject: [PATCH 3/6] 9.8 fix -> hardcording, passing parameters, name of output file --- .../DrtAnalysisControlerListener.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/DrtAnalysisControlerListener.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/DrtAnalysisControlerListener.java index e06ebd2e5a9..5e797e8043c 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/DrtAnalysisControlerListener.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/DrtAnalysisControlerListener.java @@ -166,6 +166,12 @@ public void notifyIterationEnds(IterationEndsEvent event) { .sorted(Comparator.comparing(leg -> leg.departureTime)) .collect(toList()); + List rejectionEvents = drtEventSequenceCollector.getRejectedRequestSequences() + .values() + .stream() + .sorted(Comparator.comparing(rejectionEvent -> rejectionEvent.getSubmitted().getTime())) + .collect(Collectors.toList()); + collection2Text(drtEventSequenceCollector.getRejectedRequestSequences().values(), filename(event, "drt_rejections", ".csv"), String.join(delimiter, "time", "personId", "fromLinkId", "toLinkId", "fromX", "fromY", "toX", "toY"), seq -> { DrtRequestSubmittedEvent submission = seq.getSubmitted(); @@ -242,7 +248,7 @@ public void notifyIterationEnds(IterationEndsEvent event) { writeVehicleDistances(drtVehicleStats.getVehicleStates(), filename(event, "vehicleDistanceStats", ".csv"), delimiter); analyseDetours(network, legs, drtVehicleStats.getTravelDistances(), drtCfg, filename(event, "drt_detours"), createGraphs, delimiter); analyseWaitTimes(filename(event, "waitStats"), legs, 1800, createGraphs, delimiter); - analyseRejections(filename(event,"drt_numOfRejection"), drtEventSequenceCollector,1800, createGraphs, delimiter); + analyseRejections(filename(event,"drt_rejections_perTimeBin"), rejectionEvents,1800, createGraphs, delimiter); analyseConstraints(filename(event, "constraints"), legs, createGraphs); double endTime = qSimCfg.getEndTime() @@ -390,7 +396,7 @@ public void notifyShutdown(ShutdownEvent event) { dumpOutput(event.getIteration(), "waitTimeComparison", ".png"); dumpOutput(event.getIteration(), "waitTimeComparison", ".csv"); dumpOutput(event.getIteration(), "drt_rejections", ".csv"); - dumpOutput(event.getIteration(), "drt_numOfRejection", ".csv"); + dumpOutput(event.getIteration(), "drt_rejections_perTimeBin", ".csv"); dumpOutput(event.getIteration(), "drt_legs", ".csv"); dumpOutput(event.getIteration(), "vehicleDistanceStats", ".csv"); dumpOutput(event.getIteration(), "drt_detours", ".csv"); @@ -445,10 +451,7 @@ private static Map> splitLegsIntoBins(Collection le return splitLegs; } - private static Map> splitEventsIntoBins(DrtEventSequenceCollector drtEventSequenceCollector, int startTime, int endTime, int binSize_s) { - // get all rejection events - Collection rejectionEvents = drtEventSequenceCollector.getRejectedRequestSequences().values(); - + private static Map> splitEventsIntoBins(Collection rejectionEvents, int startTime, int endTime, int binSize_s) { Map> rejections = new TreeMap<>(); for (int time = startTime; time < endTime; time = time + binSize_s) { @@ -730,11 +733,10 @@ private static void analyseWaitTimes(String fileName, List legs, int bin } - private static void analyseRejections(String fileName, DrtEventSequenceCollector drtEventSequenceCollector, int binsize_s, boolean createGraphs, String delimiter) { - - int startTime = 0; - int endTime = 86400; - Map> splitEvents = splitEventsIntoBins(drtEventSequenceCollector,startTime, endTime, binsize_s); + private static void analyseRejections(String fileName, List rejectionEvents, int binsize_s, boolean createGraphs, String delimiter) { + int startTime = ((int)(rejectionEvents.get(0).getSubmitted().getTime() / binsize_s)) * binsize_s; + int endTime = ((int)(rejectionEvents.get(rejectionEvents.size() - 1).getSubmitted().getTime() / binsize_s) + 1) * binsize_s; + Map> splitEvents = splitEventsIntoBins(rejectionEvents,startTime, endTime, binsize_s); DecimalFormat format = new DecimalFormat(); format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US)); From 265fe487791fdea3f3400a3c085d128d8152cf7d Mon Sep 17 00:00:00 2001 From: Kezhou Tong <709567093@qq.com> Date: Wed, 13 Sep 2023 03:20:09 +0200 Subject: [PATCH 4/6] 9.13 fix -> get time from rejected event rather than submitted event, clean IndexOutOfBoundsException --- .../DrtAnalysisControlerListener.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/DrtAnalysisControlerListener.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/DrtAnalysisControlerListener.java index 5e797e8043c..e0b31e02007 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/DrtAnalysisControlerListener.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/DrtAnalysisControlerListener.java @@ -169,7 +169,7 @@ public void notifyIterationEnds(IterationEndsEvent event) { List rejectionEvents = drtEventSequenceCollector.getRejectedRequestSequences() .values() .stream() - .sorted(Comparator.comparing(rejectionEvent -> rejectionEvent.getSubmitted().getTime())) + .sorted(Comparator.comparing(rejectionEvent -> rejectionEvent.getRejected().get().getTime())) .collect(Collectors.toList()); collection2Text(drtEventSequenceCollector.getRejectedRequestSequences().values(), filename(event, "drt_rejections", ".csv"), @@ -461,15 +461,15 @@ private static Map> splitEventsIntoBins(Collection endTime || rejectionTime endTime || rejectionTime < startTime) { + LogManager.getLogger(DrtAnalysisControlerListener.class).error("wrong end / start Times for analysis"); + } - if (rejectionTime > time && rejectionTime < time + binSize_s) { - rejectionList.add(seq); + if (rejectionTime > time && rejectionTime < time + binSize_s) { + rejectionList.add(seq); + } } } rejections.put((double)time, rejectionList); @@ -734,6 +734,8 @@ private static void analyseWaitTimes(String fileName, List legs, int bin } private static void analyseRejections(String fileName, List rejectionEvents, int binsize_s, boolean createGraphs, String delimiter) { + if (rejectionEvents.size() == 0) + return; int startTime = ((int)(rejectionEvents.get(0).getSubmitted().getTime() / binsize_s)) * binsize_s; int endTime = ((int)(rejectionEvents.get(rejectionEvents.size() - 1).getSubmitted().getTime() / binsize_s) + 1) * binsize_s; Map> splitEvents = splitEventsIntoBins(rejectionEvents,startTime, endTime, binsize_s); From a18a2b7a73617bf3b59a6ae1b53a0634298f32c5 Mon Sep 17 00:00:00 2001 From: Kezhou Tong <709567093@qq.com> Date: Mon, 23 Oct 2023 17:48:56 +0200 Subject: [PATCH 5/6] create a filter which for the plot only during the operation time --- .../common/timeprofile/ProfileWriter.java | 62 +++++++++++++++++-- 1 file changed, 57 insertions(+), 5 deletions(-) diff --git a/contribs/common/src/main/java/org/matsim/contrib/common/timeprofile/ProfileWriter.java b/contribs/common/src/main/java/org/matsim/contrib/common/timeprofile/ProfileWriter.java index 768ec3ea404..463eaa806df 100644 --- a/contribs/common/src/main/java/org/matsim/contrib/common/timeprofile/ProfileWriter.java +++ b/contribs/common/src/main/java/org/matsim/contrib/common/timeprofile/ProfileWriter.java @@ -20,9 +20,7 @@ package org.matsim.contrib.common.timeprofile; import java.awt.Paint; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Stream; import org.jfree.chart.JFreeChart; @@ -77,18 +75,72 @@ public void notifyIterationEnds(IterationEndsEvent event) { String file = filename(outputFile); String timeFormat = Time.TIMEFORMAT_HHMMSS; + int startTime = 0; + int endTime = 0; + try (CompactCSVWriter writer = new CompactCSVWriter(IOUtils.getBufferedWriter(file + ".txt"), matsimServices.getConfig().global().getDefaultDelimiter().charAt(0))) { String[] profileHeader = profiles.keySet().toArray(new String[0]); writer.writeNext(new CSVLineBuilder().add("time").addAll(profileHeader)); - for (int i = 0; i < times.length; i++) { + double[] stay = profiles.get("STAY"); + + //filter the time before operation and set that time as start time + for (int i = 0; i < times.length; i++){ + if (stay != null && stay.length > 0){ + double numOfStay = stay [i]; + if (numOfStay != 0){ + startTime = i; + break; + } + } + } + //filter the time after operation and set that time as end time + for (int i = times.length - 1; i > 0; i--){ + if (stay != null && stay.length > 0){ + double numOfStay = stay [i]; + if (numOfStay != 0){ + endTime = i; + break; + } + } + } + + for (int i = startTime; i <= endTime; i++) { var line = new CSVLineBuilder().add(Time.writeTime(times[i], timeFormat)).addAll(cells(profiles, i)); writer.writeNext(line); } } + //choose profiles which only happened during operation time + Map profilesInOperationTime = new HashMap<>(); + Set profilesKeys = profiles.keySet(); + for (String key : profilesKeys){ + List arrayList = new ArrayList<>(); + for(double value : profiles.get(key)) { + arrayList.add(value); + } + List subList = arrayList.subList(startTime,endTime + 1); + double[] newArray = new double[subList.size()]; + for (int i = 0; i < subList.size(); i++){ + newArray[i] = subList.get(i); + } + profilesInOperationTime.put(key,newArray); + } + + //choose operation time + List timesArrayList = new ArrayList<>(); + for (double value : times){ + timesArrayList.add(value); + } + List operationTimesArrayList = timesArrayList.subList(startTime,endTime + 1); + double[] operationsTimes = new double[operationTimesArrayList.size()]; + for (int i = 0; i < operationTimesArrayList.size(); i++){ + operationsTimes[i] = operationTimesArrayList.get(i); + } + + if (this.matsimServices.getConfig().controller().isCreateGraphs()) { - DefaultTableXYDataset xyDataset = createXYDataset(times, profiles); + DefaultTableXYDataset xyDataset = createXYDataset(operationsTimes, profilesInOperationTime); generateImage(xyDataset, TimeProfileCharts.ChartType.Line); generateImage(xyDataset, TimeProfileCharts.ChartType.StackedArea); } From b111ebf27147c6e99945e0209b7b316bd0a0a608 Mon Sep 17 00:00:00 2001 From: Kezhou Tong <709567093@qq.com> Date: Tue, 24 Oct 2023 13:06:11 +0200 Subject: [PATCH 6/6] replaced HashMap with LinkedHashMap -> output files are correct. --- .../org/matsim/contrib/common/timeprofile/ProfileWriter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contribs/common/src/main/java/org/matsim/contrib/common/timeprofile/ProfileWriter.java b/contribs/common/src/main/java/org/matsim/contrib/common/timeprofile/ProfileWriter.java index 463eaa806df..4c6a4822663 100644 --- a/contribs/common/src/main/java/org/matsim/contrib/common/timeprofile/ProfileWriter.java +++ b/contribs/common/src/main/java/org/matsim/contrib/common/timeprofile/ProfileWriter.java @@ -112,7 +112,7 @@ public void notifyIterationEnds(IterationEndsEvent event) { } //choose profiles which only happened during operation time - Map profilesInOperationTime = new HashMap<>(); + Map profilesInOperationTime = new LinkedHashMap<>(); Set profilesKeys = profiles.keySet(); for (String key : profilesKeys){ List arrayList = new ArrayList<>();