source: src/main/java/weka/experiment/RemoteExperimentSubTask.java @ 21

Last change on this file since 21 was 4, checked in by gnappo, 14 years ago

Import di weka.

File size: 3.8 KB
Line 
1/*
2 *    This program is free software; you can redistribute it and/or modify
3 *    it under the terms of the GNU General Public License as published by
4 *    the Free Software Foundation; either version 2 of the License, or
5 *    (at your option) any later version.
6 *
7 *    This program is distributed in the hope that it will be useful,
8 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
9 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 *    GNU General Public License for more details.
11 *
12 *    You should have received a copy of the GNU General Public License
13 *    along with this program; if not, write to the Free Software
14 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
15 */
16
17/*
18 *    RemoteExperimentSubTask.java
19 *    Copyright (C) 2000 University of Waikato, Hamilton, New Zealand
20 *
21 */
22
23package weka.experiment;
24
25import weka.core.RevisionHandler;
26import weka.core.RevisionUtils;
27
28import java.io.File;
29
30/**
31 * Class to encapsulate an experiment as a task that can be executed on
32 * a remote host.
33 *
34 * @author Mark Hall (mhall@cs.waikato.ac.nz)
35 * @version $Revision: 1.10 $
36 */
37public class RemoteExperimentSubTask
38  implements Task, RevisionHandler {
39
40  /* Info on the task */
41  private TaskStatusInfo m_result = new TaskStatusInfo();
42 
43  /* The (sub) experiment to execute */
44  private Experiment m_experiment;
45 
46  public RemoteExperimentSubTask() {
47    m_result.setStatusMessage("Not running.");
48    m_result.setExecutionStatus(TaskStatusInfo.TO_BE_RUN);
49  }
50
51  /**
52   * Set the experiment for this sub task
53   * @param task the experiment
54   */
55  public void setExperiment(Experiment task) {
56    m_experiment = task;
57  }
58 
59  /**
60   * Get the experiment for this sub task
61   * @return this sub task's experiment
62   */
63  public Experiment getExperiment() {
64    return m_experiment;
65  }
66 
67  /**
68   * Run the experiment
69   */
70  public void execute() {
71    //      FastVector result = new FastVector();
72    m_result = new TaskStatusInfo();
73    m_result.setStatusMessage("Running...");
74    String goodResult = "(sub)experiment completed successfully";
75    String subTaskType;
76    if (m_experiment.getRunLower() != m_experiment.getRunUpper()) {
77      subTaskType = "(dataset "
78        + ((File)m_experiment.getDatasets().elementAt(0)).getName();
79    } else {
80      subTaskType = "(exp run # "+
81        m_experiment.getRunLower();
82    }
83    try {       
84      System.err.println("Initializing " + subTaskType + ")...");
85      m_experiment.initialize();
86      System.err.println("Iterating " + subTaskType + ")...");
87      // Do not invoke runExperiment(): every exception will be lost
88      while (m_experiment.hasMoreIterations()) {
89        m_experiment.nextIteration();
90      }
91      System.err.println("Postprocessing " + subTaskType + ")...");
92      m_experiment.postProcess();
93    } catch (Exception ex) {
94      ex.printStackTrace();
95      String badResult =  "(sub)experiment " + subTaskType
96        + ") failed : "+ex.toString();
97      m_result.setExecutionStatus(TaskStatusInfo.FAILED);
98      //        m_result.addElement(new Integer(RemoteExperiment.FAILED));
99      //        m_result.addElement(badResult);
100      m_result.setStatusMessage(badResult);
101      m_result.setTaskResult("Failed");
102      //      return m_result;
103      return;
104    }           
105    //      m_result.addElement(new Integer(RemoteExperiment.FINISHED));
106    //      m_result.addElement(goodResult);
107    m_result.setExecutionStatus(TaskStatusInfo.FINISHED);
108    m_result.setStatusMessage(goodResult+" "+subTaskType+").");
109    m_result.setTaskResult("No errors");
110    //    return m_result;
111  }
112
113  public TaskStatusInfo getTaskStatus() {
114    return m_result;
115  }
116 
117  /**
118   * Returns the revision string.
119   *
120   * @return            the revision
121   */
122  public String getRevision() {
123    return RevisionUtils.extract("$Revision: 1.10 $");
124  }
125}
126
127
128
129
130
131
Note: See TracBrowser for help on using the repository browser.