Commit 644efd44 authored by Nico Mack's avatar Nico Mack

Added priority attribute to Equations

parent 496c8581
......@@ -36,6 +36,7 @@ SCALE_ATTRIBUTE=scale
DECIMALS_ATTRIBUTE=decimals
PARAMETERS_ELEMENT=parameters
PERIODIC_ATTRIBUTE=periodic
PRIORITY_ATTRIBUTE=priority
RESULT_ELEMENT=result
EQUATE_ATTRIBUTE=equate
RESULTS_ELEMENT=results
......
......@@ -206,4 +206,5 @@ public class Equation {
public String toString() {
return this.name;
}
}
\ No newline at end of file
......@@ -678,6 +678,13 @@ public class EquationSystemBuilder {
isolated = EquationSystemBundle.ISOLATED_VALUE.equals(mode);
}
String priorityAttribute = equation.getAttributeValue(EquationSystemBundle.PRIORITY_ATTRIBUTE);
int priority = System.DEFAULT_PRIORITY;
if (!Strings.isNullOrEmpty(priorityAttribute)) {
priority = Integer.parseInt(priorityAttribute);
}
for (Declaration declaration : equationParameters.get(equationName)) {
String identifier = declaration.getIdentifier();
if (independentVariables.containsKey(identifier)) {
......@@ -729,6 +736,7 @@ public class EquationSystemBuilder {
newEquation.setExecutor(executors.get(executor));
newEquation.setIsolated(isolated);
equationSystem.addEquation(newEquation);
equationSystem.setPriority(priority);
if (!periodic) {
for (Declaration declaration : equationInputs) {
......@@ -778,7 +786,7 @@ public class EquationSystemBuilder {
String identifier = declaration.getIdentifier();
if (this.resultDependencies.containsKey(identifier)) {
for (String nestedEquationName : this.resultDependencies.get(identifier)) {
system.nestSystem(this.equations.get(nestedEquationName));
system.dependsOn(this.equations.get(nestedEquationName));
}
}
}
......
......@@ -145,7 +145,15 @@ public class LinearEquationSystem extends System {
@Override
public String toString() {
return this.equations.toString();
StringBuilder rendered = new StringBuilder("["); //$NON-NLS-1$
String separator = " "; //$NON-NLS-1$
for (Equation equation : equations.values()) {
rendered.append(separator).append(equation.getName());
separator = " | "; //$NON-NLS-1$
}
rendered.append(" ]"); //$NON-NLS-1$
return rendered.toString();
}
}
\ No newline at end of file
......@@ -29,95 +29,183 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Vector;
/**
* Abstract class serving as a top level hierarchical construct for all system instances.
*
* @author Nico Mack [nico.mack@list.lu]
* @author Eric Tobias [eric.tobias@list.lu]
* @since 1.0
* @version 1.3.0
*/
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
@NonNullByDefault
public abstract class System implements InputDriver, InputChangeListener {
public abstract class System implements InputDriver, InputChangeListener, Comparable<System> {
/** Field holding the {@link Vector} of nested {@link System} instances. */
protected List<System> nestedSystems;
protected List<System> upstreamSystems;
protected List<System> downstreamSystems;
protected boolean lockSystemForNesting = true;
protected int priority = DEFAULT_PRIORITY;
// ***************************************************************************
// * Constants *
// ***************************************************************************
private static final Logger logger = LoggerFactory.getLogger(System.class.getSimpleName());
public static final int DEFAULT_PRIORITY = -1;
private static final Logger LOGGER = LoggerFactory.getLogger(System.class.getSimpleName());
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* Constructor.
*/
// ---------------------------------------------------------------------------
public System() {
nestedSystems = new ArrayList<>();
upstreamSystems = new ArrayList<>();
downstreamSystems = new ArrayList<>();
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// *Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* Allows to isolate this equation. An isolated equation will not notify dependent equations when
* evaluation entailed changes in results.
*
* @param isolateIt
*/
// ---------------------------------------------------------------------------
public void setPriority(int priority) {
this.priority = priority;
}
// ---------------------------------------------------------------------------
public int getPriority() {
return priority;
}
// ---------------------------------------------------------------------------
/**
* Method used to nest a system.
*
* @param system
* The {@link System} instance to add.
*/
public void nestSystem(System system) {
if (!nestedSystems.contains(system)) {
nestedSystems.add(system);
// ---------------------------------------------------------------------------
public void dependsOn(System system) {
if (!upstreamSystems.contains(system)) {
upstreamSystems.add(system);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("{} => {}!", this, system); //$NON-NLS-1$
}
system.requiredBy(this);
} else {
logger.trace("System {} is already known as a nested system!", system); //$NON-NLS-1$
LOGGER.trace("System {} is already known as an upstream system!", system); //$NON-NLS-1$
}
Collections.sort(upstreamSystems);
}
// ---------------------------------------------------------------------------
public void requiredBy(System system) {
if (!downstreamSystems.contains(system)) {
downstreamSystems.add(system);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("{} <= {}!", this, system); //$NON-NLS-1$
}
} else {
LOGGER.trace("System {} is already known as a downstream system!", system); //$NON-NLS-1$
}
Collections.sort(downstreamSystems);
}
// ---------------------------------------------------------------------------
/**
* {@inheritDoc}<br>
* <br>
*
* The method will issue calls to all nested stated to lock input variables after locking
* variables itself but before forwarding the call to them.
* The method will issue calls to all nested stated to lock input variables after locking variables
* itself but before forwarding the call to them.
*/
// ---------------------------------------------------------------------------
@Override
public synchronized void inputChanged(InputEvent input) {
if (lockSystemForNesting) {
saveState();
for (System nestedSystem : nestedSystems) {
for (System nestedSystem : upstreamSystems) {
if (nestedSystem != null)
nestedSystem.saveState();
}
}
for (System nestedSystem : nestedSystems) {
for (System nestedSystem : upstreamSystems) {
if (nestedSystem != null)
nestedSystem.inputChanged(input);
}
}
// ---------------------------------------------------------------------------
/**
* {@inheritDoc}<br>
* <br>
*
* The method will issue calls to all nested stated to lock input variables after locking
* variables itself but before forwarding the call to them.
* The method will issue calls to all nested stated to lock input variables after locking variables
* itself but before forwarding the call to them.
*/
// ---------------------------------------------------------------------------
@Override
public synchronized void clockTicked(long tick) {
if (lockSystemForNesting)
saveState();
for (System nestedSystem : nestedSystems) {
for (System nestedSystem : upstreamSystems) {
nestedSystem.saveState();
}
for (System nestedSystem : nestedSystems) {
for (System nestedSystem : upstreamSystems) {
nestedSystem.clockTicked(tick);
}
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
// ---------------------------------------------------------------------------
@Override
public int compareTo(System system) {
if (system == null)
throw new NullPointerException();
return Integer.compare(priority, system.getPriority());
}
// ---------------------------------------------------------------------------
/**
* Method used to announce an upcoming tick to all computation units and nested systems, hence
* the need to lock all outputs that may server as inputs in feedback loops.
* Method used to announce an upcoming tick to all computation units and nested systems, hence the
* need to lock all outputs that may server as inputs in feedback loops.
*/
// ---------------------------------------------------------------------------
public abstract void saveState();
}
\ No newline at end of file
......@@ -59,6 +59,7 @@ public class EquationSystemBundle extends NLS {
public static String PARAMETER_ELEMENT;
public static String INITIAL_ATTRIBUTE;
public static String PARAMETERS_ELEMENT;
public static String PRIORITY_ATTRIBUTE;
public static String PERIODIC_ATTRIBUTE;
public static String RESULT_ELEMENT;
public static String EPSILON_ATTRIBUTE;
......
......@@ -251,6 +251,21 @@ public class VectorVariable<B> extends Variable<List<B>> implements List<B> {
value.clear();
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
// ---------------------------------------------------------------------------
@Override
public String toString() {
StringBuilder renderer = new StringBuilder(name);
if (value != null) {
renderer.append(value);
} else {
renderer.append("null"); //$NON-NLS-1$
}
return renderer.toString();
}
/** {@inheritDoc} */
@Override
public void setValueFromObject(Object object) {
......
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