MATSIM
Public Member Functions | Private Attributes | Static Private Attributes | List of all members
org.matsim.matrices.Matrix Class Reference

Public Member Functions

 Matrix (final String id, final String desc)
 
final Entry createAndAddEntry (final String fromLocId, final String toLocId, final double value)
 
final Entry setEntry (final String fromLocId, final String toLocId, final double value)
 
final void setDesc (final String desc)
 
final void removeEntry (final String from_loc, final String to_loc)
 
final String getId ()
 
final String getDesc ()
 
final Map< String, ArrayList< Entry > > getFromLocations ()
 
final Map< String, ArrayList< Entry > > getToLocations ()
 
final List< EntrygetFromLocEntries (final String fromLocationId)
 
final List< EntrygetToLocEntries (final String toLocationId)
 
final Entry getEntry (final String from, final String to)
 
final String toString ()
 

Private Attributes

final String id
 
String desc = null
 
final TreeMap< String, ArrayList< Entry > > fromLocs = new TreeMap<>()
 
final TreeMap< String, ArrayList< Entry > > toLocs = new TreeMap<>()
 
long counter = 0
 
long nextMsg = 1
 

Static Private Attributes

static final Logger log = LogManager.getLogger(Matrix.class)
 

Detailed Description

Definition at line 31 of file Matrix.java.

Constructor & Destructor Documentation

◆ Matrix()

org.matsim.matrices.Matrix.Matrix ( final String  id,
final String  desc 
)

Definition at line 53 of file Matrix.java.

References org.matsim.matrices.Matrix.desc, and org.matsim.matrices.Matrix.id.

53  {
54  if (id == null) {
55  throw new NullPointerException("id must not be null");
56  }
57  this.id = id;
58  this.desc = desc;
59  }

Member Function Documentation

◆ createAndAddEntry()

final Entry org.matsim.matrices.Matrix.createAndAddEntry ( final String  fromLocId,
final String  toLocId,
final double  value 
)

Definition at line 65 of file Matrix.java.

Referenced by org.matsim.matrices.Matrix.setEntry(), and org.matsim.matrices.MatricesReaderMatsimV1< T >.startEntry().

65  {
66 
67  // create an entry
68  Entry e = new Entry(fromLocId, toLocId, value);
69 
70  // add it to the from location data structure
71  if (!this.fromLocs.containsKey(fromLocId)) {
72  this.fromLocs.put(fromLocId, new ArrayList<Entry>());
73  }
74  ArrayList<Entry> fe = this.fromLocs.get(fromLocId);
75  fe.add(e);
76 
77  // add it to the to location data structure
78  if (!this.toLocs.containsKey(toLocId)) {
79  this.toLocs.put(toLocId, new ArrayList<Entry>());
80  }
81  ArrayList<Entry> te = this.toLocs.get(toLocId);
82  te.add(e);
83 
84  // show counter
85  this.counter++;
86  if (this.counter % this.nextMsg == 0) {
87  this.nextMsg *= 2;
88  log.info("Matrix id=" + this.id + ": entry # " + this.counter);
89  }
90 
91  // return the new entry
92  return e;
93  }
final TreeMap< String, ArrayList< Entry > > fromLocs
Definition: Matrix.java:41
static final Logger log
Definition: Matrix.java:44
final TreeMap< String, ArrayList< Entry > > toLocs
Definition: Matrix.java:42

◆ setEntry()

final Entry org.matsim.matrices.Matrix.setEntry ( final String  fromLocId,
final String  toLocId,
final double  value 
)

Definition at line 99 of file Matrix.java.

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

99  {
100  Entry e = getEntry(fromLocId, toLocId);
101  if (e == null) {
102  return createAndAddEntry(fromLocId, toLocId, value);
103  }
104  e.setValue(value);
105  return e;
106  }
final Entry createAndAddEntry(final String fromLocId, final String toLocId, final double value)
Definition: Matrix.java:65
final Entry getEntry(final String from, final String to)
Definition: Matrix.java:175
Here is the call graph for this function:

◆ setDesc()

final void org.matsim.matrices.Matrix.setDesc ( final String  desc)

Definition at line 108 of file Matrix.java.

References org.matsim.matrices.Matrix.desc.

Referenced by org.matsim.visum.VisumMatrixReader.readFile().

108  {
109  this.desc = desc;
110  }

◆ removeEntry()

final void org.matsim.matrices.Matrix.removeEntry ( final String  from_loc,
final String  to_loc 
)

Definition at line 116 of file Matrix.java.

References org.matsim.matrices.Matrix.getEntry().

116  {
117  Entry entry = getEntry(from_loc, to_loc);
118  ArrayList<Entry> from_loc_entries = this.fromLocs.get(from_loc);
119  ArrayList<Entry> to_loc_entries = this.toLocs.get(to_loc);
120 
121  if ((from_loc_entries == null) || (to_loc_entries == null)) {
122  throw new RuntimeException("entry with from_loc_id=" + from_loc +
123  " and to_loc_id=" + to_loc + " does not exist!" +
124  " Inconsistent data strucutre!!!");
125  }
126 
127  if (!from_loc_entries.remove(entry)) {
128  throw new RuntimeException("entry with from_loc_id=" + from_loc +
129  " and to_loc_id=" + to_loc + " does not exist!" +
130  " Inconsistent data strucutre!!!");
131  }
132  if (from_loc_entries.isEmpty()) {
133  this.fromLocs.remove(from_loc);
134  }
135 
136  if (!to_loc_entries.remove(entry)) {
137  throw new RuntimeException("entry with from_loc_id=" + from_loc +
138  " and to_loc_id=" + to_loc + " does not exist!" +
139  " Inconsistent data strucutre!!!");
140  }
141  if (to_loc_entries.isEmpty()) {
142  this.toLocs.remove(to_loc);
143  }
144  log.info("entry " + entry.toString() + " removed.");
145  }
final TreeMap< String, ArrayList< Entry > > fromLocs
Definition: Matrix.java:41
static final Logger log
Definition: Matrix.java:44
final TreeMap< String, ArrayList< Entry > > toLocs
Definition: Matrix.java:42
final Entry getEntry(final String from, final String to)
Definition: Matrix.java:175
Here is the call graph for this function:

