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;
	}
}
예제 #2
0
/*
  Tests if the given string looks like an absolute path to a file.
    - unix:	string begins with `/'
    - windows:	string begins with `\' or `drv:', where drv is a drive
		designator.
*/
bool fileAbsPath (const std::string &path)
{
  const char dirsep =  CoinFindDirSeparator() ;

  // If the first two chars are drive designators then treat it as absolute
  // path (noone in their right mind would create a file named 'Z:' on unix,
  // right?...)
  const size_t len = path.length();
  if (len >= 2 && path[1] == ':') {
    const char ch = path[0];
    if (('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z')) {
      return true;
    }
  }

  return path[0] == dirsep;
}
예제 #3
0
int main (int argc, const char *argv[])
{

  // Define your favorite OsiSolver
  
  OsiClpSolverInterface solver1;

  // Read in model using argv[1]
  // and assert that it is a clean model
  std::string dirsep(1,CoinFindDirSeparator());
  std::string mpsFileName;
# if defined(SAMPLEDIR)
  mpsFileName = SAMPLEDIR ;
  mpsFileName += dirsep+"p0033.mps";
# else
  if (argc < 2) {
    fprintf(stderr, "Do not know where to find sample MPS files.\n");
    exit(1);
  }
# endif
  if (argc>=2) mpsFileName = argv[1];
  int numMpsReadErrors = solver1.readMps(mpsFileName.c_str(),"");
  if( numMpsReadErrors != 0 )
  {
     printf("%d errors reading MPS file\n", numMpsReadErrors);
     return numMpsReadErrors;
  }
  double time1 = CoinCpuTime();

  /* Options are:
     preprocess to do preprocessing
     time in minutes
     if 2 parameters and numeric taken as time
  */
  bool preProcess=false;
  double minutes=-1.0;
  int nGoodParam=0;
  for (int iParam=2; iParam<argc;iParam++) {
    if (!strcmp(argv[iParam],"preprocess")) {
      preProcess=true;
      nGoodParam++;
    } else if (!strcmp(argv[iParam],"time")) {
      if (iParam+1<argc&&isdigit(argv[iParam+1][0])) {
        minutes=atof(argv[iParam+1]);
        if (minutes>=0.0) {
          nGoodParam+=2;
          iParam++; // skip time
        }
      }
    }
  }
  if (nGoodParam==0&&argc==3&&isdigit(argv[2][0])) {
    // If time is given then stop after that number of minutes
    minutes = atof(argv[2]);
    if (minutes>=0.0) 
      nGoodParam=1;
  }
  if (nGoodParam!=argc-2&&argc>=2) {
    printf("Usage <file> [preprocess] [time <minutes>] or <file> <minutes>\n");
    exit(1);
  }
  solver1.initialSolve();
  // Reduce printout
  solver1.setHintParam(OsiDoReducePrint,true,OsiHintTry);
  // See if we want preprocessing
  OsiSolverInterface * solver2=&solver1;
#if PREPROCESS==1
  CglPreProcess process;
  if (preProcess) {
    /* Do not try and produce equality cliques and
       do up to 5 passes */
    solver2 = process.preProcess(solver1,false,5);
    if (!solver2) {
      printf("Pre-processing says infeasible\n");
      exit(2);
    }
    solver2->resolve();
  }
#endif
  CbcModel model(*solver2);
  model.solver()->setHintParam(OsiDoReducePrint,true,OsiHintTry);
  // Set up some cut generators and defaults
  // Probing first as gets tight bounds on continuous

  CglProbing generator1;
  generator1.setUsingObjective(true);
  generator1.setMaxPass(1);
  generator1.setMaxPassRoot(5);
  // Number of unsatisfied variables to look at
  generator1.setMaxProbe(10);
  generator1.setMaxProbeRoot(1000);
  // How far to follow the consequences
  generator1.setMaxLook(50);
  generator1.setMaxLookRoot(500);
  // Only look at rows with fewer than this number of elements
  generator1.setMaxElements(200);
  generator1.setRowCuts(3);

  CglGomory generator2;
  // try larger limit
  generator2.setLimit(300);

  CglKnapsackCover generator3;

  CglRedSplit generator4;
  // try larger limit
  generator4.setLimit(200);

  CglClique generator5;
  generator5.setStarCliqueReport(false);
  generator5.setRowCliqueReport(false);

  CglMixedIntegerRounding2 mixedGen;
  CglFlowCover flowGen;
  
  // Add in generators
  // Experiment with -1 and -99 etc
  model.addCutGenerator(&generator1,-1,"Probing");
  model.addCutGenerator(&generator2,-1,"Gomory");
  model.addCutGenerator(&generator3,-1,"Knapsack");
  // model.addCutGenerator(&generator4,-1,"RedSplit");
  model.addCutGenerator(&generator5,-1,"Clique");
  model.addCutGenerator(&flowGen,-1,"FlowCover");
  model.addCutGenerator(&mixedGen,-1,"MixedIntegerRounding");
  // Say we want timings
  int numberGenerators = model.numberCutGenerators();
  int iGenerator;
  for (iGenerator=0;iGenerator<numberGenerators;iGenerator++) {
    CbcCutGenerator * generator = model.cutGenerator(iGenerator);
    generator->setTiming(true);
  }
  OsiClpSolverInterface * osiclp = dynamic_cast< OsiClpSolverInterface*> (model.solver());
  // go faster stripes
  if (osiclp) {
    // Turn this off if you get problems
    // Used to be automatically set
    osiclp->setSpecialOptions(128);
    if(osiclp->getNumRows()<300&&osiclp->getNumCols()<500) {
      //osiclp->setupForRepeatedUse(2,0);
      osiclp->setupForRepeatedUse(0,0);
    }
  } 
  // Uncommenting this should switch off all CBC messages
  // model.messagesPointer()->setDetailMessages(10,10000,NULL);
  // Allow rounding heuristic

  CbcRounding heuristic1(model);
  model.addHeuristic(&heuristic1);

  // And local search when new solution found

  CbcHeuristicLocal heuristic2(model);
  model.addHeuristic(&heuristic2);

  // Redundant definition of default branching (as Default == User)
  CbcBranchUserDecision branch;
  model.setBranchingMethod(&branch);

  // Definition of node choice
  CbcCompareUser compare;
  model.setNodeComparison(compare);

  // Do initial solve to continuous
  model.initialSolve();

  // Could tune more
  double objValue = model.solver()->getObjSense()*model.solver()->getObjValue();
  double minimumDropA=CoinMin(1.0,fabs(objValue)*1.0e-3+1.0e-4);
  double minimumDrop= fabs(objValue)*1.0e-4+1.0e-4;
  printf("min drop %g (A %g)\n",minimumDrop,minimumDropA);
  model.setMinimumDrop(minimumDrop);

  if (model.getNumCols()<500)
    model.setMaximumCutPassesAtRoot(-100); // always do 100 if possible
  else if (model.getNumCols()<5000)
    model.setMaximumCutPassesAtRoot(100); // use minimum drop
  else
    model.setMaximumCutPassesAtRoot(20);
  model.setMaximumCutPasses(10);
  //model.setMaximumCutPasses(2);

  // Switch off strong branching if wanted
  // model.setNumberStrong(0);
  // Do more strong branching if small
  if (model.getNumCols()<5000)
    model.setNumberStrong(10);
  model.setNumberStrong(20);
  //model.setNumberStrong(5);
  model.setNumberBeforeTrust(5);

  model.solver()->setIntParam(OsiMaxNumIterationHotStart,100);

  // If time is given then stop after that number of minutes
  if (minutes>=0.0) {
    std::cout<<"Stopping after "<<minutes<<" minutes"<<std::endl;
    model.setDblParam(CbcModel::CbcMaximumSeconds,60.0*minutes);
  }
  // Switch off most output
  if (model.getNumCols()<3000) {
    model.messageHandler()->setLogLevel(1);
    //model.solver()->messageHandler()->setLogLevel(0);
  } else {
    model.messageHandler()->setLogLevel(2);
    model.solver()->messageHandler()->setLogLevel(1);
  }
  //model.messageHandler()->setLogLevel(2);
  //model.solver()->messageHandler()->setLogLevel(2);
  //model.setPrintFrequency(50);
  //#define DEBUG_CUTS
#ifdef DEBUG_CUTS
  // Set up debugger by name (only if no preprocesing)
  if (!preProcess) {
    std::string problemName ;
    model.solver()->getStrParam(OsiProbName,problemName) ;
    model.solver()->activateRowCutDebugger(problemName.c_str()) ;
  }
#endif
#if PREPROCESS==2
  // Default strategy will leave cut generators as they exist already
  // so cutsOnlyAtRoot (1) ignored
  // numberStrong (2) is 5 (default)
  // numberBeforeTrust (3) is 5 (default is 0)
  // printLevel (4) defaults (0)
  CbcStrategyDefault strategy(true,5,5);
  // Set up pre-processing to find sos if wanted
  if (preProcess)
    strategy.setupPreProcessing(2);
  model.setStrategy(strategy);
#endif
  // Do complete search
  
  model.branchAndBound();

  std::cout<<mpsFileName<<" took "<<CoinCpuTime()-time1<<" seconds, "
	   <<model.getNodeCount()<<" nodes with objective "
	   <<model.getObjValue()
	   <<(!model.status() ? " Finished" : " Not finished")
	   <<std::endl;

  // Print more statistics
  std::cout<<"Cuts at root node changed objective from "<<model.getContinuousObjective()
	   <<" to "<<model.rootObjectiveAfterCuts()<<std::endl;

  for (iGenerator=0;iGenerator<numberGenerators;iGenerator++) {
    CbcCutGenerator * generator = model.cutGenerator(iGenerator);
    std::cout<<generator->cutGeneratorName()<<" was tried "
	     <<generator->numberTimesEntered()<<" times and created "
	     <<generator->numberCutsInTotal()<<" cuts of which "
	     <<generator->numberCutsActive()<<" were active after adding rounds of cuts";
    if (generator->timing())
      std::cout<<" ( "<<generator->timeInCutGenerator()<<" seconds)"<<std::endl;
    else
      std::cout<<std::endl;
  }
  // Print solution if finished - we can't get names from Osi! - so get from OsiClp

  if (model.getMinimizationObjValue()<1.0e50) {
#if PREPROCESS==1
    // post process
    OsiSolverInterface * solver;
    if (preProcess) {
      process.postProcess(*model.solver());
      // Solution now back in solver1
      solver = & solver1;
    } else {
      solver = model.solver();
    }
#else
    OsiSolverInterface * solver = model.solver();
#endif
    int numberColumns = solver->getNumCols();
    
    const double * solution = solver->getColSolution();

    // Get names from solver1 (as OsiSolverInterface may lose)
    std::vector<std::string> columnNames = *solver1.getModelPtr()->columnNames();
    
    int iColumn;
    std::cout<<std::setiosflags(std::ios::fixed|std::ios::showpoint)<<std::setw(14);
    
    std::cout<<"--------------------------------------"<<std::endl;
    for (iColumn=0;iColumn<numberColumns;iColumn++) {
      double value=solution[iColumn];
      if (fabs(value)>1.0e-7&&solver->isInteger(iColumn)) 
	std::cout<<std::setw(6)<<iColumn<<" "
                 <<columnNames[iColumn]<<" "
                 <<value<<std::endl;
    }
    std::cout<<"--------------------------------------"<<std::endl;
  
    std::cout<<std::resetiosflags(std::ios::fixed|std::ios::showpoint|std::ios::scientific);
  }
  return 0;
}    
예제 #4
0
CbcGenCtlBlk::CbcGenCtlBlk ()

