AuD
Lecture 'Algorithmen und Datenstrukturen' (code examples)
aud.graph.AdjacencyMatrix< Edge > Class Template Reference

Sparse adjacency matrix. More...

+ Inheritance diagram for aud.graph.AdjacencyMatrix< Edge >:
+ Collaboration diagram for aud.graph.AdjacencyMatrix< Edge >:

Public Member Functions

 AdjacencyMatrix (boolean symmetric)
 create empty matrix More...
 
void clearColumnAndRow (int idx)
 Set all entries in row idx and column idx to null. More...
 
Iterator< Edge > iterator ()
 Get iterator over all edges. More...
 
- Public Member Functions inherited from aud.graph.matrix.SparseMatrix< T >
 SparseMatrix ()
 create empty matrix More...
 
 SparseMatrix (boolean symmetric)
 create empty matrix (see isSymmetricMatrix) More...
 
 SparseMatrix (SparseMatrix< T > other)
 copy constructor More...
 
 SparseMatrix (SparseMatrix< T > other, boolean transpose)
 copy constructor More...
 
boolean isSymmetricMatrix ()
 Was matrix created explicitly as symmetric matrix? More...
 
int getNumRows ()
 computed from maximum column index [O(1)] More...
 
int getMinRowIndex ()
 get minimum column index [O(1)] More...
 
set (int i, int j, T data)
 Set entry (i,j) to data [O(log(nnz))]. More...
 
Vector< T > getRowEntries (int i)
 get entries in row i as array More...
 
int[] getRowColumnIndices (int i)
 get column indices in row i as array More...
 
int rowDegree (int i)
 get number of nonzero entries in row i More...
 
SparseMatrixCS< T > getTransposed ()
 get transposed matrix More...
 
- Public Member Functions inherited from aud.graph.matrix.SparseMatrixCS< T >
 SparseMatrixCS ()
 create empty matrix with "arbitrarily growing" dimensions More...
 
 SparseMatrixCS (SparseMatrixCS< T > other)
 copy constructor More...
 
int nnz ()
 get number of nonzero entries More...
 
int getNumRows ()
 computes from maximium row index [O(nnz)] More...
 
int getMinRowIndex ()
 get minimum row index [O(nnz)] More...
 
int getNumColumns ()
 computed from maximum column index [O(1)] More...
 
int getMinColumnIndex ()
 get minimum row index [O(1)] More...
 
get (int i, int j)
 get entry (i,j) [O(log(nnz))] More...
 
set (int i, int j, T data)
 Set entry (i,j) to data [O(log(nnz))]. More...
 
Vector< T > getColumnEntries (int j)
 get entries in column j as array More...
 
int[] getColumnRowIndices (int j)
 get row indices in column j as array More...
 
int columnDegree (int j)
 get number of nonzero entries in column j More...
 
SparseMatrixCS< T > getTransposed ()
 get transposed matrix More...
 
SparseMatrixCS< Integer > spones ()
 Get nonzero pattern. More...
 
int[] getRowIndices ()
 Get array of row indices. More...
 
int[] getColumnIndices ()
 Get array of column indices in same order as for getRowIndices. More...
 
T[] getValues ()
 Get array of values in same order as for getRowIndices. More...
 
String toString ()
 
String toLaTeX (String name)
 get LaTeX code for displaying (TikZ) matrix More...
 
File renderSpySVG (File svgfile, Colormap< T > colormap)
 
String spyTikZ (boolean rulers, Colormap< T > colormap)
 
SVGViewer spy (String caption, Colormap< T > colormap)
 render spy plot in new window More...
 

Additional Inherited Members

- Static Public Member Functions inherited from aud.graph.matrix.SparseMatrix< T >
static void main (String args[])
 Example and test: show aud.util.ColormapCount color map. More...
 
- Protected Attributes inherited from aud.graph.matrix.SparseMatrix< T >
SparseMatrixCS< T > rmat_ = null
 Store transposed. More...
 
- Protected Attributes inherited from aud.graph.matrix.SparseMatrixCS< T >
TreeMap< Coordinate, T > mat_
 

Detailed Description

Sparse adjacency matrix.

Parameters
<Edge>edge data

Definition at line 14 of file AdjacencyMatrix.java.

Constructor & Destructor Documentation

◆ AdjacencyMatrix()

aud.graph.AdjacencyMatrix< Edge >.AdjacencyMatrix ( boolean  symmetric)

create empty matrix

Definition at line 19 of file AdjacencyMatrix.java.

19 {
20 super(symmetric);
21 }

Member Function Documentation

◆ clearColumnAndRow()

void aud.graph.AdjacencyMatrix< Edge >.clearColumnAndRow ( int  idx)

Set all entries in row idx and column idx to null.

Note that this method does not shift indices (coordinates) but only "overwrites" existing entries.

Definition at line 27 of file AdjacencyMatrix.java.

27 {
28 int[] ri=getColumnRowIndices(idx);
29 for (int k=0;k<ri.length;++k)
30 set(ri[k],idx,null);
31
32 if (!isSymmetricMatrix()) {
33 int[] ci=getRowColumnIndices(idx);
34 for (int k=0;k<ci.length;++k)
35 set(idx,ci[k],null);
36 }
37 }
int[] getColumnRowIndices(int j)
get row indices in column j as array
boolean isSymmetricMatrix()
Was matrix created explicitly as symmetric matrix?
int[] getRowColumnIndices(int i)
get column indices in row i as array

References aud.graph.matrix.SparseMatrixCS< T >.getColumnRowIndices(), aud.graph.matrix.SparseMatrix< T >.getRowColumnIndices(), and aud.graph.matrix.SparseMatrix< T >.isSymmetricMatrix().

Referenced by aud.test.AdjacencyMatrixTest.testMatrix(), and aud.test.AdjacencyMatrixTest.testSymmatrixMatrix().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ iterator()

Iterator< Edge > aud.graph.AdjacencyMatrix< Edge >.iterator ( )

Get iterator over all edges.

For a symmetric matrix, every (undirected) edges is enumerated only once.

See also
SparseMatrix::isSymmetricMatrix

Definition at line 44 of file AdjacencyMatrix.java.

44 {
45 // inefficient!
46 if (isSymmetricMatrix()) {
47 // copy and remove_if
48 TreeMap<Coordinate,Edge> m=new TreeMap<Coordinate,Edge>(mat_);
49 for (Iterator<Map.Entry<Coordinate,Edge>> ii=m.entrySet().iterator();
50 ii.hasNext();) {
51 Map.Entry<Coordinate,Edge> entry=ii.next();
52 Coordinate c=entry.getKey();
53 if (c.i>c.j)
54 ii.remove();
55 }
56 return m.values().iterator();
57 }
58 else
59 return mat_.values().iterator();
60 }
TreeMap< Coordinate, T > mat_

References aud.graph.matrix.Coordinate.i, aud.graph.matrix.SparseMatrix< T >.isSymmetricMatrix(), aud.graph.matrix.Coordinate.j, and aud.graph.matrix.SparseMatrixCS< T >.mat_.

+ Here is the call graph for this function:

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