01: /*
02: * This file is part of JGAP.
03: *
04: * JGAP offers a dual license model containing the LGPL as well as the MPL.
05: *
06: * For licencing information please see the file license.txt included with JGAP
07: * or have a look at the top of class org.jgap.Chromosome which representatively
08: * includes the JGAP license policy applicable for any file delivered with JGAP.
09: */
10: package examples.grid.mathProblemDistributed;
11:
12: import org.jgap.*;
13: import org.jgap.gp.*;
14: import org.jgap.gp.impl.*;
15: import org.jgap.distr.grid.gp.*;
16: import org.jgap.distr.grid.*;
17: import org.apache.log4j.*;
18:
19: /**
20: * Listener for feedback sent to the GP client. This is a simple sample
21: * implementation.
22: *
23: * @author Klaus Meffert
24: * @since 3.2
25: */
26: public class MyClientFeedback implements IClientFeedbackGP {
27: /** String containing the CVS revision. Read out via reflection!*/
28: private final static String CVS_REVISION = "$Revision: 1.5 $";
29:
30: private static Logger log = Logger
31: .getLogger(MyClientFeedback.class);
32:
33: public MyClientFeedback() {
34: }
35:
36: public void error(String msg, Exception ex) {
37: log.error("Error catched on client side: " + msg, ex);
38: }
39:
40: public void sendingFragmentRequest(JGAPRequestGP req) {
41: log.info("Sending work request " + req.getRID());
42: }
43:
44: public void receivedFragmentResult(JGAPRequestGP req,
45: JGAPResultGP res, int idx) {
46: // This is just a quick and dirty solution.
47: // Can you do it better?
48: // ----------------------------------------
49: GPPopulation pop = res.getPopulation();
50: if (pop == null || pop.isFirstEmpty()) {
51: IGPProgram best = res.getFittest();
52: log.warn("Receiving work (index " + idx
53: + "). Best solution: " + best.getFitnessValue());
54: return;
55: }
56: if (pop == null) {
57: log.error("Received empty result/population!");
58: } else {
59: log.warn("Receiving work (index " + idx
60: + "). First solution: " + pop.getGPProgram(0));
61: }
62: }
63:
64: public void beginWork() {
65: log.warn("Client starts sending work requests");
66: }
67:
68: public void endWork() {
69: log.warn("Your request was processed completely");
70: }
71:
72: public void info(String a_msg) {
73: log.warn(a_msg);
74: }
75:
76: public void setProgressMaximum(int max) {
77: }
78:
79: public void setProgressMinimum(int min) {
80: }
81:
82: public void setProgressValue(int val) {
83: }
84:
85: public void setRenderingTime(JGAPRequest req, long dt) {
86: }
87:
88: public void completeFrame(int idx) {
89: log.warn("Client notified that unit " + idx + " is finished.");
90: }
91: }
|