Exemple #1
0
int main(int argc, char *argv[]) //this main function should return error value, 0 = OK
{
    /* check for program parameters */
    if((getParams(argc, argv) < 0)) {help(); return -1;}

    QCoreApplication a(argc, argv);

    // Task parented to the application so that it will be deleted by the application.
    Task *task = new Task(&a);

    // Initialize the network
    task->_init(static_cast<FG::pdfType>(pdfType), nStates, vRange, extRatio, gVar);

    // train or load jpd?
    if(jpdName.isNull() || jpdName.isEmpty()) //then train jpd
    {
        if(datasetName.isNull() || datasetName.isEmpty())
        {
            printf("Cannot train jpd! Missing dataset file!!!\n"); return -1;
        } else
        {
            if(!task->_trainJPD(datasetName))
            {
                printf("Error during training jpd!\n"); return -1;
            }
            else
            {
                resultFileName = datasetName;
                resultFileName.append(".res");
            }
        }
    }
    else
    {
        if(!task->_loadJPD(jpdName))
        {
            printf("Error during loading the jpd file!\n"); return -1;
        }
        else
        {
            resultFileName = jpdName;
            resultFileName.replace(".jpd",".res");
        }
    }
    task->_setResultFile(resultFileName);   //this filename will be used during run()
    task->_setInferMode(datasetInference);

    /* print parameter information */
    qDebug() << QString("Dataset name: %1").arg(datasetName);
    qDebug() << QString("JPD name: %1").arg(jpdName);
    qDebug() << QString("Result filename: %1").arg(resultFileName);

    // This will cause the application to exit when the task signals finished.
    QObject::connect(task, SIGNAL(finished()), &a, SLOT(quit()));

    // This will run the task from the application event loop.
    QTimer::singleShot(0, task, SLOT(run()));

    return a.exec();

}