RemoteExperimentSubTask.java
Upload User: rhdiban
Upload Date: 2013-08-09
Package Size: 15085k
Code Size: 3k
Category:

Windows Develop

Development Platform:

Java

  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.  *    RemoteExperimentSubTask.java
  18.  *    Copyright (C) 2000 Mark Hall
  19.  *
  20.  */
  21. package weka.experiment;
  22. import java.io.File;
  23. /**
  24.  * Class to encapsulate an experiment as a task that can be executed on
  25.  * a remote host.
  26.  *
  27.  * @author Mark Hall (mhall@cs.waikato.ac.nz)
  28.  * @version $Revision: 1.5 $
  29.  */
  30. public class RemoteExperimentSubTask implements Task {
  31.     /* The (sub) experiment to execute */
  32.     private Experiment m_experiment;
  33.     /**
  34.      * Set the experiment for this sub task
  35.      * @param task the experiment
  36.      */
  37.     public void setExperiment(Experiment task) {
  38.       m_experiment = task;
  39.     }
  40.     /**
  41.      * Get the experiment for this sub task
  42.      * @return this sub task's experiment
  43.      */
  44.     public Experiment getExperiment() {
  45.       return m_experiment;
  46.     }
  47.     
  48.     /**
  49.      * Run the experiment
  50.      */
  51.     public TaskStatusInfo execute() {
  52.       //      FastVector result = new FastVector();
  53.       TaskStatusInfo result = new TaskStatusInfo();
  54.       result.setStatusMessage("Running...");
  55.       String goodResult = "(sub)experiment completed successfully";
  56.       String subTaskType;
  57.       if (m_experiment.getRunLower() != m_experiment.getRunUpper()) {
  58. subTaskType = "(datataset "
  59.   + ((File)m_experiment.getDatasets().elementAt(0)).getName();
  60.       } else {
  61. subTaskType = "(exp run # "+
  62.   m_experiment.getRunLower();
  63.       }
  64.       try {
  65. System.err.println("Initializing " + subTaskType + ")...");
  66. m_experiment.initialize();
  67. System.err.println("Iterating " + subTaskType + ")...");
  68. m_experiment.runExperiment();
  69. System.err.println("Postprocessing " + subTaskType + ")...");
  70. m_experiment.postProcess();
  71.       } catch (Exception ex) {
  72. ex.printStackTrace();
  73. String badResult =  "(sub)experiment " + subTaskType 
  74.   + ") failed : "+ex.toString();
  75. result.setExecutionStatus(TaskStatusInfo.FAILED);
  76. // result.addElement(new Integer(RemoteExperiment.FAILED));
  77. // result.addElement(badResult);
  78. result.setStatusMessage(badResult);
  79. result.setTaskResult("Failed");
  80. return result;
  81.       }            
  82.       //      result.addElement(new Integer(RemoteExperiment.FINISHED));
  83.       //      result.addElement(goodResult);
  84.       result.setExecutionStatus(TaskStatusInfo.FINISHED);
  85.       result.setStatusMessage(goodResult+" "+subTaskType+").");
  86.       result.setTaskResult("No errors");
  87.       return result;
  88.     }
  89. }