Exemplo n.º 1
0
/**
 * perform a stochastic ensemble calculation.
 *
 *   :param: r an existing roadrunner obj, loaded with a mode.
 *   :param: n how many ensembles to run.
 *   :param: seed the seed value, use None to continue with previous
 *           random number stream.
 *   :param: start start time
 *   :param: stop stop time
 *   :param: ntps how many points display in the result.
 */
DoubleMatrix ensemble(RoadRunner &r, int n, unsigned long seed, double start, double stop, int npts) {

    // set the seed value of the integrator
    Integrator *itg = r.getIntegrator(Integrator::GILLESPIE);
    itg->setItem("seed", seed);

    // setup the simulation
    // create a sim opt obj, loads itself with
    // default values in ctor.
    SimulateOptions o;
    o.start = start;
    o.duration = stop;
    o.steps = npts;

    // we should reset the model each time we simulate,
    // set the RESET_MODEL bit.
    o.flags |= SimulateOptions::RESET_MODEL;

    o.integrator = Integrator::GILLESPIE;

    // make a result var
    DoubleMatrix result(npts+1, n+1);

    for (int i = 0; i < n; ++i) {
        const DoubleMatrix &sim = *r.simulate(&o);

        // copy result data colum
        for (int row = 0; row < npts+1; ++row) {
            result(row, i+1) = sim(row, 1);
        }
    }

    // copy result time column
    const DoubleMatrix &sim = *r.getSimulationData();

    // copy result data colum
    for (int row = 0; row < npts+1; ++row) {
        result(row, 0) = sim(row, 0);
    }

    return result;
}