{
    version_ = CBC_GENERIC_VERSION ;
    /*
      It's unclear to me that this is a good choice for dfltDirectory. Makes
      sense for commands, but seems unnecessary for data files. Perhaps a null
      string instead?
    */
    char dirsep = CoinFindDirSeparator() ;
    dfltDirectory_ = (dirsep == '/' ? "./" : ".\\") ;
    lastMpsIn_ = "" ;
    allowImportErrors_ = false ;
    lastSolnOut_ = "stdout" ;
    printMode_ = 0 ;
    printMask_ = "" ;

    paramVec_ = 0 ;
    genParams_.first_ = 0 ;
    genParams_.last_ = 0 ;
    cbcParams_.first_ = 0 ;
    cbcParams_.last_ = 0 ;
    osiParams_.first_ = 0 ;
    osiParams_.last_ = 0 ;

    verbose_ = 0 ;
    paramsProcessed_ = 0 ;
    defaultSettings_ = true ;

    debugCreate_ = "" ;
    debugFile_ = "" ;
    debugSol_.numCols_ = -1 ;
    debugSol_.values_ = 0 ;

    printOpt_ = 0 ;

    /*
      Assigning us_en to cur_lang_ is entirely bogus, but CoinMessages::Language
      does not provide an `unspecified' code.
    */
    msgHandler_ = new CoinMessageHandler() ;
    ourMsgHandler_ = true ;
    cur_lang_ = CoinMessages::us_en ;
    msgs_ = 0 ;
    logLvl_ = 0 ;

    totalTime_ = 0.0 ;

    model_ = 0 ;
    dfltSolver_ = 0 ;
    goodModel_ = false ;
    bab_.majorStatus_ = BACInvalid ;
    bab_.minorStatus_ = BACmInvalid ;
    bab_.where_ = BACwInvalid ;
    bab_.haveAnswer_ = false ;
    bab_.answerSolver_ = 0 ;

    preProcess_ = CbcGenCtlBlk::IPPSOS ;
    cutDepth_ = -1 ;

    probing_.action_ = CbcGenCtlBlk::CGIfMove ;
    probing_.proto_ = 0 ;
    probing_.usingObjective_ = true ;
    probing_.maxPass_ = 3 ;
    probing_.maxPassRoot_ = 3 ;
    probing_.maxProbe_ = 10 ;
    probing_.maxProbeRoot_ = 50 ;
    probing_.maxLook_ = 10 ;
    probing_.maxLookRoot_ = 50 ;
    probing_.maxElements_ = 200 ;
    probing_.rowCuts_ = 3 ;

    clique_.action_ = CbcGenCtlBlk::CGIfMove ;
    clique_.proto_ = 0 ;
    clique_.starCliqueReport_ = false ;
    clique_.rowCliqueReport_ = false ;
    clique_.minViolation_ = 0.1 ;

    flow_.action_ = CbcGenCtlBlk::CGIfMove ;
    flow_.proto_ = 0 ;

    gomory_.action_ = CbcGenCtlBlk::CGIfMove ;
    gomory_.proto_ = 0 ;
    gomory_.limit_ = 50 ;
    gomory_.limitAtRoot_ = 512 ;

    knapsack_.action_ = CbcGenCtlBlk::CGIfMove ;
    knapsack_.proto_ = 0 ;

    // landp_action_ = CbcGenCtlBlk::CGOff ;
    // landp_.proto_ = 0 ;

    mir_.action_ = CbcGenCtlBlk::CGIfMove ;
    mir_.proto_ = 0 ;

    oddHole_.action_ = CbcGenCtlBlk::CGOff ;
    oddHole_.proto_ = 0 ;

    redSplit_.action_ = CbcGenCtlBlk::CGRoot ;
    redSplit_.proto_ = 0 ;

    twomir_.action_ = CbcGenCtlBlk::CGRoot ;
    twomir_.proto_ = 0 ;
    twomir_.maxElements_ = 250 ;

    fpump_.action_ = CbcGenCtlBlk::CGOn ;
    fpump_.proto_ = 0 ;

    combine_.action_ = CbcGenCtlBlk::CGOn ;
    combine_.proto_ = 0 ;
    combine_.trySwap_ = 1 ;

    greedyCover_.action_ = CbcGenCtlBlk::CGOn ;
    greedyCover_.proto_ = 0 ;
    greedyEquality_.action_ = CbcGenCtlBlk::CGOn ;
    greedyEquality_.proto_ = 0 ;

    localTree_.action_ = CbcGenCtlBlk::CGOff ;
    localTree_.proto_ = 0 ;
    localTree_.soln_ = 0 ;
    localTree_.range_ = 10 ;
    localTree_.typeCuts_ = 0 ;
    localTree_.maxDiverge_ = 0 ;
    localTree_.timeLimit_ = 10000 ;
    localTree_.nodeLimit_ = 2000 ;
    localTree_.refine_ = true ;

    rounding_.action_ = CbcGenCtlBlk::CGOn ;
    rounding_.proto_ = 0 ;

    djFix_.action_ = false ;
    djFix_.threshold_ = 1.0e100 ;

    priorityAction_ = CbcGenCtlBlk::BPOff ;
    /*
      The value for numBeforeTrust is as recommended by Achterberg. Cbc's
      implementation doesn't really have a parameter equivalent to Achterberg's
      dynamic limit on number of strong branching evaluations, so go with a fairly
      large default. As of 06.12.16, the magic number for shadow price mode meant
      `use shadow prices (penalties, I think) if there's no strong branching info'.
    */
    chooseStrong_.numBeforeTrust_ = 8 ;
    chooseStrong_.numStrong_ = 100 ;
    chooseStrong_.shadowPriceMode_ = 1 ;

    return ;
}
예제 #5
0
/*
   Tests if file readable and may change name to add
   compression extension.  Here to get ZLIB etc in one place

   stdin goes by unmolested by all the fussing with file names. We shouldn't
   close it, either.
*/
bool fileCoinReadable(std::string & fileName, const std::string &dfltPrefix)
{
  if (fileName != "stdin")
  { const char dirsep =  CoinFindDirSeparator();
    std::string directory ;
    if (dfltPrefix == "")
    { directory = (dirsep == '/' ? "./" : ".\\") ; }
    else
    { directory = dfltPrefix ;
      if (directory[directory.length()-1] != dirsep)
      { directory += dirsep ; } }

    bool absolutePath = fileAbsPath(fileName) ;
    std::string field = fileName;

    if (absolutePath) {
      // nothing to do
    } else if (field[0]=='~') {
      char * home_dir = getenv("HOME");
      if (home_dir) {
	std::string home(home_dir);
	field=field.erase(0,1);
	fileName = home+field;
      } else {
	fileName=field;
      }
    } else {
      fileName = directory+field;
    }
  }
  // I am opening it to make sure not odd
  FILE *fp;
  if (strcmp(fileName.c_str(),"stdin")) {
    fp = fopen ( fileName.c_str(), "r" );
  } else {
    fp = stdin;
  }
#ifdef COIN_HAS_ZLIB
  if (!fp) {
    std::string fname = fileName;
    fname += ".gz";
    fp = fopen ( fname.c_str(), "r" );
    if (fp)
      fileName=fname;
  }
#endif
#ifdef COIN_HAS_BZLIB
  if (!fp) {
    std::string fname = fileName;
    fname += ".bz2";
    fp = fopen ( fname.c_str(), "r" );
    if (fp)
      fileName=fname;
  }
#endif
  if (!fp) {
    return false;
  } else {
    if (fp != stdin) {
      fclose(fp);
    }
    return true;
  }
}