Switch.java

package org.mklab.sdpj.algorithm;

import org.mklab.nfc.matrix.ComplexNumericalMatrix;
import org.mklab.nfc.matrix.RealNumericalMatrix;
import org.mklab.nfc.scalar.ComplexNumericalScalar;
import org.mklab.nfc.scalar.RealNumericalScalar;
import org.mklab.sdpj.tool.Tools;


/**
 * Class <code>Switch</code> is defined to control the type of switch efficiently.
 * 
 * @author koga
 * @version $Revision$, 2009/04/24
 * @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 Switch<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 SwitchType switchType;

  /**
   * @param switchType スイッチタイプ
   */
  public Switch(SwitchType switchType) {
    this.switchType = switchType;
  }

  /**
   * @param phase 位相
   */
  public void MehrotraPredictor(Phase<RS,RM,CS,CM> phase) {
    if (phase.getValue() == PhaseType.noINFO || phase.getValue() == PhaseType.pFEAS || phase.getValue() == PhaseType.dFEAS) {
      this.switchType = SwitchType.ON; // At least one of primal or dual is infeasible.
    } else {
      this.switchType = SwitchType.OFF;
    }
  }

  /**
   * This function is no chance to be used.
   */
  public void display() {
    Tools.message(this.toString());
  }

  /**
   * @see java.lang.Object#toString()
   */
  @Override
  public String toString() {
    StringBuffer buff = new StringBuffer();
    if (this.getSwitchType() == SwitchType.ON) {
      buff.append("reduction.switchType == ON\n"); //$NON-NLS-1$
    } else {
      buff.append("reduction.switchType == OFF\n"); //$NON-NLS-1$
    }
    return buff.toString();
  }

  /**
   * @return switchTypeを返します。
   */
  public SwitchType getSwitchType() {
    return this.switchType;
  }
}