コード例 #1
0
ファイル: v_lidar_window.cpp プロジェクト: wicron/vlidar
void VLidarWindow::updateLidarGraphics()
{
    writeLogToFile();
    if(isConnectedToLidar() && updateLidar()){
        drawSignal();
        drawSignal2D();
    }
}
コード例 #2
0
ファイル: log.c プロジェクト: SnakeHunt2012/cloudfs
void formatLog(const char * format, 
               const char * fileName, 
               const char * funcName, 
               unsigned int line, 
               unsigned int level, 
               va_list ap)
{
    char aucTime[MAX_FORMAT_TIME_LEN] = {0};
    char aucBuff[MAX_LOG_BUFF] = {0};
    char * pBuff = NULL;

    // format time
    formatTime(aucTime);

    pBuff = aucBuff;

    pBuff += sprintf(pBuff, "%s ", aucTime);

    // format the log level
    switch(level)
    {
        case DEBUG:
            pBuff += sprintf(pBuff, "%s", "[D]");
            break;
        case ERROR:
            pBuff += sprintf(pBuff, "%s", "[E]");
            break;
        default:
            return;
    }

    // format the function name
    pBuff += sprintf(pBuff, "[%s]", funcName);

    // format the data which need display
    pBuff += vsprintf(pBuff, format, ap);

    // format the file name
    pBuff += sprintf(pBuff, "[%s, %d]\r\n", fileName, line);

    // write the format string into a file
    writeLogToFile(aucBuff);
}
コード例 #3
0
ファイル: main.cpp プロジェクト: utzms/StarcraftProjectAdvpt
void startBuildListOptimizer(std::string race, std::string strategy, std::string unit, size_t timeLimit, size_t populationSize)
{
    size_t individualSize = 40;
    const int selectionRate = 10;
    const size_t mutationRate = 10;
    const size_t reproductionRate = 25;
    const size_t initPopSize = populationSize;
    const size_t generations = 100;
    const size_t accuracy = 100;
    const size_t ntargets = 100000;
    std::cout << "The optimization is done with the following rates:" << std::endl;
    std::cout << "Selection Rate: " << std::to_string(selectionRate) << std::endl;
    std::cout << "Mutation Rate: " << std::to_string(mutationRate) << std::endl;
    std::cout << "Reproduction Rate: " << std::to_string(reproductionRate) << std::endl;
    std::cout << "The size of every individual is " << std::to_string(individualSize) << " entries." << std::endl;
    std::cout << "We start with " << std::to_string(initPopSize) << " Individuals." << std::endl;

    if (!strategy.compare("Push"))
    {
        if (!race.compare("Protoss"))
        {
            BuildListOptimizer<Protoss,Push> opt(accuracy,individualSize);
            try {
                opt.initialize(unit,ntargets,timeLimit,initPopSize);
                opt.optimize(unit,ntargets,timeLimit,generations,reproductionRate,mutationRate,selectionRate);
            } catch(std::exception &e)
            {
                std::cerr << "Fehler\t" <<e.what() << std::endl;
            }
            std::cout << "Final size of the population: " << opt.getPopulationSize() << std::endl;
            std::cout << "The top 1 is:" << std::endl;
            std::cout << opt.getFittestGroup(1) << std::endl;
            opt.printBest(timeLimit,unit);
            writeLogToFile(opt);
        } else if (!race.compare("Zerg"))
        {
            individualSize = 80;
            BuildListOptimizer<Zerg,Push> opt(accuracy,individualSize);
            try {
                opt.initialize(unit,ntargets,timeLimit,initPopSize);
                opt.optimize(unit,ntargets,timeLimit,generations,reproductionRate,mutationRate,selectionRate);
            } catch(std::exception &e)
            {
                std::cerr << "Fehler\t" <<e.what() << std::endl;
            }
            std::cout << "Final size of the population: " << opt.getPopulationSize() << std::endl;
            std::cout << "The top 1 is:" << std::endl;
            std::cout << opt.getFittestGroup(1) << std::endl;
            opt.printBest(timeLimit,unit);
            writeLogToFile(opt);
        } else if (!race.compare("Terran"))
        {
            BuildListOptimizer<Terran,Push> opt(accuracy,individualSize);
            try {
                opt.initialize(unit,ntargets,timeLimit,initPopSize);
                opt.optimize(unit,ntargets,timeLimit,generations,reproductionRate,mutationRate,selectionRate);
            } catch(std::exception &e)
            {
                std::cerr << "Fehler\t" <<e.what() << std::endl;
            }
            std::cout << "Final size of the population: " << opt.getPopulationSize() << std::endl;
            std::cout << "The top 1 is:" << std::endl;
            std::cout << opt.getFittestGroup(1) << std::endl;
            opt.printBest(timeLimit,unit);
            writeLogToFile(opt);
        } else
        {
            throw std::invalid_argument("No known race");
        }
    } else if (!strategy.compare("Rush"))
    {
        if (!race.compare("Protoss"))
        {
            BuildListOptimizer<Protoss,Rush> opt(accuracy,individualSize);
            try {
                opt.initialize(unit,ntargets,timeLimit,initPopSize);
                opt.optimize(unit,ntargets,timeLimit,generations,reproductionRate,mutationRate,selectionRate);
            } catch(std::exception &e)
            {
                std::cerr << "Fehler\t" <<e.what() << std::endl;
            }
            std::cout << "Final size of the population: " << opt.getPopulationSize() << std::endl;
            std::cout << "The top 1 is:" << std::endl;
            std::cout << opt.getFittestGroup(1) << std::endl;
            opt.printBest(timeLimit,unit);
            writeLogToFile(opt);
        } else if (!race.compare("Zerg"))
        {
            individualSize = 80;
            BuildListOptimizer<Zerg,Rush> opt(accuracy,individualSize);
            try {
                opt.initialize(unit,ntargets,timeLimit,initPopSize);
                opt.optimize(unit,ntargets,timeLimit,generations,reproductionRate,mutationRate,selectionRate);
            } catch(std::exception &e)
            {
                std::cerr << "Fehler\t" <<e.what() << std::endl;
            }
            std::cout << "Final size of the population: " << opt.getPopulationSize() << std::endl;
            std::cout << "The top 1 is:" << std::endl;
            std::cout << opt.getFittestGroup(1) << std::endl;
            opt.printBest(timeLimit,unit);
            writeLogToFile(opt);
        } else if (!race.compare("Terran"))
        {
            BuildListOptimizer<Terran,Rush> opt(accuracy,individualSize);
            try {
                opt.initialize(unit,ntargets,timeLimit,initPopSize);
                opt.optimize(unit,ntargets,timeLimit,generations,reproductionRate,mutationRate,selectionRate);
            } catch(std::exception &e)
            {
                std::cerr << "Fehler\t" <<e.what() << std::endl;
            }
            std::cout << "Final size of the population: " << opt.getPopulationSize() << std::endl;
            std::cout << "The top 1 is:" << std::endl;
            std::cout << opt.getFittestGroup(1) << std::endl;
            opt.printBest(timeLimit,unit);

            writeLogToFile(opt);
        } else
        {
            throw std::invalid_argument("No known race");
        }
    } else
    {
        throw std::invalid_argument("No valid strategy");
    }
}