當前位置: 首頁>>代碼示例>>Java>>正文


Java FormulaInterpreter類代碼示例

本文整理匯總了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;
}
 
開發者ID:GreenDelta,項目名稱:olca-modules,代碼行數:23,代碼來源:GlobalParameterSync.java

示例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);
	}
}
 
開發者ID:GreenDelta,項目名稱:olca-modules,代碼行數:17,代碼來源:RegionalizedCalculator.java

示例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;
	}
}
 
開發者ID:GreenDelta,項目名稱:olca-modules,代碼行數:27,代碼來源:Simulator.java

示例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;
}
 
開發者ID:GreenDelta,項目名稱:olca-modules,代碼行數:27,代碼來源:Parameter.java

示例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;
}
 
開發者ID:GreenDelta,項目名稱:olca-modules,代碼行數:9,代碼來源:ProcessParameterMapper.java

示例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;
}
 
開發者ID:GreenDelta,項目名稱:olca-modules,代碼行數:10,代碼來源:GlobalParameterSync.java

示例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;
}
 
開發者ID:GreenDelta,項目名稱:olca-modules,代碼行數:11,代碼來源:ImpactTable.java

示例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);
	}
}
 
開發者ID:GreenDelta,項目名稱:olca-modules,代碼行數:15,代碼來源:ExchangeCell.java

示例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);
	}
}
 
開發者ID:GreenDelta,項目名稱:olca-modules,代碼行數:14,代碼來源:ImpactFactorCell.java

示例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);
		}
	});
}
 
開發者ID:GreenDelta,項目名稱:olca-modules,代碼行數:9,代碼來源:ImpactFactorMatrix.java

示例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;
}
 
開發者ID:GreenDelta,項目名稱:olca-modules,代碼行數:15,代碼來源:ParameterTable.java

示例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;
}
 
開發者ID:GreenDelta,項目名稱:olca-modules,代碼行數:22,代碼來源:ParameterTable.java

示例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;
}
 
開發者ID:GreenDelta,項目名稱:olca-modules,代碼行數:9,代碼來源:ParameterTable.java

示例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);
	}
}
 
開發者ID:GreenDelta,項目名稱:olca-modules,代碼行數:14,代碼來源:ParameterTable.java

示例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;
}
 
開發者ID:GreenDelta,項目名稱:olca-modules,代碼行數:13,代碼來源:Inventory.java


注:本文中的org.openlca.expressions.FormulaInterpreter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。