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

gnodestuff.h

Go to the documentation of this file.
00001 //****************************************************
00002 //  April, 1993, University of Illinois
00003 // Copyright (C) 1993, 1994 Tianlin Wang
00004 /* Copyright (C) 1994-2003 Matvec Development Team. 
00005 
00006   This program is free software; you can redistribute it and/or
00007   modify it under the terms of the GNU Library General Public
00008   License as published by the Free Software Foundation; either
00009   version 2 of the License, or (at your option) any later version.
00010   
00011   This program 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 GNU
00014   Library General Public License for more details.
00015     
00016   You should have received a copy of the GNU Library General Public
00017   License along with this library; if not, write to the Free
00018   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00019   MA 02111-1307, USA 
00020 */
00021 
00022 #ifndef gnodestuff_h
00023 #define gnodestuff_h
00024 #include <ext/hash_map>
00025 #include <map>
00026 #include <set>
00027 #include "geneticdist.h"
00028 #include "exception.h"
00029 #include "safe_vectors.h"
00030 
00031 
00032 namespace matvec {
00033   class Population;
00034   class GNodeSet; // set of graph nodes
00035   class CutSet;
00036   class GNodeList;
00037   class GNode {  
00038   public:
00039     GNode(void); // ctor
00040     static GNodeList* gNodeListPtr;
00041         bool sampled;
00042         unsigned weight;
00043     set< GNodeSet*> SetofGNsts;
00044     CutSet* generatedSet;
00045     CutSet* myOldGNodeProbs;
00046     unsigned peelorder;
00047     unsigned id;
00048     unsigned connectFlag; // used in detecting loops
00049     unsigned numberOfCuts;
00050     float getCutsetMagnitude(void);
00051     void updateMysets(void); 
00052     CutSet* makeNeighSet(void);
00053     CutSet  calcBCutSetForPrevGNode(CutSet* FCutSetPrevGNode);
00054     CutSet  calcMyBCutSet(void);
00055     void peel(void);
00056     void reComputeGNode();
00057     void reverseSampleGNode();
00058     void sampleGNode();
00059     void release(void);
00060     bool isMyNeighbor(GNode* refGNode);
00061     SafeSTLVector<int> sampledStateCount;
00062     virtual unsigned getState(void){
00063       throw exception("GNode::getState(): called for virtual function");
00064     };
00065     virtual unsigned getOldState(void){
00066       throw exception("GNode::getOldState(): called for virtual function");
00067     };
00068     virtual unsigned getAcceptedAlleleState(void){
00069       throw exception("GNode::getAcceptedAlleleState(): called for virtual function");
00070     };
00071     virtual unsigned getMyAlleleState(void){
00072       throw exception("GNode::getmState(): called for virtual function");
00073     };
00074     virtual unsigned getMyAlleleOrigin(void){
00075       throw exception("GNode::getmState(): called for virtual function");
00076     }; 
00077     virtual unsigned getAcceptedMatState(void){
00078       throw exception("GNode::getAcceptedMatState(): called for virtual function");
00079     };
00080     virtual unsigned getAcceptedPatState(void){
00081       throw exception("GNode::getAcceptedPatState(): called for virtual function");
00082     };
00083     virtual unsigned getmState(void){
00084       throw exception("GNode::getmState(): called for virtual function");
00085     };
00086     virtual unsigned getpState(void){
00087       throw exception("GNode::getpState(): called for virtual function");
00088     };
00089     virtual unsigned getWeight(void){
00090       throw exception("GNode::getWeight(): called for virtual function");
00091     };  
00092     virtual bool incr(){
00093       throw exception("GNode::incr(): called for virtual function");
00094     };
00095     virtual void reset(int i){
00096       throw exception("GNode::reset(int i): called for virtual function");
00097     };
00098     virtual void resetAndSwitch(int i){
00099       throw exception("GNode::resetAndSwitch(int i): called for virtual function");
00100     };
00101     virtual ~GNode(void) {release();}
00102   };
00103   /*! \class GNode gnodestuff.h inc/gnodestuff.h
00104    * \brief This is the base graph node class.
00105    *
00106    * GNode class includes methods relevant to a graph node
00107    */
00108   class GNodeSet:public set<GNode*>{
00109   public:
00110     GNodeSet(void);
00111     unsigned connectFlag; // used in detecting loops
00112     unsigned numberOfCuts;
00113     static GeneticDist *prior;
00114     static unsigned currentLocus;
00115     bool incr(void);
00116     void reset(void);
00117     void attachMeToMyGnodes(void);
00118         void display(void);
00119     virtual double getValue(void){
00120       throw exception("GNodeSet::getValue(void): call for virtual function");
00121     };
00122     virtual double getTargetValue(void){
00123       throw exception("GNodeSet::getTargetValue(void): call for virtual function");
00124     };
00125     virtual double getOldValue(void){
00126       throw exception("GNodeSet::getOldValue(void): call for virtual function");
00127     }; 
00128     virtual ~GNodeSet(void) {;}
00129   };
00130   /*! \class GNodeSet gnodestuff.h inc/gnodestuff.h
00131    * \brief This is the  base "set of graph nodes" class.
00132    *
00133    * GNodeSet class includes methods relevant to a set of graph nodes
00134    */
00135   struct compareGNodesWeight: public binary_function<GNode*,GNode*,bool>{
00136     bool operator()(GNode* a,GNode* b){
00137                 unsigned aw = a->sampled ? 1 : a->getWeight();
00138                 unsigned bw = b->sampled ? 1 : b->getWeight();          
00139       return aw>bw;
00140     }
00141   };
00142   /*! \struct compareGNodes gnodestuff.h inc/gnodestuff.h
00143    * \brief This is the comparison criterion to rank Gnodes in GNodeList
00144    * based on the size of the alleleStateVector or genotypeVector
00145    */
00146     struct compareGNodesPeelId: public binary_function<GNode*,GNode*,bool>{
00147     bool operator()(GNode* a,GNode* b){
00148       return a->peelorder<b->peelorder;
00149     }
00150   };
00151   /*! \struct compareGNodes gnodestuff.h inc/gnodestuff.h
00152    * \brief This is the comparison criterion to rank Gnodes in GNodeList
00153    * based on the peeling order of the GNode
00154    */
00155   struct GNode_info {
00156     GNode* pointerToGNode; 
00157     unsigned dist;
00158   };
00159   /*! \struct GNode_info gnodestuff.h inc/gnodestuff.h
00160    * \brief Stores the id and distance from the cut of the GNode that will be sampled first
00161    */  
00162 
00163   class InvalidSample{}; 
00164 
00165   class GNodeList:public SafeSTLVector<GNode*> {
00166   public:
00167     // from here
00168     static double logTarget;
00169     static double logProposal;
00170     static double logOldProposal;
00171         static Population *popPtr;
00172     float sum;
00173     unsigned lastmember;
00174         Matrix<int> distanceMat;
00175         bool distanceMatDone;
00176         SafeSTLVector<GNode*> cutGNodesVector;
00177         set<GNode*> loopSetGNodes;
00178         GNodeList(void){distanceMatDone = false;};
00179     void  inputGNodeSets(char* fname);
00180     void  displayGNodeSets();
00181     void  getPeelOrder(char* fname);
00182     void  fill(unsigned n);
00183     void  makealleleGNodeSets(char* infile,char* outfile);
00184     void  makegenotGNodeSets(char* infile,char* outfile);
00185     // up to here are methods from the original peeling order program
00186     unsigned maxDist;
00187     GNode* sampleGNodePtr;
00188     GNode* containerGNode;
00189     set< GNodeSet*> completeSetofGNsts;
00190     set< CutSet*> completeSetofCutSets;
00191     GNodeList::iterator searchStart;
00192     GNodeList::iterator cutGNode;
00193     GNode* peelAndCut(unsigned maxCutSetSize);
00194     GNode* peelAndCutFast(void);
00195     void   peelCutAndCompute(unsigned maxCutSetSize, unsigned startBlock,unsigned stopBlock,unsigned sizeBlock);
00196     void   peelCutAndSample(unsigned maxCutSetSize, unsigned startBlock,unsigned stopBlock,unsigned sizeBlock);
00197     void   peelCutAndSample(unsigned maxCutSetSize);
00198     void   peelOrderCutAndSample(unsigned maxCutSetSize,unsigned startBlock,unsigned stopBlock,unsigned sizeBlock);
00199     void   peelOrderCutAndSample(unsigned maxCutSetSize);
00200     void   clearGNodeListForNextLocus(void);
00201     void   reinitGNodeList(void);
00202     void   releaseGNsts(void);
00203     void   releaseCutSets(void);
00204     void   resetGNodeList(void);
00205     void   setGNodeSampleFlags(unsigned startBlock, unsigned stopBlock, unsigned sizeBlock);
00206     void   setGNodeSampleFlags(void);
00207     void   findLoopAndCut();
00208         GNodeList::iterator getMinWeightGNode(void);
00209         set< GNodeSet*>::iterator  getCutGNodeSet(GNodeList::iterator cutGNode);
00210     void  propagateFlags(unsigned lowFlag, unsigned highFlag);
00211     void  resetConnectFlags(void);
00212     GNode_info choosenGNodeInfo;
00213         GNodeList isolatePureLoop(GNodeList::iterator loopCloser);
00214     void  cutLoop(GNodeList::iterator cutGNode, set< GNodeSet*>::iterator cutGNodeSet);
00215     void checkSample(void);
00216     void calculateTargetProb(void);
00217     string howToSample;
00218         void makeDistanceMatrix(void);
00219         void calcDistancefrom(GNode* refGNode);
00220         GNode* findSampleGNode(void);
00221   };
00222   /*! \class GNodeList gnodestuff.h inc/gnodestuff.h
00223    * \brief This is the "list of graph nodes" class.
00224    *
00225    * GNodeList class includes methods relevant to the list of graph
00226    * nodes
00227    */
00228 }////// end of namespace matvec 
00229 #endif

Generated on Thu Jun 16 17:13:44 2005 for Matvec by doxygen1.2.16