📄 productboundconstraint.java
字号:
package com.power.pipeengine.Constraint;
import java.util.*;
import com.power.pipeengine.Entity.*;
import com.power.pipeengine.InputData.*;
import com.power.pipeengine.LPModel.*;
import com.power.pipeengine.Variable.*;
import com.power.pipeengine.*;
import com.power.lpsolver.LPSolve.*;
public class ProductBoundConstraint extends Constraint
{
static ResourceBundle res = ResourceBundle.getBundle("com.power.pipeengine.Res",
EngineConfig.getInstance().getLocale() );
private static final ProductBoundConstraint INSTANCE =
new ProductBoundConstraint();
// Private constructor supresses
// default public constructor
private ProductBoundConstraint( ) {
setConstraintType( res.getString("PRODUCT_BOUNDS") );
}
public static ProductBoundConstraint getInstance( ) {
return INSTANCE;
}
private Vector _constraints = new Vector();
public Vector getConstraints() {
return _constraints;
}
public void buildConstraints() {
super.publishMessage();
DataModel dataModel = DataModel.getInstance();
ProductBounds prodBnds = dataModel.getProductBounds();
PIPECalendar cal = dataModel.getCalendar();
StartsVariable startsVar = StartsVariable.getInstance();
BoundVariable bndVar = BoundVariable.getInstance();
Enumeration allBnds = prodBnds.getProductBounds().elements();
Routes routes = dataModel.getRoutes();
int numBuckets = cal.getTotalNumOfBuckets();
Model mdl = Model.getInstance();
MemoryManager memMgr = MemoryManager.getInstance();
String varName = null;
while( allBnds.hasMoreElements() ) {
ProductBound prodBnd = (ProductBound) allBnds.nextElement();
Facility f = prodBnd.getFacility();
Product p = prodBnd.getProduct();
for( int t=1; t<=numBuckets; t++ ) {
Bound bnd = prodBnd.getBound( t );
if( null == bnd ) continue;
double bndQty = bnd.getBndQty();
double penaltyCost = bnd.getPenaltyCost();
String bndType = bnd.getBndType();
Bucket b = cal.getBucket( t );
Vector qualifyRoutes = routes.getRoutes( prodBnd.getFacilityID(),
prodBnd.getProductID() );
if( null == qualifyRoutes ) continue;
Enumeration allQualifyRoutes = qualifyRoutes.elements();
String constr = new String(); //hold one constraint
//add a new constraint to LP Solver
int rowNumber = mdl.getNumberOfRows();
com.power.lpsolver.LPSolve.Constraint con =
new com.power.lpsolver.LPSolve.Constraint( "PB" + rowNumber, rowNumber );
while( allQualifyRoutes.hasMoreElements() ) {
Route r = (Route) allQualifyRoutes.nextElement();
if( t > r.getLastStartBucketHavingOuts() ) continue;
varName = startsVar.getVariable( r, p, b );
constr += " + " + varName;
int colIdx = mdl.getModelVariables().addVariable( varName );
Element elem = memMgr.getElement();
elem.setProperties( colIdx, 1.0 );
con.addElement( elem );
this.addMPSElem( con, colIdx, elem );
}
// continue if no qualify routes or too late to have starts
if( constr.length() == 0 ) continue;
if( bndType.equals( res.getString("UP") ) ) {
varName = bndVar.getVariable( bndType, f, p, b );
constr += " - " + varName;
int colIdx = mdl.getModelVariables().addVariable( varName );
Element elem = memMgr.getElement();
elem.setProperties( colIdx, -1.0 );
con.addElement( elem );
this.addMPSElem( con, colIdx, elem );
constr += " <= ";
con.setSign( "<=" );
} else {
varName = bndVar.getVariable( bndType, f, p, b );
constr += " + " + varName;
int colIdx = mdl.getModelVariables().addVariable( varName );
Element elem = memMgr.getElement();
elem.setProperties( colIdx, 1.0 );
con.addElement( elem );
this.addMPSElem( con, colIdx, elem );
constr += " >= ";
con.setSign( ">=" );
}
constr += new Double( bndQty ).toString();
con.setRHS( bndQty );
mdl.addConstraint( con );
_constraints.addElement( constr );
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -