Package org.jamesii.core.math.random.generators

Examples of org.jamesii.core.math.random.generators.IRandom


   *           Signals that an I/O exception has occurred.
   */
  public static void saveGraphToDOT(String fileName, ISimpleGraph graph,
      Map<Integer, Integer> partition) throws IOException {

    IRandom rand = SimSystem.getRNGGenerator().getNextRNG();
    try (FileWriter file = new FileWriter(fileName)) {
      int vertexCount = graph.getVertexCount();

      Map<Integer, Double> vertexLabels = graph.getVertexLabels();
      Map<Integer, Map<Integer, Double>> edgeLabels = graph.getEdgeLabels();

      List<List<Integer>> adjacencyLists = graph.getAdjacencyLists();
      String nodeDefinition;
      String nodeStyle;

      if (partition != null) {
        tidyUpPartition(partition, adjacencyLists, 0, 0);
      }

      // Writing initialisation
      file.write("digraph g {\n\n");
      file.write(dotFileHeader + new Date(System.currentTimeMillis())
          + " */\n\n/* Defining nodes */\n\n");

      file.write("node [" + generalNodeStyle + "]; /* General node style*/ \n");

      // Writing all vertices
      for (int i = 0; i < vertexCount; i++) {
        nodeDefinition = "node_" + i;
        nodeStyle = "";

        if (partition != null && partition.containsKey(i)) {
          int p = partition.get(i);

          if (p >= usedColors.size()) {
            for (int k = usedColors.size(); k <= p; k++) {
              usedColors.add(rand.nextDouble() + " " + rand.nextDouble() + " "
                  + rand.nextDouble());
            }
          }

          file.write("node [color=\"" + usedColors.get(p) + "\"];\n");
        }
View Full Code Here


        }
      }
    }

    // Resort to random sampling for the rest of the portfolio
    IRandom random = SimSystem.getRNGGenerator().getNextRNG();
    portfolio.addAll(RandomSampler.sampleSet(portfolioSize - portfolio.size(),
        0, combinations.size(), combinations, random));
  }
View Full Code Here

      compJobs.add(new ComparisonJob(problemEntry.getKey(), configSetups,
          filterResults.getSecondValue()));
    }

    // If larger than allowed: dismiss jobs randomly
    IRandom random = SimSystem.getRNGGenerator().getNextRNG();
    int deleteJobs = compJobs.size() - maxJobs;
    for (int i = 0; i < deleteJobs; i++) {
      compJobs.remove((int) (random.nextDouble() * compJobs.size()));
    }
    return compJobs;
  }
View Full Code Here

  /**
   * Test genome recombination.
   */
  public void testGenomeRecombination() {

    IRandom rng = new JavaRandom();

    // Recombine 0000 and 1111
    ListIndividual parent1 = new ListIndividual(null, 4, rng);
    ListIndividual parent2 = new ListIndividual(null, 4, rng);
    parent1.generateRandomGenome(0, 4);
View Full Code Here

   *          maximal possible performance in the matrix.
   * @return a randomly generated performance matrix.
   */
  protected Double[][] generateMatrix(int numOfAlgo, int numOfProb,
      int minPerformance, int maxPerformance) {
    IRandom rng = SimSystem.getRNGGenerator().getNextRNG();
    if (numOfAlgo == 0) {
      numOfAlgo = (int) (991 * rng.nextDouble() + 10);
    }
    if (numOfProb == 0) {
      numOfProb = (int) (991 * rng.nextDouble() + 10);
    }
    UniformDistribution u =
        new UniformDistribution(rng, minPerformance, maxPerformance + 1);
    Double[][] matrix = new Double[numOfAlgo][numOfProb];
    for (Double[] mat : matrix) {
View Full Code Here

    // myQueue = internalCreate();
    eles = 1000;
    // The seed -7538847116595691071l caused a problem in one of the queues
    // (with at least 1000 and 10000 eles)
    IRandom rand = new JavaRandom(-7538847116595691071l);
    for (int i = 0; i < eles; i++) {
      myQueue.enqueue(new Object(), tim + rand.nextDouble());
    }

    // get the min
    Double ti = myQueue.getMin();
    // remember the queue size
    long st = myQueue.size();
    // take away t entries from the queue (all those with the time ti)
    t = myQueue.dequeueAll();

    assertTrue(st == myQueue.size() + t.size());

    for (Object o : t) {
      myQueue.enqueue(o, ti);
    }

    assertTrue(
        "Size is " + myQueue.size() + " but should be " + st
            + ". Time value of elements " + ti + ".  The random seed used: "
            + rand.getSeed(), myQueue.size() == st);

    int rememberSize = t.size();

    assertTrue("The queue should have as min time " + ti + " but it is "
        + myQueue.getMin(), myQueue.getMin().compareTo(ti) == 0);
    // assertTrue(myQueue.size() == eles);
    // Queue has eles elements in it

    // add 10 elements with time time, thus together with the one already in
    // there should be 11 at all
    for (int i = 0; i < 10; i++) {
      myQueue.enqueue(new NamedEntity("" + i), ti);
      assertTrue("Size should be " + (eles + i + rememberSize) + " but is "
          + myQueue.size(), myQueue.size() == eles + i + rememberSize);
    }

    assertTrue("Size is " + myQueue.size() + " instead of " + eles + 10,
        eles + 10 == myQueue.size());

    // System.out.println("enqueued 10 elements with time "+ti+"\n"+
    // myQueue+". Now there are "+myQueue.size()+" elements in the queue.");
    t = myQueue.dequeueAll();
    assertTrue(
        "Size should be " + (eles - rememberSize) + " but is " + myQueue.size()
            + "\nThe min extracted:" + ti + "\nExtracted " + t.size()
            + " elements (" + t + ") with that time\n"
            + "The queue contains the following elements\n\n"
            + myQueue.toString(), myQueue.size() == eles - rememberSize);

    assertTrue("dequeueAll should return " + (rememberSize + 10)
        + " elements but the method returned " + t.size()
        + ".\n The min value should be " + ti + "\nThe random seed used: "
        + rand.getSeed() + ". The queue contains \n" + myQueue.toString(),
        t.size() == rememberSize + 10);

    // elapsedTime = System.currentTimeMillis() - startTime;
    // System.out.println("dequeueAll finished at " + elapsedTime);
  }
View Full Code Here

  /**
   * Same as testSimple but there are null-pointer in the problemMatrixNull.
   */
  public void testNull() {
    IRandom rng = SimSystem.getRNGGenerator().getNextRNG();
    Double[][] problemMatrixNull =
        new Double[problemMatrix.length][problemMatrix[0].length];
    for (int i = 0; i < problemMatrix.length; i++) {
      for (int j = 0; j < problemMatrix[0].length; j++) {
        problemMatrixNull[i][j] = problemMatrix[i][j];
        if ((int) (rng.nextDouble() * 100) < NULL_PERCENTAGE) {
          problemMatrixNull[i][j] = null;
        }
      }
    }
    gaps.setAbortCriterion(new GenerationCountAbort(GEN_COUNT));
View Full Code Here

   *          maximal possible performance in the matrix.
   * @return a randomly generated performance matrix.
   */
  protected Double[][] generateMatrix(int numOfAlgo, int numOfProb,
      int minPerformance, int maxPerformance) {
    IRandom rng = SimSystem.getRNGGenerator().getNextRNG();
    if (numOfAlgo == 0) {
      numOfAlgo = (int) (991 * rng.nextDouble() + 10);
    }
    if (numOfProb == 0) {
      numOfProb = (int) (991 * rng.nextDouble() + 10);
    }
    UniformDistribution u =
        new UniformDistribution(rng, minPerformance, maxPerformance + 1);
    Double[][] matrix = new Double[numOfAlgo][numOfProb];
    for (Double[] mat : matrix) {
View Full Code Here

   */
  private RandomNumberGeneratorManager() {
  }

  public static synchronized long createSeedGroup(Seed seed) {
    IRandom rng = new JavaRandom(Seed.asLong(seed));
    long id = instance.counter.incrementAndGet();
    instance.groups.put(id, rng);
    instance.seeds.put(id, seed);
    return id;
  }
View Full Code Here

  }

  public static synchronized IRandom getRng(long ofGroup,
      RandomGeneratorFactory usingFactory) {
    long seed = getNextSeed(ofGroup);
    IRandom rng = usingFactory.create(seed);
    return rng;
  }
View Full Code Here

TOP

Related Classes of org.jamesii.core.math.random.generators.IRandom

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.