Commit bd393569 authored by Christian Moll's avatar Christian Moll

Merge branch 'dev-nico' into 'master'

Dev nico into master

See merge request !1
parents 37904fc2 b8ed3735
......@@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>lu.list.itis.dkd.tui</groupId>
<artifactId>tulip-cps</artifactId>
<version>1.3.1</version>
<version>1.4.0</version>
<name>TULIP Complex Problem Solving</name>
<licenses>
......@@ -47,12 +47,49 @@
<dependency>
<groupId>lu.list.itis.dkd.tui</groupId>
<artifactId>tulip</artifactId>
<version>2.3.1</version>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>dk.ange</groupId>
<groupId>maven2.dk.ange</groupId>
<artifactId>javaoctave</artifactId>
<version>0.6.4</version>
</dependency>
<dependency>
<groupId>org.python</groupId>
<artifactId>jython-standalone</artifactId>
<version>2.7.1b3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.23</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.8</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.8</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.8</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>Kenai</id>
<name>Kenai</name>
<url>https://svn.kenai.com/svn/javaoctave~maven-repository</url>
</repository>
</repositories>
</project>
\ No newline at end of file
......@@ -22,15 +22,17 @@ package lu.list.itis.dkd.tui.cps.system;
import lu.list.itis.dkd.dbc.annotation.NonNullByDefault;
import lu.list.itis.dkd.dbc.annotation.Nullable;
import lu.list.itis.dkd.tui.cps.system.executor.Executor;
import lu.list.itis.dkd.tui.cps.variable.Variable;
import com.google.common.base.Preconditions;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.LinkedHashSet;
import javax.script.ScriptEngine;
import javax.script.ScriptException;
/**
* Class modelling a mathematical equation that is evaluated by an engine.
......@@ -44,9 +46,12 @@ public class Equation {
private Mapping mapping;
private Mapping lockedMapping;
@Nullable
private ScriptEngine scriptEngine;
// private ScriptEngine scriptEngine;
private Executor scriptExecutor;
private String script;
private static Logger LOGGER = LoggerFactory.getLogger(Equation.class.getSimpleName());
/**
* Constructor
*
......@@ -77,11 +82,49 @@ public class Equation {
* mapping.
*/
public void evaluate() {
Preconditions.checkState(scriptEngine != null);
// Preconditions.checkState(scriptEngine != null);
// try {
// mapping.getDependentVariable().setValue(scriptEngine.eval(replaceVariables()));
// } catch (ScriptException e) {
// Logger.getLogger(Equation.class.getSimpleName()).log(Level.SEVERE, "Exception while
// executing script!", e); //$NON-NLS-1$
// }
LinkedHashSet<Variable> dependentVariables;
String evaluationErrors;
Preconditions.checkState(scriptExecutor != null);
try {
mapping.getDependentVariable().setValue(scriptEngine.eval(replaceVariables()));
} catch (ScriptException e) {
Logger.getLogger(Equation.class.getSimpleName()).log(Level.SEVERE, "Exception while executing script!", e); //$NON-NLS-1$
scriptExecutor.resetExecutionErrors();
for (Variable variable : lockedMapping.getIndependentVariables()) {
scriptExecutor.set(variable);
}
scriptExecutor.eval(this.script);
} catch (Exception exception) {
LOGGER.error("Error while evaluating script {}", this.script, exception); //$NON-NLS-1$
}
dependentVariables = mapping.getDependentVariables();
for (Variable variable : dependentVariables) {
try {
variable = scriptExecutor.get(variable);
} catch (Exception exception) {
LOGGER.error("Error while retrieving variable {}", variable.getName(), exception); //$NON-NLS-1$
}
}
evaluationErrors = scriptExecutor.getExecutionErrors();
if (evaluationErrors.length() > 0) {
LOGGER.warn("Error while evaluating equation : {}", evaluationErrors); //$NON-NLS-1$
LOGGER.warn("Script = {}", this.script); //$NON-NLS-1$
LinkedHashSet<Variable> independentVariables = mapping.getIndependentVariables();
for (Variable variable : independentVariables) {
LOGGER.trace("{} = {}", variable.getName(), variable.getValue()); //$NON-NLS-1$
}
}
}
......@@ -90,17 +133,20 @@ public class Equation {
*
* @return The formula with variables replaced by their values, ready for evaluation.
*/
private String replaceVariables() {
String result = new String(script);
for (Variable variable : lockedMapping.getIndependentVariables()) {
result = result.replaceAll(variable.getName(), variable.getValue().toString());
}
result = result.replaceAll(lockedMapping.getDependentVariable().getName(), lockedMapping.getDependentVariable().getValue().toString());
assert result != null;
return result;
}
// private String replaceVariables() {
// String result = new String(script);
//
// for (Variable variable : lockedMapping.getIndependentVariables()) {
// result = result.replaceAll(variable.getName(), variable.getValue().toString());
// }
//
// for (Variable variable : lockedMapping.getDependentVariables()) {
// result = result.replaceAll(variable.getName(), variable.getValue().toString());
// }
//
// assert result != null;
// return result;
// }
/**
* Method for setting the script engine to use.
......@@ -108,8 +154,17 @@ public class Equation {
* @param engine
* The {@link ScriptEngine} instance to use for evaluating the scripted formulas.
*/
public void setScriptEngine(ScriptEngine engine) {
scriptEngine = engine;
// public void setScriptEngine(ScriptEngine engine) {
// scriptEngine = engine;
// }
/**
* Method for setting the script engine to use.
*
* @param engine
* The {@link ScriptEngine} instance to use for evaluating the scripted formulas.
*/
public void setExecutor(Executor executor) {
this.scriptExecutor = executor;
}
/**
......
......@@ -22,10 +22,10 @@ package lu.list.itis.dkd.tui.cps.system;
import lu.list.itis.dkd.dbc.annotation.NonNullByDefault;
import lu.list.itis.dkd.tui.cps.Phenomenon;
import lu.list.itis.dkd.tui.cps.system.executor.Executor;
import lu.list.itis.dkd.tui.cps.utility.Externalization;
import lu.list.itis.dkd.tui.cps.variable.BooleanVariable;
import lu.list.itis.dkd.tui.cps.variable.NumericalVariable;
import lu.list.itis.dkd.tui.cps.variable.Variable;
import lu.list.itis.dkd.tui.cps.variable.tangible.TangibleNumericalVariable;
import com.google.common.base.Strings;
......@@ -33,18 +33,20 @@ import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.input.SAXBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
......@@ -60,7 +62,9 @@ import java.util.regex.Pattern;
*/
@NonNullByDefault
public class EquationSystemBuilder {
private Properties properties;
private Document equationDocument;
private Executor scriptExecutor;
private ConcurrentHashMap<String, Variable> independentVariables;
private ConcurrentHashMap<String, Variable> dependentVariables;
......@@ -70,18 +74,21 @@ public class EquationSystemBuilder {
// TODO Refactor to use Multimaps
private ConcurrentHashMap<String, List<String>> parameterDependencies;
private ConcurrentHashMap<String, List<String>> resultDependencies;
private ConcurrentHashMap<String, List<Import>> equationImports;
private ConcurrentHashMap<String, List<String>> equationParameters;
private ConcurrentHashMap<String, List<String>> equationResults;
private ConcurrentHashMap<String, LinearEquationSystem> equations;
private ConcurrentHashMap<String, Phenomenon> phenomena;
private static final Pattern booleanPattern = Pattern.compile("true|yes|1", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
private static final Logger logger = Logger.getLogger(EquationSystemBuilder.class.getSimpleName());
private static final Logger logger = LoggerFactory.getLogger(EquationSystemBuilder.class.getSimpleName());
/**
* Constructor initializing all fields.
*/
public EquationSystemBuilder() {
public EquationSystemBuilder(Properties properties) {
this.properties = properties;
this.scriptExecutor = this.instantiateExecutor(properties);
independentVariables = new ConcurrentHashMap<String, Variable>();
dependentVariables = new ConcurrentHashMap<String, Variable>();
......@@ -90,12 +97,151 @@ public class EquationSystemBuilder {
parameterDependencies = new ConcurrentHashMap<String, List<String>>();
resultDependencies = new ConcurrentHashMap<String, List<String>>();
equationImports = new ConcurrentHashMap<String, List<Import>>();
equationParameters = new ConcurrentHashMap<String, List<String>>();
equationResults = new ConcurrentHashMap<String, List<String>>();
equations = new ConcurrentHashMap<String, LinearEquationSystem>();
phenomena = new ConcurrentHashMap<String, Phenomenon>();
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
// ***************************************************************************
// ---------------------------------------------------------------------------
private Executor instantiateExecutor(Properties props) {
Executor executor = null;
String executorClass = props.getProperty(Externalization.EXECUTOR_CLASS);
try {
executor = (Executor) Class.forName(executorClass)
.getConstructor(Properties.class)
.newInstance(props);
} catch (Exception exception) {
logger.error("Failed to instantiate executor class {}!", executorClass, exception); //$NON-NLS-1$
}
return executor;
}
// ---------------------------------------------------------------------------
private Variable instantiateVariable(String name, String type, String unit, String value) {
Variable variable = null;
String variableClass = "undefined"; //$NON-NLS-1$
try {
switch (type) {
case Externalization.LOGIC_TYPE:
default:
variableClass = properties.getProperty(Externalization.LOGIC_VARIABLE_CLASS);
variable = (Variable) Class.forName(variableClass)
.getConstructor(String.class, String.class, boolean.class)
.newInstance(name, unit, false);
if (!Strings.isNullOrEmpty(value))
variable.setValue(variable.valueFromString(value));
break;
case Externalization.NUMERIC_TYPE:
variableClass = properties.getProperty(Externalization.NUMERIC_VARIABLE_CLASS);
variable = (Variable) Class.forName(variableClass)
.getConstructor(String.class, String.class, double.class)
.newInstance(name, unit, 0);
if (!Strings.isNullOrEmpty(value))
variable.setValue(variable.valueFromString(value));
}
} catch (Exception exception) {
logger.error("Failed to instantiate variable class {}!", variableClass, exception); //$NON-NLS-1$
}
return variable;
}
// ---------------------------------------------------------------------------
private HashMap<String, String> extractAttributesForVariables(Element element) {
HashMap<String, String> attributes = new HashMap<String, String>();
String attribute;
attribute = element.getChildText(Externalization.NAME_ATTRIBUTE);
if (Strings.isNullOrEmpty(attribute))
attribute = element.getAttributeValue(Externalization.NAME_ATTRIBUTE);
attributes.put(Externalization.NAME_ATTRIBUTE, attribute);
attribute = element.getChildText(Externalization.TYPE_ATTRIBUTE);
if (Strings.isNullOrEmpty(attribute))
attribute = element.getAttributeValue(Externalization.TYPE_ATTRIBUTE);
if (Strings.isNullOrEmpty(attribute))
attribute = Externalization.NUMERIC_TYPE;
attributes.put(Externalization.TYPE_ATTRIBUTE, attribute);
attribute = element.getChildText(Externalization.UNIT_ATTRIBUTE);
if (Strings.isNullOrEmpty(attribute))
attribute = element.getAttributeValue(Externalization.UNIT_ATTRIBUTE);
if (Strings.isNullOrEmpty(attribute))
attribute = Variable.NO_UNIT;
attributes.put(Externalization.UNIT_ATTRIBUTE, attribute);
attribute = element.getChildText(Externalization.INITIAL_ATTRIBUTE);
if (Strings.isNullOrEmpty(attribute))
attribute = element.getAttributeValue(Externalization.INITIAL_ATTRIBUTE);
attributes.put(Externalization.INITIAL_ATTRIBUTE, attribute);
attribute = element.getChildText(Externalization.MINIMUM_ATTRIBUTE);
if (Strings.isNullOrEmpty(attribute))
attribute = element.getAttributeValue(Externalization.MINIMUM_ATTRIBUTE);
attributes.put(Externalization.MINIMUM_ATTRIBUTE, attribute);
attribute = element.getChildText(Externalization.MAXIMUM_ATTRIBUTE);
if (Strings.isNullOrEmpty(attribute))
attribute = element.getAttributeValue(Externalization.MAXIMUM_ATTRIBUTE);
attributes.put(Externalization.MAXIMUM_ATTRIBUTE, attribute);
attribute = element.getChildText(Externalization.EQUATE_ATTRIBUTE);
if (Strings.isNullOrEmpty(attribute))
attribute = element.getAttributeValue(Externalization.EQUATE_ATTRIBUTE);
attributes.put(Externalization.EQUATE_ATTRIBUTE, attribute);
return attributes;
}
// ---------------------------------------------------------------------------
private Variable createVariable(HashMap<String, String> attributes) {
Variable variable;
// String scale = xmlElement.getAttributeValue(Externalization.SCALE_ATTRIBUTE);
// String decimals = xmlElement.getAttributeValue(Externalization.DECIMALS_ATTRIBUTE);
variable = this.instantiateVariable(attributes.get(Externalization.NAME_ATTRIBUTE),
attributes.get(Externalization.TYPE_ATTRIBUTE),
attributes.get(Externalization.UNIT_ATTRIBUTE),
attributes.get(Externalization.INITIAL_ATTRIBUTE));
if (Externalization.NUMERIC_TYPE.equals(attributes.get(Externalization.TYPE_ATTRIBUTE))) {
NumericalVariable numericVariable = (NumericalVariable) variable;
if (!Strings.isNullOrEmpty(attributes.get(Externalization.MINIMUM_ATTRIBUTE)))
numericVariable.setMinValue((Double) numericVariable.valueFromString(attributes.get(Externalization.MINIMUM_ATTRIBUTE)));
if (!Strings.isNullOrEmpty(attributes.get(Externalization.MAXIMUM_ATTRIBUTE)))
numericVariable.setMinValue((Double) numericVariable.valueFromString(attributes.get(Externalization.MAXIMUM_ATTRIBUTE)));
if (!Strings.isNullOrEmpty(attributes.get(Externalization.EQUATE_ATTRIBUTE)))
numericVariable.setEquate(attributes.get(Externalization.EQUATE_ATTRIBUTE));
variable = numericVariable;
}
return variable;
}
/**
* Checks whether the specified equation creates a dependency cycle. Dependency cycles occur
......@@ -108,9 +254,9 @@ public class EquationSystemBuilder {
* otherwise.
*/
private boolean hasDependencyCycle(Element equation) {
String equationName = equation.getChildText(Externalization.NAME_ELEMENT);
String equationName = equation.getChildText(Externalization.NAME_ATTRIBUTE);
if (Strings.isNullOrEmpty(equationName))
equationName = equation.getAttributeValue(Externalization.NAME_ELEMENT);
equationName = equation.getAttributeValue(Externalization.NAME_ATTRIBUTE);
boolean dependencyCycle = false;
for (String parameter : equationParameters.get(equationName)) {
......@@ -147,19 +293,17 @@ public class EquationSystemBuilder {
}
List<Element> outputElements = outputs.get(0).getChildren(Externalization.OUTPUT_ELEMENT);
HashMap<String, String> outputAttributes;
for (Element output : outputElements) {
String name = output.getChildText(Externalization.NAME_ELEMENT);
if (Strings.isNullOrEmpty(name))
name = output.getAttributeValue(Externalization.NAME_ELEMENT);
String unit = output.getChildText(Externalization.UNIT_ELEMENT);
if (Strings.isNullOrEmpty(unit))
unit = output.getAttributeValue(Externalization.UNIT_ELEMENT);
if (Strings.isNullOrEmpty(name)) {
outputAttributes = this.extractAttributesForVariables(output);
String identifier = outputAttributes.get(Externalization.NAME_ATTRIBUTE);
if (Strings.isNullOrEmpty(identifier)) {
throw new EquationSystemException("For each output the name needs to be defined!"); //$NON-NLS-1$
}
addVariable(outputVariables, name, unit);
outputVariables.put(identifier, this.createVariable(outputAttributes));
}
}
......@@ -167,6 +311,7 @@ public class EquationSystemBuilder {
private void extractEquations(List<Element> equationElements) throws EquationSystemException {
// First pass to gather all Parameters and Results and to determine dependencies
for (Element equation : equationElements) {
extractImports(equation);
addDependencies(equation);
}
......@@ -179,40 +324,59 @@ public class EquationSystemBuilder {
resolveDependencies();
if (!this.allOutputsAssigned()) {
logger.warning("Not all defined outputs are assigned to an equation!"); //$NON-NLS-1$
logger.warn("Not all defined outputs are assigned to an equation!"); //$NON-NLS-1$
// throw new EquationSystemException (message);
}
}
private void extractImports(Element equation) {
String equationName;
List<Element> importDeclarations;
List<Import> imports;
equationName = equation.getAttributeValue(Externalization.NAME_ATTRIBUTE);
if (Strings.isNullOrEmpty(equationName))
equationName = equation.getAttributeValue(Externalization.NAME_ATTRIBUTE);
Element importsTag = equation.getChild(Externalization.IMPORTS_ELEMENT);
if (importsTag != null) {
imports = new ArrayList<Import>();
importDeclarations = importsTag.getChildren(Externalization.IMPORT_ELEMENT);
for (Element declaration : importDeclarations) {
String function = declaration.getAttributeValue(Externalization.FUNCTION_ATTRIBUTE);
String from = declaration.getAttributeValue(Externalization.FROM_ATTRIBUTE);
imports.add(new Import(function, from));
}
this.equationImports.put(equationName, imports);
}
}
private void addParameterDependencies(Element equation) {
String equationName = equation.getChildText(Externalization.NAME_ELEMENT);
String equationName = equation.getChildText(Externalization.NAME_ATTRIBUTE);
if (Strings.isNullOrEmpty(equationName))
equationName = equation.getAttributeValue(Externalization.NAME_ELEMENT);
equationName = equation.getAttributeValue(Externalization.NAME_ATTRIBUTE);
List<Element> parameters = equation.getChild(Externalization.PARAMETERS_ELEMENT).getChildren(Externalization.PARAMETER_ELEMENT);
List<String> _equationParameters = new ArrayList<String>();
HashMap<String, String> parameterAttributes;
for (Element parameter : parameters) {
String parameterName = parameter.getChildText(Externalization.NAME_ELEMENT);
if (Strings.isNullOrEmpty(parameterName))
parameterName = parameter.getAttributeValue(Externalization.NAME_ELEMENT);
String parameterUnit = parameter.getChildText(Externalization.UNIT_ELEMENT);
if (Strings.isNullOrEmpty(parameterUnit))
parameterUnit = parameter.getAttributeValue(Externalization.UNIT_ELEMENT);
_equationParameters.add(parameterName);
parameterAttributes = this.extractAttributesForVariables(parameter);
String identifier = parameterAttributes.get(Externalization.NAME_ATTRIBUTE);
if (parameterDependencies.containsKey(parameterName)) {
parameterDependencies.get(parameterName).add(equationName);
_equationParameters.add(identifier);
if (parameterDependencies.containsKey(identifier)) {
parameterDependencies.get(identifier).add(equationName);
} else {
List<String> dependencies = new ArrayList<String>();
dependencies.add(equationName);
parameterDependencies.put(parameterName, dependencies);
parameterDependencies.put(identifier, dependencies);
}
if (!dependentVariables.containsKey(parameterName) && !independentVariables.containsKey(parameterName)) {
addVariable(independentVariables, parameterName, parameterUnit);
if (!dependentVariables.containsKey(identifier) && !independentVariables.containsKey(identifier)) {
independentVariables.put(identifier, this.createVariable(parameterAttributes));
}
}
equationParameters.put(equationName, _equationParameters);
......@@ -228,67 +392,81 @@ public class EquationSystemBuilder {
* The map to add the variable to.
* @param name
* The name of the variable to create.
* @param initial
* The (optional) initial value to be assigned to the newly created variable
* @param unit
* The name of the unit the variable will carry.
* @param equate
* The (optional) equate
*/
private void addVariable(Map<String, Variable> map, String name, String unit) {
switch (unit) {
case "boolean": //$NON-NLS-1$
map.put(name, new BooleanVariable(name, false));
break;
default:
map.put(name, new TangibleNumericalVariable(name, unit, 0));
break;
}
}
// private void addVariable(Map<String, Variable> map, String name, Object initial, String unit,
// String equate) {
// Variable newVariable = null;
// if (unit != null) {
// switch (unit) {
// case "boolean": //$NON-NLS-1$
// newVariable = new BooleanVariable(name, false);
// newVariable.setEquate(equate);
// break;
// default:
// newVariable = instantiateVariable(properties, name, unit, 0);
// newVariable.setEquate(equate);
// break;
// }
// } else {
// newVariable = instantiateVariable(properties, name, unit, 0);
// newVariable.setEquate(equate);
// map.put(name, newVariable);
// }
// if (initial != null) {
// newVariable.setValue(initial);
// }
// map.put(name, newVariable);
// }
private void addResultDependencies(Element equation) {
String equationName = equation.getChildText(Externalization.NAME_ELEMENT);
String equationName = equation.getChildText(Externalization.NAME_ATTRIBUTE);
if (Strings.isNullOrEmpty(equationName))
equationName = equation.getAttributeValue(Externalization.NAME_ELEMENT);
equationName = equation.getAttributeValue(Externalization.NAME_ATTRIBUTE);
List<Element> results = equation.getChild(Externalization.RESULTS_ELEMENT).getChildren(Externalization.RESULT_ELEMENT);
List<String> _equationResults = new ArrayList<String>();
HashMap<String, String> resultAttributes;
for (Element result : results) {
String resultName = result.getChildText(Externalization.NAME_ELEMENT);
if (Strings.isNullOrEmpty(resultName))
resultName = result.getAttributeValue(Externalization.NAME_ELEMENT);
String resultUnit = result.getChildText(Externalization.UNIT_ELEMENT);
if (Strings.isNullOrEmpty(resultUnit))
resultUnit = result.getAttributeValue(Externalization.UNIT_ELEMENT);
resultAttributes = this.extractAttributesForVariables(result);
String identifier = resultAttributes.get(Externalization.NAME_ATTRIBUTE);
_equationResults.add(resultName);
_equationResults.add(identifier);
if (resultDependencies.containsKey(resultName)) {
resultDependencies.get(resultName).add(equationName);
if (resultDependencies.containsKey(identifier)) {
resultDependencies.get(identifier).add(equationName);
} else {
List<String> dependencies = new ArrayList<String>();
dependencies.add(equationName);
resultDependencies.put(resultName, dependencies);
resultDependencies.put(identifier, dependencies);
}
if (!dependentVariables.containsKey(resultName)) {
if (outputVariables.containsKey(resultName)) {
dependentVariables.put(resultName, outputVariables.get(resultName));
if (!dependentVariables.containsKey(identifier)) {
Variable output = null;
if (outputVariables.containsKey(identifier)) {
output = outputVariables.get(identifier);
output.setEquate(resultAttributes.get(Externalization.EQUATE_ATTRIBUTE));
dependentVariables.put(identifier, output);
} else {
addVariable(dependentVariables, resultName, resultUnit);
dependentVariables.put(identifier, this.createVariable(resultAttributes));
}
}
if (this.independentVariables.containsKey(resultName)) {
this.independentVariables.remove(resultName);
if (this.independentVariables.containsKey(identifier)) {
this.independentVariables.remove(identifier);
}
}
equationResults.put(equationName, _equationResults);
}
private void addDependencies(Element equation) throws EquationSystemException {
String periodicity = equation.getChildText(Externalization.PERIODIC_ELEMENT);
String periodicity = equation.getAttributeValue(Externalization.PERIODIC_ATTRIBUTE);
boolean periodic = false;
if (!Strings.isNullOrEmpty(periodicity)) {
......@@ -300,25 +478,23 @@ public class EquationSystemBuilder {
if (!periodic) {
if (hasDependencyCycle(equation)) {
String equationName = equation.getChildText(Externalization.NAME_ELEMENT);
String equationName = equation.getChildText(Externalization.NAME_ATTRIBUTE);
if (Strings.isNullOrEmpty(equationName))
equationName = equation.getAttributeValue(Externalization.NAME_ELEMENT);
equationName = equation.getAttributeValue(Externalization.NAME_ATTRIBUTE);
throw new EquationSystemException("Dependency Cycle detected for equation " + equationName); //$NON-NLS-1$
}
}
}
private void createEquations(Element equation) throws EquationSystemException {