001: /*
002: * This file is part of JGAP.
003: *
004: * JGAP offers a dual license model containing the LGPL as well as the MPL.
005: *
006: * For licencing information please see the file license.txt included with JGAP
007: * or have a look at the top of class org.jgap.Chromosome which representatively
008: * includes the JGAP license policy applicable for any file delivered with JGAP.
009: */
010: package org.jgap.distr.grid;
011:
012: import org.homedns.dade.jcgrid.*;
013: import org.jgap.*;
014: import org.jgap.util.*;
015: import org.homedns.dade.jcgrid.worker.*;
016:
017: /**
018: * An instance that creates single requests to be sent to a worker.
019: *
020: * @author Klaus Meffert
021: * @since 3.1
022: */
023: public class JGAPRequest extends WorkRequest implements ICloneable {
024: /** String containing the CVS revision. Read out via reflection!*/
025: private final static String CVS_REVISION = "$Revision: 1.9 $";
026:
027: private Configuration m_config;
028:
029: private Population m_pop;
030:
031: private IWorkerEvolveStrategy m_evolveStrategy;
032:
033: private IWorkerReturnStrategy m_returnStrategy;
034:
035: private IGenotypeInitializer m_genotypeInitializer;
036:
037: private GridWorkerFeedback m_workerFeedback;
038:
039: /**
040: * Constructor.
041: *
042: * @param a_name String
043: * @param a_id int
044: * @param a_config Configuration
045: * @param a_strategy the strategy to choose for evolution
046: *
047: * @author Klaus Meffert
048: * @since 3.1
049: */
050: public JGAPRequest(String a_name, int a_id, Configuration a_config,
051: IWorkerEvolveStrategy a_strategy) {
052: super (a_name, a_id);
053: m_config = a_config;
054: m_evolveStrategy = a_strategy;
055: }
056:
057: /**
058: * Constructor.
059: *
060: * @param a_name session name
061: * @param a_id request id
062: * @param a_config Configuration
063: *
064: * @author Klaus Meffert
065: * @since 3.1
066: */
067: public JGAPRequest(String a_name, int a_id, Configuration a_config) {
068: this (a_name, a_id, a_config, new DefaultEvolveStrategy());
069: }
070:
071: /**
072: * Constructor. Allows to specify a preset population with which the genotype
073: * will be initialized.
074: *
075: * @param a_name session name
076: * @param a_id request id
077: * @param a_config Configuration
078: * @param a_pop Population
079: * @param a_strategy the strategy to choose for evolution
080: *
081: * @author Klaus Meffert
082: * @since 3.2
083: */
084: public JGAPRequest(String a_name, int a_id, Configuration a_config,
085: Population a_pop, IWorkerEvolveStrategy a_strategy) {
086: this (a_name, a_id, a_config, a_strategy);
087: m_pop = a_pop;
088: }
089:
090: /**
091: * Constructor. Allows to specify a preset population with which the genotype
092: * will be initialized.
093: *
094: * @param a_name session name
095: * @param a_id request id
096: * @param a_config Configuration
097: * @param a_pop Population
098: *
099: * @author Klaus Meffert
100: * @since 3.2
101: */
102: public JGAPRequest(String a_name, int a_id, Configuration a_config,
103: Population a_pop) {
104: this (a_name, a_id, a_config, a_pop, new DefaultEvolveStrategy());
105: }
106:
107: /**
108: * Sets the strategy to use for executing the evolution with a worker for
109: * a single request.
110: *
111: * @param a_evolveStrategy the evolve strategy to use
112: *
113: * @author Klaus Meffert
114: * @since 3.2
115: */
116: public void setEvolveStrategy(IWorkerEvolveStrategy a_evolveStrategy) {
117: m_evolveStrategy = a_evolveStrategy;
118: }
119:
120: /**
121: * @return the evolve strategy set
122: *
123: * @author Klaus Meffert
124: * @since 3.2
125: */
126: public IWorkerEvolveStrategy getWorkerEvolveStrategy() {
127: return m_evolveStrategy;
128: }
129:
130: public void setWorkerReturnStrategy(IWorkerReturnStrategy a_strategy) {
131: m_returnStrategy = a_strategy;
132: }
133:
134: /**
135: * @return the strategy which part of a result is returned by a worker
136: *
137: * @author Klaus Meffert
138: * @since 3.2
139: */
140: public IWorkerReturnStrategy getWorkerReturnStrategy() {
141: return m_returnStrategy;
142: }
143:
144: public GridWorkerFeedback getWorkerFeedback() {
145: return m_workerFeedback;
146: }
147:
148: public void setWorkerFeedback(GridWorkerFeedback a_feedback) {
149: m_workerFeedback = a_feedback;
150: }
151:
152: /**
153: * @param a_initializer the IGenotypeInitializer to use
154: *
155: * @author Klaus Meffert
156: * @since 3.2
157: */
158: public void setGenotypeInitializer(
159: IGenotypeInitializer a_initializer) {
160: m_genotypeInitializer = a_initializer;
161: }
162:
163: /**
164: * @return the IGenotypeInitializer set
165: *
166: * @author Klaus Meffert
167: * @since 3.2
168: */
169: public IGenotypeInitializer getGenotypeInitializer() {
170: return m_genotypeInitializer;
171: }
172:
173: /**
174: * Sets the Population to store in this request so that it can be passed to
175: * workers.
176: *
177: * @param a_pop the Population to store
178: *
179: * @author Klaus Meffert
180: * @since 3.2
181: */
182: public void setPopulation(Population a_pop) {
183: m_pop = a_pop;
184: }
185:
186: /**
187: * @return the configuration set
188: *
189: * @author Klaus Meffert
190: * @since 3.1
191: */
192: public Configuration getConfiguration() {
193: return m_config;
194: }
195:
196: /**
197: * Set a modified configuration. Should only be used to re-set a configuration
198: * because some parts have not been serialized.
199: * @param a_conf the Configuration to set
200: *
201: * @author Klaus Meffert
202: * @since 3.2
203: */
204: public void setConfiguration(Configuration a_conf) {
205: m_config = a_conf;
206: }
207:
208: /**
209: * @return the population used to initialize new requests. May be null or
210: * empty
211: *
212: * @author Klaus Meffert
213: * @since 3.2
214: */
215: public Population getPopulation() {
216: return m_pop;
217: }
218:
219: /**
220: * @return deep clone of current instance
221: *
222: * @author Klaus Meffert
223: * @since 3.2
224: */
225: public Object clone() {
226: JGAPRequest result = newInstance(getSessionName(), getRID());
227: return result;
228: }
229:
230: /**
231: * Creates a new instance using the given name and ID. Reason for this method:
232: * ID cannot be set other than with construction!
233: *
234: * @param a_name the name to set
235: * @param a_ID unique ID to set
236: * @return newly created JGAPRequest object
237: *
238: * @author Klaus Meffert
239: * @since 3.2
240: */
241: public JGAPRequest newInstance(String a_name, int a_ID) {
242: JGAPRequest result = new JGAPRequest(a_name, a_ID,
243: getConfiguration(), getPopulation());
244: result.setEvolveStrategy(getWorkerEvolveStrategy());
245: result.setGenotypeInitializer(getGenotypeInitializer());
246: result.setWorkerReturnStrategy(getWorkerReturnStrategy());
247: return result;
248: }
249: }
|