Isorropia_EpetraCostDescriber.hpp

Go to the documentation of this file.
00001 //@HEADER
00002 /*
00003 ************************************************************************
00004 
00005               Isorropia: Partitioning and Load Balancing Package
00006                 Copyright (2006) Sandia Corporation
00007 
00008 Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00009 license for use of this work by or on behalf of the U.S. Government.
00010 
00011 This library is free software; you can redistribute it and/or modify
00012 it under the terms of the GNU Lesser General Public License as
00013 published by the Free Software Foundation; either version 2.1 of the
00014 License, or (at your option) any later version.
00015 
00016 This library is distributed in the hope that it will be useful, but
00017 WITHOUT ANY WARRANTY; without even the implied warranty of
00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 Lesser General Public License for more details.
00020 
00021 You should have received a copy of the GNU Lesser General Public
00022 License along with this library; if not, write to the Free Software
00023 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 USA
00025 
00026 ************************************************************************
00027 */
00028 //@HEADER
00029 
00030 #ifndef _Isorropia_EpetraCostDescriber_hpp_
00031 #define _Isorropia_EpetraCostDescriber_hpp_
00032 
00033 #include <Isorropia_ConfigDefs.hpp>
00034 #include <Isorropia_CostDescriber.hpp>
00035 #include <Teuchos_RCP.hpp>
00036 #include <Teuchos_ParameterList.hpp>
00037 
00038 #include <map>
00039 #include <list>
00040 #include <set>
00041 #include <iostream>
00042 
00043 #ifdef HAVE_EPETRA
00044 class Epetra_Vector;
00045 class Epetra_CrsMatrix;
00046 
00047 namespace Isorropia {
00048 
00086 class Operator;
00087 
00088 namespace Epetra {
00089 
00107 // Forward declarations of friends
00108 
00109 namespace ZoltanLib{
00110   class QueryObject;
00111 }
00112 class InternalPartitioner;
00113 class ZoltanLibClass;
00114 
00115 class CostDescriber : public Isorropia::CostDescriber {
00116 
00117   // public methods are part of API, private methods are used by different
00118   // classes in isorropia
00119 
00120   friend class Isorropia::Operator;
00121   friend class Isorropia::Epetra::ZoltanLib::QueryObject;
00122   friend class Isorropia::Epetra::InternalPartitioner;
00123   friend class Isorropia::Epetra::ZoltanLibClass;
00124 
00125 public:
00127   CostDescriber();
00128 
00130   ~CostDescriber();
00131 
00134   friend std::ostream& operator <<(std::ostream &, const Isorropia::Epetra::CostDescriber &cd);
00135 
00141   void setVertexWeights(Teuchos::RCP<const Epetra_Vector> vwts);
00142 
00154   void setGraphEdgeWeights(Teuchos::RCP<const Epetra_CrsMatrix> gewts);
00155 
00165   void setHypergraphEdgeWeights(Teuchos::RCP<const Epetra_Vector> hgewts);
00166 
00183   void setHypergraphEdgeWeights(int numHGedges, const int *hgGIDs, const float *hgEwgts);
00184 
00188   void setHypergraphEdgeWeights(int numHGedges, const int *hgGIDs, const double *hgEwgts);
00189 
00198   void getCosts(std::map<int, float > &vertexWeights,
00199                 std::map<int, std::map<int, float > > &graphEdgeWeights,
00200                 std::map<int, float > &hypergraphEdgeWeights) const;
00201 
00204   void show_cd(std::ostream &) const;
00205 
00206 private:
00207 
00210   void setParameters(const Teuchos::ParameterList& paramlist);
00211 
00214   bool haveVertexWeights() const;
00217   int getNumVertices() const;
00220   void getVertexWeights(int numVertices,
00221                       int* global_ids, float* weights) const; 
00224   bool haveGraphEdgeWeights() const;
00227   int getNumGraphEdges(int vertex_global_id) const;
00228 
00233   int getGraphEdgeVertices(std::set<int> &gids) const;
00234 
00235 
00238   void getGraphEdgeWeights(int vertex_global_id,
00239                                    int num_neighbors,
00240                                    int* neighbor_global_ids,
00241                                    float* weights) const; 
00244   bool haveHypergraphEdgeWeights() const;
00247   int getNumHypergraphEdgeWeights() const;
00250   void getHypergraphEdgeWeights(int numEdges,
00251                                         int* global_ids,
00252                                         float* weights) const;
00253 
00259    int getHypergraphEdgeWeights(std::map<int, float> &wgtMap) const;
00260 
00261 
00267   int getVertexWeights(std::map<int, float> &wgtMap) const;
00268 
00269 
00270 
00278   int getGraphEdgeWeights(int vertex_global_id, std::map<int, float> &wgtMap) const;
00279 
00280 
00281 
00285   bool haveGlobalVertexWeights() const;
00286 
00290   void setNumGlobalVertexWeights(int num);
00291 
00295   bool haveGlobalGraphEdgeWeights() const;
00296 
00300   void setNumGlobalGraphEdgeWeights(int num);
00301 
00305   bool haveGlobalHypergraphEdgeWeights() const;
00306 
00310   void setNumGlobalHypergraphEdgeWeights(int num);
00311 
00314   void allocate_hg_edge_weights_(int n);
00315 
00318   void free_hg_edge_weights_();
00319 
00320   Teuchos::RCP<const Epetra_Vector> vertex_weights_;
00321   Teuchos::RCP<const Epetra_CrsMatrix> graph_edge_weights_;
00322   std::set<int> graph_self_edges_;
00323 
00324   Teuchos::ParameterList paramlist_;
00325 
00326   int *hg_edge_gids_;
00327   float *hg_edge_weights_;
00328   int num_hg_edge_weights_;
00329 
00330   int numGlobalVertexWeights_;
00331   int numGlobalGraphEdgeWeights_;
00332   int numGlobalHypergraphEdgeWeights_;
00333 
00346   int getEdges(int vertexGID, int len, int *nborGID, float *weights) const;
00347 
00348 
00349 };//class CostDescriber
00350 
00351 }//namespace Epetra
00352 }//namespace Isorropia
00353 
00354 #endif //HAVE_EPETRA
00355 
00356 #endif
00357