<commit_before>// Begin CVS Header
//   $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/model/Attic/CMathTrigger.cpp,v $
//   $Revision: 1.12 $
//   $Name:  $
//   $Author: shoops $
//   $Date: 2009/06/17 19:16:15 $
// End CVS Header

// Copyright (C) 2008 by <NAME>, Virginia Tech Intellectual
// Properties, Inc., EML Research, gGmbH, University of Heidelberg,
// and The University of Manchester.
// All rights reserved.

#include "copasi.h"

#include "CMathTrigger.h"
#include "function/CEvaluationNode.h"
#include "report/CCopasiObjectReference.h"

CMathTrigger::CRootFinder::CRootFinder(const CCopasiContainer * pParent) :
    CCopasiContainer("Root", pParent),
    mRoot("Expression", this),
    mpRootValue(NULL),
    mEquality(false),
    mActive(0.0)
{
  initObjects();
}

CMathTrigger::CRootFinder::CRootFinder(const CMathTrigger::CRootFinder & src,
                                       const CCopasiContainer * pParent) :
    CCopasiContainer(src, pParent),
    mRoot(src.mRoot, this),
    mpRootValue(NULL),
    mEquality(src.mEquality),
    mActive(src.mActive)
{
  initObjects();
}

CMathTrigger::CRootFinder::~CRootFinder()
{}

void CMathTrigger::CRootFinder::initObjects()
{
  mpRootValue =
    (C_FLOAT64 *)mRoot.getObject(std::string("Reference=Value"))->getValuePointer();

  addDirectDependency(&mRoot);
  setRefresh(&mRoot, &CExpression::refresh);
}

bool CMathTrigger::CRootFinder::compile(std::vector< CCopasiContainer * > listOfContainer)
{
  bool success = true;

  success &= mRoot.compile(listOfContainer);

  return true;
}

CEvaluationNode * CMathTrigger::CRootFinder::getTrueExpression() const
{
  CEvaluationNode * pNode = new CEvaluationNodeLogical(CEvaluationNodeLogical::GE, "GE");
  pNode->addChild(new CEvaluationNodeObject(mpRootValue));
  pNode->addChild(new CEvaluationNodeNumber(CEvaluationNodeNumber::DOUBLE, "0.0"));

  return pNode;
}

CEvaluationNode * CMathTrigger::CRootFinder::getFireExpression() const
{
  CEvaluationNode * pNode = new CEvaluationNodeLogical(CEvaluationNodeLogical::AND, "AND");
  pNode->addChild(new CEvaluationNodeObject(&mActive));
  pNode->addChild(getTrueExpression());

  return pNode;
}

CEvaluationNode * CMathTrigger::CRootFinder::getEqualityExpression() const
{
  if (mEquality)
    return new CEvaluationNodeConstant(CEvaluationNodeConstant::TRUE, "TRUE");
  else
    return new CEvaluationNodeConstant(CEvaluationNodeConstant::FALSE, "FALSE");
}

void CMathTrigger::CRootFinder::charge()
{
  // TODO ALGORITHM We need to experiment with this!

  if ((mActive < 1.0) &&
      ((*mpRootValue < 0.0) ||
       ((*mpRootValue <= 0.0) && !mEquality)))
    {
      mActive = 1.0;
    }

  return;
}

void CMathTrigger::CRootFinder::calculateInitialActivity()
{
  if ((*mpRootValue < 0.0)
      || ((*mpRootValue <= 0.0) && !mEquality))
    {<commit_msg>Fixed charge to also deactivate the trigger if appropriate.<commit_after>// Begin CVS Header
//   $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/model/Attic/CMathTrigger.cpp,v $
//   $Revision: 1.13 $
//   $Name:  $
//   $Author: shoops $
//   $Date: 2009/06/18 17:09:33 $
// End CVS Header

// Copyright (C) 2008 by <NAME>, Virginia Tech Intellectual
// Properties, Inc., EML Research, gGmbH, University of Heidelberg,
// and The University of Manchester.
// All rights reserved.

#include "copasi.h"

#include "CMathTrigger.h"
#include "function/CEvaluationNode.h"
#include "report/CCopasiObjectReference.h"

CMathTrigger::CRootFinder::CRootFinder(const CCopasiContainer * pParent) :
    CCopasiContainer("Root", pParent),
    mRoot("Expression", this),
    mpRootValue(NULL),
    mEquality(false),
    mActive(0.0)
{
  initObjects();
}

CMathTrigger::CRootFinder::CRootFinder(const CMathTrigger::CRootFinder & src,
                                       const CCopasiContainer * pParent) :
    CCopasiContainer(src, pParent),
    mRoot(src.mRoot, this),
    mpRootValue(NULL),
    mEquality(src.mEquality),
    mActive(src.mActive)
{
  initObjects();
}

CMathTrigger::CRootFinder::~CRootFinder()
{}

void CMathTrigger::CRootFinder::initObjects()
{
  mpRootValue =
    (C_FLOAT64 *)mRoot.getObject(std::string("Reference=Value"))->getValuePointer();

  addDirectDependency(&mRoot);
  setRefresh(&mRoot, &CExpression::refresh);
}

bool CMathTrigger::CRootFinder::compile(std::vector< CCopasiContainer * > listOfContainer)
{
  bool success = true;

  success &= mRoot.compile(listOfContainer);

  return true;
}

CEvaluationNode * CMathTrigger::CRootFinder::getTrueExpression() const
{
  CEvaluationNode * pNode = new CEvaluationNodeLogical(CEvaluationNodeLogical::GE, "GE");
  pNode->addChild(new CEvaluationNodeObject(mpRootValue));
  pNode->addChild(new CEvaluationNodeNumber(CEvaluationNodeNumber::DOUBLE, "0.0"));

  return pNode;
}

CEvaluationNode * CMathTrigger::CRootFinder::getFireExpression() const
{
  CEvaluationNode * pNode = new CEvaluationNodeLogical(CEvaluationNodeLogical::AND, "AND");
  pNode->addChild(new CEvaluationNodeObject(&mActive));
  pNode->addChild(getTrueExpression());

  return pNode;
}

CEvaluationNode * CMathTrigger::CRootFinder::getEqualityExpression() const
{
  if (mEquality)
    return new CEvaluationNodeConstant(CEvaluationNodeConstant::TRUE, "TRUE");
  else
    return new CEvaluationNodeConstant(CEvaluationNodeConstant::FALSE, "FALSE");
}

void CMathTrigger::CRootFinder::charge()
{
  // TODO ALGORITHM We need to experiment with this!

  if ((mActive < 1.0) &&
      ((*mpRootValue < 0.0) ||
       ((*mpRootValue <= 0.0) && !mEquality)))
    {
      mActive = 1.0;
    }
  else if ((mActive > 0.0) &&
           ((*mpRootValue > 0.0) ||
            ((*mpRootValue >= 0.0) && mEquality)))
    {
      mActive = 0.0;
    }

  return;
}

void CMathTrigger::CRootFinder::calculateInitialActivity()
{
  if ((*mpRootValue < 0.0)
      || ((*mpRootValue <= 0.0) && !mEquality))
    {
{'fraction_non_alphanumeric': 0.14293015332197614, 'fraction_numerical': 0.01465076660988075, 'mean_word_length': 4.502343017806935, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4485850', 'n_tokens_mistral': 2044, 'n_tokens_neox': 2001, 'n_words': 349}