int main(int argc, char const *argv[]) { int trials = 1; int i, dim, **city; float opt_value, prec_err, best_dist, **dist; clock_t start; clock_t end; int succ_times; // = times of finding optima / trials float run_time; float total_best_dist; FILE *f, *fw; if (argc == 2) { f = fopen(argv[1], "r"); } else if (argc == 3) { f = fopen(argv[1], "r"); trials = atoi(argv[2]); } else { printf("Usage: main_cpu / main_gpu [alg] [data file] [trials]\n"); return -1; } fw = fopen("result_cpu.txt", "w"); dim = readHeader(f, fw); // read nodes if (dim == 442) city = readExp(f, dim); else city = readNorm(f, dim); dist = genDistMatrix(city, dim); // get optimal value opt_value = getOptValue(dim); prec_err = opt_value*0.01; total_best_dist = 0; run_time = 0; succ_times = 0; // run serveral times to get average results for (i = 0; i < trials; ++i) { start = clock(); best_dist = TabuSearch(dist, dim); end = clock(); run_time += (float)(end-start); total_best_dist += best_dist; printf("Shortest distance: %f\n", best_dist); if (best_dist <= opt_value+prec_err && best_dist >= opt_value-prec_err) { succ_times++; } } printf("\n"); fprintf(fw, "Search Algorithm: Tabu Search\n"); fprintf(fw, "Trials: %d\n", trials); fprintf(fw, "Average Best Distance: %.2f\n", ((float)total_best_dist/(float)trials)); fprintf(fw, "Average Run Time: %.2f\n", (float)(run_time/trials)/CLOCKS_PER_SEC); fprintf(fw, "Success Rate: %f\n", (float)((float)succ_times/(float)trials*(float)100)); free(dist); free(city); return 0; }
/*----------------------------------------------------------------------------*/ int main(int argc, char *argv[]) { QApplication a(argc, argv); a.addLibraryPath(a.applicationDirPath() + "/plugins"); config = new DDAConfig(&a); if(config->fileExists() && config->isError()) { QMessageBox::critical(NULL, QObject::tr("Error load config"), config->message()); } translator = new Translator(&a); QString locale; locale = config->settings().localeName; if(locale.isEmpty()) locale = QLocale::system().name(); if(!translator->load("dda-messages.xml") && !translator->load("dda-messages.xml", QDir::currentPath()) && !translator->load("dda-messages.xml", QLibraryInfo::location(QLibraryInfo::TranslationsPath)) && locale != "C") { QString error = QString("Error load language file '%1': %2").arg("dda-messages.xml").arg(translator->errorString()); QMessageBox::critical(NULL, "Error translation", error); if(config->settings().localeName.isEmpty()) { DDASettings s = config->settings(); s.localeName = "C"; config->setSettings(s); } } else { if(!translator->setLang(locale)) { QString error = QString("Error set language: %1").arg(translator->errorString()); QMessageBox::critical(NULL, "Error translation", error); if(config->settings().localeName.isEmpty()) { DDASettings s = config->settings(); s.localeName = "C"; config->setSettings(s); } } else if(config->settings().localeName.isEmpty()) { DDASettings s = config->settings(); s.localeName = QLocale::system().name(); config->setSettings(s); } } a.installTranslator(translator); database = new DDADatabase(&a); if(database->isError()) { QMessageBox::critical(NULL, QObject::tr("Error open database"), database->message()); } QStringList profiles = config->profileList(); /* if(profiles.size() > 1) { ProfileSelectDialog dlg; if(dlg.exec() != QDialog::Accepted || dlg.selectedProfile() < 0 || dlg.selectedProfile() > profiles.size()) return 1; config->setProfileIndex(dlg.selectedProfile()); } else */ if(profiles.isEmpty()) { DDAProfile profile; config->defaultProfle(&profile); EditProfileDialog dlg; dlg.setProfile(profile); if(dlg.exec() != QDialog::Accepted) return 1; config->addProfile(dlg.profile()); config->setProfileIndex(0); } int defaultProfile = getOptValue("profile", 'p', -1).toInt(); if(defaultProfile > 0) config->setProfileIndex(defaultProfile - 1); session = new DDAMeasureSession(&a); if(getOptSwitch("demo", 'd') || getOptSwitch("demo-mode", 'D')) controller = new DemoController(&a); else controller = new DDAController(&a); QObject::connect(controller, SIGNAL(measure(double,double,int)), session, SLOT(addMeasure(double,double,int))); QObject::connect(controller, SIGNAL(serialReceived(QString)), session, SLOT(setSerial(QString))); QObject::connect(controller, SIGNAL(endOfMeasuring()), session, SLOT(onEndOfMeasuring())); QObject::connect(controller, SIGNAL(noParticle()), session, SLOT(onNoParticle())); QObject::connect(controller, SIGNAL(measure(double,double,int)), database, SLOT(measure(double,double,int))); QObject::connect(controller, SIGNAL(serialReceived(QString)), database, SLOT(setSerial(QString))); QObject::connect(controller, SIGNAL(endOfMeasuring()), database, SLOT(onEndOfMeasuring())); QObject::connect(controller, SIGNAL(noParticle()), database, SLOT(onNoParticle())); MeasureWindow w; w.show(); //w.showMaximized(); return a.exec(); }