DoubleBaseContinuousDynamicSystem.java
/*
* $Id: BaseContinuousDynamicSystem.java,v 1.21 2008/06/26 10:10:34 koga Exp $
*
* Copyright (C) 2004 Koga Laboratory. All rights reserved.
*
*/
package org.mklab.tool.control.system.continuous;
import org.mklab.nfc.matrix.DoubleMatrix;
import org.mklab.nfc.matrix.IntMatrix;
import org.mklab.nfc.ode.SolverStopException;
import org.mklab.tool.control.system.DoubleSystemOperator;
/**
* 常微分方程式で表現される連続時間動的システムを表わすクラスです。
*
* @author Koga Laboratory
* @version $Revision: 1.21 $, 2004/11/09
*/
public abstract class DoubleBaseContinuousDynamicSystem extends DoubleSystemOperator implements DoubleContinuousDynamicSystem {
/** 状態の初期値 */
private DoubleMatrix initialState;
/** 状態の微分の初期値 */
private DoubleMatrix initialStateDerivative;
/** 状態 */
private DoubleMatrix state;
/** 状態の微分。 */
private DoubleMatrix stateDerivative;
/** 結合システムにおける状態の順番 */
private int stateNumber;
/** 指数 */
private IntMatrix index;
/**
* 新しく生成された<code>BaseContinuousDynamicSystem</code>オブジェクトを初期化します。
*
* @param inputSize 入力の数
* @param outputSize 出力の数
* @param stateSize 状態の数
*/
public DoubleBaseContinuousDynamicSystem(final int inputSize, final int outputSize, final int stateSize) {
super();
setInputSize(inputSize);
setOutputSize(outputSize);
setStateSize(stateSize);
setDynamic(true);
if (inputSize == 0) {
setForcedSystem(false);
}
this.initialState = new DoubleMatrix(stateSize, 1);
this.initialStateDerivative = new DoubleMatrix(stateSize, 1);
this.state = this.initialState.createClone();
this.index = new IntMatrix(stateSize, 1);
}
/**
* {@inheritDoc}
*/
@Override
public void initialize() {
setState(getInitialState());
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!super.equals(o)) {
return false;
}
if (o == null) {
return false;
}
if (o.getClass() != getClass()) {
return false;
}
DoubleBaseContinuousDynamicSystem castedObj = (DoubleBaseContinuousDynamicSystem)o;
return ((this.initialState == null ? castedObj.initialState == null : this.initialState.equals(castedObj.initialState)) &&
(this.state == null ? castedObj.state == null : this.state.equals(castedObj.state)) &&
(this.index == null ? castedObj.index == null : this.index.equals(castedObj.index)));
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
int hashCode = super.hashCode();
hashCode = 31 * hashCode + (this.initialState == null ? 0 : this.initialState.hashCode());
hashCode = 31 * hashCode + (this.state == null ? 0 : this.state.hashCode());
hashCode = 31 * hashCode + (this.index == null ? 0 : this.index.hashCode());
return hashCode;
}
/**
* {@inheritDoc}
*/
@Override
public DoubleBaseContinuousDynamicSystem clone() {
final DoubleBaseContinuousDynamicSystem inst = (DoubleBaseContinuousDynamicSystem)super.clone();
inst.setInitialState(this.getInitialState() == null ? null : this.getInitialState().createClone());
inst.setState(this.getState() == null ? null : this.getState().createClone());
inst.setIndex(this.getIndex() == null ? null : this.getIndex().createClone());
return inst;
}
/**
* {@inheritDoc}
*/
public void setInitialState(final DoubleMatrix initialState) {
this.initialState = initialState.createClone();
}
/**
* {@inheritDoc}
*/
public DoubleMatrix getInitialState() {
if (this.initialState == null) {
return null;
}
return this.initialState.createClone();
}
/**
* {@inheritDoc}
*/
public void setInitialStateDerivative(final DoubleMatrix initialStateDerivative) {
this.initialStateDerivative = initialStateDerivative.createClone();
}
/**
* {@inheritDoc}
*/
public DoubleMatrix getInitialStateDerivative() {
if (this.initialStateDerivative == null) {
return null;
}
return this.initialStateDerivative.createClone();
}
/**
* {@inheritDoc}
*/
public DoubleMatrix getState() {
if (this.state == null) {
return null;
}
return this.state.createClone();
}
/**
* {@inheritDoc}
*/
public void setState(final DoubleMatrix state) {
this.state = state.createClone();
}
/**
* {@inheritDoc}
*/
public DoubleMatrix inputOutputEquation(final double t, final DoubleMatrix x) throws SolverStopException {
if (hasDirectFeedthrough()) {
throw new SolverStopException(Messages.getString("BaseContinuousDynamicSystem.0")); //$NON-NLS-1$
}
final DoubleMatrix u = new DoubleMatrix(getInputSize(), 1);
final DoubleMatrix y = outputEquation(t, x);
return u.appendDown(y);
}
/**
* {@inheritDoc}
*/
public DoubleMatrix outputEquation( final double t, final DoubleMatrix x, final DoubleMatrix u) throws SolverStopException {
throw new SolverStopException(Messages.getString("BaseContinuousDynamicSystem.1")); //$NON-NLS-1$
}
/**
* {@inheritDoc}
*/
public DoubleMatrix outputEquation( final double t, final DoubleMatrix x) throws SolverStopException {
throw new SolverStopException(Messages.getString("BaseContinuousDynamicSystem.2")); //$NON-NLS-1$
}
/**
* {@inheritDoc}
*/
public int getStateNumber() {
return this.stateNumber;
}
/**
* {@inheritDoc}
*/
public void setStateNumber(final int stateNumber) {
this.stateNumber = stateNumber;
}
/**
* {@inheritDoc}
*/
public IntMatrix getIndex() {
return this.index;
}
/**
* {@inheritDoc}
*/
public void setIndex(IntMatrix index) {
this.index = index;
}
/**
* {@inheritDoc}
*/
public DoubleMatrix getStateDerivative() {
return this.stateDerivative;
}
/**
* {@inheritDoc}
*/
public void setStateDerivative(DoubleMatrix stateDerivative) {
this.stateDerivative = stateDerivative;
}
}