int main(int argc, char *argv[]) {
	bool verbose = false;
	/* Argomenti passati all'eseguibile */
	ArgumentList args = ArgumentList(argc, argv);

	if ( argc < 2 || argc > 3 ) {
		cerr << "Utilizzo: " << args.getFirst() << " [-v] <file_istanza_tsp>" << endl;
		cerr << "\t-v : verboso." << endl << endl;
		return -1;
	}
	else {
		cout << args.getFirst() << endl;
	}

	/* Istanza del problema */
	TSPInstance< w_type > *problema = new TSPInstance< w_type >;
	/* Loader dell'istanza */
	TSPReader< w_type > *reader = new TSPReader< w_type >(problema);
	/* Nome del file da cui caricare l'istanza */
	string filename = "";
	/* Soluzione del problema */
	vector< vertice * > *soluzione;

	verbose = args.getSwitch("-v");
	filename = args.getFirst();

	reader->setInputFile(filename);

	if ( ! reader->read() ) {
		cerr << "Impossibile leggere l'istanza." << endl;
		delete problema;
		delete reader;
		return -1;
	}

	if ( verbose ) {
		cout << "Istanza caricata, sta per essere eseguito l'algoritmo di risoluzione." << endl;
	}

	soluzione = new vector< vertice * >;

	christofides(problema->getGrafo(), soluzione);
	stampaDimensioneCircuito(*soluzione);
	cout << endl;
	stampaCostoCircuito(*soluzione, *(problema->getGrafo()));

	delete soluzione;
	delete problema;
	delete reader;
	return 0;
}
Exemple #2
0
int main(int argc, char *argv[])
{
  ArgumentList *argList = new ArgumentList(argc, argv);

#if QT_VERSION < 0x050000
  QApplication::setGraphicsSystem(QLatin1String("raster"));
#endif

  QString packagesToInstall;
  QString arg;

  for (int c=1; c<argc; c++)
  {
    arg = argv[c];
    if (arg.contains("pkg.tar*"))
    {
      packagesToInstall += arg + ",";
    }
  }

  QtSingleApplication app( StrConstants::getApplicationName(), argc, argv );

  if (app.isRunning())
  {
    if (argList->getSwitch("-sysupgrade"))
    {
      app.sendMessage("SYSUPGRADE");
    }
    else if (argList->getSwitch("-sysupgrade-noconfirm"))
    {
      app.sendMessage("SYSUPGRADE_NOCONFIRM");
    }
    else if (argList->getSwitch("-close"))
    {
      app.sendMessage("CLOSE");
    }
    else if (argList->getSwitch("-hide"))
    {
      app.sendMessage("HIDE");
    }
    else if (!packagesToInstall.isEmpty())
    {
      app.sendMessage(packagesToInstall);
    }
    else
    {
      app.sendMessage("RAISE");
    }

    return 0;
  }

  //This sends a message just to awake the socket-based QtSingleApplication engine
  app.sendMessage("RAISE");

  QTranslator appTranslator;
  appTranslator.load(":/resources/translations/octopi_" +
                     QLocale::system().name());
  app.installTranslator(&appTranslator);

  if (argList->getSwitch("-help")){
    std::cout << StrConstants::getApplicationCliHelp().toLatin1().data() << std::endl;
    return(0);
  }
  else if (argList->getSwitch("-version")){
    std::cout << "\n" << StrConstants::getApplicationName().toLatin1().data() <<
                 " " << StrConstants::getApplicationVersion().toLatin1().data() << "\n" << std::endl;
    return(0);
  }

  if (UnixCommand::isRootRunning() && !WMHelper::isKDERunning()){
    QMessageBox::critical( 0, StrConstants::getApplicationName(), StrConstants::getErrorRunningWithRoot());
    return ( -2 );
  }

  MainWindow w;
  app.setActivationWindow(&w);
  app.setQuitOnLastWindowClosed(false);

#if QT_VERSION < 0x050000
  #ifndef NO_GTK_STYLE
  if (!argList->getSwitch("-style"))
  {
    if (UnixCommand::getLinuxDistro() == ectn_MANJAROLINUX &&
        (!WMHelper::isKDERunning() && (!WMHelper::isRazorQtRunning())))
    {
      app.setStyle(new QGtkStyle());
    }
    else if(UnixCommand::getLinuxDistro() != ectn_CHAKRA)
    {
      app.setStyle(new QCleanlooksStyle());
    }
  }
  #endif
#endif

  if (argList->getSwitch("-sysupgrade-noconfirm"))
  {
    w.setCallSystemUpgradeNoConfirm();
  }
  else if (argList->getSwitch("-sysupgrade"))
  {
    w.setCallSystemUpgrade();
  }

  if (!packagesToInstall.isEmpty())
  {
    QStringList packagesToInstallList =
        packagesToInstall.split(",", QString::SkipEmptyParts);

    w.setPackagesToInstallList(packagesToInstallList);
  }

  w.setRemoveCommand("Rcs"); //argList->getSwitchArg("-removecmd", "Rcs"));
  w.show();

  QResource::registerResource("./resources.qrc");

  return app.exec();
}
Exemple #3
0
int main(int argc, char *argv[])
{
    ArgumentList *argList = new ArgumentList(argc, argv);
    QString packagesToInstall;
    QString arg;

    for (int c=1; c<argc; c++)
    {
        arg = argv[c];
        if (arg.contains(QRegExp("pkg.tar.[gz|xz]")))
        {
            packagesToInstall += arg + ",";
        }
    }

    QtSingleApplication app( StrConstants::getApplicationName(), argc, argv );

    if (app.isRunning())
    {
        if (argList->getSwitch("-sysupgrade"))
        {
            app.sendMessage("SYSUPGRADE");
        }
        else if (argList->getSwitch("-sysupgrade-noconfirm"))
        {
            app.sendMessage("SYSUPGRADE_NOCONFIRM");
        }
        else if (argList->getSwitch("-close"))
        {
            app.sendMessage("CLOSE");
        }
        else if (argList->getSwitch("-hide"))
        {
            app.sendMessage("HIDE");
        }
        else if (!packagesToInstall.isEmpty())
        {
            app.sendMessage(packagesToInstall);
        }
        else
        {
            app.sendMessage("RAISE");
        }

        return 0;
    }
    else if (UnixCommand::isAppRunning("octopi", false))
        return 0;

    //This sends a message just to enable the socket-based QtSingleApplication engine
    app.sendMessage("RAISE");

    QTranslator appTranslator;
    bool success = appTranslator.load(":/resources/translations/octopi_" +
                                      QLocale::system().name());
    if (!success)
    {
        appTranslator.load(":/resources/translations/octopi_en.qm");
    }

    app.installTranslator(&appTranslator);

    if (argList->getSwitch("-help")) {
        std::cout << StrConstants::getApplicationCliHelp().toLatin1().data() << std::endl;
        return(0);
    }
    else if (argList->getSwitch("-version")) {
        std::cout << "\n" << StrConstants::getApplicationName().toLatin1().data() <<
                  " " << StrConstants::getApplicationVersion().toLatin1().data() << "\n" << std::endl;
        return(0);
    }

    if (UnixCommand::isRootRunning() && !WMHelper::isKDERunning()) {
        QMessageBox::critical( 0, StrConstants::getApplicationName(), StrConstants::getErrorRunningWithRoot());
        return ( -2 );
    }

    MainWindow w;
    app.setActivationWindow(&w);
    app.setQuitOnLastWindowClosed(false);

    if (argList->getSwitch("-sysupgrade-noconfirm"))
    {
        w.setCallSystemUpgradeNoConfirm();
    }
    else if (argList->getSwitch("-sysupgrade"))
    {
        w.setCallSystemUpgrade();
    }

    if (argList->getSwitch("-d"))
    {
        //If user chooses to switch debug info on...
        w.turnDebugInfoOn();
    }

    if (!packagesToInstall.isEmpty())
    {
        QStringList packagesToInstallList =
            packagesToInstall.split(",", QString::SkipEmptyParts);

        w.setPackagesToInstallList(packagesToInstallList);
    }

    w.setRemoveCommand("Rcs"); //argList->getSwitchArg("-removecmd", "Rcs"));
    w.show();

    QResource::registerResource("./resources.qrc");

    return app.exec();
}
int main(int argc, char *argv[]) {
	bool verbose = false;
	unsigned int distribuzione[21] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
	double maxB = 0.5, minB = std::numeric_limits< double >::max(), averageB = 0, tempB = 1.0;
	/* Argomenti passati all'eseguibile */
	ArgumentList args = ArgumentList(argc, argv);

	if ( argc < 2 || argc > 3 ) {
		cerr << "Utilizzo: " << args.getFirst() << " [-v] <file_istanza_tsp>" << endl;
		cerr << "\t-v : verboso." << endl << endl;
		return -1;
	}
	else {
		cout << endl << args.getFirst() << endl << endl;
	}

	/* Istanza del problema */
	TSPInstance< w_type > *problema = new TSPInstance< w_type >;
	/* Loader dell'istanza */
	TSPReader< w_type > *reader = new TSPReader< w_type >(problema);
	/* Nome del file da cui caricare l'istanza */
	string filename = "";
	istringstream converter;

	verbose = args.getSwitch("-v");
	filename = args.getFirst();

	reader->setInputFile(filename);

	if ( ! reader->read() ) {
		cerr << "Impossibile leggere l'istanza." << endl;
		delete problema;
		delete reader;
		return -1;
	}

	if ( verbose ) {
		cout << "Istanza caricata, sta per essere eseguito l'algoritmo di calcolo della beta metricita' del grafo." << endl;
	}

	unsigned int counter = ((problema->getGrafo())->numVertici() * ((problema->getGrafo())->numVertici() - 1) * ((problema->getGrafo())->numVertici() - 2)) / 2;

	for ( Grafo< w_type >::vertice_iterator x = (problema->getGrafo())->lista_vertici.begin(); x != --((problema->getGrafo())->lista_vertici.end()); x++ ) {
		Grafo< w_type >::vertice_iterator temp = x;
		for ( Grafo< w_type >::vertice_iterator y = ++temp; y != --((problema->getGrafo())->lista_vertici.end()); y++ ) {
			temp = y;
			for ( Grafo< w_type >::vertice_iterator z = ++temp; z != (problema->getGrafo())->lista_vertici.end(); z++ ) {

				w_type xy = (problema->getGrafo())->getPesoArcoCompreso(*x, *y), xz = (problema->getGrafo())->getPesoArcoCompreso(*x, *z), yz = (problema->getGrafo())->getPesoArcoCompreso(*y, *z);

				/* Primo vincolo */
				tempB = 1.01;
				while ( static_cast< double >(xy) < static_cast< double >(tempB * (xz + yz)) && tempB >= 0 ) {
					tempB -= 0.01;
				}
				if ( tempB > maxB ) {
					maxB = tempB;
				}
				if ( tempB < minB ) {
					minB = tempB;
				}
				distribuzione[mappaDistribuzione(tempB)] += 1;
				if ( mappaDistribuzione(tempB) != 20 ) {
					averageB += tempB;
				}

				/* Secondo vincolo */
				tempB = 1.01;
				while ( static_cast< double >(xz) < static_cast< double >(tempB * (xy + yz)) && tempB >= 0 ) {
					tempB -= 0.01;
				}
				if ( tempB > maxB ) {
					maxB = tempB;
				}
				if ( tempB < minB ) {
					minB = tempB;
				}
				distribuzione[mappaDistribuzione(tempB)] += 1;
				if ( mappaDistribuzione(tempB) != 20 ) {
					averageB += tempB;
				}

				/* Terzo vincolo */
				tempB = 1.01;
				while ( static_cast< double >(yz) < static_cast< double >(tempB * (xz + xy)) && tempB >= 0 ) {
					tempB -= 0.01;
				}
				if ( tempB > maxB ) {
					maxB = tempB;
				}
				if ( tempB < minB ) {
					minB = tempB;
				}
				distribuzione[mappaDistribuzione(tempB)] += 1;
				if ( mappaDistribuzione(tempB) != 20 ) {
					averageB += tempB;
				}
			}
		}
	}

	averageB /= (counter - distribuzione[20]);

	cout << fixed << setprecision (3) << endl;
	cout << "Il valore massimo di beta nel grafo è pari a: " << maxB << endl;
	cout << "Il valore minimo di beta nel grafo è pari a: " << minB << endl;
	cout << "Il valore medio di beta nel grafo è pari a: " << averageB << endl;
	cout << endl;
	cout << "La distribuzione è la seguente: " << endl;
	cout << endl;
	cout << "0.00 - 0.05 : " << static_cast< double >(((static_cast< double >(distribuzione[0]) / 100) * 100) / (counter / 100)) << "%" << endl;
	cout << "0.06 - 0.10 : " << static_cast< double >(((static_cast< double >(distribuzione[1]) / 100) * 100) / (counter / 100)) << "%" << endl;
	cout << "0.11 - 0.15 : " << static_cast< double >(((static_cast< double >(distribuzione[2]) / 100) * 100) / (counter / 100)) << "%" << endl;
	cout << "0.16 - 0.20 : " << static_cast< double >(((static_cast< double >(distribuzione[3]) / 100) * 100) / (counter / 100)) << "%" << endl;
	cout << "0.21 - 0.25 : " << static_cast< double >(((static_cast< double >(distribuzione[4]) / 100) * 100) / (counter / 100)) << "%" << endl;
	cout << "0.26 - 0.30 : " << static_cast< double >(((static_cast< double >(distribuzione[5]) / 100) * 100) / (counter / 100)) << "%" << endl;
	cout << "0.31 - 0.35 : " << static_cast< double >(((static_cast< double >(distribuzione[6]) / 100) * 100) / (counter / 100)) << "%" << endl;
	cout << "0.36 - 0.40 : " << static_cast< double >(((static_cast< double >(distribuzione[7]) / 100) * 100) / (counter / 100)) << "%" << endl;
	cout << "0.41 - 0.45 : " << static_cast< double >(((static_cast< double >(distribuzione[8]) / 100) * 100) / (counter / 100)) << "%" << endl;
	cout << "0.46 - 0.50 : " << static_cast< double >(((static_cast< double >(distribuzione[9]) / 100) * 100) / (counter / 100)) << "%" << endl;
	cout << "0.51 - 0.55 : " << static_cast< double >(((static_cast< double >(distribuzione[10]) / 100) * 100) / (counter / 100)) << "%" << endl;
	cout << "0.56 - 0.60 : " << static_cast< double >(((static_cast< double >(distribuzione[11]) / 100) * 100) / (counter / 100)) << "%" << endl;
	cout << "0.61 - 0.65 : " << static_cast< double >(((static_cast< double >(distribuzione[12]) / 100) * 100) / (counter / 100)) << "%" << endl;
	cout << "0.66 - 0.70 : " << static_cast< double >(((static_cast< double >(distribuzione[13]) / 100) * 100) / (counter / 100)) << "%" << endl;
	cout << "0.71 - 0.75 : " << static_cast< double >(((static_cast< double >(distribuzione[14]) / 100) * 100) / (counter / 100)) << "%" << endl;
	cout << "0.76 - 0.80 : " << static_cast< double >(((static_cast< double >(distribuzione[15]) / 100) * 100) / (counter / 100)) << "%" << endl;
	cout << "0.81 - 0.85 : " << static_cast< double >(((static_cast< double >(distribuzione[16]) / 100) * 100) / (counter / 100)) << "%" << endl;
	cout << "0.86 - 0.90 : " << static_cast< double >(((static_cast< double >(distribuzione[17]) / 100) * 100) / (counter / 100)) << "%" << endl;
	cout << "0.91 - 0.95 : " << static_cast< double >(((static_cast< double >(distribuzione[18]) / 100) * 100) / (counter / 100)) << "%" << endl;
	cout << "0.96 - 1.00 : " << static_cast< double >(((static_cast< double >(distribuzione[19]) / 100) * 100) / (counter / 100)) << "%" << endl;
	cout << "     > 1.00 : " << static_cast< double >(((static_cast< double >(distribuzione[20]) / 100) * 100) / (counter / 100)) << "%" << endl;
	cout << endl;

	return 0;
}
Exemple #5
0
int main(int argc, char *argv[])
{
    bool debugInfo = false;

    ArgumentList *argList = new ArgumentList(argc, argv);
    if (argList->getSwitch("-d"))
    {
        //If user chooses to switch debug info on...
        debugInfo = true;
    }

    if (debugInfo)
        qDebug() << QString("Octopi Notifier - " + StrConstants::getApplicationVersion() +
                            " (" + StrConstants::getQtVersion() + ")");

    if (UnixCommand::isAppRunning("octopi-notifier"))
    {
        qDebug() << "Aborting notifier as another instance is already running!";
        return (-1);
    }

    if (!QFile::exists(ctn_PACMANHELPER_BINARY))
    {
        qDebug() << "Aborting notifier as 'pacmanhelper' binary could not be found! [" << ctn_PACMANHELPER_BINARY << "]";
        return (-2);
    }

    if (!QFile::exists(ctn_DBUS_PACMANHELPER_SERVICE))
    {
        qDebug() << "Aborting notifier as 'pacmanhelper' DBus service could not be found! [" << ctn_DBUS_PACMANHELPER_SERVICE << "]";
        return (-3);
    }

    QApplication a(argc, argv);

#if QT_VERSION < 0x050000
#ifndef NO_GTK_STYLE
    QApplication::setGraphicsSystem(QLatin1String("raster"));

    if(!WMHelper::isKDERunning() && (!WMHelper::isLXQTRunning()) && (!WMHelper::isRazorQtRunning()))
    {
        qApp->setStyle(new QGtkStyle());
    }
    else
        qApp->setStyle(new QCleanlooksStyle);
#endif
#endif

    QTranslator appTranslator;
    appTranslator.load(":/resources/translations/octopi_" +
                       QLocale::system().name());

    a.installTranslator(&appTranslator);
    a.setQuitOnLastWindowClosed(false);

    MainWindow w;
    QResource::registerResource("./resources.qrc");

    if (debugInfo)
        w.turnDebugInfoOn();

    return a.exec();
}
int main(int argc, char *argv[]) {
	unsigned int n = 0;
	double beta = 0.0;
	bool verbose = false, correggi = false, shortest = false, l1 = false, l2 = false, linf = false, endpoint = false, interval = false;
	w_type maxPeso = 100000;
	string outfile = "";
	istringstream converter;
	GrafoNonOrientatoBetaMetrico_ListaArchi< w_type > grafo;
	TSPInstance< w_type > problema;
	TSPWriter< w_type > *writer;

	ArgumentList args = ArgumentList(argc, argv);

	if ( argc < 7 || argc > 9 ) {
		cerr << "Utilizzo: " << args.getFirst() << " [-c] [-v] [-s|-e|-l1|-l2|-li] -n <nodi> -b <beta> <outfile>" << endl;
		cerr << "\t-c\t : correggi se non beta metrico;" << endl;
		cerr << "\t-i\t : metrica intervallo (base, base*2beta);" << endl;
		cerr << "\t-s\t : metrica shortest path;" << endl;
		cerr << "\t-e\t : metrica endpoint;" << endl;
		cerr << "\t-l1\t : metrica spazio l1;" << endl;
		cerr << "\t-l2\t : metrica spazio l2;" << endl;
		cerr << "\t-li\t : metrica spazio linf;" << endl;
		cerr << "\t-v\t : verboso." << endl << endl;
		return -1;
	}
	else {
		cout << args.getFirst() << endl;
	}

	verbose = args.getSwitch("-v");
	correggi = args.getSwitch("-c");
	shortest = args.getSwitch("-s");
	interval = args.getSwitch("-i");
	endpoint = args.getSwitch("-e");
	l1 = args.getSwitch("-l1");
	l2 = args.getSwitch("-l2");
	linf = args.getSwitch("-li");
	converter.str(args.getSwitchArgument("-n"));
	converter >> n;
	converter.clear();
	converter.str(args.getSwitchArgument("-b"));
	converter >> beta;

	if ( n < 2 || beta < 0.5 ) {
		cerr << "Il numero di nodi del grafo dev'essere maggiore di 2 ed il valore di beta >= 0.5" << endl;
		return -1;
	}

	outfile = args.getFirst();

	grafo.clear();
	problema.clear();
	grafo.setBeta(beta);

	srand(time(NULL));

	if ( interval ) {
		/* Metrica intervall (base, base*2beta) */

		grafo.generaRandom(n);
	}
	else if ( shortest ) {
		/* Metrica shortest path */

		for ( unsigned int i(0); i < n; i++ ) {
			vertice *temp = grafo.aggiungiVertice();
			temp->setKey(i);
		}

		for ( Grafo< w_type >::vertice_iterator x = grafo.lista_vertici.begin(); x != --(grafo.lista_vertici.end()); x++ ) {
			Grafo< w_type >::vertice_iterator temp = x;
			for ( Grafo< w_type >::vertice_iterator y = ++temp; y != grafo.lista_vertici.end(); y++ ) {
				grafo.aggiungiArco(*x, *y, static_cast< w_type >(1.0 + (maxPeso * (rand() / (RAND_MAX + 1.0)))));
			}
		}

		map< pair<vertice*, vertice*>, w_type > distanze = FloydWarshall(grafo);

		for ( Grafo< w_type >::vertice_iterator x = grafo.lista_vertici.begin(); x != --(grafo.lista_vertici.end()); x++ ) {
			Grafo< w_type >::vertice_iterator temp = x;
			for ( Grafo< w_type >::vertice_iterator y = ++temp; y != grafo.lista_vertici.end(); y++ ) {
				if ( distanze[pair<vertice*, vertice*>(*x, *y)] < grafo.getPesoArcoCompreso(*x, *y) ) {
					(grafo.getArcoCompreso(*x, *y))->costo = distanze[pair<vertice*, vertice*>(*x, *y)];
				}
			}
		}
	}
	else if ( endpoint ) {
		/* Metrica endpoint */

		double beta = grafo.getBeta();
		double betaC = (pow(beta, 2.0) - pow(1 - beta, 2.0)) / (beta * (1 - beta));
		double betaN = (1 - beta) / beta;
		double betaNx = beta / (1 - beta);
		arco< w_type > *tempArco = 0, *minArco = 0, *maxArco = 0;

		for ( unsigned int i(0); i < n; i++ ) {
			vertice *temp = grafo.aggiungiVertice();
			temp->setKey(i);
		}

		for ( Grafo< w_type >::vertice_iterator x = grafo.lista_vertici.begin(); x != --(grafo.lista_vertici.end()); x++ ) {
			bool first = true;
			Grafo< w_type >::vertice_iterator temp = x;
			for ( Grafo< w_type >::vertice_iterator y = ++temp; y != grafo.lista_vertici.end(); y++ ) {
				double Bmin = (2 * pow(beta, 2.0)) / (1 - beta);
				double Bmax = (1 - beta) / (2 * pow(beta, 2.0));

				if (  y == ++(grafo.lista_vertici.begin()) && x == grafo.lista_vertici.begin() ) {
					tempArco = grafo.aggiungiArco(*x, *y, static_cast< w_type >(1.0 + (maxPeso * (rand() / (RAND_MAX + 1.0)))));
					minArco = tempArco;
					maxArco = tempArco;
				}
				else {
					tempArco = grafo.aggiungiArco(*x, *y, static_cast< w_type >(1.0 + (maxPeso * (rand() / (RAND_MAX + 1.0)))));
					tempArco->costo = static_cast< w_type >((tempArco->costo * betaC) + betaN);
					if ( first ) {
						Grafo< w_type >::vertice_iterator tempVertice = x;
						tempArco->costo *= grafo.getPesoArcoCompreso(*(--tempVertice), *x);
						first = false;
					}
					else {
						Grafo< w_type >::vertice_iterator tempVertice = y;
						tempArco->costo *= grafo.getPesoArcoCompreso(*x, *(--tempVertice));
					}

					if ( grafo.sonoArchiAdiacenti(tempArco, minArco) ) {
						Bmin = betaNx;
					}
					if ( grafo.sonoArchiAdiacenti(tempArco, maxArco) ) {
						Bmax = betaN;
					}

					if ( tempArco->costo > (Bmin * minArco->costo) || tempArco->costo < (Bmax * maxArco->costo) ) {
						tempArco->costo = static_cast< w_type >(floor((Bmax * maxArco->costo) + (((Bmin * minArco->costo) - (Bmax * maxArco->costo)) * (rand() / (RAND_MAX + 1.0)))));
					}

					if ( tempArco-> costo > maxArco->costo ) {
						maxArco = tempArco;
					}
					if ( tempArco->costo < minArco->costo ) {
						minArco = tempArco;
					}
				}
			}
		}
	}
	else {
		Space< w_type > spazio;
		map< vertice *, Point * > verticeToPoint;

		for ( unsigned int i(0); i < n; i++ ) {
			vertice *temp = grafo.aggiungiVertice();
			temp->setKey(i);
			verticeToPoint[temp] = spazio.addPoint(static_cast< w_type >(1.0 + (maxPeso * (rand() / (RAND_MAX + 1.0)))), static_cast< w_type >(1.0 + (maxPeso * (rand() / (RAND_MAX + 1.0)))));
		}

		for ( Grafo< w_type >::vertice_iterator v = grafo.lista_vertici.begin(); v != --(grafo.lista_vertici.end()); v++ ) {
			Grafo< w_type >::vertice_iterator temp = v;
			for ( Grafo< w_type >::vertice_iterator u = ++temp; u != grafo.lista_vertici.end(); u++ ) {
				if ( l1 ) {
					/* Metrica spazio l1 */
					grafo.aggiungiArco(*v, *u, static_cast< w_type >(spazio.l1Distance(verticeToPoint[*v], verticeToPoint[*u])));
				}
				else if ( l2 ) {
					/* Metrica spazio l2 */
					grafo.aggiungiArco(*v, *u, static_cast< w_type >(spazio.l2Distance(verticeToPoint[*v], verticeToPoint[*u])));
				}
				else if ( linf ) {
					/* Metrica spazio linf */
					grafo.aggiungiArco(*v, *u, static_cast< w_type >(spazio.lInfDistance(verticeToPoint[*v], verticeToPoint[*u])));
				}
			}
		}
	}

	if ( verbose ) {
		cout << "Grafo generato con n = " << grafo.numVertici() << " ed m = " << grafo.numArchi() << endl;
	}

	if ( correggi ) {
		while ( !grafo.verifyBetaMetric(correggi) ) {};
		if ( verbose ) {
			cout << "Il grafo è risultato " << grafo.getBeta() << "-metrico." << endl;
		}
	}

	problema.setProblemType("TSP");
	problema.setEdgeWType("EXPLICIT");
	problema.setEdgeWFormat("UPPER_ROW");
	problema.setGrafo(&grafo);

	writer = new TSPWriter< w_type >(&problema);
	writer->setOutputFile(outfile);
	if ( !writer->write() ) {
		cerr << "Si e' verificato un problema durante il salvataggio dell'istanza su file." << endl;
		delete writer;
		return 1;
	}
	delete writer;

	if ( verbose ) {
		cout << "L'istanza e' stata salvata in " << outfile << endl;
	}

	return 0;
}
int main(int argc, char *argv[]) {
	bool verbose = false;
	unsigned int intervalli = 10;
	/* Argomenti passati all'eseguibile */
	ArgumentList args = ArgumentList(argc, argv);

	if ( argc < 4 || argc > 5 ) {
		cerr << "Utilizzo: " << args.getFirst() << " [-v] -k <intervalli> <file_istanza_tsp>" << endl;
		cerr << "\t-k: numero di intervalli;" << endl;
		cerr << "\t-v : verboso." << endl << endl;
		return -1;
	}
	else {
		cout << endl << args.getFirst() << endl << endl;
	}

	/* Istanza del problema */
	TSPInstance< w_type > *problema = new TSPInstance< w_type >;
	/* Loader dell'istanza */
	TSPReader< w_type > *reader = new TSPReader< w_type >(problema);
	/* Nome del file da cui caricare l'istanza */
	string filename = "";
	istringstream converter;

	verbose = args.getSwitch("-v");
	converter.str(args.getSwitchArgument("-k"));
	converter >> intervalli;
	filename = args.getFirst();

	reader->setInputFile(filename);

	if ( ! reader->read() ) {
		cerr << "Impossibile leggere l'istanza." << endl;
		delete problema;
		delete reader;
		return -1;
	}

	if ( verbose ) {
		cout << "Istanza caricata, sta per essere eseguito l'algoritmo di calcolo della distribuzione dei pesi." << endl;
	}

	/* Mappa contenente gli intervalli di distribuzione dei pesi e le percentuali */
	map< double, double > *distribuzione = new map< double, double >();
	/* Dimensioni di un intervallo */
	double dimBlocco = 0;
	/* Peso minimo e massimo di un arco */
	w_type min = std::numeric_limits< w_type >::max(), max = std::numeric_limits< w_type >::min();

	for ( Grafo< w_type >::arco_const_iterator e = (problema->getGrafo())->lista_archi.begin(); e != (problema->getGrafo())->lista_archi.end(); e++ ) {
		if ( (*e)->costo < min ) {
			min = (*e)->costo;
		}

		if ( (*e)->costo > max ) {
			max = (*e)->costo;
		}
	}

	if ( verbose ) {
		cout << "Il peso minimo di un arco e' " << min << " mentre il peso massimo e' " << max << endl;
	}

	dimBlocco = (max - min) / static_cast< double >(intervalli);

	for ( unsigned int i(0); i <= intervalli; i++ ) {
		distribuzione->insert(pair< double, unsigned int >(min + (i * dimBlocco), 0));
	}

	for ( Grafo< w_type >::arco_const_iterator e = (problema->getGrafo())->lista_archi.begin(); e != (problema->getGrafo())->lista_archi.end(); e++ ) {
		for ( unsigned int i(1); i <= intervalli; i++ ) {
			if ( min + (i * dimBlocco) > (*e)->costo ) {
				((distribuzione->find(min + ((i - 1) * dimBlocco)))->second)++;
				break;
			}
		}
	}

	for ( map< double, double >::iterator i = (distribuzione->begin())++; i != distribuzione->end(); i++ ) {
		(*i).second = static_cast< double >(((*i).second * 100)) / (problema->getGrafo())->numArchi();
	}

	cout << endl;
	for ( map< double, double >::iterator i = (distribuzione->begin())++; i != --(distribuzione->end()); i++ ) {
		cout << fixed << setprecision (2) << "Da " << (*(--i)).first << " a " << (*(++i)).first << ": " << (*i).second << "%" << endl;
	}
	cout << endl;

	return 0;
}