1 /**
2 * @(#)StateInitialized.java
3 * Copyright (C) 2008-2011 delhezi.com
4 *
5 * This class is released under the:
6 * GNU Lesser General Public License (LGPL) version 3 or later.
7 * http://www.gnu.org/copyleft/lesser.html
8 */
9 package com.delhezi.ga;
10
11 import com.delhezi.ga.exception.GeneticAlgorithmException;
12 //import java.util.logging.Logger;
13
14 /**
15 * <code>StateInitialized</code>: Klasa określająca stan
16 * algorytmu genetycznego.
17 * @version 1.0 2011-01-10
18 * @author <a href="mailto:wojciech.wolszczak@delhezi.com">
19 * Wojciech Wolszczak</a>
20 */
21 public class StateInitialized implements State {
22 /** Logger object. */
23 //private static final Logger LOGGER =
24 // Logger.getLogger(StateInitialized.class.getName());
25
26 /** Delhezi Error Code. */
27 //private static final String DERC = "1-9-";
28 private GeneticAlgorithm ga;
29
30 /**
31 * Konstruktor.
32 * @param ga Referencja do obiektu algorytmu genetycznego.
33 * @since 1.0
34 */
35 public StateInitialized(final GeneticAlgorithm ga) {
36 this.ga = ga;
37 }
38
39 /**
40 * Uruchamia działanie algorytmu gentycznego.
41 * @throws GeneticAlgorithmException xxx
42 * @since 1.0
43 */
44 @Override
45 public final void run() throws GeneticAlgorithmException {
46 ga.setState(GeneticAlgorithmState.RUNNING);
47
48 while ((ga.getPopulation().getGeneration() <
49 ga.getMaxGenerationCount() ||
50 ga.getMaxGenerationCount() < 1) &&
51 (ga.getPopulation().getGeneration() -
52 ga.getPopulation().getTopChromosomeGenerationFound() <
53 ga.getLastGenerationTopChromosomeFind() ||
54 ga.getLastGenerationTopChromosomeFind() < 1)) {
55
56 if (ga.getState() != GeneticAlgorithmState.RUNNING) {
57 return;
58 }
59
60 ga.getPopulation().generation();
61 }
62
63 if (ga.getState() != GeneticAlgorithmState.ERROR) {
64 ga.setState(GeneticAlgorithmState.STOPPED);
65 }
66 }
67
68 /**
69 * Zatrzymuje działanie algorytmu gentycznego.
70 * @throws GeneticAlgorithmException xxx
71 * @since 1.0
72 */
73 @Override
74 public final void stop() throws GeneticAlgorithmException {
75 return;
76 }
77
78 /**
79 * Zwraca status algorytmu gentycznego.
80 * @return Status algorytmu gegentycznego.
81 * @since 1.0
82 */
83 @Override
84 public final GeneticAlgorithmState getState() {
85 return GeneticAlgorithmState.INITIALIZED;
86 }
87 }
88