LCOV - code coverage report
Current view: top level - builds/barbot/Cosmos/src/Simulator - spn.hpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 6 8 75.0 %
Date: 2021-06-16 15:43:28 Functions: 6 8 75.0 %

          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 & 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             : 
      27             : /**
      28             :  * This classe is the interface for SPN
      29             :  */
      30             : 
      31             : #ifndef _SPN_HPP
      32             : #define _SPN_HPP
      33             : 
      34             : #include <iostream>
      35             : #include <string>
      36             : #include <sstream>
      37             : #include <set>
      38             : #include <array>
      39             : #include <vector>
      40             : #include <map>
      41             : #include <math.h>
      42             : #include <assert.h>
      43             : #include <limits.h>
      44             : #include <stdlib.h>
      45             : 
      46             : #include "DistributionDef.hpp"
      47             : #include "marking.hpp"
      48             : 
      49             : #define TR_PL_ID unsigned long
      50             : #define REAL_TYPE double
      51             : 
      52             : /**
      53             :  * Datatype for transition of the SPN
      54             :  */
      55           0 : struct _trans {
      56             :         _trans(){};
      57             :         
      58             :         //! transition constructor
      59             :         _trans(unsigned int id,DistributionType dti,bool MD,size_t nbb,bool am):
      60             :     Id(id),DistTypeIndex(dti),MarkingDependent(MD),AgeMemory(am),bindingLinkTable(nbb,std::string::npos){};
      61             :     _trans(unsigned int id,DistributionType dti,bool MD,size_t nbb,bool am,std::string l):
      62             :     Id(id),label(l),DistTypeIndex(dti),MarkingDependent(MD),AgeMemory(am),bindingLinkTable(nbb,std::string::npos){};
      63             :         
      64             :         //! number of the transition
      65             :         unsigned int Id;
      66             :         
      67             :         //! Name of the transition, can be empty
      68             :     std::string label;
      69             :         DistributionType DistTypeIndex;
      70             :         
      71             :         bool MarkingDependent;
      72             :         //! true if the memory policy of the transition is age memory
      73             :         bool AgeMemory;
      74             :         //! List of alowed binding for this transition.
      75             :     std::vector<abstractBinding> bindingList;
      76             :         //! Table to access bindings of the transition.
      77             :     std::vector<size_t> bindingLinkTable;
      78             : };
      79             : typedef struct _trans spn_trans;
      80             : 
      81             : template<typename T, typename C >
      82             : bool greaterIndex(std::vector< T * > v,C c ,int i,int j) {
      83             :     for(let d:v){
      84             :         int r = d->compare(c,i,j);
      85             :         if( r > 0)return true;
      86             :         if( r < 0 )return false;
      87             :     }
      88             :     return false;
      89             : }
      90             : 
      91             : /**
      92             :  * DataType for place of the SPN
      93             :  */
      94           0 : struct _place {
      95             :         _place():isTraced(true){};
      96             :         
      97             :         //! name of the place, can be empty
      98             :     std::string label;
      99             :         
     100             :         //! set to true if the place should appear in outputted trace
     101             :         bool isTraced;
     102             : };
     103             : typedef struct _place spn_place;
     104             : 
     105             : 
     106             : /**
     107             :  * \brief Class of the SPN.
     108             :  *
     109             :  * All the implementation of this class are generated at runtime.
     110             :  */
     111          21 : class SPN {
     112             : public:
     113             :     using stateType = abstractMarking;
     114             :     
     115             :     
     116             :     //! Current marking
     117             :     stateType Marking;
     118             : 
     119             :         //! Initialize all the data
     120             :         SPN();
     121             : 
     122             :     const CustomDistr& customDistr;
     123             : 
     124             :     //! Number of places
     125             :     const size_t pl;
     126             :     //! Number of transitions
     127             :     const size_t tr;
     128             :     
     129             :     //!contains all the transitions of the Petri net
     130             :     std::vector<spn_trans> Transition;
     131             :     //!contains all the places of the Petri net
     132             :     std::vector <spn_place> Place;
     133             : 
     134   157984346 :     const abstractMarking& getState()const {return Marking;};
     135        1806 :     void setState(const abstractMarking &s){ Marking = s;} ;
     136        1204 :     void setState(const std::vector<int> &v){Marking.setVector(v);};
     137        1591 :     void symmetrize(){Marking.Symmetrize();};
     138             :     
     139             :         //! set the marking to the initial marking
     140             :         void reset();
     141             : 
     142             :     /**
     143             :      * \brief fire a given transition.
     144             :      * The implementation of this function is generated
     145             :      * at runtime.
     146             :      * @param tr a transition of the SPN
     147             :      * @param b a binding of the transition of the SPN
     148             :      * @param time, the current time of the simulation, only used when link
     149             :      * with external code.
     150             :      */
     151             :     void
     152             :     fire(size_t tr,const abstractBinding& b, double time);
     153             :     
     154             :     /**
     155             :      * \brief unfire a given transition.
     156             :      * The implementation of this function is generated
     157             :      * at runtime.
     158             :      * This function is only used for rare event
     159             :      * @param tr a transition of the SPN
     160             :      * @param b a binding of the transition of the SPN
     161             :      */
     162             :     void unfire(size_t tr,const abstractBinding& b);
     163             : 
     164             :     /**
     165             :          * \brief A vector use to store temporary parameters value.
     166             :          * This vector is used to to store parameter of distribution
     167             :          * When the simulator ask for parameters the function GetDistParameter
     168             :          * store them inside this vector.
     169             :          * This is done to avoid allocating a new vector too frequently.
     170             :          */
     171             :         mutable std::array<double,PARAM_TBL_SIZE> ParamDistr;
     172             :         
     173             :         /**
     174             :          * \brief Check if a given transition is enabled.
     175             :          * The implementation of this function is generated
     176             :          * at runtime.
     177             :          * @param tr a transition of the SPN
     178             :          * @param b a binding of the transition of the SPN
     179             :          */
     180             :         bool
     181             :         IsEnabled(size_t tr,const abstractBinding& b)const;
     182             :     
     183             :     
     184             :     /**
     185             :      * \brief compute the the parameters value of a given
     186             :      * transition.
     187             :      * The implementation of this function is generated
     188             :      * at runtime.
     189             :      * @param tr a transition of the SPN
     190             :      * @param b a binding of the transition of the SPN
     191             :      */
     192             :     void GetDistParameters(size_t tr, const abstractBinding& b)const;
     193             :     
     194             :     /**
     195             :      *  Selected Place for state space exploration
     196             :      */
     197             :     std::vector<int> Msimpletab;
     198             : 
     199             :     size_t lastTransition; //! store the last fired transition
     200             :     double lastTransitionTime; //! store the last fired transition time for hybrid part.
     201             :     
     202             : /*private */
     203             :     
     204             :         void setConditionsVector();
     205             :         
     206             :         //! compute the the weight value of a given transition
     207             :         double GetWeight(size_t, const abstractBinding&)const;
     208             :         
     209             :         //! compute the the priority value of a given transition
     210             :         double GetPriority(size_t, const abstractBinding&)const;
     211             : 
     212             :     //! A table of set of transitions that may be enabled after firing the last transition
     213             :     static const int* PossiblyEnabled[];
     214             : 
     215             :     //! A table of set of transitions that may be disabled after firing the last transition
     216             :     static const int* PossiblyDisabled[];
     217             : 
     218             :     //! A table of set of transition without constrain but marking dependant
     219             :     static const int* FreeMarkDepT[];
     220             : 
     221             :     const abstractBinding* nextPossiblyEnabledBinding(size_t tr,const abstractBinding& b,size_t*) const;
     222             :     const abstractBinding* nextPossiblyDisabledBinding(size_t tr,const abstractBinding& b,size_t*) const;
     223             :     
     224             : private:
     225             :     
     226             :     //! The path of the file use to generate the implementation
     227             :     std::string Path;
     228             :     
     229             :     void Msimple();
     230             :     
     231             :         //------------------------- On the fly enabling disabling transition--------
     232             :         std::vector<int> TransitionConditions;
     233             :         std::vector<int> initTransitionConditions;
     234             :         //-------------------------/On the fly enabling disabling transition--------
     235             :         
     236             :         
     237             : };
     238             : 
     239           1 : class REHandling{
     240             : public:
     241             :     void print_state(const std::vector<int>&);
     242             :     void lumpingFun(const abstractMarking& ,std::vector<int>&);
     243             :     bool precondition(const abstractMarking&);
     244             : };
     245             : 
     246             : 
     247             : #endif  /* _SPN_HPP */

Generated by: LCOV version 1.13