◆ getId()

final String org.matsim.matrices.Matrix.getId ( )

Definition at line 151 of file Matrix.java.

References org.matsim.matrices.Matrix.id.

151  {
152  return this.id;
153  }

◆ getDesc()

final String org.matsim.matrices.Matrix.getDesc ( )

Definition at line 155 of file Matrix.java.

References org.matsim.matrices.Matrix.desc.

155  {
156  return this.desc;
157  }

◆ getFromLocations()

final Map<String, ArrayList<Entry> > org.matsim.matrices.Matrix.getFromLocations ( )

Definition at line 159 of file Matrix.java.

References org.matsim.matrices.Matrix.fromLocs.

Referenced by org.matsim.visum.VisumMatrixWriter.VisumMatrixWriter(), and org.matsim.matrices.MatricesWriter.write().

159  {
160  return this.fromLocs;
161  }
final TreeMap< String, ArrayList< Entry > > fromLocs
Definition: Matrix.java:41

◆ getToLocations()

final Map<String, ArrayList<Entry> > org.matsim.matrices.Matrix.getToLocations ( )

Definition at line 163 of file Matrix.java.

References org.matsim.matrices.Matrix.toLocs.

Referenced by org.matsim.visum.VisumMatrixWriter.VisumMatrixWriter().

163  {
164  return this.toLocs;
165  }
final TreeMap< String, ArrayList< Entry > > toLocs
Definition: Matrix.java:42

◆ getFromLocEntries()

final List<Entry> org.matsim.matrices.Matrix.getFromLocEntries ( final String  fromLocationId)

Definition at line 167 of file Matrix.java.

167  {
168  return this.fromLocs.get(fromLocationId);
169  }
final TreeMap< String, ArrayList< Entry > > fromLocs
Definition: Matrix.java:41

◆ getToLocEntries()

final List<Entry> org.matsim.matrices.Matrix.getToLocEntries ( final String  toLocationId)

Definition at line 171 of file Matrix.java.

171  {
172  return this.toLocs.get(toLocationId);
173  }
final TreeMap< String, ArrayList< Entry > > toLocs
Definition: Matrix.java:42

◆ getEntry()

final Entry org.matsim.matrices.Matrix.getEntry ( final String  from,
final String  to 
)

Definition at line 175 of file Matrix.java.

References org.matsim.matrices.Entry.getToLocation().

Referenced by org.matsim.matrices.Matrix.removeEntry(), org.matsim.matrices.Matrix.setEntry(), and org.matsim.visum.VisumMatrixWriter.writeFile().

175  {
176  ArrayList<Entry> fe = this.fromLocs.get(from);
177  if (fe == null) return null;
178  for (int i=0; i<fe.size(); i++) {
179  Entry e = fe.get(i);
180  if (e.getToLocation().equals(to)) {
181  return e;
182  }
183  }
184  return null;
185  }
final TreeMap< String, ArrayList< Entry > > fromLocs
Definition: Matrix.java:41
Here is the call graph for this function:

◆ toString()

final String org.matsim.matrices.Matrix.toString ( )

Definition at line 192 of file Matrix.java.

192  {
193  return "[id=" + this.id + "]" +
194  "[desc=" + this.desc + "]" +
195  "[nof_from_locs=" + this.fromLocs.size() + "]" +
196  "[nof_to_locs=" + this.toLocs.size() + "]";
197  }
final TreeMap< String, ArrayList< Entry > > fromLocs
Definition: Matrix.java:41
final TreeMap< String, ArrayList< Entry > > toLocs
Definition: Matrix.java:42

Member Data Documentation

◆ id

final String org.matsim.matrices.Matrix.id
private

◆ desc

String org.matsim.matrices.Matrix.desc = null
private

◆ fromLocs

final TreeMap<String,ArrayList<Entry> > org.matsim.matrices.Matrix.fromLocs = new TreeMap<>()
private

Definition at line 41 of file Matrix.java.

Referenced by org.matsim.matrices.Matrix.getFromLocations().

◆ toLocs

final TreeMap<String,ArrayList<Entry> > org.matsim.matrices.Matrix.toLocs = new TreeMap<>()
private

Definition at line 42 of file Matrix.java.

Referenced by org.matsim.matrices.Matrix.getToLocations().

◆ log

final Logger org.matsim.matrices.Matrix.log = LogManager.getLogger(Matrix.class)
staticprivate

Definition at line 44 of file Matrix.java.

◆ counter

long org.matsim.matrices.Matrix.counter = 0
private

Definition at line 46 of file Matrix.java.

◆ nextMsg

long org.matsim.matrices.Matrix.nextMsg = 1
private

Definition at line 47 of file Matrix.java.


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