示例#1
0
//===========================================================================//
int main(int argc, char ** argv){
   try{

      //---
      //--- create the utility class for parsing parameters
      //---
      UtilParameters utilParam(argc, argv);  
            
      bool doGenRandom    = utilParam.GetSetting("doGenRandom",    false);
      int  randSeed       = utilParam.GetSetting("randSeed",       1    );
      int  randNumAtms    = utilParam.GetSetting("randNumAtms",    5    );
      int  randNumDates   = utilParam.GetSetting("randNumDates",   10   );
      
      bool doCut          = utilParam.GetSetting("doCut",          true);
      bool doPriceCut     = utilParam.GetSetting("doPriceCut",     false);
      bool doDirect       = utilParam.GetSetting("doDirect",       false);
      
      UtilTimer timer;
      double    timeSetupReal = 0.0;
      double    timeSetupCpu  = 0.0;
      double    timeSolveReal = 0.0;
      double    timeSolveCpu  = 0.0;

      //---
      //--- start overall timer
      //---
      timer.start();
      if(doGenRandom){
	 //---
	 //--- generate a random instance
	 //---
	 ATM_Instance instance;
	 instance.generateRandom(randNumAtms, randNumDates, randSeed);	 
      }
      else{
         //---
         //--- create the user application (a DecompApp)
         //---      
         ATM_DecompApp atm(utilParam); 
                  
         //---
         //--- create the algorithm (a DecompAlgo)
         //---
         DecompAlgo * algo = NULL;
         assert(doCut + doPriceCut == 1);

         //---
         //--- create the CPM algorithm object
         //---      
         if(doCut)
            algo = new DecompAlgoC(&atm, utilParam);
         
         //---
         //--- create the PC algorithm object
         //---
         if(doPriceCut)
            algo = new DecompAlgoPC(&atm, utilParam);
         
         
         if(doCut && doDirect){
            timer.stop();
            timeSetupCpu  = timer.getCpuTime();
            timeSetupReal = timer.getRealTime();

            //---
            //--- solve
            //---
            timer.start();      
            algo->solveDirect();
            timer.stop();
            timeSolveCpu  = timer.getCpuTime();
            timeSolveReal = timer.getRealTime();
         }
         else{            
            //---
            //--- create the driver AlpsDecomp model
            //---
	    int             status = 0;
            AlpsDecompModel alpsModel(utilParam, algo);
	    
	    timer.stop();
            timeSetupCpu  = timer.getCpuTime();
            timeSetupReal = timer.getRealTime();
	    
            //---
            //--- solve
            //---
            timer.start();      
            status = alpsModel.solve();
            timer.stop();
            timeSolveCpu  = timer.getCpuTime();
            timeSolveReal = timer.getRealTime();

            //TODO: move doDirect solve into alpsModel so access
            //  solution the same way?

            //---
            //--- sanity check
            //---
            cout << setiosflags(ios::fixed|ios::showpoint);
	    cout << "Status= " << status 
		 << " BestLB= " << setw(10) 
                 << UtilDblToStr(alpsModel.getGlobalLB(),2)
                 << " BestUB= " << setw(10)
                 << UtilDblToStr(alpsModel.getGlobalUB(),2)        
                 << " Nodes= " << setw(6) 
                 << alpsModel.getNumNodesProcessed()
                 << " SetupCPU= "  << timeSetupCpu
                 << " SolveCPU= "  << timeSolveCpu 
                 << " TotalCPU= "  << timeSetupCpu + timeSolveCpu
                 << " SetupReal= " << timeSetupReal
                 << " SolveReal= " << timeSolveReal
                 << " TotalReal= " << timeSetupReal + timeSolveReal
                 << endl;      

	    //---
	    //--- now, initialize direct solve with best
	    //---   solution to PC
	    //--- TODO: only useful if stop early on time or nodes   
	    //--- TODO: cbc currently doesn't use warm-start, only cpx
	    //---
	    //DecompAlgo * algoC = new DecompAlgoC(&atm, &utilParam);
	    //algoC->solveDirect(algo->getXhatIPBest());
	    //delete algoC;
         }
	 
         //---
         //--- free local memory
         //---
         delete algo;
      }
   }
   catch(CoinError & ex){
      cerr << "COIN Exception [ " << ex.message() << " ]"
           << " at " << ex.fileName()  << ":L" << ex.lineNumber()
           << " in " << ex.className() << "::" << ex.methodName() << endl;
   }
   return 0;
}
示例#2
0
//===========================================================================//
int main(int argc, char ** argv){
   try {

      //---
      //--- create the utility class for parsing parameters
      //---
      UtilParameters utilParam(argc, argv);  
            
      bool doCut          = utilParam.GetSetting("doCut",          true);
      bool doPriceCut     = utilParam.GetSetting("doPriceCut",     false);
      bool doDirect       = utilParam.GetSetting("doDirect",       false);
      
      UtilTimer timer;
      double    timeSetupReal = 0.0;
      double    timeSetupCpu  = 0.0;
      double    timeSolveReal = 0.0;
      double    timeSolveCpu  = 0.0;      

      //---
      //--- start overall timer
      //---
      timer.start();

      //---
      //--- create the user application (a DecompApp)
      //---   
      MMKP_DecompApp mmkp(utilParam);

      //---
      //--- create the algorithm (a DecompAlgo)
      //---
      DecompAlgo * algo = NULL;
      assert(doCut + doPriceCut == 1);

      //---
      //--- create the CPM algorithm object
      //---      
      if(doCut)	 
         algo = new DecompAlgoC(&mmkp, &utilParam);

      //---
      //--- create the PC algorithm object
      //---
      if(doPriceCut)
         algo = new DecompAlgoPC(&mmkp, &utilParam);


      if(doCut && doDirect){
	 timer.stop();
	 timeSetupCpu  = timer.getCpuTime();
	 timeSetupReal = timer.getRealTime();
	 
	 //---
	 //--- solve
	 //---
	 timer.start();      
	 algo->solveDirect();
	 timer.stop();
	 timeSolveCpu  = timer.getCpuTime();
	 timeSolveReal = timer.getRealTime();
      }
      else{
	 //---
	 //--- create the driver AlpsDecomp model
	 //---
         int             status = 0;
	 AlpsDecompModel alpsModel(utilParam, algo);
	 
	 timer.stop();
	 timeSetupCpu  = timer.getCpuTime();
	 timeSetupReal = timer.getRealTime();
	 
	 //---
	 //--- solve
	 //---
	 timer.start();      
	 status = alpsModel.solve();
	 timer.stop();
	 timeSolveCpu  = timer.getCpuTime();
	 timeSolveReal = timer.getRealTime();

	 //---
	 //--- sanity check
	 //---
	 cout << setiosflags(ios::fixed|ios::showpoint);
	 cout << "Status= "   << status  
	      << " BestLB=  " << setw(10) 
	      << UtilDblToStr(alpsModel.getGlobalLB(),5)
	      << " BestUB= " << setw(10)
	      << UtilDblToStr(alpsModel.getGlobalUB(),5)        
	      << " Nodes= " << setw(6) 
	      << alpsModel.getNumNodesProcessed()
	      << " SetupCPU= "  << timeSetupCpu
	      << " SolveCPU= "  << timeSolveCpu 
	      << " TotalCPU= "  << timeSetupCpu + timeSolveCpu
	      << " SetupReal= " << timeSetupReal
	      << " SolveReal= " << timeSolveReal
	      << " TotalReal= " << timeSetupReal + timeSolveReal
	      << endl;      
	 
         if(status == AlpsExitStatusOptimal && mmkp.getBestKnownUB() < 1.0e50){
            //---
            //--- the assumption here is that the BestKnownLB/UB is optimal
            //---
            double diff 
               = fabs(mmkp.getBestKnownUB() - alpsModel.getGlobalUB());
            if(diff > 1.0e-4){
               cerr << "ERROR. BestKnownUB= " << mmkp.getBestKnownUB()
                    << " but DECOMP claims GlobalUB= " 
                    << alpsModel.getGlobalUB() << endl;
               throw UtilException("Invalid claim of optimal.", 
                                   "main", "DECOMP");
            }
         }
	 
	 //---
	 //--- free local memory
	 //---
	 delete algo;
      }
   }
   catch(CoinError & ex){
      cerr << "COIN Exception [ " << ex.message() << " ]"
           << " at " << ex.fileName()  << ":L" << ex.lineNumber()
           << " in " << ex.className() << "::" << ex.methodName() << endl;
      return 1;
   }
   return 0;
}
示例#3
0
文件: MCF_Main.cpp 项目: coin-or/Dip
//===========================================================================//
int main(int argc, char** argv)
{
   try {
      //---
      //--- create the utility class for parsing parameters
      //---
      UtilParameters utilParam(argc, argv);
      bool doCut          = utilParam.GetSetting("doCut",          true);
      bool doPriceCut     = utilParam.GetSetting("doPriceCut",     false);
      bool doDirect       = utilParam.GetSetting("doDirect",       false);
      UtilTimer timer;
      double    timeSetupReal = 0.0;
      double    timeSetupCpu  = 0.0;
      double    timeSolveReal = 0.0;
      double    timeSolveCpu  = 0.0;
      //---
      //--- start overall timer
      //---
      timer.start();
      //---
      //--- create the user application (a DecompApp)
      //---
      MCF_DecompApp mmkp(utilParam);
      //---
      //--- create the algorithm (a DecompAlgo)
      //---
      DecompAlgo* algo = NULL;
      assert(doCut + doPriceCut == 1);

      //---
      //--- create the CPM algorithm object
      //---
      if (doCut) {
         algo = new DecompAlgoC(&mmkp, utilParam);
      }

      //---
      //--- create the PC algorithm object
      //---
      if (doPriceCut) {
         algo = new DecompAlgoPC(&mmkp, utilParam);
      }

      if (doCut && doDirect) {
         timer.stop();
         timeSetupCpu  = timer.getCpuTime();
         timeSetupReal = timer.getRealTime();
         //---
         //--- solve
         //---
         timer.start();
         algo->solveDirect();
         timer.stop();
         timeSolveCpu  = timer.getCpuTime();
         timeSolveReal = timer.getRealTime();
      } else {
         //---
         //--- create the driver AlpsDecomp model
         //---
         int             status = 0;
         AlpsDecompModel alpsModel(utilParam, algo);
         timer.stop();
         timeSetupCpu  = timer.getCpuTime();
         timeSetupReal = timer.getRealTime();
         //---
         //--- solve
         //---
         timer.start();
         status = alpsModel.solve();
         timer.stop();
         timeSolveCpu  = timer.getCpuTime();
         timeSolveReal = timer.getRealTime();
         //---
         //--- sanity check
         //---
         cout << setiosflags(ios::fixed | ios::showpoint);
         cout << "Status= "   << status
              << " BestLB=  " << setw(10)
              << UtilDblToStr(alpsModel.getGlobalLB(), 5)
              << " BestUB= " << setw(10)
              << UtilDblToStr(alpsModel.getGlobalUB(), 5)
              << " Nodes= " << setw(6)
              << alpsModel.getNumNodesProcessed()
              << " SetupCPU= "  << timeSetupCpu
              << " SolveCPU= "  << timeSolveCpu
              << " TotalCPU= "  << timeSetupCpu + timeSolveCpu
              << " SetupReal= " << timeSetupReal
              << " SolveReal= " << timeSolveReal
              << " TotalReal= " << timeSetupReal + timeSolveReal
              << endl;
         //---
         //--- free local memory
         //---
         delete algo;
      }
   } catch (CoinError& ex) {
      cerr << "COIN Exception [ " << ex.message() << " ]"
           << " at " << ex.fileName()  << ":L" << ex.lineNumber()
           << " in " << ex.className() << "::" << ex.methodName() << endl;
      return 1;
   }

   return 0;
}