Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

SimSeqs.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                                                 SimSeqs.h  -  description
00003                                                 -----------------
00004                 begin                           : Sun May 29 2000
00005                 copyright                       : (C) 2001 by Reinhold Kainhofer
00006                 email                           : reinhold@kainhofer.com
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *
00011  *  This program is free software; you can redistribute it and/or modify
00012  *  it under the terms of the GNU General Public License as published by
00013  *  the Free Software Foundation; either version 2 of the License, or
00014  *  (at your option) any later version.
00015  *
00016  ***************************************************************************/
00017 
00018 
00019 #ifndef SIMSEQS_H
00020 #define SIMSEQS_H
00021 //#include <stdlib.h>
00022 //#include <stdio.h>
00023 //#include <math.h>
00024 #include "BaseDefinitions.h"
00025 
00028 #define USEMC 1
00029 #define USEHALTON 2
00030 #define USENET 4
00031 #define USENIEDER 8
00032 #define USESOBOL 16
00033 #define USEFAURE 32
00034 #define USEATANASSOV 64
00035 #define USEHAMMERSLEY 128
00036 #define USENALPHA 256
00037 #define USEMAX USENALPHA
00038 
00039 
00040         // constants for the recursive construction of the Halton sequence
00041 #define GENAU           1E-9
00042 #define BGENAU   29
00043 #define MAXLONG 2147483647
00044 #define MAXPREC 30
00045 #define primefile "primes.dat"
00046 
00053 #define NAlphaOnes .6180339887498948482045969343656391177203091798058
00054 #define NAlphaTwos .4142135623730950488016887242096980785696718753769
00055 #define NAlphaThrees .3027756377319946465596106337352479731256482869226
00056 #define NAlphaFours .2360679774997896964091736687312762354406183596115
00057 
00058 /* *********************************************************** */
00059 /* Konstanten, Typen                                                                                                                                                             */
00060 /* *********************************************************** */
00061 //TODO
00062 #define maxanz 310
00063 #define max_nieder 900000000 // Max. Anz.der Niederr. Vektoren
00064 #define maxdim 310      // max. dimension for the sequence. set this to a high value to allow 400-dim. sequences as we need them.
00065 #define MAX_I_NORMAL 1025
00066 
00067 typedef double double_vektor[maxanz];
00068 typedef int             int_vektor[maxanz];
00069 typedef struct
00070                                 {
00071                                         int                             deg;                                            // degree of the polynomial
00072                                         int_vektor coeff;                                       // coefficients
00073                                                                                                                                                  // p(x)= coeff[0]+coeff[1]*x+ ...
00074                                 } polynom;
00075 typedef polynom polarr[maxdim+4];
00076 //endTODO */
00077 
00082 class longpoly {
00083 protected:
00086         long deg;
00089         long base;
00090 public:
00095         longpoly(long cflen=15, long bs=0);
00096         ~longpoly();
00099         long GetDegree();
00102         long SetDegree(long deg);
00105         long SetCoeff(long k, long val);
00108         long GetCoeff(long k);
00109 
00112         longpoly* times(longpoly& poly1);
00113 //      longpoly* operator *(longpoly& poly1);
00114 
00115 protected:
00118         long*coeff;
00121         long coefflen;
00122 };
00123 
00124 
00125 //c lass LDSqBase;
00129 long ReadPrimes(long* primes, long m);
00132 long NextPrime(long current);
00136 long*InitGenericPrimes(long dm);
00140 long*InitGenericInts(long dm);
00141 
00142 
00143 
00144 
00145 #define NTAB 32
00146 
00182 class LDSqBase {
00183 protected:
00186         char* name, *ext;
00189         long dim;
00192         long len;
00195         long* bases;
00200         double* numbers;
00204         bool created;
00205                         /* needed for the Pseudo random generators. Stores state and some other coefficients for shuffling
00206                         */
00207         long state, iy, iv[NTAB], type;
00208 public:
00213         long lastnr;
00214 
00215 public:
00220         /*const*/ bool qmc;
00230         LDSqBase(long*b=NULL, long dm=0,long iterations=0,
00231                         long genau=0, double genau1=0., char* ex="",char* nm="");
00232         virtual ~LDSqBase();
00233 
00236         virtual long GetDimension() {return dim;};
00239         virtual long GetLength() {return len;};
00240         virtual char* GetName() {return name;};
00241         virtual char* GetExtension() {return ext;};
00245         virtual long SetBases(long*b, long dm, long genau, double genau1);
00249         virtual long GetBases(long*b, long dm) {
00250                         for (long i=0;i<min(dm, dim);i++) b[i]=bases[i]; return min(dm, dim);}
00260         virtual long NextElement(double*buffer, long bufflen, long nr=-1);
00265         virtual bool CreateNumbers();
00269         virtual void SetNames(char* ex="",char* nm="");
00272         virtual void SetSeed(long int status) {state=status;}
00276         double ran1(long*idum);
00280         double ran2(long*idum);
00284         double ran3(long*idum);
00285 
00286 protected:
00297         virtual void InitMethod(long*b=NULL, long dm=0,long iterations=0,
00298                         long genau=0, double genau1=0., char* ex="",char* nm="");
00303         virtual long CalculateNextElement(long nr, double*buffer, long bufflen);
00306         virtual long InitData(long genau, double genau1);
00310         virtual long ExitData() { return 0;}
00315         virtual long*InitGenericBases(long dm) {return NULL;};
00316 };
00317 
00318 
00319 
00322 #define MC1 1   // "minimal" random number generator of Park and Miller with Bays-Durham shuffle and added safeguards
00323 #define MC2 2   // long period rng of L'Ecuyer with Bays-Durham shuffle and added safeguards
00324 #define MC3 3   // Knuth's subtractive method rng
00325 
00330 class LDSqMonteCarlo : public LDSqBase  {
00331 public:
00336         LDSqMonteCarlo(long tp=MC1, long status=-44891368, char* ex="mc",char* nm="Monte Carlo");
00337 protected:
00340         virtual long CalculateNextElement(long nr, double*buffer, long bufflen) {
00341                 switch (type) {
00342                         case MC2:       for (long i=0;i<bufflen;i++) { buffer[i]=ran2(&state);}; break;
00343                         case MC3:       for (long i=0;i<bufflen;i++) { buffer[i]=ran3(&state);}; break;
00344                         case MC1:default: for (long i=0;i<bufflen;i++) { buffer[i]=ran1(&state);}; break;
00345                 }
00346                 return dim;
00347         }
00348         virtual long InitData(long genau, double genau1){return dim;};
00349         virtual long ExitData(){return 0;};
00350 };
00351 
00352 
00357 class LDSqAfflerbach : public LDSqMonteCarlo {
00361         long altx;
00362 public:
00365         LDSqAfflerbach(char* ex="aff", char*nm="Afflerbach"):LDSqMonteCarlo(MC1,0,ex,nm) {altx=12785;}
00366 protected:
00367         virtual long CalculateNextElement(long nr, double*buffer, long bufflen) {
00368                 for (long i=0;i<bufflen;i++) buffer[i]=createNumber();
00369                 return dim;
00370         }
00371 private:
00374         virtual double createNumber(){
00375                 long xx=(532393*altx+1);
00376                 while (xx>=268435456) xx-=268435456;
00377                 altx=xx;
00378                 return ((double)xx/(double)268435456);
00379         }
00380 };
00381 
00382 
00385 class LDSqNAlpha : public LDSqBase {
00386 public:
00387         LDSqNAlpha(Zahl*alph=NULL, long dm=0, long iterations=0, char*ex="nalpha", char*nm="[n Alpha]"):
00388                         LDSqBase(NULL, dm, iterations, 0,0,ex,nm) {
00389                         alpha=alph;
00390                         InitMethod(NULL, dm, iterations, 0,0,ex,nm); }
00391 protected:
00394         virtual long*InitGenericBases(long dm) {return NULL;/*TODO!!!*/};
00397         virtual long CalculateNextElement(long nr, double*buffer, long bufflen) {
00398                 long d=min(bufflen,dim);
00399                 for (long i=0; i<d;i++) buffer[i]=(nr*alpha[i])-floor((nr*alpha[i]));
00400                 return d; }
00403         Zahl*alpha;
00404 };
00405 
00409 class LDSqHalton : public LDSqBase      {
00410 public:
00411         LDSqHalton(long*b=NULL, long dm=0,long iterations=0, long genau=BGENAU,
00412                         double genau1=GENAU, char* ex="hal",char* nm="Halton"):
00413                         LDSqBase(b, dm, iterations, genau, genau1, ex, nm){
00414                         p=NULL; q=NULL; lastnr=0; InitMethod(b, dm, iterations, genau, genau1,  ex, nm);}
00415 protected:
00421         virtual long CalculateNextElement(long nr, double*buffer, long bufflen);
00424         virtual long InitData(long genau, double genau1);
00425         virtual long ExitData();
00426         virtual long*InitGenericBases(long dm) {return InitGenericPrimes(dm);};
00429         long prec;
00432         double *q,*p;
00433 };
00434 
00435 
00436 
00439 class LDSqAtanassov : public LDSqBase   {
00440 protected: // Protected attributes
00443         long* factors;
00446         long* proots;
00449         long* modifiers;
00450 public:
00451         LDSqAtanassov(long*b=NULL, long dm=NULL,long iterations=0, long genau=BGENAU,
00452                         double genau1=GENAU, char* ex="ata",char* nm="Atanassov", long*prts=NULL,long*mdfs=NULL):
00453                         LDSqBase(b, dm, iterations, genau, genau1, ex, nm){
00454                         proots=prts; modifiers=mdfs; InitMethod(b, dm, iterations, genau, genau1,       ex, nm);}
00456 protected:
00457         virtual long CalculateNextElement(long nr, double*buffer, long bufflen);
00458         virtual long InitData(long genau=0, double genau1=0);
00459         virtual long ExitData();
00460         virtual long*InitGenericBases(long dm) {return InitGenericPrimes(dm);};
00461 private:
00464         bool GeneratePrimitiveRoots(long*bases, long*prts, long dim);
00467         bool GenerateModifiers(long*bases, long*prts, long*modfs, long dim);
00468 };
00469 
00474 class LDSqHammersley : public LDSqHalton        {
00475 protected:
00480         int Npos;
00481 public:
00486         LDSqHammersley(long*b=NULL, long dm=0,long iterations=0, long genau=0,
00487                         double genau1=0., int npos=1, char* ex="ham",char* nm="Hammersley"):
00488                         LDSqHalton(b,dm-1, iterations, genau, genau1,ex,nm) {
00489                         Npos=((npos%dm)+dm)%dm;dim++;};
00491 protected:
00492         virtual long CalculateNextElement(long nr, double*buffer, long bufflen);
00493 };
00494 
00495 
00496 #define konst 1073741824
00497 
00500 class LDSqSobol : public LDSqBase       {
00501 protected:
00502         long*V;
00503 public:
00504         LDSqSobol(long*b=NULL, long dm=0,long iterations=0, long genau=0,
00505                         double genau1=0., char* ex="sob",char* nm="Sobol"):
00506                         LDSqBase(b, dm, iterations, genau, genau1, ex,nm){
00507                         V=NULL;InitMethod(b, dm, iterations, genau, genau1,ex,nm);}
00508                                 // write the next element(s) of the sequence in a buffer.
00509 protected:
00510         virtual long CalculateNextElement(long nr, double*buffer, long bufflen);
00511         virtual long InitData(long genau, double genau1);
00512         virtual long ExitData();
00513 private:
00514         void dirnum_erz();
00515 };
00516 
00517 
00518 
00523 class LDSqFaure : public LDSqBase       {
00524 protected:
00525         long r, base;
00526         long*c;
00527 public:
00528         // fstep contains base^fstp
00529         long fstep;
00530 public:
00531         LDSqFaure(long*b=NULL, long dm=0,long iterations=0, long genau=0,
00532                         double genau1=0., long fstp=0, char* ex="fau",char* nm="Faure");
00533 protected:
00534         virtual long CalculateNextElement(long nr, double*buffer, long bufflen);
00535         virtual long InitData(long genau, double genau1);
00536         virtual long ExitData();
00537 private:
00541         void cyMultiply(long*cc, long*yold, long*ynew, long dm, long coefflen, long bs);
00542 protected:
00543         virtual void CreateDirMx(long*cc, long len, long bs);
00544 };
00545 
00549 class LDSqNetz : public LDSqBase        {
00550 protected:
00551         long base, nu, lambda;
00552         long nprime, ncurr, ncmax;
00553         long*ncoeff, *ypji;
00554         long ypjilen;
00555 public:
00556         LDSqNetz(long*b=NULL, long bas=5, long dm=0,long iterations=0,
00557                         long lamb=5, char* ex="ts" ,char* nm="(t,s)-Sequence");
00558 protected:
00559         virtual long CalculateNextElement(long nr, double*buffer, long bufflen);
00560         virtual long InitData(long genau, double genau1);
00561         virtual long ExitData();
00565         virtual long*InitGenericBases(long dm) {return InitGenericInts(dm);};
00566 private:
00567         long getypji(long p, long j, long i);
00568         long getypji(long index);
00569         long setypji(long p, long j, long i, long value);
00570         long setypji(long index, long value);
00571         long getindex(long p, long j, long i);
00572 };
00573 
00577 class LDSqNiederreiter : public LDSqBase        {
00578 protected:
00579         long basis;
00580         long maxnum,log_N;
00581         int_vektor q;
00582         long max_num;
00583         long c[32][32][maxanz]; //      c_ij acc. B-F-N Niederr
00584         polarr monic_pols;
00585 //      longpoly**MonicPolys;
00586 //      long nu, lambda;
00587 //      long nprime, ncurr, ncmax;
00588 //      long*ncoeff, *ypji;
00589 //      long ypjilen;
00590 public:
00591         LDSqNiederreiter(long*b=NULL, long bas=5, long dm=0,long iterations=0,
00592                         char* ex="nie" ,char* nm="Niederreiter (t,s)-Sequence");
00593 protected:
00594         virtual long CalculateNextElement(long nr, double*buffer, long bufflen);
00595         virtual long InitData(long genau, double genau1);
00596         virtual long ExitData();
00597 private:
00598         void pol_mult(polynom ap, polynom bp, polynom* cp);
00599         int entw_in_basis (int n, int *a);
00600         void gen_poly(polynom* pol );
00601 };
00602 
00603 
00604 
00605 #endif

Generated at Wed Jun 20 19:47:41 2001 for LDSequences by doxygen1.2.7 written by Dimitri van Heesch, © 1997-2001