1
2
3
4
5
6
7
8
9 package com.delhezi.ga.selection.factory;
10
11 import com.delhezi.ga.exception.GeneticAlgorithmException;
12 import com.delhezi.ga.selection.ISelect;
13 import com.delhezi.ga.selection.LinearRanking;
14 import com.delhezi.ga.selection.RouletteWheelEffectiveImplementation;
15 import com.delhezi.ga.selection.RouletteWheelElementaryImplementation;
16 import com.delhezi.ga.selection.Tournament;
17
18 import java.util.logging.Level;
19 import java.util.logging.Logger;
20
21
22
23
24
25
26
27 public class SelectionFactory {
28
29
30 private static final Logger LOGGER =
31 Logger.getLogger(SelectionFactory.class.getName());
32
33
34 private static final String DERC = "1-8.1-1-";
35
36
37 private static final String CLASS_NAME = SelectionFactory.class.getName();
38
39
40
41
42
43
44
45
46
47 public static ISelect getSelectionMethod(
48 final SelectionMethodType selectionMethod)
49 throws GeneticAlgorithmException {
50 LOGGER.entering(CLASS_NAME, "getSelectionMethod", selectionMethod);
51 switch (selectionMethod) {
52 case RouletteWheelElementaryImplementation:
53 return new RouletteWheelElementaryImplementation();
54 case RouletteWheelEffectiveImplementation:
55 return new RouletteWheelEffectiveImplementation();
56 case Tournament:
57 return new Tournament();
58 case LinearRanking:
59 return new LinearRanking();
60 }
61
62 GeneticAlgorithmException e =
63 new GeneticAlgorithmException("DERC-" + DERC +
64 "1: Parametr selectionMethod=" +
65 selectionMethod +
66 " is not recognized.");
67 LOGGER.log(Level.WARNING, "CrossoverFactory", e);
68 throw e;
69 }
70
71
72
73
74
75
76
77
78 public static SelectionMethodType getSelectionMethodType(
79 final ISelect selectionMethod)
80 throws GeneticAlgorithmException {
81 LOGGER.entering(CLASS_NAME, "getSelectionMethodType", selectionMethod);
82
83 String pClassName = selectionMethod.getClass().getName();
84
85 if (pClassName.equals("com.delhezi.ga.selection.RouletteWheelElementaryImplementation")) {
86 return SelectionMethodType.RouletteWheelElementaryImplementation;
87 } else if (pClassName.equals("com.delhezi.ga.selection.RouletteWheelEffectiveImplementation")) {
88 return SelectionMethodType.RouletteWheelEffectiveImplementation;
89 } else if (pClassName.equals("com.delhezi.ga.selection.Tournament")) {
90 return SelectionMethodType.Tournament;
91 } else if (pClassName.equals("com.delhezi.ga.selection.LinearRanking")) {
92 return SelectionMethodType.LinearRanking;
93 }
94
95 GeneticAlgorithmException e =
96 new GeneticAlgorithmException("DERC-" + DERC +
97 "2: Parametr selectionMethod=" +
98 pClassName + " is not recognized.");
99 LOGGER.log(Level.WARNING, "CrossoverFactory", e);
100 throw e;
101 }
102
103 }