//===========================================================================// void GAP_DecompApp::initializeApp(UtilParameters& utilParam) { UtilPrintFuncBegin(m_osLog, m_classTag, "initializeApp()", m_appParam.LogLevel, 2); //--- //--- get application parameters //--- m_appParam.getSettings(utilParam); if (m_appParam.LogLevel >= 1) { m_appParam.dumpSettings(m_osLog); } //--- //--- read instance // string instanceFile = m_appParam.DataDir + UtilDirSlash() + m_appParam.Instance; m_instance.readInstance(instanceFile); //--- //--- read best known lb/ub (for debugging) //--- string bestKnownFile = m_appParam.DataDir + UtilDirSlash() + "gap.opt"; m_instance.readBestKnown(bestKnownFile, m_appParam.Instance); setBestKnownLB(m_instance.getBestKnownLB()); setBestKnownUB(m_instance.getBestKnownUB()); //--- //--- create models //--- createModels(); UtilPrintFuncEnd(m_osLog, m_classTag, "initializeApp()", m_appParam.LogLevel, 2); }
//===========================================================================// void MILPBlock_DecompApp::readBlockFile(){ ifstream is; string fileName = m_appParam.DataDir + UtilDirSlash() + m_appParam.BlockFile; //--- //--- is there a permutation file? //--- this file just remaps the row ids //--- (for use in submission of atm to MIPLIB2010 and debugging) //--- map<int,int> permute; map<int,int>::iterator mit; string fileNameP = m_appParam.DataDir + UtilDirSlash() + m_appParam.PermuteFile; if(m_appParam.PermuteFile.size() > 0){ ifstream isP; int rowIdOld, rowIdNew; //--- //--- open file streams //--- UtilOpenFile(isP, fileName.c_str()); while(!isP.eof()){ if(isP.eof()) break; isP >> rowIdOld >> rowIdNew; permute.insert(make_pair(rowIdOld, rowIdNew)); } isP.close(); }
//===========================================================================// void ATM_DecompApp::initializeApp() { UtilPrintFuncBegin(m_osLog, m_classTag, "initializeApp()", m_appParam.LogLevel, 2); //--- //--- read instance // string fileNameA, fileNameD, fileNameAD; if (m_appParam.DataDir != "") { fileNameA = m_appParam.DataDir + UtilDirSlash() + m_appParam.DataAtm; fileNameD = m_appParam.DataDir + UtilDirSlash() + m_appParam.DataDate; fileNameAD = m_appParam.DataDir + UtilDirSlash() + m_appParam.DataAtmDate; } else { fileNameA = m_appParam.DataAtm; fileNameD = m_appParam.DataDate; fileNameAD = m_appParam.DataAtmDate; } m_instance.readInstance(fileNameA, fileNameD, fileNameAD); //--- //--- create models //--- createModels(); UtilPrintFuncEnd(m_osLog, m_classTag, "initializeApp()", m_appParam.LogLevel, 2); }
//===========================================================================// void ATM_DecompApp::initializeApp(UtilParameters & utilParam) { UtilPrintFuncBegin(m_osLog, m_classTag, "initializeApp()", m_appParam.LogLevel, 2); //--- //--- get application parameters //--- m_appParam.getSettings(utilParam); if(m_appParam.LogLevel >= 1) m_appParam.dumpSettings(m_osLog); //--- //--- read instance // string fileNameA, fileNameD, fileNameAD; if (m_appParam.DataDir != "") { fileNameA = m_appParam.DataDir + UtilDirSlash() + m_appParam.DataAtm; fileNameD = m_appParam.DataDir + UtilDirSlash() + m_appParam.DataDate; fileNameAD = m_appParam.DataDir + UtilDirSlash() + m_appParam.DataAtmDate; } else { fileNameA = m_appParam.DataAtm; fileNameD = m_appParam.DataDate; fileNameAD = m_appParam.DataAtmDate; } m_instance.readInstance(fileNameA, fileNameD, fileNameAD); //--- //--- create models //--- createModels(); UtilPrintFuncEnd(m_osLog, m_classTag, "initializeApp()", m_appParam.LogLevel, 2); }
//===========================================================================// void MILPBlock_DecompApp::initializeApp() { UtilPrintFuncBegin(m_osLog, m_classTag, "initializeApp()", m_appParam.LogLevel, 2); //--- //--- read MILPBlock instance (mps format) //--- string fileName; if (m_appParam.DataDir != "") { fileName = m_appParam.DataDir + UtilDirSlash() + m_param.Instance; } else { fileName = m_appParam.Instance; } m_mpsIO.messageHandler()->setLogLevel(m_param.LogLpLevel); int rstatus = m_mpsIO.readMps(fileName.c_str()); if(rstatus < 0){ cerr << "Error: Filename = " << fileName << " failed to open." << endl; throw UtilException("I/O Error.", "initalizeApp", "MILPBlock_DecompApp"); } if(m_appParam.LogLevel >= 2) (*m_osLog) << "Objective Offset = " << UtilDblToStr(m_mpsIO.objectiveOffset()) << endl; //--- //--- set best known lb/ub //--- double offset = m_mpsIO.objectiveOffset(); setBestKnownLB(m_appParam.BestKnownLB + offset); setBestKnownUB(m_appParam.BestKnownUB + offset); //--- //--- read block file //--- readBlockFile(); //--- //--- create models //--- createModels(); UtilPrintFuncEnd(m_osLog, m_classTag, "initializeApp()", m_appParam.LogLevel, 2); }
//===========================================================================// void SDPUC_DecompApp::initializeApp() { UtilPrintFuncBegin(m_osLog, m_classTag, "initializeApp()", m_appParam.LogLevel, 2); //--- //--- read problem instance //--- string instanceFile = m_appParam.DataDir + UtilDirSlash() + m_appParam.Instance; int rc = m_instance.readInstance(instanceFile, false); if(rc) throw UtilException("Error in readInstance", "initializeApp", "MCF_DecompApp"); //--- //--- create models //--- createModels(); UtilPrintFuncEnd(m_osLog, m_classTag, "initializeApp()", m_appParam.LogLevel, 2); }
void OSDipApp::initializeApp(UtilParameters & utilParam) { UtilPrintFuncBegin(m_osLog, m_classTag, "initializeApp()", m_appParam.LogLevel, 2); //--- //--- get application parameters //--- m_appParam.getSettings(utilParam); if (m_appParam.LogLevel >= 1) m_appParam.dumpSettings(m_osLog); try { //--- //--- read OSiL instance // if (m_appParam.OSiLFile.size() <= 1) throw ErrorClass("An OSiL file not specified in the paramater file"); std::string osilFile = m_appParam.DataDir + UtilDirSlash() + m_appParam.OSiLFile; m_osInterface.readOSiL( osilFile); //--- //--- read OSoL instance -- it is not necessary, if not there //-- all constraints become block constraints // //if(m_appParam.OSoLFile.size() <= 1) throw ErrorClass("An OSoL file not specified in the paramater file"); if (m_appParam.OSoLFile.size() > 0) { std::string osolFile = m_appParam.DataDir + UtilDirSlash() + m_appParam.OSoLFile; m_osInterface.readOSoL( osolFile); } //--- //--- create models //--- createModels(); //just temporary playing around /** std::cout << std::endl << std::endl << std::endl; std::cout << "VARIABLE INDEX TESTING " <<std::endl; std::vector<std::set<int> > blockVars; std::set<int>::iterator sit; blockVars = m_osInterface.getBlockVarIndexes(); for(int i = 0; i < blockVars.size(); i++){ std::cout << "INSIDE BLOCK " << i << std::endl; for (sit = blockVars[i].begin(); sit != blockVars[i].end(); sit++) { std::cout << "VARIABLE = " << *sit << std::endl; } } //now test core constraints std::cout << "CORE CONSTRAINT TESTING " <<std::endl; std::set<int> conIndexes; conIndexes = m_osInterface.getCoreConstraintIndexes(); for (sit = conIndexes.begin(); sit != conIndexes.end(); sit++) { std::cout << "CORE INDEX = " << *sit << std::endl; } std::cout << "BLOCK CONSTRAINT INDEX TESTING " <<std::endl; std::vector<std::map<int, int> > blockCons; std::map<int, int>::iterator mit; blockCons = m_osInterface.getBlockConstraintIndexes(); for(int i = 0; i < blockCons.size(); i++){ std::cout << "INSIDE BLOCK " << i << std::endl; for (mit = blockCons[i].begin(); mit != blockCons[i].end(); mit++) { std::cout << "CONSTRAINT INDEX = " << mit->first << std::endl; } } */ m_blockOSInstances = m_osInterface.getBlockOSInstances(); //loop over the instances and generate a solver std::vector<OSInstance* >::iterator vit1; OSDipBlockCoinSolver *coinSolver = NULL; for (vit1 = m_blockOSInstances.begin(); vit1 != m_blockOSInstances.end(); vit1++) { coinSolver = new OSDipBlockCoinSolver( *vit1) ; m_osDipBlockCoinSolver.push_back( coinSolver ) ; } std::vector<std::set<int> >::iterator vit2; std::set<int>::iterator sit; std::set<int> blockVar; std::vector<IndexValuePair*> solIndexValPair; std::vector<IndexValuePair*>::iterator vit3; double optVal; double *cost = NULL; int index; int whichBlock; m_blockVars = m_osInterface.getBlockVarIndexes(); whichBlock = 0; for (vit2 = m_blockVars.begin(); vit2 != m_blockVars.end(); vit2++) { blockVar = *vit2; cost = new double[ blockVar.size() ]; index = 0; for (sit = blockVar.begin(); sit != blockVar.end(); sit++) { cost[index] = m_objective[ *sit]; index++; } m_osDipBlockCoinSolver[whichBlock++]->solve( cost, &solIndexValPair, &optVal); std::cout << "OPTIMAL VALUE = " << optVal << std::endl; std::cout << "solIndexValPair SIZE 2 = " << solIndexValPair.size() << std::endl; for (vit3 = solIndexValPair.begin(); vit3 != solIndexValPair.end(); vit3++) { std::cout << "IDEX = " << (*vit3)->idx << std::endl; std::cout << "VALUE = " << (*vit3)->value << std::endl; } delete []cost; } } catch (const ErrorClass& eclass) { throw ErrorClass(eclass.errormsg); } UtilPrintFuncEnd(m_osLog, m_classTag, "initializeApp()", m_appParam.LogLevel, 2); }//end initializeApp
// --------------------------------------------------------------------- // void MAD_DecompApp::initializeApp(UtilParameters & utilParam) { UtilPrintFuncBegin(m_osLog, m_classTag, "initializeApp()", m_param.LogDebugLevel, 2); //--- //--- get application parameters //--- m_appParam.getSettings(utilParam); m_appParam.dumpSettings(m_osLog); //use message handler //--- //--- read instance from lp file (from MADLIB) //--- http://elib.zib.de/pub/mp-testdata/madlib/index.html //--- string lpFile = m_appParam.DataDir + UtilDirSlash(); lpFile += m_appParam.Instance; if(m_appParam.DataSubDir == "miplib"){ lpFile += ".p.lp"; } else if(m_appParam.DataSubDir == "netlib"){ lpFile += ".ob4"; } m_instance.readLp(lpFile.c_str()); m_nOrigRows = m_instance.getNumRows(); m_beta = m_appParam.NumBlocks; //--- //--- read best known lb/ub //--- string bestKnownFile = m_appParam.DataDir + UtilDirSlash(); bestKnownFile += "madlib." + m_appParam.DataSubDir + ".opt"; { ifstream is; string instanceName; double bestLB, bestUB; UtilOpenFile(is, bestKnownFile); while(!is.eof()){ //--- //--- these are the number of rows in the border (less is better) //--- is >> instanceName >> bestLB >> bestUB; //printf("Instance = %15s bestLB = %6g bestUB = %6g\n", // instanceName.c_str(), bestLB, bestUB); instanceName = UtilStrTrim(instanceName); if(instanceName == m_appParam.Instance){ //--- //--- the paper solves z = max sum x, //--- where x is an assignment to a block //--- so, nBorder = nRows - z //--- or, z = nRows - nBorder //--- //--- but we only do min, so we solve -z = min sum (-x) //---- so, -z = nBorder - nRows //--- m_bestKnownLB = bestLB - m_nOrigRows; m_bestKnownUB = bestUB - m_nOrigRows; break; } } } //--- //--- set capacity based on MADLIB study (if it is not set): //--- http://elib.zib.de/pub/mp-testdata/madlib/index.en.html //--- if(m_appParam.Capacity != -1){ m_kappa = m_appParam.Capacity; } else{ m_kappa = static_cast<int>(ceil(static_cast<double>(m_nOrigRows)/m_beta)); if(m_appParam.DataSubDir == "netlib" || m_appParam.DataSubDir == "equipart"){ m_kappa = static_cast<int>(ceil(static_cast<double>(m_nOrigRows)/m_beta)); } else if(m_appParam.DataSubDir == "miplib" || m_appParam.DataSubDir == "miplibT"){ m_kappa = static_cast<int>(ceil( 1.05 * m_nOrigRows / m_beta) ); } else if(m_appParam.DataSubDir == "steiner"){ if(m_appParam.Instance[0] == 'g'){ m_kappa = 30; } else if (m_appParam.Instance[0] == 'd'){ m_kappa = 50; } } } UTIL_DEBUG(m_param.LogDebugLevel, 1, (*m_osLog) << "Instance = " << m_appParam.Instance << endl << " nRows = " << m_nOrigRows << endl << " bestLB = " << m_bestKnownLB << endl << " bestUB = " << m_bestKnownUB << endl << " Beta = " << m_beta << endl << " Kappa = " << m_kappa << endl; );