BaseSampledDataDynamicSystem.java
/*
* $Id: BaseSampledDataDynamicSystem.java,v 1.11 2008/07/16 03:51:36 koga Exp $
*
* Copyright (C) 2004-2005 Koga Laboratory. All rights reserved.
*/
package org.mklab.tool.control.system.sampled;
import org.mklab.nfc.matrix.ComplexNumericalMatrix;
import org.mklab.nfc.matrix.RealNumericalMatrix;
import org.mklab.nfc.ode.SolverStopException;
import org.mklab.nfc.scalar.ComplexNumericalScalar;
import org.mklab.nfc.scalar.RealNumericalScalar;
import org.mklab.tool.control.system.SystemOperator;
/**
* サンプル値動的システムを表わすクラスです。
*
* @author koga
* @version $Revision: 1.11 $
* @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 abstract class BaseSampledDataDynamicSystem<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>> extends SystemOperator<RS,RM,CS,CM> implements SampledDataDynamicSystem<RS,RM,CS,CM> {
/** 連続時間システムの初期状態 */
private RM continuousInitialState;
/** 離散時間システムの初期状態 */
private RM discreteInitialState;
/** 連続時間システムの状態 */
private RM continuousState;
/** 離散時間システムの状態 */
private RM discreteState;
/** サンプル点ならばtrue */
private boolean atSamplingPoint;
/**
* 新しく生成された<code>AbstractSampledDataDynamicSystem</code>オブジェクトを初期化します。
*
* @param inputSize 入力の数
* @param outputSize 出力の数
* @param continuousStateSize 状態の数
* @param discreteStateSize 状態の数
* @param sunit unit of scalar
*/
public BaseSampledDataDynamicSystem(final int inputSize, final int outputSize, final int continuousStateSize, final int discreteStateSize, RS sunit) {
super(sunit);
setInputSize(inputSize);
setOutputSize(outputSize);
setStateSize(continuousStateSize + discreteStateSize);
setDynamic(true);
if (inputSize == 0) {
setForcedSystem(false);
}
this.continuousInitialState = sunit.createZeroGrid(continuousStateSize, 1);
this.continuousState = this.continuousInitialState.createClone();
this.discreteInitialState = sunit.createZeroGrid(discreteStateSize, 1);
this.discreteState = this.discreteInitialState.createClone();
}
/**
* @see org.mklab.tool.control.system.SystemOperator#initialize()
*/
@Override
public void initialize() {
setContinuousState(getContinuousInitialState());
setDiscreteState(getDiscreteInitialState());
this.atSamplingPoint = false;
}
/**
* {@inheritDoc}
*/
public RM differentialEquation(final RS t, final RM xc, final RM xd, final RM inputOutput) throws SolverStopException {
return continuousStateEquation(t, xc, xd, inputOutput);
}
/**
* {@inheritDoc}
*/
public RM differenceEquation(final RS t, final RM xc, final RM xd, final RM inputOutput) throws SolverStopException {
return discreteStateEquation(t, xc, xd, inputOutput);
}
/**
* @see org.mklab.tool.control.system.sampled.SampledDataDynamicSystem#getContinuousInitialState()
*/
public RM getContinuousInitialState() {
return this.continuousInitialState.createClone();
}
/**
* @see org.mklab.tool.control.system.sampled.SampledDataDynamicSystem#getContinuousState()
*/
public RM getContinuousState() {
return this.continuousState.createClone();
}
/**
* {@inheritDoc}
*/
public void setContinuousState(final RM state) {
this.continuousState = state;
}
/**
* {@inheritDoc}
*/
public void setDiscreteState(final RM state) {
this.discreteState = state;
}
/**
* {@inheritDoc}
*/
public void setContinuousInitialState(final RM initialState) {
this.continuousInitialState = initialState;
}
/**
* @see org.mklab.tool.control.system.sampled.SampledDataDynamicSystem#getDiscreteInitialState()
*/
public RM getDiscreteInitialState() {
return this.discreteInitialState.createClone();
}
/**
* @see org.mklab.tool.control.system.sampled.SampledDataDynamicSystem#getDiscreteState()
*/
public RM getDiscreteState() {
return this.discreteState.createClone();
}
/**
* {@inheritDoc}
*/
public void setDiscreteInitialState(final RM initialState) {
this.discreteInitialState = initialState;
}
/**
* {@inheritDoc}
*/
public RM outputEquation( final RS t, final RM xc, final RM xd,
final RM u) throws SolverStopException {
throw new SolverStopException(Messages.getString("BaseSampledDataDynamicSystem.0")); //$NON-NLS-1$
}
/**
* {@inheritDoc}
*/
public RM outputEquation( final RS t, final RM xc, final RM xd) throws SolverStopException {
throw new SolverStopException(Messages.getString("BaseSampledDataDynamicSystem.1")); //$NON-NLS-1$
}
/**
* @see org.mklab.tool.control.system.sampled.SampledDataDynamicSystem#getContinuousStateSize()
*/
public int getContinuousStateSize() {
return this.continuousState.length();
}
/**
* @see org.mklab.tool.control.system.sampled.SampledDataDynamicSystem#getDiscreteStateSize()
*/
public int getDiscreteStateSize() {
return this.discreteState.length();
}
/**
* @see org.mklab.nfc.ode.Sampling#isAtSamplingPoint()
*/
public boolean isAtSamplingPoint() {
return this.atSamplingPoint;
}
/**
* @see org.mklab.nfc.ode.Sampling#setAtSamplingPoint(boolean)
*/
public void setAtSamplingPoint(final boolean samplingPoint) {
this.atSamplingPoint = samplingPoint;
}
/**
* @see org.mklab.tool.control.system.SystemOperator#equals(java.lang.Object)
*/
@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;
}
BaseSampledDataDynamicSystem<RS,RM,CS,CM> castedObj = (BaseSampledDataDynamicSystem<RS,RM,CS,CM>)o;
return ((this.continuousInitialState == null ? castedObj.continuousInitialState == null : this.continuousInitialState.equals(castedObj.continuousInitialState))
&& (this.discreteInitialState == null ? castedObj.discreteInitialState == null : this.discreteInitialState.equals(castedObj.discreteInitialState))
&& (this.continuousState == null ? castedObj.continuousState == null : this.continuousState.equals(castedObj.continuousState))
&& (this.discreteState == null ? castedObj.discreteState == null : this.discreteState.equals(castedObj.discreteState)) && (this.atSamplingPoint == castedObj.atSamplingPoint));
}
/**
* @see org.mklab.tool.control.system.SystemOperator#hashCode()
*/
@Override
public int hashCode() {
int hashCode = super.hashCode();
hashCode = 31 * hashCode + (this.continuousInitialState == null ? 0 : this.continuousInitialState.hashCode());
hashCode = 31 * hashCode + (this.discreteInitialState == null ? 0 : this.discreteInitialState.hashCode());
hashCode = 31 * hashCode + (this.continuousState == null ? 0 : this.continuousState.hashCode());
hashCode = 31 * hashCode + (this.discreteState == null ? 0 : this.discreteState.hashCode());
hashCode = 31 * hashCode + (this.atSamplingPoint ? 1231 : 1237);
return hashCode;
}
}