Isorropia: Partitioning, Load Balancing and more
Isorropia_EpetraCostDescriber.hpp
Go to the documentation of this file.
00001 //@HEADER
00002 //************************************************************************
00003 //
00004 //              Isorropia: Partitioning and Load Balancing Package
00005 //                Copyright (2006) Sandia Corporation
00006 //
00007 //Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 //license for use of this work by or on behalf of the U.S. Government.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 //************************************************************************
00038 //@HEADER
00039 
00040 #ifndef _Isorropia_EpetraCostDescriber_hpp_
00041 #define _Isorropia_EpetraCostDescriber_hpp_
00042 
00043 #include <Isorropia_ConfigDefs.hpp>
00044 #include <Isorropia_CostDescriber.hpp>
00045 #include <Teuchos_RCP.hpp>
00046 #include <Teuchos_ParameterList.hpp>
00047 
00048 #include <map>
00049 #include <list>
00050 #include <set>
00051 #include <iostream>
00052 
00053 #ifdef HAVE_EPETRA
00054 class Epetra_Vector;
00055 class Epetra_CrsMatrix;
00056 class Epetra_RowMatrix;
00057 class Epetra_MultiVector;
00058 class Epetra_Import;
00059 class Epetra_CrsGraph;
00060 
00061 namespace Isorropia {
00062 
00100 class Operator;
00101 
00102 namespace Epetra {
00103 
00121 // Forward declarations of friends
00122 
00123 namespace ZoltanLib{
00124   class QueryObject;
00125 }
00126 class ZoltanLibClass;
00127 
00128 class CostDescriber : public Isorropia::CostDescriber {
00129 
00130   // public methods are part of API, private methods are used by different
00131   // classes in isorropia
00132 
00133   friend class Isorropia::Operator;
00134   friend class Isorropia::Epetra::ZoltanLib::QueryObject;
00135   friend class Isorropia::Epetra::ZoltanLibClass;
00136 
00137 public:
00139   CostDescriber();
00140 
00142   ~CostDescriber();
00143 
00145   CostDescriber(const CostDescriber &costs);
00146 
00149   friend std::ostream& operator <<(std::ostream &, const Isorropia::Epetra::CostDescriber &cd);
00150 
00159   void setVertexWeights(Teuchos::RCP<const Epetra_Vector> vwgts);
00160 
00172   void setGraphEdgeWeights(Teuchos::RCP<const Epetra_CrsMatrix> gewts);
00173 
00183   void setHypergraphEdgeWeights(Teuchos::RCP<const Epetra_Vector> hgewts);
00184 
00201   void setHypergraphEdgeWeights(int numHGedges, const int *hgGIDs, const float *hgEwgts);
00202 
00206   void setHypergraphEdgeWeights(int numHGedges, const int *hgGIDs, const double *hgEwgts);
00207 
00216   void getCosts(std::map<int, float > &vertexWeights,
00217                 std::map<int, std::map<int, float > > &graphEdgeWeights,
00218                 std::map<int, float > &hypergraphEdgeWeights) const;
00219 
00222   void show_cd(std::ostream &) const;
00223 
00224   // Add documentation
00225 
00226 #ifdef USE_UTILS
00227   int compareBeforeAndAfterHypergraph( const Epetra_RowMatrix &in_m, const Epetra_RowMatrix &out_m,
00228             const Epetra_Import &importer,
00229             std::vector<double> &balance, std::vector<double> &cutn, std::vector<double> &cutl) const;
00230 
00231   int compareBeforeAndAfterGraph( const Epetra_RowMatrix &in_m, const Epetra_RowMatrix &out_m,
00232             const Epetra_Import &importer,
00233             std::vector<double> &balance, std::vector<int> &numCuts, std::vector<double> &cutWgt,
00234             std::vector<double> &cutn, std::vector<double> &cutl) const;
00235 
00236   int compareBeforeAndAfterGraph( const Epetra_CrsGraph &in_g, const Epetra_CrsGraph &out_g,
00237             const Epetra_Import &importer,
00238             std::vector<double> &balance, std::vector<int> &numCuts, std::vector<double> &cutWgt,
00239             std::vector<double> &cutn, std::vector<double> &cutl) const;
00240 
00241   int compareBeforeAndAfterImbalance(const Epetra_MultiVector &mv, const  Epetra_Import &importer,
00242                   std::vector<double> &min, std::vector<double> &max, std::vector<double> &avg) const;
00243 #endif
00244 
00245 private:
00246 
00247   void _transformWeights(const Epetra_Import &importer);
00248 
00249   int _compareBeforeAndAfterGraph( const Epetra_RowMatrix *in_m, const Epetra_RowMatrix *out_m,
00250             const Epetra_CrsGraph *in_g, const Epetra_CrsGraph *out_g,
00251             const Epetra_Import &importer,
00252             std::vector<double> &balance, std::vector<int> &numCuts, std::vector<double> &cutWgt,
00253             std::vector<double> &cutn, std::vector<double> &cutl) const;
00254 
00257   void setParameters(const Teuchos::ParameterList& paramlist);
00258 
00261   bool haveVertexWeights() const;
00264   int getNumVertices() const;
00267   void getVertexWeights(int numVertices,
00268                       int* global_ids, float* weights) const; 
00271   bool haveGraphEdgeWeights() const;
00274   int getNumGraphEdges(int vertex_global_id) const;
00275 
00280   int getGraphEdgeVertices(std::set<int> &gids) const;
00281 
00282 
00285   void getGraphEdgeWeights(int vertex_global_id,
00286                                    int num_neighbors,
00287                                    int* neighbor_global_ids,
00288                                    float* weights) const; 
00291   bool haveHypergraphEdgeWeights() const;
00294   int getNumHypergraphEdgeWeights() const;
00297   void getHypergraphEdgeWeights(int numEdges,
00298                                         int* global_ids,
00299                                         float* weights) const;
00300 
00306    int getHypergraphEdgeWeights(std::map<int, float> &wgtMap) const;
00307 
00308 
00314   int getVertexWeights(std::map<int, float> &wgtMap) const;
00315 
00316   // TODO documentation
00317   const Epetra_Vector &getVertexWeights() { return *vertex_weights_;}
00318 
00319 
00327   int getGraphEdgeWeights(int vertex_global_id, std::map<int, float> &wgtMap) const;
00328 
00329 
00330 
00334   bool haveGlobalVertexWeights() const;
00335 
00339   void setNumGlobalVertexWeights(int num);
00340 
00344   bool haveGlobalGraphEdgeWeights() const;
00345 
00349   void setNumGlobalGraphEdgeWeights(int num);
00350 
00354   bool haveGlobalHypergraphEdgeWeights() const;
00355 
00359   void setNumGlobalHypergraphEdgeWeights(int num);
00360 
00363   void allocate_hg_edge_weights_(int n);
00364 
00367   void free_hg_edge_weights_();
00368 
00369   Teuchos::RCP<const Epetra_Vector> vertex_weights_;
00370   Teuchos::RCP<const Epetra_CrsMatrix> graph_edge_weights_;
00371   std::set<int> graph_self_edges_;
00372 
00373   Teuchos::ParameterList paramlist_;
00374 
00375   int *hg_edge_gids_;
00376   float *hg_edge_weights_;
00377   int num_hg_edge_weights_;
00378 
00379   int numGlobalVertexWeights_;
00380   int numGlobalGraphEdgeWeights_;
00381   int numGlobalHypergraphEdgeWeights_;
00382 
00395   int getEdges(int vertexGID, int len, int *nborGID, float *weights) const;
00396 
00397 };//class CostDescriber
00398 
00399 }//namespace Epetra
00400 }//namespace Isorropia
00401 
00402 #endif //HAVE_EPETRA
00403 
00404 #endif
00405