From 49b4c99529228ca17d65d0aac98f9fc450718f1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Dr=C3=A4ger?= Date: Wed, 1 Sep 2010 13:49:17 +0000 Subject: [PATCH] Moving DES system from base package to probs package --- .../tools/math/des/AbstractDESSolver.java | 16 - src/eva2/tools/math/des/DESAssignment.java | 36 -- src/eva2/tools/math/des/DESSolver.java | 63 --- src/eva2/tools/math/des/DESystem.java | 43 -- src/eva2/tools/math/des/EventDESystem.java | 35 -- src/eva2/tools/math/des/RKSolver.java | 471 ------------------ 6 files changed, 664 deletions(-) delete mode 100644 src/eva2/tools/math/des/AbstractDESSolver.java delete mode 100644 src/eva2/tools/math/des/DESAssignment.java delete mode 100644 src/eva2/tools/math/des/DESSolver.java delete mode 100644 src/eva2/tools/math/des/DESystem.java delete mode 100644 src/eva2/tools/math/des/EventDESystem.java delete mode 100644 src/eva2/tools/math/des/RKSolver.java diff --git a/src/eva2/tools/math/des/AbstractDESSolver.java b/src/eva2/tools/math/des/AbstractDESSolver.java deleted file mode 100644 index a4a63972..00000000 --- a/src/eva2/tools/math/des/AbstractDESSolver.java +++ /dev/null @@ -1,16 +0,0 @@ -/** - * - */ -package eva2.tools.math.des; - -/** - * This Class represents an Solver for event-driven DES - * - * @author Alexander Dörr - * @date 2010-02-04 - * - */ -public abstract class AbstractDESSolver implements DESSolver { - - -} diff --git a/src/eva2/tools/math/des/DESAssignment.java b/src/eva2/tools/math/des/DESAssignment.java deleted file mode 100644 index 3ef59028..00000000 --- a/src/eva2/tools/math/des/DESAssignment.java +++ /dev/null @@ -1,36 +0,0 @@ -package eva2.tools.math.des; - -public class DESAssignment{ - private double processTime; - private int index; - private Double value; - - public DESAssignment(double processTime, int index, Double value){ - this.processTime = processTime; - this.index = index; - this.value = value; - } - - public DESAssignment(double processTime, int index){ - this.processTime = processTime; - this.index = index; - this.value = null; - } - - public double getProcessTime() { - return processTime; - } - - public int getIndex() { - return index; - } - - public Double getValue() { - return value; - } - - public void setValue(Double value) { - this.value = value; - } - -} diff --git a/src/eva2/tools/math/des/DESSolver.java b/src/eva2/tools/math/des/DESSolver.java deleted file mode 100644 index c8797a0e..00000000 --- a/src/eva2/tools/math/des/DESSolver.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Title: JAVA-EVA Description: Copyright: Copyright (c) 2002 Company: - * University of Tübingen, Computer Architecture - * - * @author - * @version 1.0 - */ - -package eva2.tools.math.des; - -import java.io.Serializable; - -/** - * - * TODO: comment missing - * - * @since 2.0 - * @version Copyright (c) ZBiT, University of Tübingen, Germany Compiler: - * JDK 1.6.0 - * @date Sep 10, 2007 - * @depend - - DESystem - */ -public interface DESSolver extends Serializable { - - /** - * - * @return - */ - public boolean isUnstable(); - - /** - * put your documentation comment here - * - * @param DES - * @param initalvalue - * @param x - * @param h - * @param steps - * @return - */ - public double[][] solve(DESystem DES, double[] initalvalue, double x, - double h, int steps); - - /** - * - * @param DES - * @param initialvalue - * @param timepoints - * @return - */ - public double[][] solveAtTimePoints(DESystem DES, double[] initialvalue, - double[] timepoints); - - /** - * - * @param DES - * @param initconditions - * @param timepoints - * @return - */ - public double[][] solveAtTimePointsWithInitialConditions(DESystem DES, - double[][] initconditions, double[] timepoints); -} diff --git a/src/eva2/tools/math/des/DESystem.java b/src/eva2/tools/math/des/DESystem.java deleted file mode 100644 index b27adf3d..00000000 --- a/src/eva2/tools/math/des/DESystem.java +++ /dev/null @@ -1,43 +0,0 @@ -package eva2.tools.math.des; - -import java.io.Serializable; - -/** - * Title: JAVA-EVA Description: Copyright: Copyright (c) 2002 Company: - * University of Tübingen, Computer Architecture - * - * @author Hannes Planatscher - * @version 1.0 - */ - -public interface DESystem extends Serializable { - - /** - * Returns the number of dimensions of this ODE system. - * - * @return Returns the number of dimensions of this ODE system. - */ - public int getDESystemDimension(); - - /** - * Returns the value of the ODE system at the time t given the current - * values of Y - * - * @param t - * @param Y - * @return - * @deprecated use getValue(double t, double[] Y, double[] res) to avoid - * array reallocations and gain speed - */ - public double[] getValue(double t, double[] Y); - - /** - * Returns the value of the ODE system at the time t given the current - * values of Y within resultVector. - * - * @param t - * @param Y - * @param resultVector - */ - public void getValue(double t, double[] Y, double[] resultVector); -} diff --git a/src/eva2/tools/math/des/EventDESystem.java b/src/eva2/tools/math/des/EventDESystem.java deleted file mode 100644 index 9b267a4d..00000000 --- a/src/eva2/tools/math/des/EventDESystem.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * - */ -package eva2.tools.math.des; - -import java.util.List; - - - -/** - * This Class represents an event-driven DES - * - * @author Alexander Dörr - * @date 2010-02-04 - * - */ -public interface EventDESystem extends DESystem { - - /** - * Returns an array with delays (entries >=0) for the - * events triggered either by the time t or by the concentrations - * of the species stored in Y. The new values for the species - * are stored in res. The positions in the array returned by this method - * correspond to the positions in Y/res. - * @param res - * - * @return Returns an array with delays for the change of concentration due to events - */ - public List processEvents(double t, double Y[]); - - public List processAssignmentRules(double t, double Y[]); - - public List processAlgebraicRules(double t, double Y[]); - -} diff --git a/src/eva2/tools/math/des/RKSolver.java b/src/eva2/tools/math/des/RKSolver.java deleted file mode 100644 index fa8336a2..00000000 --- a/src/eva2/tools/math/des/RKSolver.java +++ /dev/null @@ -1,471 +0,0 @@ -package eva2.tools.math.des; - -import java.io.Serializable; - -import eva2.tools.math.Mathematics; - -/** - * Title: JAVA-EVA Description: Runge-Kutta Method Copyright: Copyright (c) 2002 - * Company: University of Tübingen, Computer Architecture - * - * @author Hannes Planatscher - * @author Andreas Dräger - * @author Marcel Kronfeld - * @version 1.0 Status: works, but numerical inaccurate - * @depend - - Mathematics - */ -public class RKSolver implements DESSolver, Serializable { - /** - * - */ - private static final long serialVersionUID = -3383457963743552159L; - /** - * - */ - private static boolean useLinearCalc = true; - - /** - * - * @param args - */ - public static void main(String args[]) { - new RKSolver(0.01); - } - - /** - * - */ - transient protected double[] k0tmp, k1tmp, k2tmp; - /** - * - */ - transient protected double[][] kVals = null; - /** - * - */ - boolean nonnegative = true; - /** - * - */ - double stepSize = 0.01; - /** - * - */ - boolean unstableFlag; - - /** - * - */ - public RKSolver() { - } - - /** - * A constructor. - * - * @param withLinearCalc - * set whether the linear or old calculation method will be used. - */ - public RKSolver(boolean withLinearCalc) { - useLinearCalc = withLinearCalc; - } - - /** - * put your documentation comment here - */ - public RKSolver(double stepSize) { - this.stepSize = stepSize; - } - - /** - * @return - */ - public double getStepSize() { - return stepSize; - } - - /** - * @return - */ - public boolean isUnstable() { - return unstableFlag; - } - - /** - * @param stepSize - */ - public void setStepSize(double stepSize) { - this.stepSize = stepSize; - } - - /** - * @param unstableFlag - */ - public void setUnstableFlag(boolean unstableFlag) { - this.unstableFlag = unstableFlag; - } - - /** - * Set whether the linear or old calculation method will be used. - * - * @param withLinearCalc - */ - public void setWithLinearCalc(boolean withLinearCalc) { - useLinearCalc = withLinearCalc; - } - - /** - * put your documentation comment here - * - * @param DES - * @param initialValues - * @param x - * @param h - * @param steps - * @return - */ - public double[][] solve(DESystem DES, double[] initialValues, double x, - double h, int steps) { - double[] timeVector = new double[steps]; - for (int i = 0; i < steps; i++) - timeVector[i] = x + i * h; - return solveAtTimePoints(DES, initialValues, timeVector); - } - - public double[][] solveAtTimePoints(DESystem DES, double[] initialValues, - double[] timePoints) { - return solveAtTimePoints(DES, initialValues, timePoints, false); - } - - /** - * This method returns a matrix in which the first column includes all time - * points. Every row is composed as time and all values at this time point. - * It uses the same integration method than the regular - * solveatTimepoints method. - * - * @param DES - * @param initialValues - * @param timePoints - * @return - */ - public double[][] solveAtTimePointsIncludingTime(DESystem DES, - double[] initialValues, double[] timePoints) { - return solveAtTimePoints(DES, initialValues, timePoints, true); - } - - /* - * (non-Javadoc) - * @see eva2.tools.math.des.DESSolver#solveAtTimePointsWithInitialConditions(eva2.tools.math.des.DESystem, double[][], double[]) - */ - public double[][] solveAtTimePointsWithInitialConditions(DESystem DES, - double[][] initConditions, double[] timePoints) { - int order = DES.getDESystemDimension(); - double[][] result = new double[timePoints.length][order]; - result[0] = initConditions[0]; - double x = timePoints[0]; - for (int i = 1; i < timePoints.length; i++) { - double h = stepSize; - double[] Ytemp = new double[order]; - int inbetweensteps = (int) Math - .floor((timePoints[i] - timePoints[i - 1]) / h); - Ytemp = (double[]) initConditions[i - 1].clone(); - for (int j = 0; j < inbetweensteps; j++) { - double change[] = rkTerm(DES, h, x, Ytemp); - Ytemp = Mathematics.vvAdd(Ytemp, change); - x += h; - } - - h = timePoints[i] - x; - double change[] = rkTerm(DES, h, x, Ytemp); - - Ytemp = Mathematics.vvAdd(Ytemp, change); - - if (this.nonnegative) { - for (int k = 0; k < Ytemp.length; k++) { - if (Ytemp[k] < 0) { - Ytemp[k] = 0; - } - } - } - result[i] = Ytemp; - x += h; - } - - return result; - - } - - /** - * @param DES - * @param initialValues - * @param timeBegin - * @param timeEnd - * @return - */ - public double[][] solveByStepSize(DESystem DES, double[] initialValues, - double timeBegin, double timeEnd) { - return solveByStepSize(DES, initialValues, timeBegin, timeEnd, false); - } - - /** - * @param DES - * @param initialValues - * @param timeBegin - * @param timeEnd - * @return - */ - public double[][] solveByStepSizeIncludingTime(DESystem DES, - double[] initialValues, double timeBegin, double timeEnd) { - return solveByStepSize(DES, initialValues, timeBegin, timeEnd, true); - } - - /** - * @param DES - * @param h - * @param x - * @param Ytemp - * @return - */ - private double[] rkTerm(DESystem DES, double h, double x, double[] Ytemp) { - double[][] K = new double[4][]; - K[0] = Mathematics.svMult(h, DES.getValue(x, Ytemp)); - K[1] = Mathematics.svMult(h, DES.getValue(x + h / 2, Mathematics.vvAdd( - Ytemp, Mathematics.svMult(0.5, K[0])))); - K[2] = Mathematics.svMult(h, DES.getValue(x + h / 2, Mathematics.vvAdd( - Ytemp, Mathematics.svMult(0.5, K[1])))); - K[3] = Mathematics.svMult(h, DES.getValue(x + h, Mathematics.vvAdd( - Ytemp, K[2]))); - - double[] change = Mathematics.svDiv(6, Mathematics.vvAdd(K[0], - Mathematics.vvAdd(Mathematics.svMult(2, K[1]), Mathematics - .vvAdd(Mathematics.svMult(2, K[2]), K[3])))); - for (int k = 0; k < change.length; k++) { - if (Double.isNaN(change[k])) { - unstableFlag = true; - change[k] = 0; - // return result; - } - } - return change; - } - - /** - * Linearized code for speed-up (no allocations). - * - * @param DES - * @param h - * @param x - * @param Ytemp - * @return - */ - private void rkTerm2(DESystem DES, double h, double x, double[] Ytemp, - double[] res) { - if (kVals == null) { // "static" vectors which are allocated only once - k0tmp = new double[DES.getDESystemDimension()]; - k1tmp = new double[DES.getDESystemDimension()]; - k2tmp = new double[DES.getDESystemDimension()]; - kVals = new double[4][DES.getDESystemDimension()]; - } - - // double[][] K = new double[4][]; - DES.getValue(x, Ytemp, kVals[0]); - Mathematics.svMult(h, kVals[0], kVals[0]); - - // K[0] = svMult(h, DES.getValue(x, Ytemp)); - - Mathematics.svMult(0.5, kVals[0], k0tmp); - Mathematics.vvAdd(Ytemp, k0tmp, k0tmp); - DES.getValue(x + h / 2, k0tmp, kVals[1]); - Mathematics.svMult(h, kVals[1], kVals[1]); - - // K[1] = svMult(h, DES.getValue(x + h / 2, vvAdd(Ytemp, svMult(0.5, - // K[0])))); - - Mathematics.svMult(0.5, kVals[1], k1tmp); - Mathematics.vvAdd(Ytemp, k1tmp, k1tmp); - DES.getValue(x + h / 2, k1tmp, kVals[2]); - Mathematics.svMult(h, kVals[2], kVals[2]); - - // K[2] = svMult(h, DES.getValue(x + h / 2, vvAdd(Ytemp, svMult(0.5, - // K[1])))); - - Mathematics.vvAdd(Ytemp, kVals[2], k2tmp); - DES.getValue(x + h, k2tmp, k1tmp); - Mathematics.svMult(h, k1tmp, kVals[3]); - - // K[3] = svMult(h, DES.getValue(x + h, vvAdd(Ytemp, K[2]))); - - Mathematics.svMult(2, kVals[2], k0tmp); - Mathematics.vvAdd(k0tmp, kVals[3], k0tmp); - - Mathematics.svMult(2, kVals[1], k1tmp); - Mathematics.vvAdd(k1tmp, k0tmp, k2tmp); - - Mathematics.vvAdd(kVals[0], k2tmp, k1tmp); - Mathematics.svDiv(6, k1tmp, res); - - // double[] change = svDiv(6, vvAdd(K[0], vvAdd(svMult(2, K[1]), - // vvAdd(svMult(2, K[2]), K[3])))); - // for (int i=0; i 0.00000001) System.out.println("!!! "); - // } - - // double[] change = svdiv(6, vvadd(kVals[0], vvadd(svmult(2, kVals[1]), - // vvadd(svmult(2, kVals[2]), kVals[3])))); - for (int k = 0; k < res.length; k++) { - if (Double.isNaN(res[k])) { - unstableFlag = true; - res[k] = 0; - // return result; - } - } - } - - /** - * When set to TRUE, includeTimes will make the - * solver to return a matrix with the first column containing the times. By - * default the result of the ODE solver just returns the values for Y. - * - * @param includeTimes - */ - private double[][] solveAtTimePoints(DESystem DES, double[] initialValues, - double[] timePoints, boolean includeTimes) { - // sorted timepoints!!!!!!!!!!!!!!!!!!!!! - int order = DES.getDESystemDimension(); - double result[][], x = timePoints[0]; - if (includeTimes) { - result = new double[timePoints.length][order + 1]; - result[0][0] = timePoints[0]; - for (int i = 1; i <= order; i++) - result[0][i] = initialValues[i - 1]; - } else { - result = new double[timePoints.length][order]; - for (int i = 0; i < order; i++) - result[0][i] = initialValues[i]; - } - // System.out.println("JavaCalled"); - unstableFlag = false; - - double h = stepSize; - double change[] = new double[order]; - double[] Ytemp = new double[order]; - - for (int i = 1; i < timePoints.length; i++) { - h = stepSize; - - // int inbetweensteps = (int) Math.round((timePoints[i] - - // timePoints[i - - // 1]) / h + 1); - int inbetweensteps = (int) Math - .floor((timePoints[i] - timePoints[i - 1]) / h); - - // System.out.println("inbetweensteps at " + i + ": " + - // inbetweensteps); - if (includeTimes) - System.arraycopy(result[i - 1], 1, Ytemp, 0, - result[i - 1].length - 1); - else - Ytemp = result[i - 1].clone(); - - for (int j = 0; j < inbetweensteps; j++) { - if (useLinearCalc) - rkTerm2(DES, h, x, Ytemp, change); - else - change = rkTerm(DES, h, x, Ytemp); - // System.out.println("aft change 0 " + change[0]); - - Mathematics.vvAdd(Ytemp, change, Ytemp); - - if (this.nonnegative) { - for (int k = 0; k < Ytemp.length; k++) { - if (Ytemp[k] < 0) - Ytemp[k] = 0; - } - } - - x += h; - } - - h = timePoints[i] - x; - - if (useLinearCalc) - rkTerm2(DES, h, x, Ytemp, change); - else - change = rkTerm(DES, h, x, Ytemp); - - Mathematics.vvAdd(Ytemp, change, Ytemp); - - if (this.nonnegative) { - for (int k = 0; k < Ytemp.length; k++) { - if (Ytemp[k] < 0) - Ytemp[k] = 0; - } - } - - if (includeTimes) { - result[i][0] = timePoints[i]; - System.arraycopy(Ytemp, 0, result[i], 1, Ytemp.length); - } else - result[i] = Ytemp; - x += h; - - } - - return result; - } - - /** - * @param DES - * @param initialValues - * @param timeBegin - * @param timeEnd - * @return - */ - private double[][] solveByStepSize(DESystem DES, double[] initialValues, - double timeBegin, double timeEnd, boolean time) { - int numsteps = (int) Math.round(((timeEnd - timeBegin) / stepSize) + 1); - unstableFlag = false; - // System.out.println(numsteps); - int order = DES.getDESystemDimension(), i; - double[][] result; - if (time) { - result = new double[numsteps][order + 1]; - result[0][0] = timeBegin; - for (i = 0; i < order; i++) - result[0][i + 1] = initialValues[i]; - } else { - result = new double[numsteps][order]; - for (i = 0; i < order; i++) - result[0][i] = initialValues[i]; - } - double x = timeBegin; - for (i = 1; i < numsteps; i++) { - double h = stepSize, change[] = null, Ytemp[] = null; - if (time) { - double tmp[] = new double[result[i - 1].length - 1]; - System.arraycopy(result[i - 1], 1, tmp, 0, - result[i - 1].length - 1); - change = rkTerm(DES, h, x, tmp); - Ytemp = Mathematics.vvAdd(tmp, change); - } else { - change = rkTerm(DES, h, x, result[i - 1]); - Ytemp = Mathematics.vvAdd(result[i - 1], change); - } - if (this.nonnegative) { - for (int k = 0; k < Ytemp.length; k++) { - if (Ytemp[k] < 0) - Ytemp[k] = 0; - } - } - x += h; - if (time) { - System.arraycopy(Ytemp, 0, result[i], 1, Ytemp.length); - result[i][0] = x; - } else - result[i] = Ytemp; - } - - return result; - } - -}