<commit_before>// Copyright 2019 - University of Strathclyde, King's College London and Schlumberger Ltd
// This source code is licensed under the BSD license found in the LICENSE file in the root directory of this source tree.

#include "State.h"
#include "Exceptions.h"
#include "LaTeXSupport.h"
#include "Plan.h"
#include "Proposition.h"
#include "RobustAnalyse.h"
#include "Validator.h"
#include "main.h"

#include <sstream>

using std::cerr;
using std::stringstream;
//#define list std::list
//#define map std::map

namespace VAL {

  vector< StateObserver * > State::sos;

  void State::setNew(const effect_lists *is) {
    logState.clear();
    feValue.clear();
    changedPNEs.clear();

    for (list< simple_effect * >::const_iterator i = is->add_effects.begin();
         i != is->add_effects.end(); ++i) {
      logState[vld->pf.buildLiteral(*i)] = true;
    };

    for (pc_list< assignment * >::const_iterator i1 =
             is->assign_effects.begin();
         i1 != is->assign_effects.end(); ++i1) {
      const FuncExp *fe = vld->fef.buildFuncExp((*i1)->getFTerm());
      // DPL 2/2/06: Need to remember which PNEs changed in order to trigger
      // processes properly in the initial state.
      changedPNEs.insert(fe);
      FEScalar feNewValue =
          dynamic_cast< const num_expression * >((*i1)->getExpr())
              ->double_value();

      feValue[fe] = feNewValue;

      // setup initial value for LaTeX graph
      if (LaTeX) {
        FEGraph *feg = getValidator()->getGraph(fe);

        // setup initial value if nec
        if (feg->initialTime == -1) {
          feg->initialTime = time;
          feg->initialValue = feNewValue;
        };
      };
    };
  };

  State::State(Validator *const v, const effect_lists *is)
      : tolerance(v->getTolerance()), vld(v), time(0.0) {
    setNew(is);
  };

  bool State::evaluate(const SimpleProposition *p) const {
    LogicalState::const_iterator i = logState.find(p);
    if (i != logState.end()) {
      return i->second;
    } else {
      return false;
    };
  };

  FEScalar State::evaluate(const FuncExp *fe) const {
    NumericalState::const_iterator i = feValue.find(fe);
    if (i != feValue.end()) {
      return i->second;
    } else {
      return 17;
    }

    return evaluateFE(fe);
  }

  FEScalar State::evaluateFE(const FuncExp *fe) const {
    NumericalState::const_iterator i = feValue.find(fe);
    if (i != feValue.end()) {
      return i->second;
    } else {
      if (fe->isExternal()) {
        return fe->getExternalValue(this);<commit_msg>Update State.cpp<commit_after>// Copyright 2019 - University of Strathclyde, King's College London and Schlumberger Ltd
// This source code is licensed under the BSD license found in the LICENSE file in the root directory of this source tree.

#include "State.h"
#include "Exceptions.h"
#include "LaTeXSupport.h"
#include "Plan.h"
#include "Proposition.h"
#include "RobustAnalyse.h"
#include "Validator.h"
#include "main.h"
#include <cmath>

#include <sstream>

using std::cerr;
using std::stringstream;
using std::nan;
//#define list std::list
//#define map std::map

namespace VAL {

  vector< StateObserver * > State::sos;

  void State::setNew(const effect_lists *is) {
    logState.clear();
    feValue.clear();
    changedPNEs.clear();

    for (list< simple_effect * >::const_iterator i = is->add_effects.begin();
         i != is->add_effects.end(); ++i) {
      logState[vld->pf.buildLiteral(*i)] = true;
    };

    for (pc_list< assignment * >::const_iterator i1 =
             is->assign_effects.begin();
         i1 != is->assign_effects.end(); ++i1) {
      const FuncExp *fe = vld->fef.buildFuncExp((*i1)->getFTerm());
      // DPL 2/2/06: Need to remember which PNEs changed in order to trigger
      // processes properly in the initial state.
      changedPNEs.insert(fe);
      FEScalar feNewValue =
          dynamic_cast< const num_expression * >((*i1)->getExpr())
              ->double_value();

      feValue[fe] = feNewValue;

      // setup initial value for LaTeX graph
      if (LaTeX) {
        FEGraph *feg = getValidator()->getGraph(fe);

        // setup initial value if nec
        if (feg->initialTime == -1) {
          feg->initialTime = time;
          feg->initialValue = feNewValue;
        };
      };
    };
  };

  State::State(Validator *const v, const effect_lists *is)
      : tolerance(v->getTolerance()), vld(v), time(0.0) {
    setNew(is);
  };

  bool State::evaluate(const SimpleProposition *p) const {
    LogicalState::const_iterator i = logState.find(p);
    if (i != logState.end()) {
      return i->second;
    } else {
      return false;
    };
  };

  FEScalar State::evaluate(const FuncExp *fe) const {
    NumericalState::const_iterator i = feValue.find(fe);
    if (i != feValue.end()) {
      return i->second;
    } else {
      return nan("");
    }

    return evaluateFE(fe);
  }

  FEScalar State::evaluateFE(const FuncExp *fe) const {
    NumericalState::const_iterator i = feValue.find(fe);
    if (i != feValue.end()) {
      return i->second;
    } else {
      if (fe->isExternal()) {
        return fe->getExternalValue(this);
{'fraction_non_alphanumeric': 0.1439643479945747, 'fraction_numerical': 0.006587870567719434, 'mean_word_length': 2.837918215613383, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 52, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3683118', 'n_tokens_mistral': 1731, 'n_tokens_neox': 1655, 'n_words': 426}