-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1827 from LBNL-UCB-STI/art/merge-develope-to-mast…
…er-3 Merge develope to master
- Loading branch information
Showing
131 changed files
with
3,871 additions
and
1,942 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
src/main/java/beam/analysis/physsim/PhyssimNetworkComparisonEuclideanVsLengthAttribute.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package beam.analysis.physsim; | ||
|
||
import beam.analysis.plots.GraphUtils; | ||
import beam.sim.config.BeamConfig; | ||
import org.jfree.chart.ChartFactory; | ||
import org.jfree.chart.JFreeChart; | ||
import org.jfree.chart.plot.PlotOrientation; | ||
import org.jfree.chart.plot.XYPlot; | ||
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; | ||
import org.jfree.data.xy.XYSeries; | ||
import org.jfree.data.xy.XYSeriesCollection; | ||
import org.matsim.api.core.v01.network.Link; | ||
import org.matsim.api.core.v01.network.Network; | ||
import org.matsim.core.controler.OutputDirectoryHierarchy; | ||
import org.matsim.core.utils.geometry.CoordUtils; | ||
import org.matsim.core.utils.io.IOUtils; | ||
|
||
import java.awt.geom.Ellipse2D; | ||
import java.io.BufferedWriter; | ||
import java.io.IOException; | ||
|
||
public class PhyssimNetworkComparisonEuclideanVsLengthAttribute { | ||
private BeamConfig beamConfig; | ||
private Network network; | ||
private OutputDirectoryHierarchy outputDirectoryHierarchy; | ||
|
||
public PhyssimNetworkComparisonEuclideanVsLengthAttribute(Network network, OutputDirectoryHierarchy outputDirectoryHierarchy, BeamConfig beamConfig) { | ||
this.network = network; | ||
this.outputDirectoryHierarchy = outputDirectoryHierarchy; | ||
this.beamConfig = beamConfig; | ||
} | ||
|
||
/** | ||
* Iteration stop notification event listener | ||
* @param iteration the count of the current iteration | ||
*/ | ||
public void notifyIterationEnds(int iteration) { | ||
if (beamConfig.beam().outputs().writeGraphs()) { | ||
try { | ||
writeComparisonEuclideanVsLengthAttributeCsv(iteration); | ||
writeComparisonEuclideanVsLengthAttributePlot(iteration); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Write CSV file with comparison of euclidean and length attribute of the network | ||
* @param iterationNumber | ||
* @throws IOException | ||
*/ | ||
private void writeComparisonEuclideanVsLengthAttributeCsv(int iterationNumber) throws IOException { | ||
String pathToCsv = outputDirectoryHierarchy.getIterationFilename( | ||
iterationNumber, | ||
"EuclideanVsLengthAttribute.csv" | ||
); | ||
|
||
BufferedWriter writerObservedVsSimulated = IOUtils.getBufferedWriter(pathToCsv); | ||
writerObservedVsSimulated.write("linkId,euclidean,length\n"); | ||
|
||
for (Link link : network.getLinks().values()) { | ||
writerObservedVsSimulated.write( | ||
String.format("%s,%f,%f\n", | ||
link.getId().toString(), | ||
CoordUtils.calcEuclideanDistance( | ||
link.getFromNode().getCoord(), | ||
link.getToNode().getCoord() | ||
), link.getLength()) | ||
); | ||
} | ||
|
||
writerObservedVsSimulated.close(); | ||
} | ||
|
||
/** | ||
* Make plot with comparison of euclidean and length attribute of the network | ||
* @param iterationNumber | ||
* @throws IOException | ||
*/ | ||
private void writeComparisonEuclideanVsLengthAttributePlot(int iterationNumber) throws IOException { | ||
String pathToPlot = outputDirectoryHierarchy.getIterationFilename( | ||
iterationNumber, | ||
"EuclideanVsLengthAttributePlot.png" | ||
); | ||
|
||
XYSeries series = new XYSeries("Euclidean vs Length attribute", false); | ||
|
||
for (Link link : network.getLinks().values()) { | ||
series.add( | ||
CoordUtils.calcEuclideanDistance( | ||
link.getFromNode().getCoord(), | ||
link.getToNode().getCoord() | ||
), link.getLength()); | ||
} | ||
|
||
XYSeriesCollection dataset = new XYSeriesCollection(); | ||
dataset.addSeries(series); | ||
|
||
JFreeChart chart = ChartFactory.createScatterPlot( | ||
"Euclidean vs Length attribute", | ||
"Euclidean", | ||
"Length", | ||
dataset, | ||
PlotOrientation.VERTICAL, | ||
true, | ||
true, | ||
false | ||
); | ||
|
||
XYPlot xyplot = chart.getXYPlot(); | ||
xyplot.setDomainCrosshairVisible(false); | ||
xyplot.setRangeCrosshairVisible(false); | ||
|
||
XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); | ||
renderer.setSeriesShape(0, new Ellipse2D.Double(0, 0, 5, 5)); | ||
renderer.setSeriesLinesVisible(0, false); | ||
|
||
xyplot.setRenderer(0, renderer); | ||
|
||
GraphUtils.saveJFreeChartAsPNG( | ||
chart, | ||
pathToPlot, | ||
1000, | ||
1000 | ||
); | ||
} | ||
} |
Oops, something went wrong.