⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 experimentoperator.java

📁 著名的开源仿真软件yale
💻 JAVA
字号:
/* *  YALE - Yet Another Learning Environment *  Copyright (C) 2002, 2003 *      Simon Fischer, Ralf Klinkenberg, Ingo Mierswa,  *          Katharina Morik, Oliver Ritthoff *      Artificial Intelligence Unit *      Computer Science Department *      University of Dortmund *      44221 Dortmund,  Germany *  email: yale@ls8.cs.uni-dortmund.de *  web:   http://yale.cs.uni-dortmund.de/ * *  This program is free software; you can redistribute it and/or *  modify it under the terms of the GNU General Public License as  *  published by the Free Software Foundation; either version 2 of the *  License, or (at your option) any later version.  * *  This program is distributed in the hope that it will be useful, but *  WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *  General Public License for more details. * *  You should have received a copy of the GNU General Public License *  along with this program; if not, write to the Free Software *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *  USA. */package edu.udo.cs.yale.operator;import edu.udo.cs.yale.Experiment;import edu.udo.cs.yale.ExperimentListener;import edu.udo.cs.yale.operator.parameter.*;import edu.udo.cs.yale.tools.LogService;import edu.udo.cs.yale.tools.TempFileService;import edu.udo.cs.yale.tools.Tools;import java.util.List;import java.util.LinkedList;import java.util.Iterator;import java.io.File;/** Each experiment must contain exactly one operator of this class and it must be *  the root operator of the experiment. The only purpose of this operator is to provide  *  some parameters that have global relevance. * *  @yale.xmlclass Experiment *  @author Ingo *  @version $Id: ExperimentOperator.java,v 2.5 2003/07/24 15:40:59 fischer Exp $ */final public class ExperimentOperator extends OperatorChain {    private List listenerList = new LinkedList();    public ExperimentOperator() {	super();    }    /** Creates an empty operator chain. */    public ExperimentOperator(Experiment experiment) {	super();	setExperiment(experiment);    }    /** Returns the highest possible value for the maximum number of innner operators. */    public int getMaxNumberOfInnerOperators() { return Integer.MAX_VALUE; }    /** Returns 0 for the minimum number of innner operators. */    public int getMinNumberOfInnerOperators() { return 0; }    public List getParameterTypes() {	List types = super.getParameterTypes();	types.add(new ParameterTypeCategory("logverbosity", "Log verbosity level.", LogService.LOG_VERBOSITY_NAMES, LogService.MINIMUM+1));	types.add(new ParameterTypeFile("logfile", "File to write logging information to.", true));	types.add(new ParameterTypeFile("resultfile", "File to write results to.", true));	types.add(new ParameterTypeFile("temp_dir", "Directory for temp files.", true));	types.add(new ParameterTypeCategory("delete_temp_files", "Keep all or none of the generated temporary files.", TempFileService.DELETE_TEMP_FILES, TempFileService.DIRECTLY));	types.add(new ParameterTypeInt("random_seed", "Global random seed for random generators.", Integer.MIN_VALUE, Integer.MAX_VALUE, 2001));	types.add(new ParameterTypeString("notification_email", "Email address for the notification mail.", true));	return types;    }    public int getNumberOfSteps() {	return getNumberOfChildrensSteps();    }    public void addExperimentListener(ExperimentListener l) {	listenerList.add(l);    }    public void removeExperimentListener(ExperimentListener l) {	listenerList.remove(l);    }    public void countStep() {	super.countStep();	Iterator i = listenerList.iterator();	while (i.hasNext()) {	    ((ExperimentListener)i.next()).experimentStep(this);	}    }    public void sendEmail(IOContainer results, Throwable e) {	String email = getParameterAsString("notification_email");	if (email == null) return;	LogService.logMessage("Sending notification email to '"+email+"'", LogService.STATUS);  	String name = email;  	int at = name.indexOf("@");	if (at >= 0) name = name.substring(0, at);	String subject = "Experiment "+getName()+" finished";	String content = "Hello "+name+",\n\n";	content += "I'm sending you a notification message on your experiment '"+getName()+"'.\n";	File logFile = LogService.getLogFile();	if (logFile != null) {	    content += "Logfile is file://"+logFile.getAbsolutePath()+"\n\n";	}	if (e != null) {	    content += "Experiment failed: "+e.toString();	    subject =  "Experiment "+getName()+" failed";	} 	if (results != null) {	    content += "\n\nResults:";	    ResultObject result;	    int i = 0;	    do {		try {		    result = (ResultObject)results.getInput(ResultObject.class, i, false);		    content += "\n\n\n" + result.toResultString();		    i++;		} catch (MissingIOObjectException exc) {		    break;		}	    } while (result != null);	}	Tools.sendEmail(email, subject, content);    }    public Class[] getInputClasses() {	return new Class[0];    }    public Class[] getOutputClasses() {	return new Class[0];    }    /** Returns true if and only if all inner operators accept their precessors' ouput     *  as input. */    public Class[] checkIO(Class[] input) throws IllegalInputException {	for (int i = 0; i < getNumberOfOperators(); i++) {	    Operator o = getOperator(i);	    input = o.checkIO(input);	}	return input;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -