Beispiel #1
0
double RungeKuttaSolver::SolveEquation()
{
    double h = GetStepSize();
    double t_previous = GetInitialTime();
    double t1 = GetFinalTime();
    double y_previous = getInitialValue();

    double y_current = getInitialValue();
    double k1, k2, k3, k4;

    while (t_previous + h < t1)
    {
        k1 = h * RightHandSide(y_previous, t_previous);
        k2 = h * RightHandSide(y_previous + 0.5 * k1, t_previous + 0.5 * h);
        k3 = h * RightHandSide(y_previous + 0.5 * k2, t_previous + 0.5 * h);
        k4 = h * RightHandSide(y_previous + k3, t_previous + h);

        y_current = y_previous + (1.0 / 6.0) * (k1 + 2 * k2 + 2 * k3 + k4);

        t_previous += h;
        y_previous = y_current;
    }

    return y_current;
}
void AminoModelJump::resetState(TreeAln &traln)
{  
  auto primVar = getPrimaryParameterView();
  assert(primVar.size() == 1 ); 
  auto partitions = primVar[0]->getPartitions();
  for(auto p: partitions )
    traln.setProteinModel(p,savedMod);


  // necessary, if we have fixed branch lengths  
  for(auto &param : getBranchLengthsParameterView() )
    {
      if( not param->getPrior()->needsIntegration() )
	{
	  auto prior = param->getPrior() ;
	  for(auto &b : traln.extractBranches(param))
	    {
	      auto content = prior->getInitialValue(); 
	      b.setLength(InternalBranchLength::fromAbsolute(content.values[0], param->getMeanSubstitutionRate())); 
	      if(not BoundsChecker::checkBranch(b))
		BoundsChecker::correctBranch(b); 
	      traln.setBranch(b,param); 
	    }
	}
      else 
	{
	  // TODO inefficient =/ but cannot use the _oldFcs. That
	  // would cause trouble in proposal sets
	  param->updateMeanSubstRate(traln);
	}
    }
}
static void initializePoints(double * * points, int rowFrom, int howMany, int numPointsPerDimension)
{
    int i, j;
    for (i = rowFrom; i < rowFrom + howMany; ++i)
    {
        for (j = 0; j < numPointsPerDimension; ++j)
        {
            points[i-rowFrom][j] = getInitialValue(i, j, numPointsPerDimension);
        }
    }
}
Beispiel #4
0
// virtual
LLXMLNodePtr LLSlider::getXML(bool save_children) const
{
	LLXMLNodePtr node = LLUICtrl::getXML();

	node->createChild("initial_val", TRUE)->setFloatValue(getInitialValue());
	node->createChild("min_val", TRUE)->setFloatValue(getMinValue());
	node->createChild("max_val", TRUE)->setFloatValue(getMaxValue());
	node->createChild("increment", TRUE)->setFloatValue(getIncrement());
	node->createChild("volume", TRUE)->setBoolValue(mVolumeSlider);

	return node;
}
Beispiel #5
0
// virtual
LLXMLNodePtr LLMultiSlider::getXML(bool save_children) const
{
    LLXMLNodePtr node = LLUICtrl::getXML();

    node->setName(LL_MULTI_SLIDER_TAG);

    node->createChild("initial_val", TRUE)->setFloatValue(getInitialValue());
    node->createChild("min_val", TRUE)->setFloatValue(getMinValue());
    node->createChild("max_val", TRUE)->setFloatValue(getMaxValue());
    node->createChild("increment", TRUE)->setFloatValue(getIncrement());

    return node;
}
Beispiel #6
0
// virtual
LLXMLNodePtr LLSlider::getXML(bool save_children) const
{
	LLXMLNodePtr node = LLUICtrl::getXML();

	if (mVolumeSlider)
	{
		node->setName(LL_VOLUME_SLIDER_CTRL_TAG);
	}
	else
	{
		node->setName(LL_SLIDER_TAG);
	}

	node->createChild("initial_val", TRUE)->setFloatValue(getInitialValue());
	node->createChild("min_val", TRUE)->setFloatValue(getMinValue());
	node->createChild("max_val", TRUE)->setFloatValue(getMaxValue());
	node->createChild("increment", TRUE)->setFloatValue(getIncrement());
	node->createChild("volume", TRUE)->setBoolValue(mVolumeSlider);

	return node;
}
Beispiel #7
0
/**
 * Set attributes of the node that represents this class
 * in the XMI document.
 */
void CodeParameter::setAttributesOnNode ( QDomDocument & doc, QDomElement & blockElement)
{
    // set local attributes
    blockElement.setAttribute("parent_id",getID());

    // setting ID's takes special treatment
    // as UMLRoles arent properly stored in the XMI right now.
    // (change would break the XMI format..save for big version change )
    UMLRole * role = dynamic_cast<UMLRole*>(m_parentObject);
    if(role)
        blockElement.setAttribute("role_id", role->role());
    else
        blockElement.setAttribute("role_id","-1");

    blockElement.setAttribute("initialValue",getInitialValue());

    // a comment which we will store in its own separate child node block
    QDomElement commElement = doc.createElement( "header" );
    getComment()->saveToXMI(doc, commElement); // comment
    blockElement.appendChild( commElement);
}
Beispiel #8
0
QString
vleSmDT::getData()
{
    QString tpl = "/**\n"                                               \
        "  * @file {{classname}}.cpp\n"                                 \
        "  * @author ...\n"                                             \
        "  * ...\n"                                                     \
        "  */\n\n"                                                      \
        "/*\n"                                                          \
        " * @@tagdynamic@@\n"                                           \
        " * @@tagdepends: vle.discrete-time @@endtagdepends\n"          \
        "*/\n\n"                                                        \
        "#include <vle/DiscreteTimeDbg.hpp>\n"                          \
        "#include <vle/devs/DynamicsDbg.hpp>\n\n"                       \
        "{{includes}}"                                                  \
        "namespace vd = vle::devs;\n\n"                                 \
        "namespace vv = vle::value;\n\n"                                \
        "namespace vle {\n"                                             \
        "namespace discrete_time {\n"                                   \
        "namespace {{namespace}} {\n\n"                                 \
        "class {{classname}} : public DiscreteTimeDyn\n"                \
        "{\n"                                                           \
        "public:\n"                                                     \
        "{{classname}}(\n"                                              \
        "    const vd::DynamicsInit& init,\n"                           \
        "    const vd::InitEventList& evts)\n"                          \
        "        : DiscreteTimeDyn(init, evts)\n"                       \
        "{\n"                                                           \
        "{{for i in var}}"                                              \
        "    {{var^i}}.init(this, \"{{var^i}}\", evts);\n"              \
        "{{end for}}"                                                   \
        "{{for i in init_value_var}}"                                   \
        "    {{init_value_var^i}}.init_value({{init_value_val^i}});\n"  \
        "{{end for}}"                                                   \
        "{{construct}}"                                                 \
        "\n"                                                            \
        "}\n"                                                           \
        "\n"                                                            \
        "virtual ~{{classname}}()\n"                                    \
        "{}\n"                                                          \
        "\n"                                                            \
        "void compute(const vle::devs::Time& t)\n"                      \
        "{\n"                                                           \
        "{{compute}}"                                                   \
        "}\n"                                                           \
        "\n"                                                            \
        "{{for i in var}}"                                              \
        "    Var {{var^i}};\n"                                          \
        "{{end for}}"                                                   \
        "{{userSection}}"                                               \
        "};\n\n"                                                        \
        "} // namespace {{namespace}}\n"                                \
        "} // namespace discrete_time\n"                                \
        "} // namespace vle\n\n"                                        \
        "DECLARE_DYNAMICS("                                             \
        "vle::discrete_time::{{namespace}}::{{classname}})\n\n";


    vle::utils::Template vleTpl(tpl.toStdString());
    vleTpl.stringSymbol().append("classname", getClassName().toStdString());
    vleTpl.stringSymbol().append("namespace", getNamespace().toStdString());

    vleTpl.listSymbol().append("var");
    vleTpl.listSymbol().append("init_value_var");
    vleTpl.listSymbol().append("init_value_val");


    QDomNodeList variablesXml = variablesFromDoc();
    for (int i = 0; i < variablesXml.length(); i++) {
        QDomNode variable = variablesXml.item(i);
        QString varName = variable.attributes().namedItem("name").nodeValue();
        vle::value::Value* val = getInitialValue(varName);
        if (val) {
            vleTpl.listSymbol().append("init_value_var", varName.toStdString());
            vleTpl.listSymbol().append("init_value_val", val->writeToString());
            delete val;
        }

        vleTpl.listSymbol().append("var", varName.toStdString());


    }

    vleTpl.stringSymbol().append("includes", "");
    vleTpl.stringSymbol().append("compute", getComputeBody().toStdString());
    vleTpl.stringSymbol().append("construct","");
    vleTpl.stringSymbol().append("userSection","");

    std::ostringstream out;
    vleTpl.process(out);

    return QString(out.str().c_str());
}