Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ | |
import org.apache.commons.math.ode.events.EventHandler; | ||
import org.simulator.math.Mathematics; | ||
import org.simulator.math.odes.MultiTable.Block.Column; | ||
import org.simulator.sbml.SBMLinterpreter; | ||
|
||
/** | ||
* This Class represents an abstract solver for event-driven DES | ||
|
@@ -123,6 +124,12 @@ public static long getSerialversionuid() { | |
*/ | ||
public static final String PROGRESS = "progress"; | ||
|
||
/** | ||
* Key used when informing listeners about change in the result by this | ||
* solver. | ||
*/ | ||
public static final String RESULT = "result"; | ||
|
||
/** | ||
* Initialize with default integration step size and non-negative attribute | ||
* {@code true}. | ||
|
@@ -272,8 +279,8 @@ boolean checkSolution(double[] currentChange, double[] yPrev) { | |
return !unstableFlag; | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see java.lang.Object#clone() | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public abstract AbstractDESSolver clone(); | ||
|
@@ -431,16 +438,18 @@ public int eventOccurred(double t, double[] y, boolean increasing) | |
return STOP; | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see org.sbml.simulator.math.odes.DESSolver#firePropertyChanged(double, double) | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public void firePropertyChange(double oldValue, double newValue /*, double[] currResult, double[] additionalResult*/) { | ||
public void firePropertyChange(double oldValue, double newValue, double[] currResult) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
hemilpanchiwala
Author
Owner
|
||
if (!listenerList.isEmpty()) { | ||
PropertyChangeEvent evt = new PropertyChangeEvent(this, PROGRESS, oldValue, newValue); | ||
PropertyChangeEvent evt1 = new PropertyChangeEvent(this, PROGRESS, oldValue, newValue); | ||
PropertyChangeEvent evt2 = new PropertyChangeEvent(this, RESULT, currResult, currResult); | ||
// logger.info(String.format("Progress: %s %%", StringTools.toString(newValue))); | ||
for (PropertyChangeListener listener : listenerList) { | ||
listener.propertyChange(evt); | ||
listener.propertyChange(evt1); | ||
listener.propertyChange(evt2); | ||
} | ||
} | ||
} | ||
|
@@ -770,10 +779,12 @@ public MultiTable solve(DESystem DES, double[] initialValues, double timeBegin, | |
if (fastFlag) { | ||
result[0] = computeSteadyState(((FastProcessDESystem) DES), result[0], timeBegin); | ||
} | ||
addPropertyChangeListener((SBMLinterpreter) DES); | ||
|
||
// execute events that trigger at 0.0 | ||
processEvents((EventDESystem) DES, 0d, 0d, result[0]); | ||
System.arraycopy(result[0], 0, yTemp, 0, yTemp.length); | ||
firePropertyChange(0d, 0d, result[0]); | ||
for (int i = 1; (i < result.length) && (!Thread.currentThread().isInterrupted()); i++) { | ||
double oldT = t; | ||
System.arraycopy(yTemp, 0, yPrev, 0, yTemp.length); | ||
|
@@ -790,7 +801,7 @@ public MultiTable solve(DESystem DES, double[] initialValues, double timeBegin, | |
// if (logger.getLevel().intValue() < Level.INFO.intValue()) { | ||
// logger.fine("additional results: " + Arrays.toString(v)); | ||
// } | ||
firePropertyChange(oldT * intervalFactor, t * intervalFactor); | ||
firePropertyChange(oldT * intervalFactor, t * intervalFactor, yTemp); | ||
} | ||
return data; | ||
} | ||
|
@@ -837,9 +848,11 @@ public MultiTable solve(DESystem DES, double[] initialValues, double[] timePoint | |
result[0] = computeSteadyState(((FastProcessDESystem) DES), result[0], timePoints[0]); | ||
} | ||
|
||
addPropertyChangeListener((SBMLinterpreter) DES); | ||
// execute events that trigger at 0.0 | ||
processEvents((EventDESystem) DES, 0d, 0d, result[0]); | ||
System.arraycopy(result[0], 0, yTemp, 0, result[0].length); | ||
firePropertyChange(0d, 0d, result[0]); | ||
for (int i = 1; (i < timePoints.length) && (!Thread.currentThread().isInterrupted()); i++) { | ||
h = stepSize; | ||
// h = h / 10; | ||
|
@@ -866,7 +879,7 @@ public MultiTable solve(DESystem DES, double[] initialValues, double[] timePoint | |
// if (logger.getLevel().intValue() < Level.INFO.intValue()) { | ||
// logger.fine("additional results: " + Arrays.toString(v)); | ||
// } | ||
firePropertyChange(timePoints[i - 1] * intervalFactor, timePoints[i] * intervalFactor); | ||
firePropertyChange(timePoints[i - 1], timePoints[i], yTemp); | ||
t = timePoints[i]; | ||
} | ||
return data; | ||
|
@@ -881,6 +894,7 @@ public MultiTable solve(DESystem DES, MultiTable.Block initConditions, double[] | |
if (DES instanceof DelayedDESystem) { | ||
((DelayedDESystem) DES).registerDelayValueHolder(this); | ||
} | ||
addPropertyChangeListener((SBMLinterpreter) DES); | ||
double[] timePoints = initConditions.getTimePoints(); | ||
|
||
// of items to be simulated, this will cause a problem! | ||
|
@@ -909,6 +923,7 @@ public MultiTable solve(DESystem DES, MultiTable.Block initConditions, double[] | |
double[] change = new double[DES.getDimension()]; | ||
double t = timePoints[0]; | ||
double v[] = additionalResults(DES, t, result[0], data, 0); | ||
firePropertyChange(0d, 0d, result[0]); | ||
for (i = 1; (i < timePoints.length) && (!Thread.currentThread().isInterrupted()); i++) { | ||
double h = stepSize; | ||
if (!missingIds.isEmpty()) { | ||
|
@@ -940,7 +955,7 @@ public MultiTable solve(DESystem DES, MultiTable.Block initConditions, double[] | |
// if ((logger != null) && (logger.getLevel().intValue() < Level.INFO.intValue())) { | ||
// logger.fine("additional results: " + Arrays.toString(v)); | ||
// } | ||
firePropertyChange(timePoints[i - 1] * intervalFactor, timePoints[i] * intervalFactor); | ||
firePropertyChange(timePoints[i - 1] * intervalFactor, timePoints[i] * intervalFactor, yTemp); | ||
t = timePoints[i]; | ||
} | ||
return data; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,8 @@ | |
*/ | ||
package org.simulator.sbml; | ||
|
||
import java.beans.PropertyChangeEvent; | ||
import java.beans.PropertyChangeListener; | ||
import java.text.MessageFormat; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
|
@@ -58,7 +60,6 @@ | |
import org.sbml.jsbml.Species; | ||
import org.sbml.jsbml.SpeciesReference; | ||
import org.sbml.jsbml.Symbol; | ||
import org.sbml.jsbml.util.ValuePair; | ||
import org.sbml.jsbml.validator.ModelOverdeterminedException; | ||
import org.sbml.jsbml.validator.OverdeterminationValidator; | ||
import org.simulator.math.RNG; | ||
|
@@ -108,7 +109,7 @@ | |
*/ | ||
public class SBMLinterpreter | ||
implements DelayedDESystem, EventDESystem, FastProcessDESystem, | ||
RichDESystem, SBMLValueHolder { | ||
RichDESystem, SBMLValueHolder, PropertyChangeListener { | ||
|
||
/** | ||
* A {@link Logger}. | ||
|
@@ -480,6 +481,17 @@ public int getConstraintListenerCount() { | |
|
||
private boolean containsDelays; | ||
|
||
/** | ||
* The value of the last time point processed | ||
*/ | ||
private double lastTimePoint; | ||
|
||
/** | ||
* An array of the concentration of each species at last processed time point | ||
* within the model system. | ||
*/ | ||
private double[] lastTimePointResult; | ||
|
||
|
||
/** | ||
* <p> | ||
|
@@ -571,6 +583,8 @@ public SBMLinterpreter(Model model, double defaultSpeciesValue, double defaultPa | |
reactionReversible = new boolean[model.getReactionCount()]; | ||
initialValues = new double[Y.length]; | ||
nodes = new LinkedList<ASTNode>(); | ||
lastTimePoint = 0d; | ||
lastTimePointResult = new double[Y.length]; | ||
init(true, defaultSpeciesValue, defaultParameterValue, defaultCompartmentValue, amountHash); | ||
} | ||
|
||
|
@@ -2692,4 +2706,31 @@ public Map<String, Boolean> getConstantHash() { | |
public double[] getY() { | ||
return Y; | ||
} | ||
|
||
@Override | ||
public void propertyChange(PropertyChangeEvent propertyChangeEvent) { | ||
|
||
if (propertyChangeEvent.getPropertyName().equals("result")){ | ||
This comment has been minimized.
Sorry, something went wrong.
draeger
Collaborator
|
||
setLastTimePointResult((double[]) propertyChangeEvent.getNewValue()); | ||
}else { | ||
setLastTimePoint((Double) propertyChangeEvent.getNewValue()); | ||
} | ||
|
||
} | ||
|
||
public double getLastTimePoint() { | ||
This comment has been minimized.
Sorry, something went wrong.
draeger
Collaborator
|
||
return lastTimePoint; | ||
} | ||
|
||
public void setLastTimePoint(double lastTimePoint) { | ||
this.lastTimePoint = lastTimePoint; | ||
} | ||
|
||
public double[] getLastTimePointResult() { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
return lastTimePointResult; | ||
} | ||
|
||
public void setLastTimePointResult(double[] lastTimePointResult) { | ||
This comment has been minimized.
Sorry, something went wrong.
draeger
Collaborator
|
||
this.lastTimePointResult = lastTimePointResult; | ||
} | ||
} |
It is not clear to me why we have
oldValue
andnewValue
. This method is, to my knowledge, used when some value is replaced with a new version. But here, we are dealing with a new result vector in each iteration. It seems to me we should implement a Listener class so that it only has a method that receives some kind of an event object, which can encapsulate the information we need, i.e., the latest time point and the latest result vector.