Esempio n. 1
0
  // on a modifie le constructeur pour indiquer si l'on veut optimiser un covoiturage ou effectuer
  // une simple recherche de PCC
  public Pcc(Graphe gr, PrintStream sortie, Readarg readarg, int covoit) {
    super(gr, sortie, readarg);
    // integer lie au covoiturage : 0 = pas de covoiturage, 1=pieton, 2=voiture
    this.setcovoit(covoit);

    if (covoit == 0) {
      // ALGORITHME CLASSIQUE DE PCC
      this.zoneOrigine = gr.getZone();
      while ((this.origine = readarg.lireInt("Numero du sommet d'origine ? "))
          >= this.graphe.sommets.size()) { // le sommet n'appartient pas au graphe !
        System.out.println("Sommet inexistant ! Retapez un numéro de sommet.");
      }

      // Demander la zone et le sommet destination.
      this.zoneDestination = gr.getZone();
      while ((this.destination = readarg.lireInt("Numero du sommet destination ? "))
          >= this.graphe.sommets.size()) { // le sommet n'appartient pas au graphe !
        System.out.println("Sommet inexistant ! Retapez un numéro de sommet.");
      }
    } else {
      // ALGORITHME DE COVOITURAGE
      // Seul le sommet d'origine nous interesse car on calcule les plus courts chemins vers tous
      // les autres.
      // on instancie arbitrarement le sommet de destination sur celui d'origine, puisque dans tout
      // les cas
      // on a ajoute une condition dans l'algorithme qui le force a calculer le PCC vers tous les
      // autres sommets, sans s'arreter a la destination.
      this.zoneOrigine = gr.getZone();
      while ((this.origine = readarg.lireInt("Numero du sommet? "))
          >= this.graphe.sommets.size()) { // le sommet n'appartient pas au graphe
        System.out.println("Sommet inexistant ! Retapez un numéro de sommet.");
      }
      this.zoneDestination = gr.getZone();
      this.destination = this.origine;
    }
  }
Esempio n. 2
0
  public void go() {

    try {
      System.out.println("**");
      System.out.println("** Programme de test des algorithmes de graphe.");
      System.out.println("**");
      System.out.println();

      // On obtient ici le nom de la carte a utiliser.
      String nomcarte = this.readarg.lireString("Nom du fichier .map a utiliser ? ");
      DataInputStream mapdata = Openfile.open(nomcarte);

      boolean display =
          (1 == this.readarg.lireInt("Voulez-vous une sortie graphique (0 = non, 1 = oui) ? "));
      Dessin dessin = (display) ? new DessinVisible(800, 600) : new DessinInvisible();

      Graphe graphe = new Graphe(nomcarte, mapdata, dessin);

      // Boucle principale : le menu est accessible
      // jusqu'a ce que l'on quitte.
      boolean continuer = true;
      int choix;

      while (continuer) {
        this.afficherMenu();
        choix = this.readarg.lireInt("Votre choix ? ");

        // Algorithme a executer
        Algo algo = null;

        // Le choix correspond au numero du menu.
        switch (choix) {
          case 0:
            continuer = false;
            break;

          case 1:
            algo = new Connexite(graphe, this.fichierSortie(), this.readarg);
            break;

          case 2:
            algo = new Pcc(graphe, this.fichierSortie(), this.readarg);
            break;

          case 3:
            algo = new PccStar(graphe, this.fichierSortie(), this.readarg);
            break;

          case 4:
            algo = new Esclave(graphe, System.out, this.readarg);
            continuer = false;
            break;

          case 5:
            graphe.situerClick();
            break;

          case 6:
            String nom_chemin =
                this.readarg.lireString("Nom du fichier .path contenant le chemin ? ");
            graphe.verifierChemin(Openfile.open(nom_chemin), nom_chemin);
            break;

          default:
            System.out.println("Choix de menu incorrect : " + choix);
            System.exit(1);
        }

        if (algo != null) {
          algo.run();
        }
      }

      System.out.println("Programme termine.");
      System.exit(0);

    } catch (Throwable t) {
      t.printStackTrace();
      System.exit(1);
    }
  }