Chromosome.java
01 /*
02  * Java Genetic Algorithm Library (jenetics-1.6.0).
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 javolution.lang.Immutable;
25 
26 import org.jenetics.util.Factory;
27 import org.jenetics.util.ISeq;
28 import org.jenetics.util.Verifiable;
29 
30 /**
31  * A chromosome consists of one or more genes. It also provides a factory
32  * method for creating new, random chromosome instances of the same type and the
33  * same constraint.
34  *
35  @see <a href="http://en.wikipedia.org/wiki/Chromosome">Wikipdida: Chromosome</a>
36  *
37  @author <a href="mailto:franz.wilhelmstoetter@gmx.at">Franz Wilhelmstötter</a>
38  @since 1.0
39  @version 1.0 &mdash; <em>$Date: 2014-02-15 $</em>
40  */
41 public interface Chromosome<G extends Gene<?, G>>
42     extends
43         Verifiable,
44         Iterable<G>,
45         Immutable,
46         Factory<Chromosome<G>>,
47         Serializable
48 {
49 
50     /**
51      * A factory method which creates a new {@link Chromosome} of specific type
52      * and the given {@code genes}.
53      *
54      @param genes the genes of the new chromosome. The given genes array is
55      *         not copied.
56      @return A new {@link Chromosome} of the same type with the given genes.
57      @throws NullPointerException if the given {@code gene}s are {@code null}.
58      */
59     public Chromosome<G> newInstance(final ISeq<G> genes);
60 
61     /**
62      * Return the first gene of this chromosome. Each chromosome must contain
63      * at least one gene.
64      *
65      @return the first gene of this chromosome.
66      */
67     public G getGene();
68 
69     /**
70      * Return the gene on the specified index.
71      *
72      @param index The gene index.
73      @return the wanted gene.
74      @throws IndexOutOfBoundsException if the index is out of range
75      *          (index &lt; 1 || index &gt;= length()).
76      */
77     public G getGene(final int index);
78 
79     /**
80      * Returns the length of the Chromosome. The minimal length of a
81      * chromosome is one.
82      *
83      @return Length of the Chromosome
84      */
85     public int length();
86 
87     /**
88      * Return an unmodifiable sequence of the genes of this chromosome.
89      *
90      @return an immutable gene sequence.
91      */
92     public ISeq<G> toSeq();
93 
94 }