<commit_before>//===========================================================================//
// This file is part of the DIP Solver Framework.                            //
//                                                                           //
// DIP is distributed under the Eclipse Public License as part of the        //
// COIN-OR repository (http://www.coin-or.org).                              //
//                                                                           //
// Author: <NAME>, SAS Institute Inc. (<EMAIL>)       //
//                                                                           //
// Conceptual Design: <NAME>, SAS Institute Inc.                     //
//                    <NAME>, Lehigh University                          //
//                                                                           //
// Copyright (C) 2002-2013, Lehigh University, <NAME>, <NAME>    //
// All Rights Reserved.                                                      //
//===========================================================================//

#include "DecompApp.h"
#include "DecompVar.h"
#include "DecompConfig.h"
#include <vector>
#include <set>
#include <fstream>
#include <string>

//#if defined(autoDecomp) && defined(PaToH)
#if  defined(PaToH)

#include "patoh.h"

//#elif defined(autoDecomp)
#else 

extern "C"{
#if defined (COIN_HAS_METIS)
#include "hmetis.h"
#endif
}

#endif

using namespace std;

// --------------------------------------------------------------------- //
void DecompApp::startupLog(){
   if(m_param.LogLevel >= 0){
      (*m_osLog)
	 << "\n========================================================"
	 << "\n========================================================"
	 <<   "\nWelcome to the DIP Decomposition Framework"
	 <<   "\nCopyright 2002-2013 Lehigh University and others"
	 <<   "\nAll Rights Reserved"
	 <<   "\nDistributed under the Eclipse Public License 1.0"
	 <<   "\nVersion: " << DIP_VERSION
	 <<   "\nBuild Date: " << __DATE__
#ifdef DIP_SVN_REV
	 <<   "\nRevision Number: " << DIP_SVN_REV
#endif
	 << "\n========================================================"
	 << "\n========================================================"
	 << "\n";
      
   }
   if(m_param.LogLevel > 1){
      //m_param.dumpSettings(m_osLog);        
   }
}

// --------------------------------------------------------------------- //
int DecompApp::generateInitVars(DecompVarList & initVars){ 
   // ---
   // --- this function does nothing by default
   // ---
   UtilPrintFuncBegin(m_osLog, m_classTag,
		      "generateInitVars()", m_param.LogDebugLevel, 2);
   UtilPrintFuncEnd(m_osLog, m_classTag,
		      "generateInitVars()", m_param.LogDebugLevel, 2);
   return 0;
}

// --------------------------------------------------------------------- //
int DecompApp::generateCuts(const double  * x, 
			    DecompCutList & newCuts){

   // ---
   // --- this function does nothing by default
   // ---
   UtilPrintFuncBegin(m_osLog, m_classTag,
		      "generateCuts()", m_param.LogDebugLevel, 2);
   UtilPrintFuncEnd(m_osLog, m_classTag,
		    "generateCuts()", m_param.LogDebugLevel, 2);
   return 0;
}

/*-------------------------------------------------------------------------*/
void DecompApp::printOriginalColumn(const int index, 
                                    ostream * os) const {
   (*os) << index << " ";
}

/*-------------------------------------------------------------------------*/
void DecompApp::printOriginalSolution(const int              n_cols, 
				      const vector<string> & colNames,
                                      const double         * solution,
                                      ostream              * os) const{
   int i;
   bool hasNames = false;

   //---
   //--- do we have column names?
   //---
   if(colNames.size() > 0)
      hasNames = true;

   (*os) << setiosflags(ios::fixed|ios::showpoint);
   for(i = 0; i < n_cols; i++){
      if(!UtilIsZero(solution[i])){
         printOriginalColumn(i,os);
         if(hasNames)
            (*os) << "\t" << colNames[i]
                  << "\t" << solution[i] << endl;
         else
            (*os) << "\t" << solution[i] << endl;
      }
   }
   (*os) << resetiosflags(ios::fixed|ios::showpoint|ios::scientific); 
}

/*
 *  The following methods are from MILPBlock_DecompApp
 */

void DecompApp::initializeApp(UtilParameters & utilParam)  {
   
   UtilPrintFuncBegin(m_osLog, m_classTag,
		      "initializeApp()", m_param.LogLevel, 2);
   
   //---
   //--- get application parameters
   //---   

   m_param.getSettings(utilParam);   

   if(m_param.LogLevel >= 1)
      m_param.dumpSettings();

   //---
   //--- read MILP instance (mps format)
   //---
   string fileName;
   if (m_param.DataDir != ""){
      fileName = m_param.DataDir + UtilDirSlash() + m_param.Instance;
   }else{
      fileName = m_param.Instance;
   }      

   if(m_param.Instance.empty()){
     cerr << "==========================================================="<< std::endl
	  << "Usage:" << std::endl
	  << "./dip  --MILP:BlockFileFormat List" << std::endl
	  << "       --MILP:Instance /FilePath/ABC.mps" << std::endl
	  << "       --MILP:BlockFile /FilePath/ABC.block" << std::endl
	  << "==========================================================="<< std::endl
	  << std::endl;
       throw UtilException("I/O Error.", "initializeApp", "DecompApp"); 
   }
   m_mpsIO.messageHandler()->setLogLevel(m_param.LogLpLevel);

   int rstatus = 0;
   bool foundFormat = false;
   if (m_param.InstanceFormat == ""){
       string::size_type idx = fileName.rfind('.');
       
       if (idx != string::npos){
	   string extension = fileName.substr(idx+1);
	   if (extension == "MPS" || extension == "mps"){
	       m_param.InstanceFormat = "MPS";
	   }else if (extension == "LP" || extension == "lp"){ 
	       m_param.InstanceFormat = "LP";<commit_msg>Should not throw an error<commit_after>//===========================================================================//
// This file is part of the DIP Solver Framework.                            //
//                                                                           //
// DIP is distributed under the Eclipse Public License as part of the        //
// COIN-OR repository (http://www.coin-or.org).                              //
//                                                                           //
// Author: <NAME>, SAS Institute Inc. (<EMAIL>)       //
//                                                                           //
// Conceptual Design: <NAME>, SAS Institute Inc.                     //
//                    <NAME>, Lehigh University                          //
//                                                                           //
// Copyright (C) 2002-2013, Lehigh University, <NAME>, <NAME>    //
// All Rights Reserved.                                                      //
//===========================================================================//

#include "DecompApp.h"
#include "DecompVar.h"
#include "DecompConfig.h"
#include <vector>
#include <set>
#include <fstream>
#include <string>

//#if defined(autoDecomp) && defined(PaToH)
#if  defined(PaToH)

#include "patoh.h"

//#elif defined(autoDecomp)
#else 

extern "C"{
#if defined (COIN_HAS_METIS)
#include "hmetis.h"
#endif
}

#endif

using namespace std;

// --------------------------------------------------------------------- //
void DecompApp::startupLog(){
   if(m_param.LogLevel >= 0){
      (*m_osLog)
	 << "\n========================================================"
	 << "\n========================================================"
	 <<   "\nWelcome to the DIP Decomposition Framework"
	 <<   "\nCopyright 2002-2013 Lehigh University and others"
	 <<   "\nAll Rights Reserved"
	 <<   "\nDistributed under the Eclipse Public License 1.0"
	 <<   "\nVersion: " << DIP_VERSION
	 <<   "\nBuild Date: " << __DATE__
#ifdef DIP_SVN_REV
	 <<   "\nRevision Number: " << DIP_SVN_REV
#endif
	 << "\n========================================================"
	 << "\n========================================================"
	 << "\n";
      
   }
   if(m_param.LogLevel > 1){
      //m_param.dumpSettings(m_osLog);        
   }
}

// --------------------------------------------------------------------- //
int DecompApp::generateInitVars(DecompVarList & initVars){ 
   // ---
   // --- this function does nothing by default
   // ---
   UtilPrintFuncBegin(m_osLog, m_classTag,
		      "generateInitVars()", m_param.LogDebugLevel, 2);
   UtilPrintFuncEnd(m_osLog, m_classTag,
		      "generateInitVars()", m_param.LogDebugLevel, 2);
   return 0;
}

// --------------------------------------------------------------------- //
int DecompApp::generateCuts(const double  * x, 
			    DecompCutList & newCuts){

   // ---
   // --- this function does nothing by default
   // ---
   UtilPrintFuncBegin(m_osLog, m_classTag,
		      "generateCuts()", m_param.LogDebugLevel, 2);
   UtilPrintFuncEnd(m_osLog, m_classTag,
		    "generateCuts()", m_param.LogDebugLevel, 2);
   return 0;
}

/*-------------------------------------------------------------------------*/
void DecompApp::printOriginalColumn(const int index, 
                                    ostream * os) const {
   (*os) << index << " ";
}

/*-------------------------------------------------------------------------*/
void DecompApp::printOriginalSolution(const int              n_cols, 
				      const vector<string> & colNames,
                                      const double         * solution,
                                      ostream              * os) const{
   int i;
   bool hasNames = false;

   //---
   //--- do we have column names?
   //---
   if(colNames.size() > 0)
      hasNames = true;

   (*os) << setiosflags(ios::fixed|ios::showpoint);
   for(i = 0; i < n_cols; i++){
      if(!UtilIsZero(solution[i])){
         printOriginalColumn(i,os);
         if(hasNames)
            (*os) << "\t" << colNames[i]
                  << "\t" << solution[i] << endl;
         else
            (*os) << "\t" << solution[i] << endl;
      }
   }
   (*os) << resetiosflags(ios::fixed|ios::showpoint|ios::scientific); 
}

/*
 *  The following methods are from MILPBlock_DecompApp
 */

void DecompApp::initializeApp(UtilParameters & utilParam)  {
   
   UtilPrintFuncBegin(m_osLog, m_classTag,
		      "initializeApp()", m_param.LogLevel, 2);
   
   //---
   //--- get application parameters
   //---   

   m_param.getSettings(utilParam);   

   if(m_param.LogLevel >= 1)
      m_param.dumpSettings();

   //---
   //--- read MILP instance (mps format)
   //---
   string fileName;
   if (m_param.DataDir != ""){
      fileName = m_param.DataDir + UtilDirSlash() + m_param.Instance;
   }else{
      fileName = m_param.Instance;
   }      

   if(m_param.Instance.empty()){
     cerr << "==========================================================="<< std::endl
	  << "Usage:" << std::endl
	  << "./dip  --MILP:BlockFileFormat List" << std::endl
	  << "       --MILP:Instance /FilePath/ABC.mps" << std::endl
	  << "       --MILP:BlockFile /FilePath/ABC.block" << std::endl
	  << "==========================================================="<< std::endl
	  << std::endl;
      exit(0);
   }
   m_mpsIO.messageHandler()->setLogLevel(m_param.LogLpLevel);

   int rstatus = 0;
   bool foundFormat = false;
   if (m_param.InstanceFormat == ""){
       string::size_type idx = fileName.rfind('.');
       
       if (idx != string::npos){
	   string extension = fileName.substr(idx+1);
	   if (extension == "MPS" || extension == "mps"){
	       m_param.InstanceFormat = "MPS";
	   }else if (extension == "LP" || extension == "lp"){ 
	       m_param.InstanceFormat = "LP";
{'fraction_non_alphanumeric': 0.27783452502553624, 'fraction_numerical': 0.005532856656452162, 'mean_word_length': 1.6551412429378531, 'pattern_counts': {'":': 0, '<': 187, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 34, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3266620', 'n_tokens_mistral': 3400, 'n_tokens_neox': 3146, 'n_words': 655}