MATSIM
Public Member Functions | List of all members
org.matsim.visum.VisumMatrixWriter Class Reference

Public Member Functions

 VisumMatrixWriter (final Matrix matrix)
 
void setIds (final Set< String > ids)
 
void writeFile (final String filename)
 

Detailed Description

Author
mrieser

Writes a single matrix in a VISUM-compatible format to file. Can be used e.g. for OD-matrices.

Definition at line 40 of file VisumMatrixWriter.java.

Constructor & Destructor Documentation

◆ VisumMatrixWriter()

org.matsim.visum.VisumMatrixWriter.VisumMatrixWriter ( final Matrix  matrix)

Definition at line 47 of file VisumMatrixWriter.java.

References org.matsim.matrices.Matrix.getFromLocations(), and org.matsim.matrices.Matrix.getToLocations().

47  {
48  super();
49  this.matrix = matrix;
50  this.ids = new TreeSet<>();
51  this.ids.addAll(matrix.getFromLocations().keySet());
52  this.ids.addAll(matrix.getToLocations().keySet());
53  }
final Map< String, ArrayList< Entry > > getFromLocations()
Definition: Matrix.java:159
final Map< String, ArrayList< Entry > > getToLocations()
Definition: Matrix.java:163
Here is the call graph for this function:

Member Function Documentation

◆ setIds()

void org.matsim.visum.VisumMatrixWriter.setIds ( final Set< String >  ids)
Parameters
idsSet of ids to use as row- and column-header in the matrix

sets the row- and column-header used when writing the matrix. If the ids are not set explicitly, the ids in the matrix are used.
useful, if the matrix is sparse and not all possible rows and columns contain values, but should still be written out in the matrix containing only zeros.

Definition at line 64 of file VisumMatrixWriter.java.

64  {
65  this.ids = ids;
66  }

◆ writeFile()

void org.matsim.visum.VisumMatrixWriter.writeFile ( final String  filename)

Definition at line 68 of file VisumMatrixWriter.java.

References org.matsim.matrices.Matrix.getEntry(), and org.matsim.matrices.Entry.getValue().

68  {
69 
70  try (BufferedWriter out = new BufferedWriter(new FileWriter(filename))) {
71  out.write("$VN;Y5\n");
72  out.write("*\n");
73  out.write("*\tAnzahl Bezirke\n");
74  out.write(this.ids.size() + "\n");
75 
76  out.write("*\tBezirksNummern\n");
77  int cnt = 0;
78  for (String value : this.ids) {
79  cnt++;
80  if (cnt > 1) {
81  out.write("\t");
82  }
83  out.write(value);
84  }
85  out.write("\n");
86 
87  for (String from : this.ids) {
88  out.write("*\t" + from + "\n");
89  cnt = 0;
90  for (String to : this.ids) {
91  cnt++;
92  Entry e = this.matrix.getEntry(from, to);
93  if (cnt > 1) {
94  out.write("\t");
95  }
96  if (e == null) {
97  out.write("0");
98  } else {
99  out.write(Double.toString(e.getValue()));
100  }
101  }
102  out.write("\n");
103  }
104 
105  out.write("\n");
106 
107  } catch (IOException e) {
108  e.printStackTrace();
109  }
110  }
final Entry getEntry(final String from, final String to)
Definition: Matrix.java:175
Here is the call graph for this function:

The documentation for this class was generated from the following file: