bool OSOutput::SetPrintLevel(std::string name, ENUM_OUTPUT_LEVEL* level, int dim) { int k = FindChannel(name); if (k < 0) throw ErrorClass("Device was not defined before"); for (int i=1; i<dim; i++) { if (level[i] < 0) throw ErrorClass("printLevel must be nonnegative"); else if (level[i] >= ENUM_OUTPUT_LEVEL_NUMBER_OF_LEVELS) throw ErrorClass("illegal printLevel specified"); } return (outputChannel[k]->setAllPrintLevels(level, dim)); }
/** Set different print levels for all areas * @param level holds an array of valid print levels * @param dim holds the number of entries in the array level * @return whether the set() was successful */ bool OSOutputChannel::setAllPrintLevels(ENUM_OUTPUT_LEVEL* level, int dim) { if (dim < 0) throw ErrorClass("Array of output levels must have nonnegative size."); int n = (dim < ENUM_OUTPUT_AREA_NUMBER_OF_AREAS ? dim : ENUM_OUTPUT_AREA_NUMBER_OF_AREAS); for (int i=0; i < n; i++) { #ifdef NDEBUG if (level[i] > ENUM_OUTPUT_LEVEL_debug) throw ErrorClass("Encountered print level not supported in production code.\n Recompile with debug enabled."); #endif printLevel[i] = level[i]; } for (int i=n+1; i < ENUM_OUTPUT_AREA_NUMBER_OF_AREAS; i++) printLevel[i] = ENUM_OUTPUT_LEVEL_error; return true; }
void OSOutputChannel::flushBuffer() { if (file != NULL) fflush(file); else throw ErrorClass("File not open for output"); return; }
bool OSOutputChannel::setPrintLevel(ENUM_OUTPUT_AREA area, ENUM_OUTPUT_LEVEL level) { #ifdef NDEBUG if (level > ENUM_OUTPUT_LEVEL_debug) throw ErrorClass("Encountered print level not supported in production code.\n Recompile with debug enabled."); #endif printLevel[area] = level; return true; }
bool OSOutputChannel::setAllPrintLevels(ENUM_OUTPUT_LEVEL level) { #ifdef NDEBUG if (level > ENUM_OUTPUT_LEVEL_debug) throw ErrorClass("Encountered print level not supported in production code.\n Recompile with debug enabled."); #endif for (int i=0; i < ENUM_OUTPUT_AREA_NUMBER_OF_AREAS; i++) printLevel[i] = level; return true; }
OSOutputChannel::OSOutputChannel(std::string name) { this->name = name; for (int i=0; i<ENUM_OUTPUT_AREA_NUMBER_OF_AREAS; i++) this->printLevel[i] = DEFAULT_OUTPUT_LEVEL; if (this->name != "stderr" && this->name != "stdout") { this->file = fopen (this->name.c_str(), "w+" ); std::string temp = ("Could not open file " + this->name); if (this->file == NULL) throw ErrorClass(temp); } }
int main(int argC, char* argV[]) { WindowsErrorPopupBlocker(); FileUtil *fileUtil = NULL; const char dirsep = CoinFindDirSeparator(); std::string osilFileNameWithPath; std::string osilFileName; std::string osil; std::string uploadResult; std::string actualServer; /* Replace this URL as needed */ std::string defaultServer = "http://128.135.130.17:8080/os/servlet/OSFileUpload"; try{ if( argC == 1 || argC > 3 || argV[1] == "-?") throw ErrorClass( "usage: OSFileUpload <filename> [<serverURL>]"); fileUtil = new FileUtil(); time_t start, finish, tmp; osilFileNameWithPath = argV[ 1]; std::cout << "FILE NAME = " << argV[1] << std::endl; std::cout << "Read the file into a string" << std::endl; osil = fileUtil->getFileAsString( osilFileNameWithPath.c_str() ); OSSolverAgent* osagent = NULL; if (argC == 2) actualServer = defaultServer; else actualServer = argV[2]; osagent = new OSSolverAgent(actualServer); // strip off just the file name // modify to into a file C:filename int index = osilFileNameWithPath.find_last_of( dirsep); int slength = osilFileNameWithPath.size(); osilFileName = osilFileNameWithPath.substr( index + 1, slength) ; std::cout << std::endl << std::endl; std::cout << "Place remote synchronous call" << std::endl; start = time( &tmp); uploadResult = osagent->fileUpload(osilFileName, osil); finish = time( &tmp); std::cout << "File Upload took (seconds): "<< difftime(finish, start) << std::endl; std::cout << uploadResult << std::endl; if(fileUtil != NULL) delete fileUtil; return 0; } catch( const ErrorClass& eclass){ std::cout << eclass.errormsg << std::endl; if(fileUtil != NULL) delete fileUtil; return 0; } }
OSDecompSolver* OSDecompSolverFactory::createOSDecompSolver(const std::string &solverName) throw(ErrorClass){ if( factories.find(solverName) != factories.end() ){ return factories[ solverName]->create(); }else{ throw ErrorClass( solverName + " is not a valid OSDecompSolver"); } }//end
OSInstance* OSiLReader::readOSiL(const std::string& posil) throw(ErrorClass) { try { const char *ch = posil.c_str(); yygetOSInstance( ch, m_osinstance, m_parserData, m_osglData, m_osnlData); return m_osinstance; } catch(const ErrorClass& eclass) { throw ErrorClass( eclass.errormsg); } }//end readOSiL
OSResult* OSrLReader::readOSrL(const std::string& posrl) throw(ErrorClass) { try { const char *ch = posrl.c_str(); yygetOSResult( ch, m_osresult, m_parserData, m_osglData); return m_osresult; } catch(const ErrorClass& eclass) { throw ErrorClass( eclass.errormsg); } }
bool OSOutput::SetPrintLevel(std::string name, ENUM_OUTPUT_LEVEL level) { int aLevel, area; int k = FindChannel(name); if (k < 0) throw ErrorClass("Device was not defined before"); if (level < 0) throw ErrorClass("printLevel must be nonnegative"); if (level < 100) if (level >= ENUM_OUTPUT_LEVEL_NUMBER_OF_LEVELS) throw ErrorClass("illegal printLevel specified"); else return (outputChannel[k]->setAllPrintLevels((ENUM_OUTPUT_LEVEL)level)); else { aLevel = level % 100; area = level / 100; if (aLevel >= ENUM_OUTPUT_LEVEL_NUMBER_OF_LEVELS || area >= ENUM_OUTPUT_AREA_NUMBER_OF_AREAS) throw ErrorClass("illegal printLevel specified"); else return (outputChannel[k]->setPrintLevel((ENUM_OUTPUT_AREA)area, (ENUM_OUTPUT_LEVEL)aLevel)); } }
void OSOutputChannel::OSPrintf(ENUM_OUTPUT_AREA area, ENUM_OUTPUT_LEVEL level, std::string str) { if (isAccepted(area,level)) { if (this->name == "stderr") fprintf(stderr, "%s\n", str.c_str()); else if (this->name == "stdout") printf("%s\n", str.c_str()); else if (this->file != NULL) fprintf(file, "%s\n", str.c_str()); else throw ErrorClass("File not open for output"); return; } }
bool InputDialogue::testInput(int lowerRange, int upperRange) { //firstly Test whether it is a correct input... bool ok; int value = ui->lineEdit->text().toInt(&ok,10); if(!ok){ //means that it is not an integer throw ErrorClass("The input value is not numeric"); } if(value > upperRange || value < lowerRange){ return false; } else{ return true; } }
char * scsi_error(int code) { static char text[80], *cp; if (code == 0) return "No error"; if (code == ComeAgain) return "Busy"; switch (ErrorClass(code)) { case ErrorClass(SenseKey): return senseTab[code & 0x0F]; case ErrorClass(ExtendedError): switch (senseMode) { case TDC3600: sprintf(text, "Error code: %s", find_error(tdc3600ercd, ErrorCode(code))); break; default: sprintf(text, "Additional sense code: %02X", ErrorCode(code)); } break; case ErrorClass(StatusError): sprintf(text, "Target status: %s", find_error(targetStatusTab, ErrorCode(code))); break; case ErrorClass(DriverError): sprintf(text, "Operation not implemented"); break; case ErrorClass(SystemError): cp = strerror(ErrorCode(code)); if (cp) strcpy(text, cp); else sprintf(text, "System error: %u", ErrorCode(code)); break; case ErrorClass(HostError): sprintf(text, "Host adapter error: %u", ErrorCode(code)); break; default: sprintf(text, "Other error: %04X", code); break; } return text; }
bool OSOutputChannel::Open() { if (name == "stdout") { file = stdout; return true; } if (name == "stderr") { file = stderr; return true; } if (file != NULL) throw ErrorClass ("File previously opened."); file = fopen(name.c_str(), "w"); if (file != NULL) return true; return false; }
void APISetStatus (IO_REQ_PTR Req, // Request structure APIStatus Status, // Status TerminateCode Terminal, // Is this the terminal (Notify completion) AutosenseCode IsSenseable) // Auto sense allowed? { static U8 REQStats[]={ SRB_STATUS_PENDING, SRB_STATUS_PENDING, SRB_STATUS_ABORTED, SRB_STATUS_BAD_FUNCTION, SRB_STATUS_INVALID_REQUEST, SRB_STATUS_NO_HBA, SRB_STATUS_DATA_OVERRUN, SRB_STATUS_SELECTION_TIMEOUT, SRB_STATUS_INVALID_TARGET_ID, SRB_STATUS_INVALID_LUN }; static U8 ADStats[]={ SRB_STATUS_NO_HBA, SRB_STATUS_BUSY, SRB_STATUS_UNEXPECTED_BUS_FREE, SRB_STATUS_PHASE_SEQUENCE_FAILURE, SRB_STATUS_BUS_RESET, SRB_STATUS_AUTOSENSE_VALID, SRB_STATUS_ERROR}; // Make sure the high numbers match what this module knows of: #if S_LAST_S_REQ != 0x09 #err #endif #if S_LAST_S_AD != 0x06 #err #endif #if S_LAST_S_SYS != 0 #err #endif switch (ErrorClass(Status)) { case RequestClass: DEBUG(0, if (Status == S_REQ_ABORT) TRACE(0, ("APISetStatus(): Set Req (%x) status to aborted\n")) ); Req->SrbStatus = REQStats[ErrorCode(Status)]; break; case AdapterClass: Req->SrbStatus = ADStats[ErrorCode(Status)]; break; case TargetClass: Req->ScsiStatus = ErrorCode(Status); switch (ErrorCode(Status)) { case STATUS_CKCOND: ReqDataCount(Req) = ReqSavedIndex(Req); #if defined(AUTOSENSE) if ((IsSenseable == Senseable) && ReqSenseCount(Req)) { Terminal = NonTerminal; QueueInternalRequest(ReqAdapterPtr(Req), Req, RTAutoSenseReq); } else #endif Req->SrbStatus = SRB_STATUS_ERROR; break; case STATUS_GOOD: case STATUS_CONDMET: case STATUS_INTGOOD: case STATUS_INTCONDMET: Req->SrbStatus = SRB_STATUS_SUCCESS; if (ReqDataCount(Req) > ReqSavedIndex(Req)) { Req->SrbStatus = SRB_STATUS_DATA_OVERRUN; // Update number of bytes transferred. // ReqSavedIndex is the number of bytes successfully transfered // One thing the NT people will have to address is zero latency // xfers. How will number of bytes xfered be represented // on an error, when the xfer has holes? ReqDataCount(Req) = ReqSavedIndex(Req); } break; default: Req->SrbStatus = SRB_STATUS_ERROR; break; } TRACE(4, ("APISetStatus(): Setting target status to %02x\n", Req->ScsiStatus)); break; } TRACE(4, ("APISetStatus(): Setting request status to %02x\n", Req->SrbStatus)); if (Terminal != NonTerminal) { TRACE(3, ("APISetStatus(): Notifying completion\n")); Notify(ReqAdapterPtr(Req), Req); } }
int OSDipApp::generateInitVars(DecompVarList & initVars) { //--- //--- generateInitVars is a virtual method and can be overriden //--- if the user has some idea how to initialize the list of //--- initial variables (columns in the DW master) //--- std::cout << "GENERATE INIT VARS" << std::endl; UtilPrintFuncBegin(m_osLog, m_classTag, "generateInitVars()", m_appParam.LogLevel, 2); //--- //--- Get the initial solution from the OSOption object //--- we want the variable other option where name="initialCol" //--- //std::vector<OtherVariableOption*> getOtherVariableOptions(std::string solver_name); std::vector<OtherVariableOption*> otherVarOptions; std::vector<OtherVariableOption*>::iterator vit; int *index = NULL; double *value = NULL; int i; double objValue; int whichBlock; DecompVar *var; try{ if (m_osInterface.m_osoption != NULL && m_osInterface.m_osoption->getNumberOfOtherVariableOptions() > 0) { std::cout << "Number of other variable options = " << m_osInterface.m_osoption->getNumberOfOtherVariableOptions() << std::endl; otherVarOptions = m_osInterface.m_osoption->getOtherVariableOptions( "Dip"); //iterate over the vector for (vit = otherVarOptions.begin(); vit != otherVarOptions.end(); vit++) { // see if we have an initialCol option if ((*vit)->name.compare("initialCol") == 0) { index = new int[(*vit)->numberOfVar]; value = new double[(*vit)->numberOfVar]; objValue = 0.0; for (i = 0; i < (*vit)->numberOfVar; i++) { index[i] = (*vit)->var[i]->idx; //convert the string to integer value[ i] = atoi((*vit)->var[i]->value.c_str()); objValue += m_objective[index[i]]; } whichBlock = atoi( (*vit)->value.c_str() ); var = new DecompVar((*vit)->numberOfVar, index, value, objValue); var->setBlockId(whichBlock); initVars.push_back(var); //free local memory UTIL_DELARR( index); UTIL_DELARR( value); } } } }//end try catch(const ErrorClass& eclass){ throw ErrorClass( eclass.errormsg); } UtilPrintFuncEnd(m_osLog, m_classTag, "generateInitVars()", m_appParam.LogLevel, 2); return static_cast<int> (initVars.size()); }
//===========================================================================// void OSDipApp::createModels() { UtilPrintFuncBegin(m_osLog, m_classTag, "createModels()", m_appParam.LogLevel, 2); int i; int j; const int nCols = m_osInterface.getVariableNumber(); const int nRows = m_osInterface.getConstraintNumber(); try{ //First the define the objective function over the entire variable space //Create the memory for the objective function m_objective = new double[nCols]; for (i = 0; i < nCols; i++) { m_objective[i] = m_osInterface.getObjectiveFunctionCoeff()[i]; //std::cout << "obj coeff = " << m_objective[i] << std::endl; } setModelObjective( m_objective); //--- //--- Construct the core matrix. //--- int nRowsRelax, nRowsCore; nRowsRelax = 0; nRowsCore = 0; std::vector<OtherConstraintOption*> otherConstraintOptions; std::vector<OtherConstraintOption*>::iterator vit; // // Now construct the block matrices // int *rowsRelax; int whichBlock; DecompConstraintSet *modelRelax = NULL; std::set<int> blockVars; //variables indexes in the specific block std::set<int> blockVarsAll; //all variable indexes that appear in a block std::set<int> blockConAll; //all constraint indexes that appear in a block std::set<int>::iterator sit; CoinPackedVector *row; int *rowVars; int rowSize; if (m_osInterface.m_osoption != NULL && m_osInterface.m_osoption->getNumberOfOtherConstraintOptions() > 0) { otherConstraintOptions = m_osInterface.m_osoption->getOtherConstraintOptions("Dip"); //iterate over the vector of contraint options for (vit = otherConstraintOptions.begin(); vit != otherConstraintOptions.end(); vit++) { // see if we have a Core Constraint Set if( ( (*vit)->name.compare("constraintSet") == 0) && ( (*vit)->type.compare("Block") == 0)) { //get the block number //ch = new char[(*vit)->value.size() + 1]; //ch[(*vit)->value.size()] = 0; //memcpy(ch, (*vit)->value.c_str(), (*vit)->value.size()); //whichBlock = atoi(ch); //delete ch; whichBlock = atoi( (*vit)->value.c_str() ); // first get the number of constraints in this block nRowsRelax = (*vit)->numberOfCon; rowsRelax = new int[nRowsRelax]; //now get the variable indexes for just this block //first clear indexes from a previous block blockVars.clear(); for (i = 0; i < nRowsRelax; i++) { rowsRelax[i] = (*vit)->con[i]->idx; if( (*vit)->con[i]->idx >= nRows) throw ErrorClass( "found an invalid row index in OSoL file"); m_blocks[ whichBlock].push_back( rowsRelax[i] ); //also add to the set of all rows if (blockConAll.find( (*vit)->con[i]->idx ) == blockConAll.end()) { blockConAll.insert( (*vit)->con[i]->idx ); } //add the variables for this row to the set blockVars row = m_osInterface.getRow(rowsRelax[i]); rowSize = row->getNumElements(); rowVars = row->getIndices(); for (j = 0; j < rowSize; j++) { if (blockVars.find(rowVars[j]) == blockVars.end()) { blockVars.insert(rowVars[j]); } } delete row; }//end for or rows in this block modelRelax = new DecompConstraintSet(); CoinAssertHint(modelRelax, "Error: Out of Memory"); //create the active columns in this block for (sit = blockVars.begin(); sit != blockVars.end(); sit++) { modelRelax->activeColumns.push_back( *sit); //insert into the all variables set also, but throw an execption //if already there -- same variable cannot be in more than one block if (blockVarsAll.find( *sit) == blockVarsAll.end()) { blockVarsAll.insert (*sit); }else{ throw ErrorClass("Variable " + UtilIntToStr(*sit) + " appears in more than one block"); } } // // if (m_appParam.LogLevel >= 3) { (*m_osLog) << "Active Columns : " << whichBlock << endl; UtilPrintVector(modelRelax->activeColumns, m_osLog); } createModelPartSparse(modelRelax, nRowsRelax, rowsRelax); //does not work for cutting planes //createModelPart(modelRelax, nRowsRelax, rowsRelax); //modelRelax->fixNonActiveColumns(); m_modelR.insert(make_pair(whichBlock + 1, modelRelax)); setModelRelax(modelRelax, "relax" + UtilIntToStr(whichBlock), whichBlock); if (m_appParam.LogLevel >= 3) { (*m_osLog) << std::endl << std::endl; (*m_osLog) << "HERE COMES THE DUPLICATION (WHEN createModelPartSparse USED)" << std::endl; } UtilPrintVector( modelRelax->activeColumns, m_osLog); //free local memory UTIL_DELARR( rowsRelax); } }//end for over constraint options }// if on ospton null //get the core constraints -- constraints NOT in a block int *rowsCore = NULL; int kount = 0; nRowsCore = nRows - blockConAll.size(); if(nRowsCore <= 0) throw ErrorClass("We need at least one coupling constraint"); rowsCore = new int[nRowsCore]; for(i = 0; i < nRows; i++){ if (blockConAll.find( i ) == blockConAll.end() ){ rowsCore[ kount++] = i; } } if( kount != nRowsCore) throw ErrorClass("There was an error counting coupling constraints"); DecompConstraintSet * modelCore = new DecompConstraintSet(); createModelPart(modelCore, nRowsCore, rowsCore); setModelCore(modelCore, "core"); //--- //--- save a pointer so we can delete it later //--- m_modelC = modelCore; //get the master only variables //modelCore->masterOnlyCols.push_back(i); for (i = 0; i < nCols; i++) { if (blockVarsAll.find(i) == blockVarsAll.end()) { modelCore->masterOnlyCols.push_back(i); std::cout << "MASTER ONLY VARIABLE " << i << std::endl; } } //--- //--- create an extra "empty" block for the master-only vars //--- since I don't know what OSI will do with empty problem //--- we will make column bounds explicity rows //--- int nMasterOnlyCols = static_cast<int> (modelCore->masterOnlyCols.size()); if (nMasterOnlyCols) { if (m_appParam.LogLevel >= 1) (*m_osLog) << "Create model part Master-Only." << endl; createModelMasterOnlys2(modelCore->masterOnlyCols); } UtilPrintFuncBegin(m_osLog, m_classTag, "printCurrentProblem()", m_appParam.LogLevel, 2); //free local memory UTIL_DELARR( rowsCore); }//end try catch(const ErrorClass& eclass){ throw ErrorClass( eclass.errormsg); } }// end createModels()
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