001/*
002 * Java Genetic Algorithm Library (jenetics-7.2.0).
003 * Copyright (c) 2007-2023 Franz Wilhelmstötter
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 *
017 * Author:
018 *    Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com)
019 */
020package io.jenetics;
021
022import io.jenetics.internal.util.Requires;
023
024/**
025 * Abstract implementation of the alterer interface.
026 *
027 * @author <a href="mailto:franz.wilhelmstoetter@gmail.com">Franz Wilhelmstötter</a>
028 * @since 1.0
029 * @version 6.0
030 */
031public abstract class AbstractAlterer<
032        G extends Gene<?, G>,
033        C extends Comparable<? super C>
034>
035        implements Alterer<G, C>
036{
037
038        /**
039         * The altering probability.
040         */
041        protected final double _probability;
042
043        /**
044         * Constructs an alterer with a given recombination probability.
045         *
046         * @param probability The recombination probability.
047         * @throws IllegalArgumentException if the {@code probability} is not in the
048         *         valid range of {@code [0, 1]}.
049         */
050        protected AbstractAlterer(final double probability) {
051                _probability = Requires.probability(probability);
052        }
053
054        /**
055         * Return the recombination/alter probability for this alterer.
056         *
057         * @return The recombination probability.
058         */
059        public double probability() {
060                return _probability;
061        }
062
063}