Search in sources :

Example 1 with IDASolverStandalone

use of cbit.vcell.solver.ode.IDASolverStandalone in project vcell by virtualcell.

the class ParameterEstimationTaskSimulatorIDA method getRowColumnRestultSetByBestEstimations.

public RowColumnResultSet getRowColumnRestultSetByBestEstimations(ParameterEstimationTask parameterEstimationTask, String[] paramNames, double[] paramValues) throws Exception {
    // create a temp simulation based on math description
    KeyValue key = new KeyValue("" + Math.abs(new Random().nextLong()));
    SimulationVersion dummyVersion = new SimulationVersion(key, "name", new User("temp", new KeyValue("1")), null, null, null, null, null, null, null);
    Simulation simulation = new Simulation(dummyVersion, parameterEstimationTask.getSimulationContext().getMathDescription());
    ReferenceData refData = parameterEstimationTask.getModelOptimizationSpec().getReferenceData();
    double[] times = refData.getDataByColumn(0);
    double endTime = times[times.length - 1];
    ExplicitOutputTimeSpec exTimeSpec = new ExplicitOutputTimeSpec(times);
    // set simulation ending time and output interval
    simulation.getSolverTaskDescription().setTimeBounds(new TimeBounds(0, endTime));
    simulation.getSolverTaskDescription().setOutputTimeSpec(exTimeSpec);
    // set parameters as math overrides
    MathOverrides mathOverrides = simulation.getMathOverrides();
    for (int i = 0; i < paramNames.length; i++) {
        mathOverrides.putConstant(new Constant(paramNames[i], new Expression(paramValues[i])));
    }
    SimulationTask simTask = new SimulationTask(new SimulationJob(simulation, 0, null), 0);
    IDASolverStandalone idaSolver = new IDASolverStandalone(simTask, ResourceUtil.getLocalSimDir("temp"), false);
    // startSolver();
    idaSolver.runSolver();
    Thread.sleep(1000);
    long startTimeMS = System.currentTimeMillis();
    while (idaSolver.getSolverStatus().isRunning() && System.currentTimeMillis() < (startTimeMS + 10000L)) {
        Thread.sleep(500);
    }
    ODESolverResultSet resultset = idaSolver.getODESolverResultSet();
    return resultset;
}
Also used : KeyValue(org.vcell.util.document.KeyValue) User(org.vcell.util.document.User) SimulationTask(cbit.vcell.messaging.server.SimulationTask) Constant(cbit.vcell.math.Constant) ReferenceData(cbit.vcell.opt.ReferenceData) TimeBounds(cbit.vcell.solver.TimeBounds) MathOverrides(cbit.vcell.solver.MathOverrides) ExplicitOutputTimeSpec(cbit.vcell.solver.ExplicitOutputTimeSpec) SimulationVersion(org.vcell.util.document.SimulationVersion) Random(java.util.Random) Simulation(cbit.vcell.solver.Simulation) Expression(cbit.vcell.parser.Expression) IDASolverStandalone(cbit.vcell.solver.ode.IDASolverStandalone) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) SimulationJob(cbit.vcell.solver.SimulationJob)

Aggregations

Constant (cbit.vcell.math.Constant)1 SimulationTask (cbit.vcell.messaging.server.SimulationTask)1 ReferenceData (cbit.vcell.opt.ReferenceData)1 Expression (cbit.vcell.parser.Expression)1 ExplicitOutputTimeSpec (cbit.vcell.solver.ExplicitOutputTimeSpec)1 MathOverrides (cbit.vcell.solver.MathOverrides)1 Simulation (cbit.vcell.solver.Simulation)1 SimulationJob (cbit.vcell.solver.SimulationJob)1 TimeBounds (cbit.vcell.solver.TimeBounds)1 IDASolverStandalone (cbit.vcell.solver.ode.IDASolverStandalone)1 ODESolverResultSet (cbit.vcell.solver.ode.ODESolverResultSet)1 Random (java.util.Random)1 KeyValue (org.vcell.util.document.KeyValue)1 SimulationVersion (org.vcell.util.document.SimulationVersion)1 User (org.vcell.util.document.User)1