老师布置了一个作业,就是用java实现string matching 的几个算法,让我们在这个模板下实现naive algorithm,KMP,Boyer-Moore.我现在只要先弄出来一个,后面的就应该要好点.模板如下:
package algorithms;import java.util.Vector;import gui.AlgorithmParameter;
import gui.BioinfAlgorithm;public class NaiveSearch extends BioinfAlgorithm {
public NaiveSearch()
{
super("dummy value");
//initialisation
}
public Vector<AlgorithmParameter> getInputParameters() {
// TODO 自动生成方法存根
return null;
}
public String getName() {
// TODO 自动生成方法存根
return null;
}
public String run(Vector<AlgorithmParameter> params) {
// TODO 自动生成方法存根
return null;
} public static void main(String[] args) { BioinfAlgorithm algo = new NaiveSearch(); Vector<String> n = null;
Vector<AlgorithmParameter> params = algo.getInputParameters(); for (int i = 0; i < params.size(); i++) {
params.elementAt(i).data = params.elementAt(i).defVal;
} System.out.println(algo.run(params)); }
}老师还同时给出了GUI,包括BioAlgorithm.java,如下:
package gui;
import java.util.Vector;/**
* This class is the superclass for the BioinfAlgo algorithm
* gui-interface. It defines and provides access functions
* for a generic gui creation and algorithm call.
*
* @author mmann
*
*/
public abstract class BioinfAlgorithm {
/**
* the URL-string to the description file in html format
*/
protected String descriptionFileName;
/**
* Constructor initialises the descriptionFileName.
*
* @param descrFileName the URL-string to the description file in html format
*/
public BioinfAlgorithm(String descrFileName) {
descriptionFileName = descrFileName;
}
/**
* Acces to the description file url
*
* @return the URL-string representation to the description file in html format
*/
public String getDescriptionFileName() {
return descriptionFileName;
}
/**
* Access to the algorithm name.
*
* @return the name of the algorithm
*/
abstract public String getName();
/**
* The returned parameter descriptions will be used to set up the
* parameter input interface in the gui. The parameters are listed in
* the order given by the returned vector.
*
* @return the neccessary parameters for the algorithm
*/
abstract public Vector<AlgorithmParameter> getInputParameters();
/**
* Starts the algorithm with the given parameters in param. The algorithm
* output will be returned as string. In error case the error messages
* are returned via String too.
*
* @param params the input parameters for the run
* @return the output of the algorithm or an error message
*/
abstract public String run(Vector<AlgorithmParameter> params);
}
还有一个GUI是AlgorithmParameter.java,代码如下:package gui;/**
* This class provides a generic representation for the input parameters
* of BioinfAlgorithm. It is used to build up a GUI for user inputs and
* to run the algorithm
*
* @author mmann
*
*/
public class AlgorithmParameter {
/**
* A short name of the parameter.
*/
public String name = "";
/**
* A detailed description of the parameter.
*/
public String description = ""; /**
* The class of the Parameter. (Currently all Number derived classes
* and String supported.)
*/
public Class type = Object.class;
/**
* The value of the parameter submitted to run the algorithm.
*/
public Object data = null;
/**
* The default value of the parameter.
*/
public Object defVal = null;
/**
* Creates a parameter and initialises the internal datastructures.
*
* @param name_ a short name of the parameter
* @param descr_ a detailed parameter description
* @param type_ the type of the parameter (String or Number derived classes)
*/
public AlgorithmParameter(String name_, String descr_, Class type_) {
name = name_;
description = descr_;
type = type_;
} /**
* Creates a parameter and initialises the internal datastructures.
*
* @param name_ a short name of the parameter
* @param descr_ a detailed parameter description
* @param type_ the type of the parameter (String or Number derived classes)
* @param defaultData the default value of the parameter
*/
public AlgorithmParameter(String name_, String descr_, Class type_, Object defaultData) {
this(name_, descr_, type_);
// check if the default value can be casted
if (defaultData != null && !defaultData.getClass().equals(type_))
throw new ClassCastException();
else
defVal = defaultData;
}
}我现在用eclipse把上面两个文件都放到GUI这个包下面,然后就是要想办法在第一个模板下面实现算法,老师说最后的效果是通过gui可以可视化这些算法.希望有牛人可以帮我看看.
具体作业的网址我贴出来,不过是德语的,本人在德国上学:http://www.bioinf.uni-freiburg.de/Lehre/Courses/2009_WS/Prakt_Algorithem_in_der_Bioinformatik/
package algorithms;import java.util.Vector;import gui.AlgorithmParameter;
import gui.BioinfAlgorithm;public class NaiveSearch extends BioinfAlgorithm {
public NaiveSearch()
{
super("dummy value");
//initialisation
}
public Vector<AlgorithmParameter> getInputParameters() {
// TODO 自动生成方法存根
return null;
}
public String getName() {
// TODO 自动生成方法存根
return null;
}
public String run(Vector<AlgorithmParameter> params) {
// TODO 自动生成方法存根
return null;
} public static void main(String[] args) { BioinfAlgorithm algo = new NaiveSearch(); Vector<String> n = null;
Vector<AlgorithmParameter> params = algo.getInputParameters(); for (int i = 0; i < params.size(); i++) {
params.elementAt(i).data = params.elementAt(i).defVal;
} System.out.println(algo.run(params)); }
}老师还同时给出了GUI,包括BioAlgorithm.java,如下:
package gui;
import java.util.Vector;/**
* This class is the superclass for the BioinfAlgo algorithm
* gui-interface. It defines and provides access functions
* for a generic gui creation and algorithm call.
*
* @author mmann
*
*/
public abstract class BioinfAlgorithm {
/**
* the URL-string to the description file in html format
*/
protected String descriptionFileName;
/**
* Constructor initialises the descriptionFileName.
*
* @param descrFileName the URL-string to the description file in html format
*/
public BioinfAlgorithm(String descrFileName) {
descriptionFileName = descrFileName;
}
/**
* Acces to the description file url
*
* @return the URL-string representation to the description file in html format
*/
public String getDescriptionFileName() {
return descriptionFileName;
}
/**
* Access to the algorithm name.
*
* @return the name of the algorithm
*/
abstract public String getName();
/**
* The returned parameter descriptions will be used to set up the
* parameter input interface in the gui. The parameters are listed in
* the order given by the returned vector.
*
* @return the neccessary parameters for the algorithm
*/
abstract public Vector<AlgorithmParameter> getInputParameters();
/**
* Starts the algorithm with the given parameters in param. The algorithm
* output will be returned as string. In error case the error messages
* are returned via String too.
*
* @param params the input parameters for the run
* @return the output of the algorithm or an error message
*/
abstract public String run(Vector<AlgorithmParameter> params);
}
还有一个GUI是AlgorithmParameter.java,代码如下:package gui;/**
* This class provides a generic representation for the input parameters
* of BioinfAlgorithm. It is used to build up a GUI for user inputs and
* to run the algorithm
*
* @author mmann
*
*/
public class AlgorithmParameter {
/**
* A short name of the parameter.
*/
public String name = "";
/**
* A detailed description of the parameter.
*/
public String description = ""; /**
* The class of the Parameter. (Currently all Number derived classes
* and String supported.)
*/
public Class type = Object.class;
/**
* The value of the parameter submitted to run the algorithm.
*/
public Object data = null;
/**
* The default value of the parameter.
*/
public Object defVal = null;
/**
* Creates a parameter and initialises the internal datastructures.
*
* @param name_ a short name of the parameter
* @param descr_ a detailed parameter description
* @param type_ the type of the parameter (String or Number derived classes)
*/
public AlgorithmParameter(String name_, String descr_, Class type_) {
name = name_;
description = descr_;
type = type_;
} /**
* Creates a parameter and initialises the internal datastructures.
*
* @param name_ a short name of the parameter
* @param descr_ a detailed parameter description
* @param type_ the type of the parameter (String or Number derived classes)
* @param defaultData the default value of the parameter
*/
public AlgorithmParameter(String name_, String descr_, Class type_, Object defaultData) {
this(name_, descr_, type_);
// check if the default value can be casted
if (defaultData != null && !defaultData.getClass().equals(type_))
throw new ClassCastException();
else
defVal = defaultData;
}
}我现在用eclipse把上面两个文件都放到GUI这个包下面,然后就是要想办法在第一个模板下面实现算法,老师说最后的效果是通过gui可以可视化这些算法.希望有牛人可以帮我看看.
具体作业的网址我贴出来,不过是德语的,本人在德国上学:http://www.bioinf.uni-freiburg.de/Lehre/Courses/2009_WS/Prakt_Algorithem_in_der_Bioinformatik/
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货