ConnectionMatrix.java
/*
* Created on 2006/11/05
* Copyright (C) 2006 Koga Laboratory. All rights reserved.
*
*/
package org.mklab.tool.control.system.graph;
import org.mklab.nfc.matrix.BooleanMatrix;
import org.mklab.nfc.matrix.ComplexNumericalMatrix;
import org.mklab.nfc.matrix.FundamentalArray;
import org.mklab.nfc.matrix.RealNumericalMatrix;
import org.mklab.nfc.scalar.ComplexNumericalScalar;
import org.mklab.nfc.scalar.RealNumericalScalar;
import org.mklab.tool.control.system.SystemOperator;
/**
* 連結行列(Connection Matrix)を表すクラスです。
*
* @author koga
* @version $Revision: 1.8 $, 2006/11/05
* @param <RS> type of real scalar
* @param <RM> type of real matrix
* @param <CS> type of complex scalar
* @param <CM> type of complex matrix
*/
public class ConnectionMatrix<RS extends RealNumericalScalar<RS, RM, CS, CM>, RM extends RealNumericalMatrix<RS, RM, CS, CM>, CS extends ComplexNumericalScalar<RS, RM, CS, CM>, CM extends ComplexNumericalMatrix<RS, RM, CS, CM>> {
/** 連結情報を表わす行列 */
private BooleanMatrix connectionMatrix;
/**
* 新しく生成された<code>ConnectionMatrix</code>オブジェクトを初期化します。
*
* @param adjacencyMatrix 隣接行列
*/
public ConnectionMatrix(final FundamentalArray<SystemOperator<RS, RM, CS, CM>, ?> adjacencyMatrix) {
final int rowSize = adjacencyMatrix.getRowSize();
final int columnSize = adjacencyMatrix.getColumnSize();
this.connectionMatrix = new BooleanMatrix(rowSize, columnSize);
for (int row = 0; row < rowSize; row++) {
for (int column = 0; column < columnSize; column++) {
if (row == column) {
this.connectionMatrix.setElement(row + 1, column + 1, true);
} else if (adjacencyMatrix.getElement(row + 1, column + 1).isZero() == false) {
this.connectionMatrix.setElement(row + 1, column + 1, true);
}
}
}
}
/**
* 新しく生成された<code>ConnectionMatrix</code>オブジェクトを初期化します。
*
* @param adjacencyMatrix 隣接行列
*/
public ConnectionMatrix(final RM adjacencyMatrix) {
final int rowSize = adjacencyMatrix.getRowSize();
final int columnSize = adjacencyMatrix.getColumnSize();
this.connectionMatrix = new BooleanMatrix(rowSize, columnSize);
for (int row = 0; row < rowSize; row++) {
for (int column = 0; column < columnSize; column++) {
if (row == column) {
this.connectionMatrix.setElement(row + 1, column + 1, true);
} else if (adjacencyMatrix.getElement(row + 1, column + 1).isZero() == false) {
this.connectionMatrix.setElement(row + 1, column + 1, true);
}
}
}
}
/**
* 連結情報を表わす行列を返します。
*
* @return 連結情報を表わす行列
*/
public BooleanMatrix getBooleanMatrix() {
return this.connectionMatrix.createClone();
}
/**
* 行列の次数を返します。
*
* @return 行列の次数
*/
public int getSize() {
return this.connectionMatrix.getRowSize();
}
/**
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int PRIME = 31;
int result = 1;
result = PRIME * result + ((this.connectionMatrix == null) ? 0 : this.connectionMatrix.hashCode());
return result;
}
/**
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final ConnectionMatrix<RS, RM, CS, CM> other = (ConnectionMatrix<RS, RM, CS, CM>)obj;
if (this.connectionMatrix == null) {
if (other.connectionMatrix != null) {
return false;
}
} else if (!this.connectionMatrix.equals(other.connectionMatrix)) {
return false;
}
return true;
}
}