Beispiel #1
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;
}
Beispiel #2
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;
}
/**
* 
* @brief Perform a test using the scanner card of the Instek in 
*        the 8261
*/
void Instek8261Serial::ScanTest(void) {
    UtilTimer cmdTimer;
    UtilTimer scanTimer;
    int length;
    int numBytesRx;

    for (int j = 0; j < 1; j++) {

        cmdTimer.ResetStartTimestamp();

        for (int i = 0; i < 4; i++) {

            scanTimer.ResetStartTimestamp();
            uint64_t elapsedScanTime = 0;
            sprintf(m_buffer, "rout:func scan\n");
            printf("%ld ms, Sending cmd: %s", cmdTimer.GetElapsedMillisec(), m_buffer);
            length = strlen(m_buffer);
            SendCmd(m_buffer, length);

            numBytesRx = GetResponse(m_buffer, SERIAL_BUF_LENGTH, 10000);
            m_buffer[numBytesRx] = 0;
            printf("%ld ms, %s", cmdTimer.GetElapsedMillisec(), m_buffer);
            elapsedScanTime = scanTimer.GetElapsedMillisec();
            printf(">>>> SCAN DURATION: %ld ms <<<<\n", elapsedScanTime);

            sprintf(m_buffer, "*trg\n");
            printf("%ld ms, Sending cmd: %s", cmdTimer.GetElapsedMillisec(), m_buffer);
            length = strlen(m_buffer);
            SendCmd(m_buffer, length);

            sprintf(m_buffer, "fetc?\n");
            printf("%ld ms, Sending cmd: %s", cmdTimer.GetElapsedMillisec(), m_buffer);
            length = strlen(m_buffer);
            SendCmd(m_buffer, length);

            numBytesRx = GetMultiResponse(m_buffer, SERIAL_BUF_LENGTH, 10000, 3);
            m_buffer[numBytesRx] = 0;
            printf("%ld ms, response:\n%s", cmdTimer.GetElapsedMillisec(), m_buffer);

            sprintf(m_buffer, "ROUT:FUNC OFF\n");
            printf("%ld ms, Sending cmd: %s", cmdTimer.GetElapsedMillisec(), m_buffer);
            length = strlen(m_buffer);
            SendCmd(m_buffer, length);

            // float tempF;
            // In8261ReadTemp(tempF);
            // printf("Temp: %f\n", tempF);

            // float voltF;
            // In8261ReadDCVolt(voltF);
            // printf("Volt: %f\n", tempF);

        }

        sprintf(m_buffer, "ROUT:FUNC OFF\n");
        printf("%ld ms, Sending cmd: %s", cmdTimer.GetElapsedMillisec(), m_buffer);
        length = strlen(m_buffer);
        SendCmd(m_buffer, length);

        sprintf(m_buffer, "*trg\n");
        printf("%ld ms, Sending cmd: %s", cmdTimer.GetElapsedMillisec(), m_buffer);
        length = strlen(m_buffer);
        SendCmd(m_buffer, length);

    }
}
/**
* 
* @brief Perform Instek Configuration 
*/
void Instek8261Serial::ScanInit(void) {
    // bool status = false;
    UtilTimer cmdTimer;
    int length;
    // int numBytesRx;

    for (auto& x: m_CmdInitStrings) {
        char *cmdP = (char *)x.data();
        printf("Sending cmd: %s", cmdP);
        length = strlen(cmdP);
        SendCmd(cmdP, length);
        QThread::sleep(500);
    }

    sprintf(m_buffer, "rout:adv on\n");
    printf("Sending cmd: %s", m_buffer);
    length = strlen(m_buffer);
    SendCmd(m_buffer, length);

#if 0
    sprintf(m_buffer, "AVER:COUN?\n");
    printf("Sending cmd: %s", m_buffer);
    length = strlen(m_buffer);
    numBytesRx = SendCmdAndGetResponse(m_buffer, length, m_buffer, SERIAL_BUF_LENGTH, MILLISEC_1000);
    printf("response: %s", m_buffer);

    sprintf(m_buffer, "AVER:STAT?\n");
    printf("Sending cmd: %s", m_buffer);
    length = strlen(m_buffer);
    numBytesRx = SendCmdAndGetResponse(m_buffer, length, m_buffer, SERIAL_BUF_LENGTH, MILLISEC_1000);
    printf("response: %s", m_buffer);

    sprintf(m_buffer, "rout:mult:stat?\n");
    printf("Sending cmd: %s", m_buffer);
    length = strlen(m_buffer);
    SendCmd(m_buffer, length);
    numBytesRx = GetMultiResponse(m_buffer, SERIAL_BUF_LENGTH, 10000, 18);
    m_buffer[numBytesRx] = 0;
    printf("%response:\n%s", m_buffer);
    Sleep(1000);

    sprintf(m_buffer, "rout:chan? 101\n");
    printf("Sending cmd: %s", m_buffer);
    length = strlen(m_buffer);
    numBytesRx = SendCmdAndGetResponse(m_buffer, length, m_buffer, SERIAL_BUF_LENGTH, MILLISEC_1000);
    printf("response: %s", m_buffer);
    // Sleep(1000);

    sprintf(m_buffer, "rout:chan? 102\n");
    printf("Sending cmd: %s", m_buffer);
    length = strlen(m_buffer);
    numBytesRx = SendCmdAndGetResponse(m_buffer, length, m_buffer, SERIAL_BUF_LENGTH, MILLISEC_1000);
    printf("response: %s", m_buffer);
    // Sleep(1000);

    sprintf(m_buffer, "rout:chan? 103\n");
    printf("Sending cmd: %s", m_buffer);
    length = strlen(m_buffer);
    numBytesRx = SendCmdAndGetResponse(m_buffer, length, m_buffer, SERIAL_BUF_LENGTH, MILLISEC_1000);
    printf("response: %s", m_buffer);
    // Sleep(1000);

    sprintf(m_buffer, "temp:tco:type?\n");
    printf("Sending cmd: %s", m_buffer);
    length = strlen(m_buffer);
    numBytesRx = SendCmdAndGetResponse(m_buffer, length, m_buffer, SERIAL_BUF_LENGTH, MILLISEC_1000);
    printf("response: %s", m_buffer);
    Sleep(1000);

    sprintf(m_buffer, "temp:tco:res?\n");
    printf("Sending cmd: %s", m_buffer);
    length = strlen(m_buffer);
    numBytesRx = SendCmdAndGetResponse(m_buffer, length, m_buffer, SERIAL_BUF_LENGTH, MILLISEC_1000);
    printf("response: %s", m_buffer);
    Sleep(1000);

    sprintf(m_buffer, "sens:det:rate M\n");
    printf("Sending cmd: %s", m_buffer);
    length = strlen(m_buffer);
    SendCmd(m_buffer, length);
    Sleep(2000);

    sprintf(m_buffer, "det:rate?\n");
    printf("Sending cmd: %s", m_buffer);
    length = strlen(m_buffer);
    numBytesRx = SendCmdAndGetResponse(m_buffer, length, m_buffer, SERIAL_BUF_LENGTH, MILLISEC_1000);
    printf("response: %s", m_buffer);
    Sleep(500);

    sprintf(m_buffer, "rout:adv on\n");
    printf("%ld ms, Sending cmd: %s", cmdTimer.GetElapsedMillisec(), m_buffer);
    length = strlen(m_buffer);
    SendCmd(m_buffer, length);

    sprintf(m_buffer, "ROUT:FUNC OFF\n");
    printf("%ld ms, Sending cmd: %s", cmdTimer.GetElapsedMillisec(), m_buffer);
    length = strlen(m_buffer);
    SendCmd(m_buffer, length);

    sprintf(m_buffer, "*trg\n");
    printf("%ld ms, Sending cmd: %s", cmdTimer.GetElapsedMillisec(), m_buffer);
    length = strlen(m_buffer);
    SendCmd(m_buffer, length);
#endif

}
Beispiel #5
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)
      //---
      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;
}
void TestMgr::CalibrateTempToPwm(void) {

	// int responseBytes;
	// bool outOfOrderFlag = false;
	UtilTimer runTimer;
	UtilTimer startAveragingTimer;
	uint16_t startPwm = 10;
	uint16_t stopPwm = 100;
	uint16_t testPwm = startPwm;
	bool doExit = false;
	std::vector<float> tempVec;

	printf("Temp to PWM Calibrate Thread Start\n");

	// Open file to store calibration data
	std::ofstream tempToPwmStream;
	std::stringstream fileNameSs;
	fileNameSs << "C:/ES/VocPhase1Test/PidData/TempToPwm.cpp";
	std::string fileName = fileNameSs.str();
	tempToPwmStream.open(fileName.c_str(), (std::ios::trunc | std::ios::out));
	if (tempToPwmStream.is_open()) {
		tempToPwmStream << "struct TempToPwm_t {" << std::endl;
		tempToPwmStream << "\tfloat temp;" << std::endl;
		tempToPwmStream << "\tuint8_t pwm;" << std::endl;
		tempToPwmStream << "};" << std::endl;
		tempToPwmStream << std::endl;
		tempToPwmStream << "TempToPwm_t tempToPwm[] = {" << std::endl;
	}

	m_Sub20.TurnOffCooler();

	runTimer.ResetCountdownTimer(20000);
	startAveragingTimer.ResetCountdownTimer(10000);

	while (!doExit) {
		if (m_AbortFlag) {
			doExit = true;
			break;
		}

		if (startAveragingTimer.IsCountdownTimerExpired()) {
			if (ReadTemp()) {
				printf("\n\nTempToPwm: temperature(%d):  %f, mean: %f, stdev: %f\n", testPwm, m_PlateTempDegreesC, m_TempMean, m_TempStdev);
				tempVec.push_back(m_PlateTempDegreesC);
			}

			//if (m_PlateTempDegreesC >= 50.0) {
			//    m_Sub20.TurnOffCooler();
			//}
		}

		if (runTimer.IsCountdownTimerExpired() && (m_TempStdev < 0.15)) {
			float tempSum = std::accumulate(tempVec.begin(), tempVec.end(), 0.0);
			float tempMean = tempSum / tempVec.size();
			unsigned int pwm = testPwm;
			if (tempToPwmStream.is_open()) {
				tempToPwmStream << "\t{ "
					<< std::setprecision(3) << tempMean << ", "
					<< pwm << " },"
					<< std::endl;
			}

			printf("\n\nTempToPwm: Avg temperature for pwm %d is %f, mean: %f, stdev: %f\n", testPwm, tempMean, m_TempMean, m_TempStdev);
			printf("TempToPwm: Process new pwm: %d\n", testPwm);
			QThread::msleep(1000);

			// Set new pwm
			m_Sub20.HeaterPwmUpdate(testPwm);

			// Update for next time
			testPwm++;

			// Check if we are at the end of run
			if (testPwm >= stopPwm) {
				if (tempToPwmStream.is_open()) {
					tempToPwmStream << "};" << std::endl;
					tempToPwmStream.close();
				}
				doExit = true;
				break;
			}

			runTimer.ResetCountdownTimer(20000);
			startAveragingTimer.ResetCountdownTimer(5000);
			tempVec.clear();
		}

		QThread::msleep(1000);
	}

	printf("Calibrate Thread Exit\n");

	QThread::msleep(100);

	// Signal to any slots listening
	DoneSignal();
}