Example usage for org.apache.commons.math3.exception OutOfRangeException OutOfRangeException

List of usage examples for org.apache.commons.math3.exception OutOfRangeException OutOfRangeException

Introduction

In this page you can find the example usage for org.apache.commons.math3.exception OutOfRangeException OutOfRangeException.

Prototype

public OutOfRangeException(Localizable specific, Number wrong, Number lo, Number hi) 

Source Link

Document

Construct an exception from the mismatched dimensions with a specific context information.

Usage

From source file:sos.base.util.genetic.SOSGeneticAlgorithm.java

/**
 * Create a new genetic algorithm.// w w  w . j  a v  a2 s . c  o  m
 * 
 * @param crossoverPolicy
 *            The {@link CrossoverPolicy}
 * @param crossoverRate
 *            The crossover rate as a percentage (0-1 inclusive)
 * @param mutationPolicy
 *            The {@link MutationPolicy}
 * @param mutationRate
 *            The mutation rate as a percentage (0-1 inclusive)
 * @param selectionPolicy
 *            The {@link SelectionPolicy}
 * @throws OutOfRangeException
 *             if the crossover or mutation rate is outside the [0, 1] range
 */
public SOSGeneticAlgorithm(final CrossoverPolicy crossoverPolicy, final double crossoverRate,
        final MutationPolicy mutationPolicy, final double mutationRate, final SelectionPolicy selectionPolicy,
        final SOSSelectionPolicy sosSelect) throws OutOfRangeException {

    this.sosSelect = sosSelect;
    if (crossoverRate < 0 || crossoverRate > 1) {
        throw new OutOfRangeException(LocalizedFormats.CROSSOVER_RATE, crossoverRate, 0, 1);
    }
    if (mutationRate < 0 || mutationRate > 1) {
        throw new OutOfRangeException(LocalizedFormats.MUTATION_RATE, mutationRate, 0, 1);
    }
    this.crossoverPolicy = crossoverPolicy;
    this.crossoverRate = crossoverRate;
    this.mutationPolicy = mutationPolicy;
    this.mutationRate = mutationRate;
    this.selectionPolicy = selectionPolicy;
}