MATSIM
PtBiasErrorGraph.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * PtBiasErrorGraph.java
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 2010 by the members listed in the COPYING, *
8  * LICENSE and WARRANTY file. *
9  * email : info at matsim dot org *
10  * *
11  * *********************************************************************** *
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * See also COPYING, LICENSE and WARRANTY file *
18  * *
19  * *********************************************************************** */
20 
24 package org.matsim.pt.counts.obsolete;
25 
26 import java.awt.Font;
27 import java.util.List;
28 
29 import org.jfree.chart.ChartFactory;
30 import org.jfree.chart.JFreeChart;
31 import org.jfree.chart.axis.AxisLocation;
32 import org.jfree.chart.axis.CategoryAxis;
33 import org.jfree.chart.axis.NumberAxis;
34 import org.jfree.chart.axis.ValueAxis;
35 import org.jfree.chart.labels.StandardCategoryToolTipGenerator;
36 import org.jfree.chart.plot.CategoryPlot;
37 import org.jfree.chart.plot.DatasetRenderingOrder;
38 import org.jfree.chart.plot.PlotOrientation;
39 import org.jfree.chart.renderer.category.LineAndShapeRenderer;
40 import org.jfree.data.category.DefaultCategoryDataset;
44 
49 public final class PtBiasErrorGraph extends CountsGraph {
51  private String chartTitle;
52 
59  @Deprecated // use standard counts package
60  public PtBiasErrorGraph(List<CountSimComparison> ccl, int iteration,
61  String filename, String chartTitle) {
62  super(ccl, iteration, filename, chartTitle);
63  this.chartTitle = chartTitle;
64  }
65 
66  @Override
67  @Deprecated // use standard counts package
68  public JFreeChart createChart(final int nbr) {
69  DefaultCategoryDataset dataset0 = new DefaultCategoryDataset();
70  DefaultCategoryDataset dataset1 = new DefaultCategoryDataset();
71 
72  this.errorStats = new ComparisonErrorStatsCalculator(this.ccl_);
73 
74  double[] meanRelError = errorStats.getMeanRelError();
75  // double[] meanAbsError = errorStats.getMeanAbsError();
76  double[] meanAbsBias = errorStats.getMeanBias();
77 
78  for (int h = 0; h < 24; h++) {
79  dataset0.addValue(meanRelError[h], "Mean rel error", Integer
80  .toString(h + 1));
81  // dataset1.addValue(meanAbsError[h], "Mean abs error",
82  // Integer.toString(h + 1));
83  dataset1.addValue(meanAbsBias[h], "Mean bias", Integer
84  .toString(h + 1));
85  }
86 
87  this.chart_ = ChartFactory.createLineChart(this.chartTitle, "Hour",
88  "Mean rel error [%]", dataset0, PlotOrientation.VERTICAL, true, // legend?
89  true, // tooltips?
90  false // URLs?
91  );
92  CategoryPlot plot = this.chart_.getCategoryPlot();
93  plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
94  plot.setDataset(1, dataset1);
95  plot.mapDatasetToRangeAxis(1, 1);
96 
97  final LineAndShapeRenderer renderer = new LineAndShapeRenderer();
98  renderer.setSeriesToolTipGenerator(0,
99  new StandardCategoryToolTipGenerator());
100  plot.setRenderer(0, renderer);
101 
102  final CategoryAxis axis1 = new CategoryAxis("Hour");
103  axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7));
104  plot.setDomainAxis(axis1);
105 
106  // final ValueAxis axis2 = new
107  // NumberAxis("Mean abs {bias, error} [veh/h]");
108  final ValueAxis axis2 = new NumberAxis("Mean abs bias [veh/h]");
109  plot.setRangeAxis(1, axis2);
110 
111  final ValueAxis axis3 = plot.getRangeAxis(0);
112  axis3.setRange(0.0, 100.0);
113 
114  final LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();
115  renderer2.setSeriesToolTipGenerator(0,
116  new StandardCategoryToolTipGenerator());
117  renderer2.setSeriesToolTipGenerator(1,
118  new StandardCategoryToolTipGenerator());
119  // renderer2.setSeriesPaint(0, Color.black);
120  plot.setRenderer(1, renderer2);
121  plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);
122 
123  return this.chart_;
124  }
125 
126  @Deprecated // use standard counts package
127  public double[] getMeanRelError() {
128  if (this.errorStats == null) {
129  throw new RuntimeException(
130  "Object not initialized correctly. Call createChart(..) first!");
131  }
132  return this.errorStats.getMeanRelError();
133  }
134 
135  @Deprecated // use standard counts package
136  public double[] getMeanAbsBias() {
137  if (this.errorStats == null) {
138  throw new RuntimeException(
139  "Object not initialized correctly. Call createChart(..) first!");
140  }
141  return this.errorStats.getMeanBias();
142  }
143 }
PtBiasErrorGraph(List< CountSimComparison > ccl, int iteration, String filename, String chartTitle)