ColPack
BipartiteGraphBicoloring/BipartiteGraphBicoloringInterface.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 3702
00029         BipartiteGraphBicoloringInterface::~BipartiteGraphBicoloringInterface()
00030         {
00031                 BipartiteGraphBicoloring::Clear();
00032 
00033                 Seed_reset();
00034         }
00035 
00036 
00037         //Virtual Function 3703
00038         void BipartiteGraphBicoloringInterface::Clear()
00039         {
00040                 BipartiteGraphBicoloring::Clear();
00041 
00042                 return;
00043         }
00044 
00045 
00046         //Virtual Function 3704
00047         void BipartiteGraphBicoloringInterface::Reset()
00048         {
00049                 BipartiteGraphBicoloring::Reset();
00050 
00051                 return;
00052         }
00053 
00054 
00055 
00056         void BipartiteGraphBicoloringInterface::GenerateSeedJacobian(double*** dp3_LeftSeed, int *ip1_LeftSeedRowCount, int *ip1_LeftSeedColumnCount, double*** dp3_RightSeed, int *ip1_RightSeedRowCount, int *ip1_RightSeedColumnCount, string s_OrderingVariant, string s_BicoloringVariant) {
00057         //void BipartiteGraphBicoloringInterface::GenerateSeedJacobian(unsigned int ** uip2_JacobianSparsityPattern, int i_RowCount, int i_ColumnCount, double*** dp3_LeftSeed, int *ip1_LeftSeedRowCount, int *ip1_LeftSeedColumnCount, double*** dp3_RightSeed, int *ip1_RightSeedRowCount, int *ip1_RightSeedColumnCount, string s_OrderingVariant, string s_BicoloringVariant) {
00058                 //Clear (Re-initialize) the bipartite graph
00059                 //Clear();
00060 
00061                 //Read the sparsity pattern of the given Jacobian matrix (compressed sparse rows format)
00062                 //and create the corresponding bipartite graph
00063                 //BuildBPGraphFromRowCompressedFormat(uip2_JacobianSparsityPattern, i_RowCount, i_ColumnCount);
00064 
00065                 //Color the graph based on the specified ordering and (Star) Bicoloring
00066                 Bicoloring(s_OrderingVariant, s_BicoloringVariant);
00067 
00068                 //From the coloring information, create and return the Left and Right seed matrices
00069                 *dp3_LeftSeed = GetLeftSeedMatrix(ip1_LeftSeedRowCount, ip1_LeftSeedColumnCount);
00070                 *dp3_RightSeed = GetRightSeedMatrix(ip1_RightSeedRowCount, ip1_RightSeedColumnCount);
00071 
00072         }
00073 
00074         void BipartiteGraphBicoloringInterface::GenerateSeedJacobian_unmanaged(double*** dp3_LeftSeed, int *ip1_LeftSeedRowCount, int *ip1_LeftSeedColumnCount, double*** dp3_RightSeed, int *ip1_RightSeedRowCount, int *ip1_RightSeedColumnCount, string s_OrderingVariant, string s_BicoloringVariant) {
00075 
00076                 //Color the graph based on the specified ordering and (Star) Bicoloring
00077                 Bicoloring(s_OrderingVariant, s_BicoloringVariant);
00078 
00079                 //From the coloring information, create and return the Left and Right seed matrices
00080                 *dp3_LeftSeed = GetLeftSeedMatrix_unmanaged(ip1_LeftSeedRowCount, ip1_LeftSeedColumnCount);
00081                 *dp3_RightSeed = GetRightSeedMatrix_unmanaged(ip1_RightSeedRowCount, ip1_RightSeedColumnCount);
00082         }
00083 
00084         int BipartiteGraphBicoloringInterface::Bicoloring(string s_OrderingVariant, string s_BicoloringVariant) {
00085                 m_T_Timer.Start();
00086                 int i_OrderingStatus = OrderVertices(s_OrderingVariant);
00087                 m_T_Timer.Stop();
00088                 m_d_OrderingTime = m_T_Timer.GetWallTime();
00089 
00090                 if(i_OrderingStatus != _TRUE)
00091                 {
00092                         cerr<<endl;
00093                         cerr<<s_OrderingVariant<<" Ordering Failed";
00094                         cerr<<endl;
00095 
00096                         return(1);
00097                 }
00098 
00099                 s_BicoloringVariant = toUpper(s_BicoloringVariant);
00100                 m_T_Timer.Start();
00101 
00102                 int i_ColoringStatus;
00103                 if(s_BicoloringVariant == "IMPLICIT_COVERING__STAR_BICOLORING") {
00104                         i_ColoringStatus = ImplicitCoveringStarBicoloring();
00105                 } else if (s_BicoloringVariant == "EXPLICIT_COVERING__STAR_BICOLORING") {
00106                         i_ColoringStatus = ExplicitCoveringStarBicoloring();
00107                 } else if (s_BicoloringVariant == "EXPLICIT_COVERING__MODIFIED_STAR_BICOLORING") {
00108                         i_ColoringStatus = ExplicitCoveringModifiedStarBicoloring();
00109                 } else if (s_BicoloringVariant == "IMPLICIT_COVERING__GREEDY_STAR_BICOLORING") {
00110                         i_ColoringStatus = ImplicitCoveringGreedyStarBicoloring();
00111                 } else {
00112                         cout<<" Unknown Bicoloring Method "<<s_BicoloringVariant<<". Please use a legal Method."<<endl;
00113                         m_T_Timer.Stop();
00114                         m_d_ColoringTime = m_T_Timer.GetWallTime();
00115                         return (_FALSE);
00116                 }
00117 
00118                 m_T_Timer.Stop();
00119                 m_d_ColoringTime = m_T_Timer.GetWallTime();
00120                 return(i_ColoringStatus);
00121         }
00122 
00123         BipartiteGraphBicoloringInterface::BipartiteGraphBicoloringInterface(int i_type, ...) {
00124           //cout<<"IN GraphColoringInterface(int i_type, ...)"<<endl;
00125                 Clear();
00126 
00127                 if (i_type == SRC_WAIT) return;
00128 
00129                 //---------CONVERT INPUT TO ColPack's Bipartite Graph-------------
00130                 va_list ap; /*will point to each unnamed argument in turn*/
00131                 va_start(ap,i_type); /* point to first element after i_type*/
00132 
00133                 if (i_type == SRC_MEM_ADOLC) {
00134                   //get unsigned int ** uip2_HessianSparsityPattern, int i_RowCount
00135                   unsigned int ** uip2_JacobianSparsityPattern = va_arg(ap,unsigned int **);
00136                   int i_RowCount = va_arg(ap,int);
00137                   int i_ColumnCount = va_arg(ap,int);
00138 
00139                   BuildBPGraphFromRowCompressedFormat(uip2_JacobianSparsityPattern, i_RowCount, i_ColumnCount);
00140                 }
00141                 else if (i_type == SRC_MEM_ADIC) {
00142                   // !!! add interface function that takes input from ADIC
00143                   cerr<<"ERR: GraphColoringInterface(): s_inputSource \"ADIC\" is not supported yet"<<endl;
00144 
00145                   va_end(ap); /*cleanup*/
00146                   return;
00147                 }
00148                 else if (i_type == SRC_FILE) {
00149                   // get string s_InputFile, string s_fileFormat
00150                   string s_InputFile ( va_arg(ap,char *) );
00151                   string s_fileFormat ( va_arg(ap,char *) );
00152 
00153                   ReadBipartiteGraph(s_InputFile, s_fileFormat);
00154                 }
00155                 else {
00156                   cerr<<"ERR: BipartiteGraphBicoloringInterface(): i_type =\""<< i_type <<"\" unknown or unspecified"<<endl;
00157 
00158                   va_end(ap); /*cleanup*/
00159                   return;
00160                 }
00161 #ifdef  _COLPACK_CHECKPOINT_    
00162                 string s_OutputFile = "-ColPack_debug.mtx";
00163                 s_OutputFile = "BipartiteGraphBicoloringInterface-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_BicoloringVariant( va_arg(ap,char *) );
00196                 s_BicoloringVariant = toUpper(s_BicoloringVariant);
00197                 if (s_BicoloringVariant.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_BicoloringVariant == "IMPLICIT_COVERING__STAR_BICOLORING") {
00207                         i_ColoringStatus = ImplicitCoveringStarBicoloring();
00208                 } else if (s_BicoloringVariant == "EXPLICIT_COVERING__STAR_BICOLORING") {
00209                         i_ColoringStatus = ExplicitCoveringStarBicoloring();
00210                 } else if (s_BicoloringVariant == "EXPLICIT_COVERING__MODIFIED_STAR_BICOLORING") {
00211                         i_ColoringStatus = ExplicitCoveringModifiedStarBicoloring();
00212                 } else if (s_BicoloringVariant == "IMPLICIT_COVERING__GREEDY_STAR_BICOLORING") {
00213                         i_ColoringStatus = ImplicitCoveringGreedyStarBicoloring();
00214                 } else {
00215                         cout<<" Unknown Bicoloring Method "<<s_BicoloringVariant<<". Please use a legal Method."<<endl;
00216                         m_T_Timer.Stop();
00217                         m_d_ColoringTime = m_T_Timer.GetWallTime();
00218                         return;
00219                 }
00220 
00221 
00222                 m_T_Timer.Stop();
00223 
00224                 m_d_ColoringTime = m_T_Timer.GetWallTime();
00225 //*/
00226 
00227                 va_end(ap); //cleanup
00228                 return;
00229         }
00230 
00231         double** BipartiteGraphBicoloringInterface::GetLeftSeedMatrix(int* ip1_LeftSeedRowCount, int* ip1_LeftSeedColumnCount) {
00232           return BipartiteGraphBicoloring::GetLeftSeedMatrix(ip1_LeftSeedRowCount, ip1_LeftSeedColumnCount);
00233         }
00234 
00235         double** BipartiteGraphBicoloringInterface::GetRightSeedMatrix(int* ip1_RightSeedRowCount, int* ip1_RightSeedColumnCount) {
00236           return BipartiteGraphBicoloring::GetRightSeedMatrix(ip1_RightSeedRowCount, ip1_RightSeedColumnCount);
00237         }
00238 
00239         void BipartiteGraphBicoloringInterface::GetOrderedVertices(vector<int> &output) {
00240           BipartiteGraphOrdering::GetOrderedVertices(output);
00241         }
00242 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines