public Patch[] extractPatch(Patch p) {
   // get all bytes from the (64 * ((32*pads)+settings)) + chain + system
   byte[] msgs = p.getByteArray();
   // create a Patch[] pa to hold the created Patches (2*Single and 64*Bank)
   Patch[] pa = new Patch[66];
   // do 64 times this:
   for (int i = 0; i < NR_OF_PATCHBANKS; i++) {
     // create a new byte array for a CompletePatch
     byte[] ptchbnk = new byte[PATCHBANKSIZE];
     // copy the current 915 bytes to this byte array
     System.arraycopy(msgs, i * PATCHBANKSIZE, ptchbnk, 0, PATCHBANKSIZE);
     // create a new CompletePatch with these bytes and put it in pa at the current position
     pa[i] = new Patch(ptchbnk, patch2Driver);
     // increase i with 1 or go on if i is already 63
   }
   // all CompletePatches are created
   // now create the chain patch byte array chn
   byte[] chn = new byte[CHAINSIZE];
   // copy the chain bytes into chn
   System.arraycopy(msgs, NR_OF_PATCHBANKS * PATCHBANKSIZE, chn, 0, CHAINSIZE);
   // create a new chain patch with these bytes and put it in the patcharray
   pa[64] = new Patch(chn, chainDriver);
   // now create the system byte array sstm
   byte[] sstm = new byte[SYSTEMSIZE];
   // copy the system bytes into sstm
   System.arraycopy(msgs, (NR_OF_PATCHBANKS * PATCHBANKSIZE) + CHAINSIZE, sstm, 0, SYSTEMSIZE);
   // create a new system patch with these bytes and put it in the patcharray
   pa[65] = new Patch(sstm, systemDriver);
   // return the full array of (64*CompletePatch)+Chain+System
   return pa;
 }
  /** Read all PeMS data in the given time range at the given VDS. */
  public PeMSProfile read(Interval interval, Long vdsId) throws DatabaseException {
    PeMSProfile profile;
    String pemsIdStr = "pems.{vds_id=" + vdsId + ", interval=" + interval + "}";

    long timeBegin = System.nanoTime();

    try {
      dbr.transactionBegin();
      Monitor.debug("PeMS reader transaction beginning on " + pemsIdStr);

      profile = readProfile(interval, vdsId);

      dbr.transactionCommit();
      Monitor.debug("PeMS reader transaction committing on " + pemsIdStr);
    } catch (DatabaseException dbExc) {
      Monitor.err(dbExc);
      throw dbExc;
    } finally {
      try {
        dbr.transactionRollback();
        Monitor.debug("PeMS reader transaction rollback on " + pemsIdStr);
      } catch (Exception Exc) {
        // Do nothing.
      }
    }

    long timeCommit = System.nanoTime();
    if (profile != null) {
      Monitor.duration("Read " + pemsIdStr, timeCommit - timeBegin);
    }

    return profile;
  }
  /**
   * Read one node with the given ID from the database.
   *
   * @param nodeID ID of the node in the database
   * @param networkID ID of the network
   * @return Node
   */
  public Node read(long nodeID, long networkID) throws DatabaseException {
    Node node;
    String nodeIdStr = "node.{id=" + nodeID + ", network_id=" + networkID + "}";

    long timeBegin = System.nanoTime();

    try {
      dbr.transactionBegin();
      Monitor.debug("Node reader transaction beginning on " + nodeIdStr);

      node = readWithAssociates(nodeID, networkID);

      dbr.transactionCommit();
      Monitor.debug("Node reader transaction committing on " + nodeIdStr);
    } catch (DatabaseException dbExc) {
      Monitor.err(dbExc);
      throw dbExc;
    } finally {
      try {
        dbr.transactionRollback();
        Monitor.debug("Node reader transaction rollback on " + nodeIdStr);
      } catch (Exception Exc) {
        // Do nothing.
      }
    }

    long timeCommit = System.nanoTime();
    if (node != null) {
      Monitor.duration("Read " + nodeIdStr, timeCommit - timeBegin);
    }

    return node;
  }
Beispiel #4
0
  /**
   * Creates a new instance of problem CEC2009_UF8.
   *
   * @param numberOfVariables Number of variables.
   * @param solutionType The solution type must "Real" or "BinaryReal".
   */
  public CEC2009_UF8(String solutionType, Integer numberOfVariables) throws ClassNotFoundException {
    numberOfVariables_ = numberOfVariables.intValue();
    numberOfObjectives_ = 3;
    numberOfConstraints_ = 0;
    problemName_ = "CEC2009_UF8";

    upperLimit_ = new double[numberOfVariables_];
    lowerLimit_ = new double[numberOfVariables_];

    lowerLimit_[0] = 0.0;
    upperLimit_[0] = 1.0;
    lowerLimit_[1] = 0.0;
    upperLimit_[1] = 1.0;
    for (int var = 2; var < numberOfVariables_; var++) {
      lowerLimit_[var] = -2.0;
      upperLimit_[var] = 2.0;
    } // for

    if (solutionType.compareTo("BinaryReal") == 0) solutionType_ = new BinaryRealSolutionType(this);
    else if (solutionType.compareTo("Real") == 0) solutionType_ = new RealSolutionType(this);
    else {
      System.out.println("Error: solution type " + solutionType + " invalid");
      System.exit(-1);
    }
  } // CEC2009_UF7
  /**
   * Read all PeMS aggregate data in the given time range, having a VDS ID in the given list, and at
   * the given aggregation level. List is sorted by time.
   */
  public List<PeMSStationAggregate> read(
      Interval interval, List<Long> vdsIds, PeMSAggregate.AggregationLevel level)
      throws DatabaseException {

    List<PeMSStationAggregate> list;

    String pemsIdStr =
        "pems.{vds_id=["
            + vdsIds.get(0)
            + ","
            + vdsIds.get(1)
            + ",...], interval="
            + interval
            + ", level="
            + level
            + "}";

    long timeBegin = System.nanoTime();

    try {
      dbr.transactionBegin();
      Monitor.debug("PeMS aggregate reader transaction beginning on " + pemsIdStr);

      list = readList(interval, vdsIds, level);

      dbr.transactionCommit();
      Monitor.debug("PeMS aggregate reader transaction committing on " + pemsIdStr);
    } catch (DatabaseException dbExc) {
      Monitor.err(dbExc);
      throw dbExc;
    } finally {
      try {
        dbr.transactionRollback();
        Monitor.debug("PeMS aggregate reader transaction rollback on " + pemsIdStr);
      } catch (Exception Exc) {
        // Do nothing.
      }
    }

    long timeCommit = System.nanoTime();
    if (list != null) {
      Monitor.duration("Read " + pemsIdStr, timeCommit - timeBegin);
    }

    return list;
  }
  /** Read all PeMS data in the given time range and having a VDS ID in the given list. */
  public PeMSSet read(Interval interval, List<Long> vdsIds) throws DatabaseException {
    PeMSSet set = null;

    String pemsIdStr =
        "pems.{vds_id=["
            + vdsIds.get(0)
            + ","
            + vdsIds.get(1)
            + ",...], interval="
            + interval
            + "}";

    long timeBegin = System.nanoTime();

    try {
      dbr.transactionBegin();
      Monitor.debug("PeMS reader transaction beginning on " + pemsIdStr);

      set = readSet(interval, vdsIds);

      dbr.transactionCommit();
      Monitor.debug("PeMS reader transaction committing on " + pemsIdStr);
    } catch (DatabaseException dbExc) {
      Monitor.err(dbExc);
      throw dbExc;
    } finally {
      try {
        dbr.transactionRollback();
        Monitor.debug("PeMS reader transaction rollback on " + pemsIdStr);
      } catch (Exception Exc) {
        // Do nothing.
      }
    }

    long timeCommit = System.nanoTime();
    if (set != null) {
      Monitor.duration("Read " + pemsIdStr, timeCommit - timeBegin);
    }

    return set;
  }
Beispiel #7
0
  // Ouvre un fichier de sortie pour ecrire les reponses
  public PrintStream fichierSortie() {
    PrintStream result = System.out;

    String nom = this.readarg.lireString("Nom du fichier de sortie ? ");

    if ("".equals(nom)) {
      nom = "/dev/null";
    }

    try {
      result = new PrintStream(nom);
    } catch (Exception e) {
      System.err.println("Erreur a l'ouverture du fichier " + nom);
      System.exit(1);
    }

    return result;
  }
Beispiel #8
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);
    }
  }