ColPack
BipartiteGraphPartialColoring/BipartiteGraphPartialColoringInterface.cpp
Go to the documentation of this file.
00001 /************************************************************************************
00002     Copyright (C) 2005-2008 Assefaw H. Gebremedhin, Arijit Tarafdar, Duc Nguyen,
00003     Alex Pothen
00004 
00005     This file is part of ColPack.
00006 
00007     ColPack is free software: you can redistribute it and/or modify
00008     it under the terms of the GNU Lesser General Public License as published
00009     by the Free Software Foundation, either version 3 of the License, or
00010     (at your option) any later version.
00011 
00012     ColPack is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015     GNU Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public License
00018     along with ColPack.  If not, see <http://www.gnu.org/licenses/>.
00019 ************************************************************************************/
00020 
00021 #include "ColPackHeaders.h"
00022 
00023 using namespace std;
00024 
00025 namespace ColPack
00026 {
00027 
00028         //Public Destructor 2602
00029         BipartiteGraphPartialColoringInterface::~BipartiteGraphPartialColoringInterface()
00030         {
00031                 BipartiteGraphPartialColoring::Clear();
00032 
00033                 Seed_reset();
00034         }
00035 
00036         //Public Function 2603
00037         void BipartiteGraphPartialColoringInterface::Clear()
00038         {
00039                 BipartiteGraphPartialColoring::Clear();
00040 
00041                 return;
00042         }
00043 
00044 
00045         //Public Function 2604
00046         void BipartiteGraphPartialColoringInterface::Reset()
00047         {
00048                 BipartiteGraphPartialColoring::Reset();
00049 
00050                 return;
00051         }
00052 
00053 
00054         void BipartiteGraphPartialColoringInterface::GenerateSeedJacobian(double*** dp3_seed, int *ip1_SeedRowCount, int *ip1_SeedColumnCount, string s_OrderingVariant, string s_ColoringVariant) {
00055         //void BipartiteGraphPartialColoringInterface::GenerateSeedJacobian(unsigned int ** uip2_JacobianSparsityPattern, int i_RowCount, int i_ColumnCount, double*** dp3_seed, int *ip1_SeedRowCount, int *ip1_SeedColumnCount, string s_OrderingVariant, string s_ColoringVariant) {
00056                 //Clear (Re-initialize) the bipartite graph
00057                 //Clear();
00058 
00059                 //Read the sparsity pattern of the given Jacobian matrix (compressed sparse rows format)
00060                 //and create the corresponding bipartite graph
00061                 //BuildBPGraphFromRowCompressedFormat(uip2_JacobianSparsityPattern, i_RowCount, i_ColumnCount);
00062 
00063                 //Do Partial-Distance-Two-Coloring the bipartite graph with the specified ordering
00064                 PartialDistanceTwoColoring(s_OrderingVariant, s_ColoringVariant);
00065 
00066                 //Create the seed matrix from the coloring information
00067                 (*dp3_seed) = GetSeedMatrix(ip1_SeedRowCount, ip1_SeedColumnCount);
00068         }
00069 
00070         void BipartiteGraphPartialColoringInterface::GenerateSeedJacobian_unmanaged(double*** dp3_seed, int *ip1_SeedRowCount, int *ip1_SeedColumnCount, string s_OrderingVariant, string s_ColoringVariant) {
00071 
00072                 //Do Partial-Distance-Two-Coloring the bipartite graph with the specified ordering
00073                 PartialDistanceTwoColoring(s_OrderingVariant, s_ColoringVariant);
00074 
00075                 //Create the seed matrix from the coloring information
00076                 (*dp3_seed) = GetSeedMatrix_unmanaged(ip1_SeedRowCount, ip1_SeedColumnCount);
00077         }
00078 
00079         int BipartiteGraphPartialColoringInterface::PartialDistanceTwoColoring(string s_OrderingVariant, string s_ColoringVariant) {
00080                 m_T_Timer.Start();
00081                 int i_OrderingStatus = OrderVertices(s_OrderingVariant, s_ColoringVariant);
00082                 m_T_Timer.Stop();
00083                 m_d_OrderingTime = m_T_Timer.GetWallTime();
00084 
00085                 if(i_OrderingStatus != _TRUE)
00086                 {
00087                         cerr<<endl;
00088                         cerr<<s_OrderingVariant<<" Ordering Failed";
00089                         cerr<<endl;
00090 
00091                         return(1);
00092                 }
00093 
00094                 s_ColoringVariant = toUpper(s_ColoringVariant);
00095                 m_T_Timer.Start();
00096 
00097                 int i_ColoringStatus;
00098                 if(s_ColoringVariant == "COLUMN_PARTIAL_DISTANCE_TWO") {
00099                         i_ColoringStatus = PartialDistanceTwoColumnColoring();
00100                 } else if (s_ColoringVariant == "ROW_PARTIAL_DISTANCE_TWO") {
00101                         i_ColoringStatus = PartialDistanceTwoRowColoring();
00102                 } else {
00103                         cout<<" Unknown Partial Distance Two Coloring Method "<<s_ColoringVariant<<". Please use a legal Method."<<endl;
00104                         m_T_Timer.Stop();
00105                         m_d_ColoringTime = m_T_Timer.GetWallTime();
00106                         return (_FALSE);
00107                 }
00108 
00109                 m_T_Timer.Stop();
00110                 m_d_ColoringTime = m_T_Timer.GetWallTime();
00111                 return(i_ColoringStatus);
00112         }
00113 
00114 
00115         BipartiteGraphPartialColoringInterface::BipartiteGraphPartialColoringInterface(int i_type, ...) {
00116           //cout<<"IN GraphColoringInterface(int i_type, ...)"<<endl;
00117                 Clear();
00118 
00119                 if (i_type == SRC_WAIT) return;
00120 
00121                 //---------CONVERT INPUT TO ColPack's Bipartite Graph-------------
00122                 va_list ap; /*will point to each unnamed argument in turn*/
00123                 va_start(ap,i_type); /* point to first element after i_type*/
00124 
00125                 if (i_type == SRC_MEM_ADOLC) {
00126                   //get unsigned int ** uip2_HessianSparsityPattern, int i_RowCount
00127                   unsigned int ** uip2_JacobianSparsityPattern = va_arg(ap,unsigned int **);
00128                   int i_RowCount = va_arg(ap,int);
00129                   int i_ColumnCount = va_arg(ap,int);
00130 
00131                   BuildBPGraphFromRowCompressedFormat(uip2_JacobianSparsityPattern, i_RowCount, i_ColumnCount);
00132                 }
00133                 else if (i_type == SRC_MEM_ADIC) {
00134                   std::list<std::set<int> > *  lsi_SparsityPattern = va_arg(ap,std::list<std::set<int> > *);
00135                   int i_ColumnCount = va_arg(ap,int);
00136 
00137                   BuildBPGraphFromADICFormat(lsi_SparsityPattern, i_ColumnCount);
00138                 }
00139                 else if (i_type == SRC_MEM_SSF || i_type == SRC_MEM_CSR) {
00140                   int* ip_RowIndex = va_arg(ap,int*);
00141                   int i_RowCount = va_arg(ap,int);
00142                   int i_ColumnCount = va_arg(ap,int);
00143                   int* ip_ColumnIndex = va_arg(ap,int*);
00144 
00145                   BuildBPGraphFromCSRFormat(ip_RowIndex, i_RowCount, i_ColumnCount, ip_ColumnIndex);
00146                 }
00147                 else if (i_type == SRC_FILE) {
00148                   // get string s_InputFile, string s_fileFormat
00149                   string s_InputFile ( va_arg(ap,char *) );
00150                   string s_fileFormat ( va_arg(ap,char *) );
00151 
00152                   ReadBipartiteGraph(s_InputFile, s_fileFormat);
00153                 }
00154                 else {
00155                   cerr<<"ERR: BipartiteGraphBicoloringInterface(): i_type =\""<< i_type <<"\" unknown or unspecified"<<endl;
00156 
00157                   va_end(ap); //cleanup
00158                   return;
00159                 }
00160 #ifdef  _COLPACK_CHECKPOINT_
00161                 cout<<"IN BipartiteGraphPartialColoringInterface::BipartiteGraphPartialColoringInterface(int i_type, ...)"<<endl;
00162                 string s_OutputFile = "-ColPack_debug.mtx";
00163                 s_OutputFile = "BipartiteGraphPartialColoringInterface-InternalBPGraph"+s_OutputFile;
00164                 WriteMatrixMarket(s_OutputFile);
00165 #endif
00166 
00167                 //cout<<"START PrintBipartiteGraph()"<<endl;
00168                 //PrintBipartiteGraph();
00169                 //cout<<"END"<<endl;
00170 
00171 /*
00172                 // get string s_OrderingVariant
00173                 string s_OrderingVariant( va_arg(ap,char *) );
00174                 if (s_OrderingVariant.compare("WAIT") == 0) {
00175                   va_end(ap); //cleanup
00176                   return;
00177                 }
00178 
00179                 //---------ORDERING-------------
00180                 m_T_Timer.Start();
00181 
00182                 int i_OrderingStatus = OrderVertices(s_OrderingVariant);
00183 
00184                 m_T_Timer.Stop();
00185 
00186                 m_d_OrderingTime = m_T_Timer.GetWallTime();
00187 
00188                 if(i_OrderingStatus != _TRUE)
00189                 {
00190                         cerr<<endl<<"*ERROR: "<<s_OrderingVariant<<" Ordering Failed"<<endl;
00191                         return;
00192                 }
00193 
00194                 // get string s_BicoloringVariant
00195                 string s_ColoringVariant( va_arg(ap,char *) );
00196                 s_ColoringVariant = toUpper(s_ColoringVariant);
00197                 if (s_ColoringVariant.compare("WAIT") == 0) {
00198                   va_end(ap); //cleanup
00199                   return;
00200                 }
00201 
00202                 //---------COLORING-------------
00203                 m_T_Timer.Start();
00204 
00205                 int i_ColoringStatus;
00206                 if(s_ColoringVariant == "COLUMN_PARTIAL_DISTANCE_TWO") {
00207                         i_ColoringStatus = PartialDistanceTwoColumnColoring();
00208                 } else if (s_ColoringVariant == "ROW_PARTIAL_DISTANCE_TWO") {
00209                         i_ColoringStatus = PartialDistanceTwoRowColoring();
00210                 } else {
00211                         cout<<" Unknown Partial Distance Two Coloring Method "<<s_ColoringVariant<<". Please use a legal Method."<<endl;
00212                         m_T_Timer.Stop();
00213                         m_d_ColoringTime = m_T_Timer.GetWallTime();
00214                         return;
00215                 }
00216 
00217                 m_T_Timer.Stop();
00218 
00219                 m_d_ColoringTime = m_T_Timer.GetWallTime();
00220 //*/
00221                 va_end(ap); //cleanup
00222                 return;
00223         }
00224 
00225 
00226         void BipartiteGraphPartialColoringInterface::GetOrderedVertices(vector<int> &output) {
00227           BipartiteGraphPartialOrdering::GetOrderedVertices(output);
00228         }
00229 
00230         double** BipartiteGraphPartialColoringInterface::GetSeedMatrix(int* ip1_SeedRowCount, int* ip1_SeedColumnCount) {
00231           return BipartiteGraphPartialColoring::GetSeedMatrix(ip1_SeedRowCount, ip1_SeedColumnCount);
00232         }
00233 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines