Isorropia: Partitioning, Load Balancing and more
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 class Epetra_RowMatrix;
00047 class Epetra_MultiVector;
00048 class Epetra_Import;
00049 class Epetra_CrsGraph;
00050 
00051 namespace Isorropia {
00052 
00090 class Operator;
00091 
00092 namespace Epetra {
00093 
00111 // Forward declarations of friends
00112 
00113 namespace ZoltanLib{
00114   class QueryObject;
00115 }
00116 class ZoltanLibClass;
00117 
00118 class CostDescriber : public Isorropia::CostDescriber {
00119 
00120   // public methods are part of API, private methods are used by different
00121   // classes in isorropia
00122 
00123   friend class Isorropia::Operator;
00124   friend class Isorropia::Epetra::ZoltanLib::QueryObject;
00125   friend class Isorropia::Epetra::ZoltanLibClass;
00126 
00127 public:
00129   CostDescriber();
00130 
00132   ~CostDescriber();
00133 
00135   CostDescriber(const CostDescriber &costs);
00136 
00139   friend std::ostream& operator <<(std::ostream &, const Isorropia::Epetra::CostDescriber &cd);
00140 
00149   void setVertexWeights(Teuchos::RCP<const Epetra_Vector> vwgts);
00150 
00162   void setGraphEdgeWeights(Teuchos::RCP<const Epetra_CrsMatrix> gewts);
00163 
00173   void setHypergraphEdgeWeights(Teuchos::RCP<const Epetra_Vector> hgewts);
00174 
00191   void setHypergraphEdgeWeights(int numHGedges, const int *hgGIDs, const float *hgEwgts);
00192 
00196   void setHypergraphEdgeWeights(int numHGedges, const int *hgGIDs, const double *hgEwgts);
00197 
00206   void getCosts(std::map<int, float > &vertexWeights,
00207                 std::map<int, std::map<int, float > > &graphEdgeWeights,
00208                 std::map<int, float > &hypergraphEdgeWeights) const;
00209 
00212   void show_cd(std::ostream &) const;
00213 
00214   // Add documentation
00215 
00216 #ifdef USE_UTILS
00217   int compareBeforeAndAfterHypergraph( const Epetra_RowMatrix &in_m, const Epetra_RowMatrix &out_m,
00218             const Epetra_Import &importer,
00219             std::vector<double> &balance, std::vector<double> &cutn, std::vector<double> &cutl) const;
00220 
00221   int compareBeforeAndAfterGraph( const Epetra_RowMatrix &in_m, const Epetra_RowMatrix &out_m,
00222             const Epetra_Import &importer,
00223             std::vector<double> &balance, std::vector<int> &numCuts, std::vector<double> &cutWgt,
00224             std::vector<double> &cutn, std::vector<double> &cutl) const;
00225 
00226   int compareBeforeAndAfterGraph( const Epetra_CrsGraph &in_g, const Epetra_CrsGraph &out_g,
00227             const Epetra_Import &importer,
00228             std::vector<double> &balance, std::vector<int> &numCuts, std::vector<double> &cutWgt,
00229             std::vector<double> &cutn, std::vector<double> &cutl) const;
00230 
00231   int compareBeforeAndAfterImbalance(const Epetra_MultiVector &mv, const  Epetra_Import &importer,
00232                   std::vector<double> &min, std::vector<double> &max, std::vector<double> &avg) const;
00233 #endif
00234 
00235 private:
00236 
00237   void _transformWeights(const Epetra_Import &importer);
00238 
00239   int _compareBeforeAndAfterGraph( const Epetra_RowMatrix *in_m, const Epetra_RowMatrix *out_m,
00240             const Epetra_CrsGraph *in_g, const Epetra_CrsGraph *out_g,
00241             const Epetra_Import &importer,
00242             std::vector<double> &balance, std::vector<int> &numCuts, std::vector<double> &cutWgt,
00243             std::vector<double> &cutn, std::vector<double> &cutl) const;
00244 
00247   void setParameters(const Teuchos::ParameterList& paramlist);
00248 
00251   bool haveVertexWeights() const;
00254   int getNumVertices() const;
00257   void getVertexWeights(int numVertices,
00258                       int* global_ids, float* weights) const; 
00261   bool haveGraphEdgeWeights() const;
00264   int getNumGraphEdges(int vertex_global_id) const;
00265 
00270   int getGraphEdgeVertices(std::set<int> &gids) const;
00271 
00272 
00275   void getGraphEdgeWeights(int vertex_global_id,
00276                                    int num_neighbors,
00277                                    int* neighbor_global_ids,
00278                                    float* weights) const; 
00281   bool haveHypergraphEdgeWeights() const;
00284   int getNumHypergraphEdgeWeights() const;
00287   void getHypergraphEdgeWeights(int numEdges,
00288                                         int* global_ids,
00289                                         float* weights) const;
00290 
00296    int getHypergraphEdgeWeights(std::map<int, float> &wgtMap) const;
00297 
00298 
00304   int getVertexWeights(std::map<int, float> &wgtMap) const;
00305 
00306   // TODO documentation
00307   const Epetra_Vector &getVertexWeights() { return *vertex_weights_;}
00308 
00309 
00317   int getGraphEdgeWeights(int vertex_global_id, std::map<int, float> &wgtMap) const;
00318 
00319 
00320 
00324   bool haveGlobalVertexWeights() const;
00325 
00329   void setNumGlobalVertexWeights(int num);
00330 
00334   bool haveGlobalGraphEdgeWeights() const;
00335 
00339   void setNumGlobalGraphEdgeWeights(int num);
00340 
00344   bool haveGlobalHypergraphEdgeWeights() const;
00345 
00349   void setNumGlobalHypergraphEdgeWeights(int num);
00350 
00353   void allocate_hg_edge_weights_(int n);
00354 
00357   void free_hg_edge_weights_();
00358 
00359   Teuchos::RCP<const Epetra_Vector> vertex_weights_;
00360   Teuchos::RCP<const Epetra_CrsMatrix> graph_edge_weights_;
00361   std::set<int> graph_self_edges_;
00362 
00363   Teuchos::ParameterList paramlist_;
00364 
00365   int *hg_edge_gids_;
00366   float *hg_edge_weights_;
00367   int num_hg_edge_weights_;
00368 
00369   int numGlobalVertexWeights_;
00370   int numGlobalGraphEdgeWeights_;
00371   int numGlobalHypergraphEdgeWeights_;
00372 
00385   int getEdges(int vertexGID, int len, int *nborGID, float *weights) const;
00386 
00387 };//class CostDescriber
00388 
00389 }//namespace Epetra
00390 }//namespace Isorropia
00391 
00392 #endif //HAVE_EPETRA
00393 
00394 #endif
00395