⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 element.java

📁 著名IT公司ILog的APS高级排产优化引擎
💻 JAVA
字号:
package com.power.lpsolver.LPSolve;

import java.util.ResourceBundle;
/**
 *
 * <p>Title: PIPE Engine</p>
 * <p>Description: Global Planning Optimization Engine</p>
 * <p>Copyright: Copyright (c) 2002</p>
 * <p>Company: Paraster, Inc.</p>
 * @author Wei Tan
 * @version 1.0
 */

/**
 * An element represent one entry in a matrix in the form (column number,
 * coefficient). The concept has been extended to (row number, column number,
 * coefficient).
 */
public class Element
{
    /**
     * the column number of the element.
     */
  private int _colNum;

    /**
     * the coefficient of the element.
     */
	private double _coeff;

    /**
     * Sole class constructor
     * @param col the column number (variable index).
     * @param coeff the coefficient of the variable.
     */
	public Element( int col, double coeff ) {
		_colNum = col;
		_coeff = coeff;
	}

    public Element() {
    }

    /**
     * Gets the column number (variable index) of the element.
     * @return the column number (variable index).
     */
	public int getColumnNumber() {
		return _colNum;
	}

    /**
     * Gets the coefficient of the element.
     * @return the coefficient of the element.
     */
	public double getCoefficient() {
		return _coeff;
	}

    /**
     * Sets the properties of the element - column number and coefficient.
     * @param col the column number for the element.
     * @param coeff the coefficient for the element.
     */
	public void setProperties( int col, double coeff ) {
		_colNum = col;
		_coeff = coeff;
	}

    /**
     * Adds another element to this element.
     * this = this + multiplier * elem.
     * @param multiplier the multiplier to be applied for the incoming element.
     * @param elem - the element to be added to this element.
     */
	public void addCoefficient( double multiplier, Element elem ) {
		_coeff += multiplier * elem.getCoefficient();
	}

    /**
     * Sets the coefficient of the element.
     * @param coeff the coefficient to be set.
     */
	private void setCoefficient( double coeff ) {
		_coeff = coeff;
	}

    /**
     * Sets the column index of the element.
     * @param colIdx the column index for the element.
     */
	private void setColumnIndex( int colIdx ) {
		_colNum = colIdx;
	}

    /**
     * Clones this element.
     * @return a clone of this element.
     */
	public Object clone() {
		Element elem = MemoryManager.getInstance().getElement();
		elem.setCoefficient( _coeff );
		elem.setColumnIndex( _colNum );
		return elem;
	}

    /**
     * Applies a multiplier to this element (its coefficient).
     * @param multiplier the multiplier to be applied.
     */
	public void applyMultiplier( double multiplier ) {
		_coeff *= multiplier;
	}

    /**
     * Prints the element in the form [column number, coefficient].
     */
	public void print() {
		System.out.println( "\t[" + _colNum + ", " + _coeff + "]" );
	}

    /**
     * Gets the coefficient in a string format for use in an MPS file. The
     * returned string length may not exceed 12 characters.
     * @return the string representation of the coefficient.
     */
	public String getMPSValue() {
		char[] name = new char[12];
		String value = String.valueOf( _coeff );

		int length = Math.min( 12, value.length() );
		for( int i=0; i<length; i++ ) {
			name[i] = value.charAt(i);
		}

		for( int k=length; k<12; k++ ) {
			name[k] = ' ';
		}

		//System.out.println( "coeff = " + _coeff + "\tvalue = " + name );
		return new String( name );
	}

    public int hashCode() {
        return _colNum;
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -