Chromosome.java
01 /*
02  * Java Genetic Algorithm Library (jenetics-2.0.2).
03  * Copyright (c) 2007-2014 Franz Wilhelmstötter
04  *
05  * Licensed under the Apache License, Version 2.0 (the "License");
06  * you may not use this file except in compliance with the License.
07  * You may obtain a copy of the License at
08  *
09  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * Author:
18  *    Franz Wilhelmstötter (franz.wilhelmstoetter@gmx.at)
19  */
20 package org.jenetics;
21 
22 import java.io.Serializable;
23 
24 import org.jenetics.util.Factory;
25 import org.jenetics.util.ISeq;
26 import org.jenetics.util.Verifiable;
27 
28 /**
29  * A chromosome consists of one or more genes. It also provides a factory
30  * method for creating new, random chromosome instances of the same type and the
31  * same constraint.
32  *
33  @see <a href="http://en.wikipedia.org/wiki/Chromosome">Wikipdida: Chromosome</a>
34  *
35  @author <a href="mailto:franz.wilhelmstoetter@gmx.at">Franz Wilhelmstötter</a>
36  @since 1.0
37  @version 2.0 &mdash; <em>$Date: 2014-03-10 $</em>
38  */
39 public interface Chromosome<G extends Gene<?, G>>
40     extends
41         Verifiable,
42         Iterable<G>,
43         Factory<Chromosome<G>>,
44         Serializable
45 {
46 
47     /**
48      * A factory method which creates a new {@link Chromosome} of specific type
49      * and the given {@code genes}.
50      *
51      @param genes the genes of the new chromosome. The given genes array is
52      *         not copied.
53      @return A new {@link Chromosome} of the same type with the given genes.
54      @throws NullPointerException if the given {@code gene}s are {@code null}.
55      */
56     public Chromosome<G> newInstance(final ISeq<G> genes);
57 
58     /**
59      * Return the first gene of this chromosome. Each chromosome must contain
60      * at least one gene.
61      *
62      @return the first gene of this chromosome.
63      */
64     public G getGene();
65 
66     /**
67      * Return the gene on the specified index.
68      *
69      @param index The gene index.
70      @return the wanted gene.
71      @throws IndexOutOfBoundsException if the index is out of range
72      *          (index &lt; 1 || index &gt;= length()).
73      */
74     public G getGene(final int index);
75 
76     /**
77      * Returns the length of the Chromosome. The minimal length of a
78      * chromosome is one.
79      *
80      @return Length of the Chromosome
81      */
82     public int length();
83 
84     /**
85      * Return an unmodifiable sequence of the genes of this chromosome.
86      *
87      @return an immutable gene sequence.
88      */
89     public ISeq<G> toSeq();
90 
91 }