KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgap > distr > grid > JGAPRequest


1 /*
2  * This file is part of JGAP.
3  *
4  * JGAP offers a dual license model containing the LGPL as well as the MPL.
5  *
6  * For licencing information please see the file license.txt included with JGAP
7  * or have a look at the top of class org.jgap.Chromosome which representatively
8  * includes the JGAP license policy applicable for any file delivered with JGAP.
9  */

10 package org.jgap.distr.grid;
11
12 import org.homedns.dade.jcgrid.*;
13 import org.jgap.*;
14 import org.jgap.util.*;
15 import org.homedns.dade.jcgrid.worker.*;
16
17 /**
18  * An instance that creates single requests to be sent to a worker.
19  *
20  * @author Klaus Meffert
21  * @since 3.1
22  */

23 public class JGAPRequest
24     extends WorkRequest
25     implements ICloneable {
26   /** String containing the CVS revision. Read out via reflection!*/
27   private final static String JavaDoc CVS_REVISION = "$Revision: 1.8 $";
28
29   private Configuration m_config;
30
31   private Population m_pop;
32
33   private IWorkerEvolveStrategy m_evolveStrategy;
34
35   private IWorkerReturnStrategy m_returnStrategy;
36
37   private IGenotypeInitializer m_genotypeInitializer;
38
39   private GridWorkerFeedback m_workerFeedback;
40
41   /**
42    * Constructor.
43    *
44    * @param a_name String
45    * @param a_id int
46    * @param a_config Configuration
47    * @param a_strategy the strategy to choose for evolution
48    *
49    * @author Klaus Meffert
50    * @since 3.1
51    */

52   public JGAPRequest(String JavaDoc a_name, int a_id, Configuration a_config,
53                      IWorkerEvolveStrategy a_strategy) {
54     super(a_name, a_id);
55     m_config = a_config;
56     m_evolveStrategy = a_strategy;
57   }
58
59   /**
60    * Constructor.
61    *
62    * @param name String
63    * @param id int
64    * @param a_config Configuration
65    *
66    * @author Klaus Meffert
67    * @since 3.1
68    */

69   public JGAPRequest(String JavaDoc name, int id, Configuration a_config) {
70     this(name, id, a_config, new DefaultEvolveStrategy());
71   }
72
73   /**
74    * Constructor. Allows to specify a preset population with which the genotype
75    * will be initialized.
76    *
77    * @param a_name String
78    * @param a_id int
79    * @param a_config Configuration
80    * @param a_pop Population
81    * @param a_strategy the strategy to choose for evolution
82    *
83    * @author Klaus Meffert
84    * @since 3.2
85    */

86   public JGAPRequest(String JavaDoc a_name, int a_id, Configuration a_config,
87                      Population a_pop, IWorkerEvolveStrategy a_strategy) {
88     this(a_name, a_id, a_config, a_strategy);
89     m_pop = a_pop;
90   }
91
92   /**
93    * Constructor. Allows to specify a preset population with which the genotype
94    * will be initialized.
95    *
96    * @param a_name String
97    * @param a_id int
98    * @param a_config Configuration
99    * @param a_pop Population
100    *
101    * @author Klaus Meffert
102    * @since 3.2
103    */

104   public JGAPRequest(String JavaDoc a_name, int a_id, Configuration a_config,
105                      Population a_pop) {
106     this(a_name, a_id, a_config, a_pop, new DefaultEvolveStrategy());
107   }
108
109   /**
110    * Sets the strategy to use for executing the evolution with a worker for
111    * a single request.
112    *
113    * @param a_evolveStrategy the evolve strategy to use
114    *
115    * @author Klaus Meffert
116    * @since 3.2
117    */

118   public void setEvolveStrategy(IWorkerEvolveStrategy a_evolveStrategy) {
119     m_evolveStrategy = a_evolveStrategy;
120   }
121
122   /**
123    * @return the evolve strategy set
124    *
125    * @author Klaus Meffert
126    * @since 3.2
127    */

128   public IWorkerEvolveStrategy getWorkerEvolveStrategy() {
129     return m_evolveStrategy;
130   }
131
132   public void setWorkerReturnStrategy(IWorkerReturnStrategy a_strategy) {
133     m_returnStrategy = a_strategy;
134   }
135
136   /**
137    * @return the strategy which part of a result is returned by a worker
138    *
139    * @author Klaus Meffert
140    * @since 3.2
141    */

142   public IWorkerReturnStrategy getWorkerReturnStrategy() {
143     return m_returnStrategy;
144   }
145
146   public GridWorkerFeedback getWorkerFeedback() {
147    return m_workerFeedback;
148   }
149
150   public void setWorkerFeedback(GridWorkerFeedback a_feedback) {
151    m_workerFeedback = a_feedback;
152   }
153
154   /**
155    * @param a_initializer the IGenotypeInitializer to use
156    *
157    * @author Klaus Meffert
158    * @since 3.2
159    */

160   public void setGenotypeInitializer(IGenotypeInitializer a_initializer) {
161     m_genotypeInitializer = a_initializer;
162   }
163
164
165   /**
166    * @return the IGenotypeInitializer set
167    *
168    * @author Klaus Meffert
169    * @since 3.2
170    */

171   public IGenotypeInitializer getGenotypeInitializer() {
172     return m_genotypeInitializer;
173   }
174
175   /**
176    * Sets the Population to store in this request so that it can be passed to
177    * workers.
178    *
179    * @param a_pop the Population to store
180    *
181    * @author Klaus Meffert
182    * @since 3.2
183    */

184   public void setPopulation(Population a_pop) {
185     m_pop = a_pop;
186   }
187
188
189   /**
190    * @return the configuration set
191    *
192    * @author Klaus Meffert
193    * @since 3.1
194    */

195   public Configuration getConfiguration() {
196     return m_config;
197   }
198
199   /**
200    * Set a modified configuration. Should only be used to re-set a configuration
201    * because some parts have not been serialized.
202    * @param a_conf the Configuration to set
203    *
204    * @author Klaus Meffert
205    * @since 3.2
206    */

207   public void setConfiguration(Configuration a_conf) {
208     m_config = a_conf;
209   }
210
211   /**
212    * @return the population used to initialize new requests. May be null or
213    * empty
214    *
215    * @author Klaus Meffert
216    * @since 3.2
217    */

218   public Population getPopulation() {
219     return m_pop;
220   }
221
222   /**
223    * @return deep clone of current instance
224    *
225    * @author Klaus Meffert
226    * @since 3.2
227    */

228   public Object JavaDoc clone() {
229     JGAPRequest result = newInstance(getSessionName(), getRID());
230     return result;
231   }
232
233   /**
234    * Creates a new instance using the given name and ID. Reason for this method:
235    * ID cannot be set other than with construction!
236    *
237    * @param a_name the name to set
238    * @param a_ID unique ID to set
239    * @return newly created JGAPRequest object
240    *
241    * @author Klaus Meffert
242    * @since 3.2
243    */

244   public JGAPRequest newInstance(String JavaDoc a_name, int a_ID) {
245     JGAPRequest result = new JGAPRequest(a_name, a_ID,
246                                        getConfiguration(), getPopulation());
247     result.setEvolveStrategy(getWorkerEvolveStrategy());
248     result.setGenotypeInitializer(getGenotypeInitializer());
249     result.setWorkerReturnStrategy(getWorkerReturnStrategy());
250     return result;
251   }
252 }
253
Popular Tags