本文整理汇总了Java中org.openlca.expressions.FormulaInterpreter类的典型用法代码示例。如果您正苦于以下问题:Java FormulaInterpreter类的具体用法?Java FormulaInterpreter怎么用?Java FormulaInterpreter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FormulaInterpreter类属于org.openlca.expressions包,在下文中一共展示了FormulaInterpreter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import org.openlca.expressions.FormulaInterpreter; //导入依赖的package包/类
private Parameter create(CalculatedParameterRow row,
FormulaInterpreter interpreter) {
Parameter p = new Parameter();
p.setRefId(UUID.randomUUID().toString());
p.setName(row.getName());
p.setScope(ParameterScope.GLOBAL);
p.setDescription(row.getComment());
p.setInputParameter(false);
try {
String expr = row.getExpression();
double val = interpreter.eval(expr);
p.setValue(val);
p.setFormula(expr);
} catch (Exception e) {
log.error("failed to evaluate formula for global parameter "
+ row.getName() + ": set value to 1.0", e);
p.setInputParameter(true);
p.setValue(1.0);
}
dao.insert(p);
return p;
}
示例2: eachKml
import org.openlca.expressions.FormulaInterpreter; //导入依赖的package包/类
private void eachKml(RegionalizationSetup regioSetup, ImpactTable table,
FormulaInterpreter interpreter, BiConsumer<LocationKml, IMatrix> fn) {
Scope scope = interpreter.getScope(setup.impactMethod.getId());
for (LocationKml kml : regioSetup.kmlData) {
Map<String, Double> params = regioSetup.parameterSet.get(
kml.locationId);
for (String param : params.keySet()) {
Double val = params.get(param);
if (val == null)
continue;
scope.bind(param, val.toString());
}
IMatrix factors = table.createMatrix(solver, interpreter).factorMatrix;
fn.accept(kml, factors);
}
}
示例3: nextRun
import org.openlca.expressions.FormulaInterpreter; //导入依赖的package包/类
/**
* Generates random numbers and calculates the product system. Returns true
* if the calculation was successfully done, otherwise false (this is the
* case when the resulting matrix is singular).
*/
public boolean nextRun() {
if (inventory == null || inventoryMatrix == null)
setUp();
try {
log.trace("next simulation run");
FormulaInterpreter interpreter = parameterTable.simulate();
inventory.simulate(inventoryMatrix, interpreter);
LcaCalculator solver = new LcaCalculator(matrixSolver,
inventoryMatrix);
if (impactMatrix != null) {
impactTable.simulate(impactMatrix, interpreter);
solver.setImpactMatrix(impactMatrix);
}
SimpleResult result = solver.calculateSimple();
appendResults(result);
return true;
} catch (Throwable e) {
log.trace("simulation run failed", e);
return false;
}
}
示例4: isValidName
import org.openlca.expressions.FormulaInterpreter; //导入依赖的package包/类
/**
* Returns true if the given name is a valid identifier for a parameter. We
* allow the same rules as for Java identifiers.
*/
public static boolean isValidName(String paramaterName) {
if (paramaterName == null)
return false;
String id = paramaterName.trim();
if (id.isEmpty())
return false;
for (int i = 0; i < id.length(); i++) {
char c = id.charAt(i);
if (i == 0 && !Character.isLetter(c))
return false;
if (i > 0 && !Character.isJavaIdentifierPart(c))
return false;
}
FormulaInterpreter interpreter = new FormulaInterpreter();
interpreter.bind(paramaterName, "1");
try {
interpreter.eval(paramaterName);
} catch (InterpreterException e) {
return false;
}
return true;
}
示例5: initInterpreter
import org.openlca.expressions.FormulaInterpreter; //导入依赖的package包/类
private FormulaInterpreter initInterpreter(ParameterDao dao) {
FormulaInterpreter interpreter = new FormulaInterpreter();
for (Parameter parameter : dao.getGlobalParameters()) {
interpreter.bind(parameter.getName(),
Double.toString(parameter.getValue()));
}
return interpreter;
}
示例6: createInterpreter
import org.openlca.expressions.FormulaInterpreter; //导入依赖的package包/类
private FormulaInterpreter createInterpreter(List<Parameter> globals) {
FormulaInterpreter interpreter = new FormulaInterpreter();
for (Parameter global : globals) {
String name = global.getName();
String val = Double.toString(global.getValue());
interpreter.bind(name, val);
}
return interpreter;
}
示例7: createMatrix
import org.openlca.expressions.FormulaInterpreter; //导入依赖的package包/类
public ImpactMatrix createMatrix(IMatrixSolver solver,
FormulaInterpreter interpreter) {
evalFormulas(interpreter);
ImpactMatrix matrix = new ImpactMatrix();
matrix.categoryIndex = categoryIndex;
if (factorMatrix != null)
matrix.factorMatrix = (IMatrix) factorMatrix.createRealMatrix(solver);
matrix.flowIndex = flowIndex;
return matrix;
}
示例8: eval
import org.openlca.expressions.FormulaInterpreter; //导入依赖的package包/类
void eval(FormulaInterpreter interpreter) {
if (interpreter == null)
return;
try {
Scope scope = interpreter.getScope(exchange.processId);
if (scope == null)
scope = interpreter.getGlobalScope();
tryEval(scope);
} catch (Exception e) {
Logger log = LoggerFactory.getLogger(getClass());
log.error("Formula evaluation failed, exchange "
+ exchange.exchangeId, e);
}
}
示例9: eval
import org.openlca.expressions.FormulaInterpreter; //导入依赖的package包/类
void eval(FormulaInterpreter interpreter) {
if (interpreter == null)
return;
try {
Scope scope = interpreter.getScope(methodId);
if (scope == null)
scope = interpreter.getGlobalScope();
tryEval(scope);
} catch (Exception e) {
Logger log = LoggerFactory.getLogger(getClass());
log.error("Formula evaluation failed, impact factor " + factor, e);
}
}
示例10: eval
import org.openlca.expressions.FormulaInterpreter; //导入依赖的package包/类
void eval(final FormulaInterpreter interpreter) {
iterate(new Fn() {
@Override
public void apply(int row, int col, ImpactFactorCell cell) {
cell.eval(interpreter);
}
});
}
示例11: createInterpreter
import org.openlca.expressions.FormulaInterpreter; //导入依赖的package包/类
/**
* Creates a new formula interpreter for the parameter values in this table.
*/
public FormulaInterpreter createInterpreter() {
FormulaInterpreter interpreter = new FormulaInterpreter();
TLongObjectIterator<Map<String, ParameterCell>> it = entries.iterator();
while (it.hasNext()) {
it.advance();
Map<String, ParameterCell> map = it.value();
for (ParameterCell cell : map.values())
cell.bindTo(interpreter);
}
return interpreter;
}
示例12: simulate
import org.openlca.expressions.FormulaInterpreter; //导入依赖的package包/类
/**
* Calculates new random values for the parameters in this table that have
* an uncertainty distribution assigned. The method creates a formula
* interpreter that is used for the evaluation of the uncertainty parameters
* and returned with the new values bound. Thus, the returned interpreter
* can be used in calculations.
*/
public FormulaInterpreter simulate() {
FormulaInterpreter interpreter = createInterpreter();
TLongObjectIterator<Map<String, ParameterCell>> it = entries.iterator();
while (it.hasNext()) {
it.advance();
Map<String, ParameterCell> map = it.value();
for (ParameterCell cell : map.values()) {
cell.eval(interpreter);
cell.simulate();
cell.bindTo(interpreter);
}
}
return interpreter;
}
示例13: findScope
import org.openlca.expressions.FormulaInterpreter; //导入依赖的package包/类
private Scope findScope(FormulaInterpreter interpreter) {
if (param.getScope() == ParameterScope.GLOBAL)
return interpreter.getGlobalScope();
Scope scope = interpreter.getScope(param.getOwner());
if (scope == null)
scope = interpreter.createScope(param.getOwner());
return scope;
}
示例14: eval
import org.openlca.expressions.FormulaInterpreter; //导入依赖的package包/类
void eval(FormulaInterpreter interpreter) {
if (interpreter == null)
return;
try {
Scope scope = findScope(interpreter);
tryEval(scope);
} catch (Exception e) {
Logger log = LoggerFactory.getLogger(getClass());
log.error(
"Formula evaluation failed; parameter: "
+ param.getName(), e);
}
}
示例15: createMatrix
import org.openlca.expressions.FormulaInterpreter; //导入依赖的package包/类
public InventoryMatrix createMatrix(IMatrixSolver solver,
FormulaInterpreter interpreter) {
evalFormulas(interpreter);
InventoryMatrix matrix = new InventoryMatrix();
matrix.flowIndex = flowIndex;
matrix.productIndex = productIndex;
IMatrix enviMatrix = interventionMatrix.createRealMatrix(solver);
matrix.interventionMatrix = enviMatrix;
IMatrix techMatrix = technologyMatrix.createRealMatrix(solver);
matrix.technologyMatrix = techMatrix;
return matrix;
}