Dear users, Please note that, from Monday, August 16, 2019, RSA keys shorter than 2048bit will no longer be accepted for security reasons. Please update your keys as needed before this date. If you need assistance with regard to this process, please contact sia@list.lu

Thank you for your understanding.

Commit 77d6fbd6 authored by Nico Mack's avatar Nico Mack

Added possibility to specify initial values for input and output

variables
parent 0dbde05f
......@@ -110,14 +110,14 @@ public class EquationSystemBuilder {
// ***************************************************************************
// ---------------------------------------------------------------------------
private Executor instantiateExecutor(Properties properties) {
private Executor instantiateExecutor(Properties props) {
Executor executor = null;
String executorClass = properties.getProperty(Externalization.EXECUTOR_CLASS);
String executorClass = props.getProperty(Externalization.EXECUTOR_CLASS);
try {
executor = (Executor) Class.forName(executorClass)
.getConstructor(Properties.class)
.newInstance(properties);
.newInstance(props);
} catch (Exception exception) {
logger.log(Level.SEVERE, "Failed to instantiate executor class " + executorClass + "!", exception); //$NON-NLS-1$ //$NON-NLS-2$
}
......@@ -202,11 +202,14 @@ public class EquationSystemBuilder {
unit = output.getAttributeValue(Externalization.UNIT_ELEMENT);
if (Strings.isNullOrEmpty(unit))
unit = Variable.NO_UNIT;
String initialValue = output.getChildText(Externalization.INITIAL_ATTRIBUTE);
if (Strings.isNullOrEmpty(initialValue))
initialValue = output.getAttributeValue(Externalization.INITIAL_ATTRIBUTE);
if (Strings.isNullOrEmpty(name)) {
throw new EquationSystemException("For each output the name needs to be defined!"); //$NON-NLS-1$
}
addVariable(outputVariables, name, unit, "");
addVariable(outputVariables, name, initialValue, unit, null);
}
}
......@@ -274,6 +277,10 @@ public class EquationSystemBuilder {
if (Strings.isNullOrEmpty(parameterUnit))
parameterUnit = Variable.NO_UNIT;
String initialValue = parameter.getChildText(Externalization.INITIAL_ATTRIBUTE);
if (Strings.isNullOrEmpty(initialValue))
initialValue = parameter.getAttributeValue(Externalization.INITIAL_ATTRIBUTE);
_equationParameters.add(parameterName);
if (parameterDependencies.containsKey(parameterName)) {
......@@ -285,7 +292,7 @@ public class EquationSystemBuilder {
}
if (!dependentVariables.containsKey(parameterName) && !independentVariables.containsKey(parameterName)) {
addVariable(independentVariables, parameterName, parameterUnit, "");
addVariable(independentVariables, parameterName, initialValue, parameterUnit, null);
}
}
equationParameters.put(equationName, _equationParameters);
......@@ -301,22 +308,24 @@ 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, String equate) {
Variable newVariable;
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);
map.put(name, newVariable);
break;
default:
newVariable = instantiateVariable(properties, name, unit, 0);
newVariable.setEquate(equate);
map.put(name, newVariable);
break;
}
} else {
......@@ -324,6 +333,10 @@ public class EquationSystemBuilder {
newVariable.setEquate(equate);
map.put(name, newVariable);
}
if (initial != null) {
newVariable.setValue(initial);
}
map.put(name, newVariable);
}
private void addResultDependencies(Element equation) {
......@@ -365,7 +378,7 @@ public class EquationSystemBuilder {
output.setEquate(equate);
dependentVariables.put(resultName, output);
} else {
addVariable(dependentVariables, resultName, resultUnit, equate);
addVariable(dependentVariables, resultName, null, resultUnit, equate);
}
}
if (this.independentVariables.containsKey(resultName)) {
......
......@@ -41,6 +41,7 @@ public class Externalization extends NLS {
public static String OUTPUT_ELEMENT;
public static String OUTPUTS_ELEMENT;
public static String PARAMETER_ELEMENT;
public static String INITIAL_ATTRIBUTE;
public static String PARAMETERS_ELEMENT;
public static String PERIODIC_ATTRIBUTE;
public static String RESULT_ELEMENT;
......
......@@ -7,6 +7,7 @@ NAME_ELEMENT=name
OUTPUT_ELEMENT=output
OUTPUTS_ELEMENT=outputs
PARAMETER_ELEMENT=parameter
INITIAL_ATTRIBUTE=initial
PARAMETERS_ELEMENT=parameters
PERIODIC_ATTRIBUTE=periodic
RESULT_ELEMENT=result
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment