Example usage for org.apache.commons.math3.random MersenneTwister nextLong

List of usage examples for org.apache.commons.math3.random MersenneTwister nextLong

Introduction

In this page you can find the example usage for org.apache.commons.math3.random MersenneTwister nextLong.

Prototype

public long nextLong() 

Source Link

Usage

From source file:edu.oregonstate.eecs.mcplan.domains.voyager.VoyagerHash.java

/**
 * For each planet         8/*from  w  w w  .j a  v  a  2  s  .co  m*/
 Owner                3
 Production            2
 Stored               40
 Population            200
                   245
                1960
   For each planet pair   64
 For each ETA         29
    For each player         2
       Population            200
                      400
                   11600
                742400
             744360
         
 * @param params
 * @param instance
 */
public VoyagerHash(final VoyagerParameters params, final int Nplanets, final int max_eta) {
    this.max_eta = max_eta;
    this.Nplanets = Nplanets;
    final MersenneTwister rng = new MersenneTwister(params.master_seed);

    final int Nplayers = Player.values().length;
    final int Nunit_types = Unit.values().length;
    final int population = Nunit_types * (params.max_population + 1);
    int type_costs = 0;
    for (final Unit type : Unit.values()) {
        type_costs += type.cost() + 1;
    }

    // Planet stuff
    planet_numbers = Nplanets
            * (Nplayers + (Nunit_types + 1) + type_costs + (Player.Ncompetitors * (population + Unit.max_hp)));
    planet_owner = new long[Nplanets][Nplayers];
    planet_population = new long[Nplanets][Player.Ncompetitors][Nunit_types][params.max_population + 1]; // Need +1 for zero
    planet_carry_damage = new long[Nplanets][Player.Ncompetitors][Unit.max_hp];
    planet_production = new long[Nplanets][Nunit_types + 1]; // Need one for 'null'
    planet_stored_production = new long[Nplanets][Nunit_types][];
    for (int p = 0; p < Nplanets; ++p) {
        for (int t = 0; t < Unit.values().length; ++t) {
            // FIXME: Didn't expect to need '+1' here; why doesn't
            // production happen immediately?
            planet_stored_production[p][t] = new long[Unit.values()[t].cost() + 1];
        }
    }

    // Spaceship stuff
    planet_pair_numbers = Nplanets * Nplanets * (max_eta + 1) * Player.Ncompetitors * Nunit_types
            * params.max_population;
    ships = new long[Nplanets][Nplanets][max_eta + 1][Player.Ncompetitors][Nunit_types][params.max_population];

    Nhashes = planet_numbers + planet_pair_numbers;
    //      log.info( "Nhashes = {}", Nhashes );

    // Initialize Planet hash arrays
    int total = 0;
    for (int p = 0; p < Nplanets; ++p) {
        for (int y = 0; y < Player.values().length; ++y) {
            planet_owner[p][y] = rng.nextLong();
            total += 1;
        }

        for (int y = 0; y < Player.Ncompetitors; ++y) {
            for (int d = 0; d < Unit.max_hp; ++d) {
                planet_carry_damage[p][y][d] = rng.nextLong();
                total += 1;
            }
        }

        for (int t = 0; t < Unit.values().length; ++t) {
            planet_production[p][t] = rng.nextLong();
            total += 1;

            for (int y = 0; y < Player.Ncompetitors; ++y) {
                for (int pop = 0; pop <= params.max_population; ++pop) {
                    planet_population[p][y][t][pop] = rng.nextLong();
                    total += 1;
                }
            }

            for (int prod = 0; prod <= Unit.values()[t].cost(); ++prod) {
                planet_stored_production[p][t][prod] = rng.nextLong();
                total += 1;
            }
        }

        // Need one extra for 'null'
        planet_production[p][Unit.values().length] = rng.nextLong();
        total += 1;
    }
    assert (total == planet_numbers);

    // Initialize Spaceship hash arrays
    total = 0;
    for (int p1 = 0; p1 < Nplanets; ++p1) {
        for (int p2 = 0; p2 < Nplanets; ++p2) {
            for (int eta = 0; eta <= max_eta; ++eta) {
                for (int player = 0; player < Player.Ncompetitors; ++player) {
                    for (int t = 0; t < Unit.values().length; ++t) {
                        for (int pop = 0; pop < params.max_population; ++pop) {
                            ships[p1][p2][eta][player][t][pop] = rng.nextLong();
                            total += 1;
                        }
                    }
                }
            }
        }
    }
    assert (total == planet_pair_numbers);
}