📄 allocationvariable.java
字号:
package com.power.pipeengine.Variable;
import com.power.pipeengine.Entity.*;
import java.util.ResourceBundle;
import java.util.*;
public class AllocationVariable
extends Variable {
private static final AllocationVariable INSTANCE =
new AllocationVariable();
// Private constructor supresses
// default public constructor
private AllocationVariable() {
}
public static AllocationVariable getInstance() {
return INSTANCE;
}
public String getVariable(Facility f, Product p, Route r, Bucket b) {
String varName = getDefinedVar(f, p, r, b);
if (null != varName) {
return varName;
}
varName = new String("A" + "F" + f.getVariableCode() +
"P" + p.getVariableCode() +
"R" + r.getVariableCode() +
"T" + b.getVariableCode());
addDefinedVar(f, p, r, b, varName);
return varName;
}
public String getVariable(RouteSource rteSrc, Bucket b) {
String separator = "";
Route r = rteSrc.getRoute();
String varName = getDefinedVar(r.getSrcingFacility(),
rteSrc.getSrcingProduct(),
r,
b);
if (null == varName) {
varName = new String("A" +
"F" + r.getSrcingFacility().getVariableCode() +
"P" + rteSrc.getSrcingProduct().getVariableCode() +
"R" + r.getVariableCode() +
"T" + b.getVariableCode());
addDefinedVar(r.getSrcingFacility(),
rteSrc.getSrcingProduct(),
r,
b,
varName);
}
if (rteSrc.isSingle()) {
setObjElement(varName,
0.1 + 0.01 / (rteSrc.getRank() + 1) + Math.random() * 0.0000001);
}
return varName;
}
private Hashtable _definedVars = new Hashtable();
private String getDefinedVar(Facility f, Product p, Route r, Bucket b) {
Hashtable prodHash = (Hashtable) _definedVars.get(f.getVariableCode());
if (prodHash == null)
return null;
Hashtable rteHash = (Hashtable) prodHash.get(p.getVariableCode());
if (rteHash == null)
return null;
Hashtable bucketHash = (Hashtable) rteHash.get(r.getVariableCode());
if (bucketHash == null)
return null;
return (String) bucketHash.get(b.getVariableCode());
}
private void addDefinedVar(Facility f, Product p, Route r, Bucket b,
String varName) {
Hashtable prodHash = (Hashtable) _definedVars.get(f.getVariableCode());
if (prodHash == null) {
prodHash = new Hashtable();
_definedVars.put(f.getVariableCode(), prodHash);
}
Hashtable rteHash = (Hashtable) prodHash.get(p.getVariableCode());
if (rteHash == null) {
rteHash = new Hashtable();
prodHash.put(p.getVariableCode(), rteHash);
}
Hashtable bucketHash = (Hashtable) rteHash.get(r.getVariableCode());
if (bucketHash == null) {
bucketHash = new Hashtable();
rteHash.put(r.getVariableCode(), bucketHash);
}
bucketHash.put(b.getVariableCode(), varName);
}
public void reset() {
_definedVars = new Hashtable();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -