Biorithm  1.1
 All Classes Functions Variables Typedefs Friends
GenericLattice.h
00001 /**************************************************************************
00002  * Copyright (c) 2007 Clifford Conley Owens III                           *
00003  *                                                                        *
00004  * This file is part of Biorithm.                                         *
00005  *                                                                        *
00006  * Biorithm is free software: you can redistribute it and/or modify       *
00007  * it under the terms of the GNU General Public License as published by   *
00008  * the Free Software Foundation, either version 3 of the License, or      *
00009  * (at your option) any later version.                                    *
00010  *                                                                        *
00011  * Biorithm is distributed in the hope that it will be useful,            *
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of         *
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
00014  * GNU General Public License for more details.                           *
00015  *                                                                        *
00016  * You should have received a copy of the GNU General Public License      *
00017  * along with Biorithm.  If not, see <http://www.gnu.org/licenses/>.      *
00018  *                                                                        *
00019  **************************************************************************/
00020 
00031 #ifndef GENERICLATTICE_H
00032 #define GENERICLATTICE_H
00033 
00034 // ---------------------------- Internal Headers ---------------------------- //
00035 
00036 #include "Evaluator.h"
00037 #include "ItemsetLevel.h"
00038 #include "Lattice.h"
00039 #include "BinaryMatrix.h"
00040 #include "Rotor.h"
00041 
00049 class GenericLattice: public Lattice
00050 {
00051     protected:
00052         // We need this to associate with each itemset
00053         struct assoc
00054         {
00055             unsigned int upperBound;
00056 
00057             // This is if we could *potentially* be on the positive border
00058             bool positiveBorder;
00059         };
00060 
00061         // This is the ordered vector of the sets
00062         vector<ItemsetLevel<struct assoc> > levels;
00063 
00064         // This is a level representing the itemsets that we do not need to
00065         // evaluate--the bool is arbitrary.  We don't use anything
00066         ItemsetLevel<bool> dnevals;
00067 
00068         // This is the truth matrix
00069         BinaryMatrix* bm;
00070 
00071         // The evaluator
00072         Evaluator* evaluator;
00073 
00074         // Whether or not we have to worry about things coming in order
00075         bool order;
00076 
00077         // The target level for generating candidates
00078         unsigned int targetCandidate;
00079 
00080         // The lower level for generating candidates
00081         unsigned int lowerCandidate;
00082 
00083         // The target level
00084         unsigned int kCandidate;
00085 
00086         // The level above that has been completed
00087         unsigned int upperDneval;
00088 
00089         // The rotor for generating candidates
00090         Rotor candidateRotor;
00091 
00092         // The next candidate
00093         Itemset* nextCandidate;
00094 
00095         // The itemsets in the buffer that need to be evaluated in addition
00096         // to being counted
00097         vector<Itemset*> eBuffer;
00098 
00099         // The possition in the ebuffer
00100         unsigned int eBufferPos;
00101 
00102         // The position on the positive border
00103         unsigned int borderPos;
00104 
00105         // The level at which we are getting positive borders
00106         unsigned int borderLevel;
00107 
00108         // The number of successful itemsets at each level
00109         vector<unsigned int> successful;
00110 
00111         // The maximum level we could attain during a certain analysis
00112         unsigned int maxlev;
00113 
00114         // The iterator
00115         ItemsetLevel<bool>::iterator dnevaliter;
00116 
00117         // Whether or not we should keep the failures
00118         bool keepFs;
00119 
00120         // Helper methods
00121 
00122         // Candidiate stuff
00123         virtual void createCandidate();
00124         virtual void candidateTick();
00125         virtual void makeNotPositiveSubsets(const Itemset* is);
00126         virtual void fillDnevals(Itemset* is);
00127 
00128     public:
00129         GenericLattice(BinaryMatrix* bm = NULL, unsigned int bufferSize = 1000,
00130             Evaluator* evaluator = NULL, bool order = false,
00131             bool keepFailures = false);
00132         GenericLattice(const GenericLattice& src);
00133         virtual ~GenericLattice();
00134         virtual GenericLattice& operator =(const GenericLattice& rhs);
00135         virtual void setBinaryMatrix(BinaryMatrix* bm);
00136         virtual void generateCandidates(unsigned int level);
00137         virtual void generateCandidates(unsigned int level, unsigned int k);
00138         virtual bool hasNextCandidate() const;
00139         virtual Itemset* getNextCandidate();
00140         virtual void evaluateItemset(Itemset* is);
00141         virtual void flushEvaluationBuffer();
00142         virtual unsigned int getUpperBound() const;
00143         virtual void setEvaluator(Evaluator* evaluator);
00144         virtual void setBufferSize(unsigned int bufferSize);
00145         virtual unsigned int analyzeLevel(unsigned int level);
00146         virtual unsigned int analyzeLevel(unsigned int level, double& status);
00147         virtual unsigned int analyzeLevel(unsigned int level, unsigned int k);
00148         virtual unsigned int analyzeLevel(unsigned int level, unsigned int k,
00149             double& status);
00150         virtual bool isEmpty(unsigned int level) const;
00151         virtual unsigned int getSize() const;
00152         virtual unsigned int getSize(unsigned int level) const;
00153         virtual unsigned int getSuccessful(unsigned int level) const;
00154         virtual const Itemset* getItemset(unsigned int level,
00155             unsigned int index) const;
00156         virtual const Itemset* getItemset(unsigned int level,
00157             unsigned int index, unsigned int& upperBound) const;
00158         virtual void generatePositiveBorder(unsigned int level);
00159         virtual bool hasNextPositiveBorder() const;
00160         virtual const Itemset* getNextPositiveBorder();
00161         virtual void destroy();
00162         virtual unsigned int getWidth() const;
00163         void dontKeepFailures();
00164         void keepFailures();
00165 };
00166 
00167 #endif
 All Classes Functions Variables Typedefs Friends