Line data Source code
1 : /*******************************************************************************
2 : * *
3 : * Cosmos:(C)oncept et (O)utils (S)tatistique pour les (Mo)deles *
4 : * (S)tochastiques *
5 : * *
6 : * Copyright (C) 2009-2012 LSV & LACL *
7 : * Authors: Paolo Ballarini, Benoit Barbot & Hilal Djafri *
8 : * Website: http://www.lsv.ens-cachan.fr/Software/cosmos *
9 : * *
10 : * This program is free software; you can redistribute it and/or modify *
11 : * it under the terms of the GNU General Public License as published by *
12 : * the Free Software Foundation; either version 3 of the License, or *
13 : * (at your option) any later version. *
14 : * *
15 : * This program is distributed in the hope that it will be useful, *
16 : * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 : * GNU General Public License for more details. *
19 : * *
20 : * You should have received a copy of the GNU General Public License along *
21 : * with this program; if not, write to the Free Software Foundation, Inc., *
22 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
23 : *******************************************************************************
24 : */
25 :
26 : /* This object do the main computation of the programm
27 : * it contains the SPN and the LHA
28 : */
29 :
30 :
31 :
32 : #include "LHA.hpp"
33 : #include "LHA_orig.hpp"
34 : #include "NLHA.hpp"
35 : #include "SPNBase.hpp"
36 : #include "EventsQueueSet.hpp"
37 : #include "BatchR.hpp"
38 : #include "timeGen.hpp"
39 :
40 : #include <iostream>
41 : #include <fstream>
42 :
43 :
44 : #ifndef _SIMULATOR_HPP
45 : #define _SIMULATOR_HPP
46 :
47 : template <class S, class EQT, class DEDS>
48 : class SimulatorBase:public timeGen {
49 : public:
50 : SimulatorBase(DEDS& N,LHA_orig<typename DEDS::stateType>&);
51 :
52 : //Simulator();
53 : ~SimulatorBase();
54 :
55 : //! Path to the temporary directory
56 : string tmpPath;
57 : string dotFile;
58 :
59 : /**
60 : * \brief Set the batch size
61 : * @param RI the new batch size to use
62 : */
63 : void SetBatchSize(const size_t); // set the batch size
64 :
65 : /**
66 : * \brief Open an output stream to a file to log the result value of each trajectory.
67 : * @param path is a path to a file in which the value will be log in.
68 : */
69 : void logValue(const string); //Make the simulator output each result in a file.
70 :
71 : void logTrace(const string,double); //Make the simulator output each trace in a file.
72 :
73 : /**
74 : * \brief Main entry point of the object simulate a batch of trajectory .
75 : *
76 : * Run a batch of simulation, the result is return as a BatchR structure.
77 : * @return a new BatchR structure containing the result
78 : * of the batch of simulation.
79 : */
80 : BatchR RunBatch();
81 :
82 : /* private */
83 :
84 : //! File stream to log value.
85 : fstream logvalue;
86 : //! File stream to trace.
87 : fstream logtrace;
88 :
89 : //! boolean set to true when result value should be log.
90 : bool logResult;
91 :
92 : //! interval time on which trace is log
93 : double sampleTrace;
94 : double lastSampled;
95 :
96 : //! Store result beetween two trajectory simulation.
97 : SimOutput Result;
98 :
99 : //! Size of the batch.
100 : size_t BatchSize;
101 :
102 :
103 : DEDS &N; //!The object representing the SPN
104 : LHA_orig<typename DEDS::stateType> &A; //!The object representing the LHA
105 :
106 :
107 : /**
108 : * \brief The event queue of the simulator.
109 : * The event queue is a datastructure containing the
110 : * enabled transitions with
111 : * the time at wich they will be fire if still enabled
112 : */
113 : EQT* EQ;
114 :
115 :
116 : /**
117 : * \brief Simulate a step of the system,
118 : * this function do most of the simulation job.
119 : */
120 : bool SimulateOneStep();
121 :
122 : /**
123 : * \brief Simulate single path
124 : * this function loop over SimulateOneStep until a the path terminate.
125 : */
126 : void SimulateSinglePath();
127 :
128 : void printLog(double,size_t);
129 : void printLog(double);
130 :
131 : void interactiveSimulation(); //!Wait for the user to choose the next transition
132 : double minInteractiveTime;
133 : long waitForTransition;
134 :
135 : void printSedCmd();
136 :
137 : void reset(); //! reset the simulator
138 :
139 : void returnResultTrue();
140 :
141 : void updateLikelihood(size_t);
142 :
143 : //! Stop the simulation if sink transition is taken
144 : bool transitionSink(size_t);
145 :
146 : };
147 :
148 : template <class EQT, class DEDS>
149 21 : class Simulator:public SimulatorBase<Simulator<EQT, DEDS>, EQT, DEDS>{
150 : public:
151 21 : Simulator(DEDS& deds,LHA_orig<typename DEDS::stateType>& lha):SimulatorBase<Simulator,EQT,DEDS>(deds, lha){};
152 : };
153 :
154 : #endif /* _SIMULATOR_HPP */
155 :
|