File: SimulatorDPBaseTree.cpp

package info (click to toggle)
stopt 5.12%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 8,860 kB
  • sloc: cpp: 70,456; python: 5,950; makefile: 72; sh: 57
file content (62 lines) | stat: -rw-r--r-- 1,827 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (C) 2019 EDF
// All Rights Reserved
// This code is published under the GNU Lesser General Public License (GNU LGPL)
#include <memory>
#include <vector>
#include <Eigen/Dense>
#include "geners/BinaryFileArchive.hh"
#include "geners/Reference.hh"
#include "geners/vectorIO.hh"
#include "geners/arrayIO.hh"
#include "StOpt/core/utils/eigenGeners.h"
#include "StOpt/core/utils/constant.h"
#include "StOpt/dp/SimulatorDPBaseTree.h"


using namespace Eigen ;
using namespace std ;

namespace StOpt
{

SimulatorDPBaseTree::SimulatorDPBaseTree(const shared_ptr<gs::BinaryFileArchive> &p_binForTree): m_binForTree(p_binForTree)
{
    gs::Reference< ArrayXd >(*p_binForTree, "dates", "").restore(0, &m_dates);
}

void SimulatorDPBaseTree::load(const int &p_idateCur)
{
    m_idateCur = p_idateCur;
    //load nodes
    gs::Reference< ArrayXXd>(*m_binForTree, "points", "").restore(m_idateCur, &m_nodesCurr);
    //load nodes
    if (m_idateCur < m_dates.size() - 1)
    {
        gs::Reference< ArrayXXd>(*m_binForTree, "points", "").restore(m_idateCur + 1, &m_nodesNext);
        //load probability transition  and helper
        gs::Reference< vector< double > >(*m_binForTree, "proba", "").restore(m_idateCur, &m_proba);
        // connection matrix
        gs::Reference< vector<vector< array<int, 2 > > > >(*m_binForTree, "connection", "").restore(m_idateCur, &m_connected);
    }
}



int SimulatorDPBaseTree::getNodeReachedInForward(const int &p_nodeStart, const double &p_randUni) const
{
    double probSum = 0.;
    int iret = 0;
    for (size_t i = 0; i < m_connected[p_nodeStart].size(); ++i)
    {
        probSum += m_proba[m_connected[p_nodeStart][i][1]];
        if (p_randUni < probSum)
        {
            iret = m_connected[p_nodeStart][i][0];
            break;
        }
    }
    return iret;
}

}