include/plaws/DiscreteProbabilityLaw.hpp

Go to the documentation of this file.
00001 // DiscreteProbabilityLaw.hpp: this file is part of the REGAL project.
00002 //
00003 // REGAL : Random and Exhaustive Generators for Automata - Library
00004 //
00005 // Copyright (C) 2007 Julien DAVID.
00006 //
00007 // This program is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2
00010 // of the License, or (at your option) any later version.
00011 //
00012 // The complete GNU General Public Licence Notice can be found as the
00013 // `COPYING' file in the root directory.
00014 //
00015 //
00016 #ifndef DISCRETEPROBABILITYLAW
00017 #define DISCRETEPROBABILITYLAW
00018 
00019 
00020 #include <math.h>
00021 #include<time.h>
00022 #include<stdlib.h>
00023 #include "../VerboseOption.hpp"
00024 
00025 #include <iostream>
00026 
00027 namespace regal{
00028   
00029   namespace plaws{
00030     
00031     class DiscreteProbabilityLaw{
00032     protected:
00033       double x,p;
00034       
00039       virtual void updateProbability(const int & k)=0;
00040       
00045       virtual double initProbability()=0;
00046       
00051       virtual int initCounter(){return 0;}
00052       
00053     public:
00054       
00055       
00060       int randomValue(){
00061         int k=initCounter();
00062         p=initProbability();
00063         double dice=(rand())/(double)RAND_MAX;
00064         while(dice>=p){
00065           dice-=p;
00066           k++;
00067           updateProbability(k);
00068         }
00069         return k;
00070       }
00071       
00072       
00073       
00078       DiscreteProbabilityLaw(const double & param){
00079         x=param;
00080         time_t t;
00081         srand(time(&t));
00082       }
00083       
00087       virtual ~DiscreteProbabilityLaw(){
00088         verbose("Destruction of a Discrete Probability Law");
00089       }
00090     };
00091     
00092   }
00093 
00094 }
00095   
00096 #endif
00097   

Generated on Mon Sep 29 16:33:58 2008 for REGAL by  doxygen 1.5.1