Example usage for org.apache.commons.math.random RandomDataImpl RandomDataImpl

List of usage examples for org.apache.commons.math.random RandomDataImpl RandomDataImpl

Introduction

In this page you can find the example usage for org.apache.commons.math.random RandomDataImpl RandomDataImpl.

Prototype

public RandomDataImpl() 

Source Link

Document

Construct a RandomDataImpl.

Usage

From source file:br.upe.ecomp.doss.algorithm.chargedpso.ChargedPSOParticle.java

/**
 * Updates the current position of the particle.
 * /*from   www  . java2  s . c o  m*/
 * @param problem The problem that we are trying to solve.
 */
@Override
public void updateCurrentPosition(Problem problem) {
    RandomData random = new RandomDataImpl();
    double[] position = getCurrentPosition();
    double[] velocity = getVelocity();
    double newPosition;
    for (int i = 0; i < getDimensions(); i++) {
        double p = position[i];
        newPosition = position[i] + velocity[i];
        double p1 = newPosition;
        if (charge != 0) {
            double step;

            if (newPosition > problem.getUpperBound(i)) {
                step = Math.abs(random.nextUniform(0, problem.getUpperBound(i) - problem.getLowerBound(i)));
                newPosition = problem.getUpperBound(i) - step;
            } else if (newPosition < problem.getLowerBound(i)) {
                step = Math.abs(random.nextUniform(0, problem.getUpperBound(i) - problem.getLowerBound(i)));
                newPosition = problem.getLowerBound(i) + step;
            }

            if (newPosition > problem.getUpperBound(i)) {
                System.out.println("parou");
            } else if (newPosition < problem.getLowerBound(i)) {
                System.out.println("parou 1");
            }

        } else if (newPosition > problem.getUpperBound(i)) {
            newPosition = problem.getUpperBound(i);
        } else if (newPosition < problem.getLowerBound(i)) {
            newPosition = problem.getLowerBound(i);
        }
        if (newPosition > problem.getUpperBound(i)) {
            System.out.println("ops");
        }
        position[i] = newPosition;
    }
    updateCurrentPosition(position, problem.getFitness(position));

}

From source file:evaluation.loadGenerator.randomVariable.RandomVariable.java

protected RandomVariable(String[] parameters) {
    this.parameters = parameters;
    this.randomDataImpl = new RandomDataImpl();
    this.randomDataImpl.reSeedSecure();
}

From source file:evaluation.simulator.plugins.trafficSource.PoissonClient.java

public PoissonClient(String identifier, Simulator simulator, int clientId) {
    super(identifier, simulator);
    if (Simulator.settings.getProperty("POISSON_REQUEST_SIZE").equals("AUTO"))
        this.REQUEST_SIZE = Simulator.settings.getPropertyAsInt("MIX_REQUEST_PAYLOAD_SIZE");
    else/*from   w ww  .j av a 2s .c  o  m*/
        this.REQUEST_SIZE = Simulator.settings.getPropertyAsInt("POISSON_REQUEST_SIZE");
    if (Simulator.settings.getProperty("POISSON_REPLY_SIZE").equals("AUTO"))
        this.REPLY_SIZE = Simulator.settings.getPropertyAsInt("MIX_REPLY_PAYLOAD_SIZE");
    else
        this.REPLY_SIZE = Simulator.settings.getPropertyAsInt("POISSON_REPLY_SIZE");
    this.RESOLVE_TIME = Simulator.settings.getPropertyAsInt("POISSON_RESOLVE_TIME");
    this.clientId = clientId;
    this.LAMBDA = Simulator.settings.getPropertyAsDouble("POISSON_AVERAGE_REQUESTS_PER_SECOND_AND_CLIENT");
    this.randomDataImpl = new RandomDataImpl();
    this.randomDataImpl.reSeed(secureRandom.nextLong());
}

From source file:evaluation.loadGenerator.mixPacketLevelTraffic.MPL_FS_Poisson.java

public MPL_FS_Poisson(MPL_FixedScheduleLoadGenerator owner) {
    this.settings = owner.getSettings();
    this.experimentStart = owner.getScheduler().now() + TimeUnit.SECONDS.toNanos(2);
    this.startOfPeriod = experimentStart;
    int numberOfClients = settings.getPropertyAsInt("MPL-POISSON-NUMBER_OF_CLIENTS");

    String str_avgSendsPerPulse = settings.getProperty("MPL-POISSON-AVERAGE_PACKETS_PER_PULSE");
    if (RandomVariable.isRandomVariable(str_avgSendsPerPulse)) {
        this.AVG_SENDS_PER_PERIOD = RandomVariable.createRandomVariable(str_avgSendsPerPulse);
    } else {/*from   ww  w  .jav a 2s  . com*/
        float float_avgSendsPerPulse = Float.parseFloat(str_avgSendsPerPulse);
        float_avgSendsPerPulse = float_avgSendsPerPulse * (float) numberOfClients;
        if (float_avgSendsPerPulse < 1f)
            this.AVG_SENDS_PER_PERIOD = new FakeRandom(1);
        else
            this.AVG_SENDS_PER_PERIOD = new FakeRandom(Math.round(float_avgSendsPerPulse));
    }
    this.PULSE_LENGTH = (long) (settings.getPropertyAsFloat("MPL-POISSON-PULSE_LENGTH") * 1000000000f);
    this.random = new SecureRandom();
    this.randomDataImpl = new RandomDataImpl();
    this.randomDataImpl.reSeed(this.random.nextLong());
    System.out.println("LOAD_GENERATOR: start at " + experimentStart);

    // create client
    owner.getLoadGenerator().commandLineParameters.gMixTool = ToolName.CLIENT;
    this.client = new AnonNode(owner.getLoadGenerator().commandLineParameters);
    int dstPort = settings.getPropertyAsInt("SERVICE_PORT1");
    this.scheduleTarget = new MPL_BasicWriter(this, client.IS_DUPLEX, dstPort);
    // determine number of clients and lines; create ClientWrapper objects etc
    this.clientsArray = new MPL_ClientWrapper[numberOfClients];
    CommunicationDirection cm = client.IS_DUPLEX ? CommunicationDirection.DUPLEX
            : CommunicationDirection.SIMPLEX_SENDER;
    for (int i = 0; i < numberOfClients; i++) {
        clientsArray[i] = new MPL_ClientWrapper(i);
        clientsArray[i].socket = client.createDatagramSocket(cm, true, true,
                client.ROUTING_MODE != RoutingMode.CASCADE);
    }
    if (client.IS_DUPLEX) {
        this.replyReceiver = new MPL_ReplyReceiver(clientsArray, settings);
        //this.replyReceiver.registerObserver(this);
        this.replyReceiver.start();
    }
}

From source file:evaluation.simulator.plugins.trafficSource.SendConstantClient.java

public SendConstantClient(String identifier, Simulator simulator, int clientId) {
    super(identifier, simulator);

    if (Simulator.settings.getProperty("CONSTANT_REQUEST_SIZE").equals("AUTO"))
        this.REQUEST_SIZE = Simulator.settings.getPropertyAsInt("MIX_REQUEST_PAYLOAD_SIZE");
    else/*ww w  . ja  v a2s . c om*/
        this.REQUEST_SIZE = Simulator.settings.getPropertyAsInt("CONSTANT_REQUEST_SIZE");

    if (Simulator.settings.getProperty("CONSTANT_REPLY_SIZE").equals("AUTO"))
        this.REPLY_SIZE = Simulator.settings.getPropertyAsInt("MIX_REPLY_PAYLOAD_SIZE");
    else
        this.REPLY_SIZE = Simulator.settings.getPropertyAsInt("CONSTANT_REPLY_SIZE");
    this.RESOLVE_TIME = Simulator.settings.getPropertyAsInt("CONSTANT_RESOLVE_TIME");
    this.clientId = clientId;
    this.TIME_BETWEEN_SENDS = Math.round(
            1000d / Simulator.settings.getPropertyAsDouble("CONSTANT_AVERAGE_REQUESTS_PER_SECOND_AND_CLIENT"));
    if (TIME_BETWEEN_SENDS == 0)
        throw new RuntimeException("ERROR: TIME_BETWEEN_SENDS in experiment config files must be 1000 at max.");
    this.randomDataImpl = new RandomDataImpl();
    this.randomDataImpl.reSeed(secureRandom.nextLong());
}

From source file:evaluation.simulator.plugins.trafficSource.ParetoClient.java

public ParetoClient(String identifier, Simulator simulator, int clientId) {
    super(identifier, simulator);
    if (Simulator.settings.getProperty("PARETO_REQUEST_SIZE").equals("AUTO"))
        this.REQUEST_SIZE = Simulator.settings.getPropertyAsInt("MIX_REQUEST_PAYLOAD_SIZE");
    else/*w ww  .  ja v a  2 s  . c  o m*/
        this.REQUEST_SIZE = Simulator.settings.getPropertyAsInt("PARETO_REQUEST_SIZE");
    if (Simulator.settings.getProperty("PARETO_REPLY_SIZE").equals("AUTO"))
        this.REPLY_SIZE = Simulator.settings.getPropertyAsInt("MIX_REPLY_PAYLOAD_SIZE");
    else
        this.REPLY_SIZE = Simulator.settings.getPropertyAsInt("PARETO_REPLY_SIZE");
    this.RESOLVE_TIME = Simulator.settings.getPropertyAsInt("PARETO_RESOLVE_TIME");
    this.clientId = clientId;
    this.ALPHA = Simulator.settings.getPropertyAsDouble("PARETO_ALPHA");
    this.AVERAGE_REQUESTS_PER_SECOND = Simulator.settings
            .getPropertyAsDouble("PARETO_AVERAGE_REQUESTS_PER_SECOND_AND_CLIENT");
    this.pareto = new NormalizedPareto(ALPHA, AVERAGE_REQUESTS_PER_SECOND);
    this.randomDataImpl = new RandomDataImpl();
    this.randomDataImpl.reSeed(secureRandom.nextLong());
}

From source file:es.udc.gii.common.eaf.plugin.parameter.jade.JADEFAdaptiveParameter.java

public JADEFAdaptiveParameter() {

    this.rand_imp = new RandomDataImpl();

}

From source file:evaluation.loadGenerator.fixedSchedule.ALM_FS_Poisson.java

public ALM_FS_Poisson(AL_FixedScheduleLoadGenerator owner) {
    this.settings = owner.getSettings();
    this.experimentStart = owner.getScheduler().now() + TimeUnit.SECONDS.toNanos(2);
    this.startOfPeriod = experimentStart;
    int numberOfClients = settings.getPropertyAsInt("AL-POISSON-NUMBER_OF_CLIENTS");
    String str_avgSendsPerPulse = settings.getProperty("AL-POISSON-AVERAGE_SEND_OPERATIONS_PER_PULSE");
    if (RandomVariable.isRandomVariable(str_avgSendsPerPulse)) {
        this.AVG_SENDS_PER_PERIOD = RandomVariable.createRandomVariable(str_avgSendsPerPulse);
    } else {//from  w  w  w.  j  a  v  a  2 s. c  om
        float float_avgSendsPerPulse = Float.parseFloat(str_avgSendsPerPulse);
        float_avgSendsPerPulse = float_avgSendsPerPulse * (float) numberOfClients;
        if (float_avgSendsPerPulse < 1f)
            this.AVG_SENDS_PER_PERIOD = new FakeRandom(1);
        else
            this.AVG_SENDS_PER_PERIOD = new FakeRandom(Math.round(float_avgSendsPerPulse));
    }
    String str_ReplyDelay = settings.getProperty("AL-POISSON-REPLY_DELAY");
    if (RandomVariable.isRandomVariable(str_ReplyDelay))
        this.REPLY_DELAY = RandomVariable.createRandomVariable(str_ReplyDelay);
    else
        this.REPLY_DELAY = new FakeRandom(Double.parseDouble(str_ReplyDelay));
    this.PULSE_LENGTH = (long) (settings.getPropertyAsFloat("AL-POISSON-PULSE_LENGTH") * 1000000000f);
    this.random = new SecureRandom();
    this.randomDataImpl = new RandomDataImpl();
    this.randomDataImpl.reSeed(this.random.nextLong());
    System.out.println("LOAD_GENERATOR: start at " + experimentStart);
    // create client
    owner.getLoadGenerator().commandLineParameters.gMixTool = ToolName.CLIENT;
    this.client = new AnonNode(owner.getLoadGenerator().commandLineParameters);
    this.scheduleTarget = new ALRR_BasicWriter(this, client.IS_DUPLEX);
    // determine number of clients and lines; create ClientWrapper objects etc
    this.clientsArray = new ALRR_ClientWrapper[numberOfClients];
    CommunicationDirection cm = client.IS_DUPLEX ? CommunicationDirection.DUPLEX
            : CommunicationDirection.SIMPLEX_SENDER;
    int port = settings.getPropertyAsInt("SERVICE_PORT1");
    System.out.println("LOAD_GENERATOR: connecting clients...");
    for (int i = 0; i < numberOfClients; i++) {
        clientsArray[i] = new ALRR_ClientWrapper(i);
        clientsArray[i].socket = client.createStreamSocket(cm, client.ROUTING_MODE != RoutingMode.CASCADE);
        try {
            clientsArray[i].socket.connect(port);
            clientsArray[i].outputStream = new BufferedOutputStream(clientsArray[i].socket.getOutputStream());
            if (client.IS_DUPLEX)
                clientsArray[i].inputStream = clientsArray[i].socket.getInputStream();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    String str_requestPayloadSize = settings.getProperty("AL-POISSON-REQUEST_PAYLOAD_SIZE");
    if (RandomVariable.isRandomVariable(str_requestPayloadSize)) {
        this.REQUEST_PAYLOAD_SIZE = RandomVariable.createRandomVariable(str_requestPayloadSize);
    } else {
        if (str_requestPayloadSize.equalsIgnoreCase("AUTO"))
            this.REQUEST_PAYLOAD_SIZE = new FakeRandom(clientsArray[0].socket.getMTU());
        else
            this.REQUEST_PAYLOAD_SIZE = new FakeRandom(Integer.parseInt(str_requestPayloadSize));
    }
    String str_replyPayloadSize = settings.getProperty("AL-POISSON-REPLY_PAYLOAD_SIZE");
    if (RandomVariable.isRandomVariable(str_replyPayloadSize)) {
        this.REPLY_PAYLOAD_SIZE = RandomVariable.createRandomVariable(str_replyPayloadSize);
    } else {
        if (str_replyPayloadSize.equalsIgnoreCase("AUTO"))
            this.REPLY_PAYLOAD_SIZE = new FakeRandom(clientsArray[0].socket.getMTU());
        else
            this.REPLY_PAYLOAD_SIZE = new FakeRandom(Integer.parseInt(str_replyPayloadSize));
    }
    if (client.IS_DUPLEX) {
        this.replyReceiver = new ALRR_ReplyReceiver(clientsArray, settings);
        //this.replyReceiver.registerObserver(this);
        this.replyReceiver.start();
    }
}

From source file:br.upe.ecomp.doss.algorithm.chargedpso.ChargedPSOParticle.java

private double getRandomInRange(double value1, double value2) {
    RandomData random = new RandomDataImpl();
    double lowerBound;
    double upperBound;
    if (value1 < value2) {
        lowerBound = value1;/*from  w  ww  . j a va  2 s  .  c  om*/
        upperBound = value2;
    } else {
        lowerBound = value2;
        upperBound = value1;
    }
    return random.nextUniform(lowerBound, upperBound);
}

From source file:br.upe.ecomp.doss.algorithm.volitivepso.VolitivePSO.java

private void performCollectiveVolitiveMovement() {

    RandomData random = new RandomDataImpl();
    double[] barycenter = calculateBarycenter();

    double actualSwarmWeight = getSwarmWeigth();

    double euclidianDistance;
    double[] position;
    double currentPosition;

    WeightedPSOParticle[] particles = (WeightedPSOParticle[]) getParticles();
    for (WeightedPSOParticle particle : particles) {

        euclidianDistance = MathUtils.distance(particle.getCurrentPosition(), barycenter);
        position = new double[getDimensions()];

        for (int i = 0; i < getDimensions(); i++) {
            currentPosition = particle.getCurrentPosition()[i];

            if (actualSwarmWeight > previousSwarmWeight) {

                position[i] = currentPosition - stepVol[i] * random.nextUniform(0.0, 1.0)
                        * ((currentPosition - barycenter[i]) / euclidianDistance);
            } else {
                position[i] = currentPosition + stepVol[i] * random.nextUniform(0.0, 1.0)
                        * ((currentPosition - barycenter[i]) / euclidianDistance);
            }/*  www. j  av  a  2s .  c  o m*/
            if (position[i] > getProblem().getUpperBound(i) || position[i] < getProblem().getLowerBound(i)) {
                position[i] = currentPosition;
            }
        }

        // if (getProblem().compareFitness(fish.getCurrentFitness(),
        // getProblem().getFitness(position))) {
        particle.updateCurrentPosition(position, getProblem().getFitness(position));

        if (getProblem().isFitnessBetterThan(particle.getBestFitness(), particle.getCurrentFitness())) {
            particle.updateBestPosition(particle.getCurrentPosition(), particle.getCurrentFitness());
        }
        // }
    }

    previousSwarmWeight = actualSwarmWeight;
}