恳请各位高手帮忙解决一下问题
编译时,public Swarm swarm = new Swarm(); 红色部分 这里提示找不到符号,该怎么改呢?import landing.PSO.Swarm; //PSOAlgorithm;
import landing.PSO.Particle; //PSOParameters;
import landing.PSO.PSOParameters;
import landing.PSO.GUIParameterDialog;
//import landing.PSO.PSOAlgorithm;
import java.awt.Button;
import java.awt.Checkbox;
import java.awt.Choice;
import java.awt.Color;
import java.
import java.awt.Container;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Label;
import java.awt.PrintJob;
import java.awt.TextComponent;
import java.awt.TextField;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
public class landingPSOGUI extends Frame
implements ActionListener,WindowListener, ItemListener
{
private Thread runner;
private boolean pauseFlag = false;
private boolean runDoneFlag;
private int iterationCount; //迭代计数
//private Particle particle = new Particle();
public Swarm swarm = new Swarm();
private PSOParameters psoPara = new PSOParameters();
//private PSOAlgorithm psoAl;
private String populationSize;
private String initialWeight;
private String defaultVelocityMaximum = "20";
private String velocityMaximum = this.defaultVelocityMaximum;
private String defaultPositionMaximum = "100";
private String positionMaximum = this.defaultPositionMaximum;
private String iterationMaximum;
private String defaultXIndex = "0";
private String xIndex = this.defaultXIndex;
private String defaultYIndex = "1";
private String yIndex = this.defaultYIndex;
private String defaultDisplayStepSize = "10";
private String displayStepSize = this.defaultDisplayStepSize;
private String defaultFunctionName = "landinggear";
private String functionName = this.defaultFunctionName;
private String defaultFunctionDimension = "7";
private String functionDimension = this.defaultFunctionDimension;
private int[] leftInitialRange;
private int[] rightInitialRange;
private TextField tfInitialWeight;
private TextField tfPopulationSize;
private TextField tfIterationMaximum;
private TextField tfFunctionDimension;
private TextField tfVelocityMaximum; //我加上2个
private Choice cFunctionName;
private Button bHelp;
private Button bSetParameter;
private Button bRun;
private Button bPause;
private Button bStop;
private Button bPrint;
private Button bExit;
private TextField tfIteration;
private TextField tfBestFitness;
private TextField tfAverageFitness;
private TextField tfVarianceFitness;
private TextField tfOptposition; //再加一个最优位置
public landingPSOGUI(String paramString)
{
super(paramString);
setSize(550, 300);
setLayout(new GridBagLayout());
GridBagConstraints localGridBagConstraints = new GridBagConstraints();
localGridBagConstraints.fill = 0;
localGridBagConstraints.weightx = 20.0D;
localGridBagConstraints.weighty = 100.0D;
add(new Label("Initial W"), localGridBagConstraints, 0, 0, 1, 1);
this.tfInitialWeight = new TextField("0.9", 10);
add(this.tfInitialWeight, localGridBagConstraints, 1, 0, 1, 1);
add(new Label("Popu Size"), localGridBagConstraints, 2, 0, 1, 1);
this.tfPopulationSize = new TextField("20", 10);
add(this.tfPopulationSize, localGridBagConstraints, 3, 0, 1, 1);
add(new Label("max Velocity"), localGridBagConstraints, 4, 0, 1, 1);
this.tfVelocityMaximum = new TextField("20", 10);
add(this.tfVelocityMaximum, localGridBagConstraints, 5, 0, 1, 1);
add(new Label("Function Dimension"), localGridBagConstraints, 6, 0, 1, 1);
this.tfFunctionDimension = new TextField("7", 10);
add(this.tfFunctionDimension, localGridBagConstraints, 7, 0, 1, 1);
add(new Label("Iterations"), localGridBagConstraints, 0, 1, 1, 1);
this.tfIterationMaximum = new TextField("1000", 10);
add(this.tfIterationMaximum, localGridBagConstraints, 1, 1, 1, 1);
add(new Label("Function choice"), localGridBagConstraints, 3, 1, 1, 1);
this.cFunctionName = new Choice();
this.cFunctionName.add("landinggear");
this.cFunctionName.add("Sphere");
this.cFunctionName.add("Rosenbrock");
this.cFunctionName.add("Rastrigrin");
this.cFunctionName.add("Griewank");
this.cFunctionName.add("DeJong F4");
this.cFunctionName.add("DeJong F4 with noise");
this.cFunctionName.add("Ackley");
this.cFunctionName.add("Koon F3");
this.cFunctionName.add("Bohachevsky");
this.cFunctionName.add("GoldsteinP");
this.cFunctionName.add("Easom");
this.cFunctionName.add("Floudas");
this.cFunctionName.add("Beale");
this.cFunctionName.add("Matyas");
this.cFunctionName.add("Zettl");
this.cFunctionName.addItemListener(this);
add(this.cFunctionName, localGridBagConstraints, 4, 1, 1, 1);
this.bSetParameter = new Button("Set Para");
add(this.bSetParameter, localGridBagConstraints, 0, 2, 1, 1);
this.bSetParameter.addActionListener(this);
this.bSetParameter.setEnabled(true);
this.bRun = new Button("Run");
add(this.bRun, localGridBagConstraints, 1, 2, 1, 1);
this.bRun.addActionListener(this);
this.bRun.setEnabled(false);
this.bPause = new Button("Pause");
add(this.bPause, localGridBagConstraints, 2, 2, 1, 1);
this.bPause.addActionListener(this);
this.bPause.setEnabled(false);
this.bStop = new Button("Stop");
add(this.bStop, localGridBagConstraints, 3, 2, 1, 1);
this.bStop.addActionListener(this);
this.bStop.setEnabled(false);
this.bPrint = new Button("Print");
add(this.bPrint, localGridBagConstraints, 4, 2, 1, 1);
this.bPrint.addActionListener(this);
this.bPrint.setEnabled(false);
this.bExit = new Button("Exit");
add(this.bExit, localGridBagConstraints, 5, 2, 1, 1);
this.bExit.addActionListener(this);
add(new Label("Iteration"), localGridBagConstraints, 4, 3, 1, 1);
this.tfIteration = new TextField(13);
add(this.tfIteration, localGridBagConstraints, 5, 3, 1, 1);
Label localLabel1 = new Label("Best Fitness");
localLabel1.setForeground(Color.red);
add(localLabel1, localGridBagConstraints, 4, 4, 1, 1);
this.tfBestFitness = new TextField(13);
add(this.tfBestFitness, localGridBagConstraints, 5, 4, 1, 1);
Label localLabel2 = new Label("Average fitness");
localLabel2.setForeground(Color.blue);
add(localLabel2, localGridBagConstraints, 4, 5, 1, 1);
this.tfAverageFitness = new TextField(13);
add(this.tfAverageFitness, localGridBagConstraints, 5, 5, 1, 1);
setForeground(Color.black);
add(new Label("Variance"), localGridBagConstraints, 4, 6, 1, 1);
this.tfVarianceFitness = new TextField(13);
add(this.tfVarianceFitness, localGridBagConstraints, 5, 6, 1, 1);
add(new Label("Optposition"), localGridBagConstraints, 4, 7, 1, 1);
this.tfIteration = new TextField(26);
add(this.tfIteration, localGridBagConstraints, 5, 7, 1, 1);
addWindowListener(this);
}
public void add(Component paramComponent, GridBagConstraints paramGridBagConstraints, int paramInt1, int paramInt2, int paramInt3, int paramInt4)
{
paramGridBagConstraints.gridx = paramInt1;
paramGridBagConstraints.gridy = paramInt2;
paramGridBagConstraints.gridwidth = paramInt3;
paramGridBagConstraints.gridheight = paramInt4;
add(paramComponent, paramGridBagConstraints); //添加参数组件和框架?
}
public void actionPerformed(ActionEvent paramActionEvent)
{
String str = paramActionEvent.getActionCommand();
if (str.equals("Set Para")) {
setParameter();
return;
}
if (str.equals("Run")) {
psoRun();
return;
}
if (str.equals("Pause")) {
psoPause();
return;
}
if (str.equals("Stop")) {
psoStop();
return;
}
if (str.equals("Exit")) {
psoExit();
return;
}
}
private void psoExit()
{
super.dispose();
}
private void setParameter()
{
this.initialWeight = this.tfInitialWeight.getText();
this.populationSize = this.tfPopulationSize.getText();
this.iterationMaximum = this.tfIterationMaximum.getText();
this.velocityMaximum = this.tfVelocityMaximum.getText();
this.functionDimension = this.tfFunctionDimension.getText();
if ((this.initialWeight.equals("")) || (this.positionMaximum.equals("")) ||
(this.populationSize.equals("")) || (this.iterationMaximum.equals("")) ||
(this.functionName.equals("")) || (this.functionDimension.equals(""))) {
return;
}
this.bSetParameter.setEnabled(true);
this.bRun.setEnabled(true);
this.bPause.setEnabled(false);
this.bStop.setEnabled(false);
this.bPrint.setEnabled(false);
}
private void psoRun()
{
this.pauseFlag = false;
this.runDoneFlag = false; //用了2个不懂的
this.iterationCount = 0; //迭代计数 初始为0
setPSOParameters(); //设置参数
this.psoPara.getPopulationSize();
this.psoPara.getFunctionDimension();
this.psoPara.getMaximumVelocity();
this.psoPara.getInitialWeight();
this.psoPara.getMaximumGeneration();
this.leftInitialRange[0] = 12;
this.leftInitialRange[1] = 60;
this.leftInitialRange[2] = 8;
this.leftInitialRange[3] = -115;
this.leftInitialRange[4] = 20;
this.leftInitialRange[5] = 13;
this.leftInitialRange[6] = 15;
this.rightInitialRange[0] = 14;
this.rightInitialRange[1] = 100;
this.rightInitialRange[2] = 12;
this.rightInitialRange[3] = -100;
this.rightInitialRange[4] = 24;
this.rightInitialRange[5] = 18;
this.rightInitialRange[6] = 25;
GUIParameterDialog localGUIParameterDialog = new GUIParameterDialog(this, this.psoPara);
localGUIParameterDialog.show();
if (localGUIParameterDialog.getActionFlag() == true)
{
swarm = new Swarm (this.psoPara.getFunctionDimension(), this.psoPara.getPopulationSize(),this.psoPara.getMaximumVelocity(),this.leftInitialRange,this.rightInitialRange,this.psoPara.getInitialWeight() );
//进入到算法中
this.bSetParameter.setEnabled(false);
this.bRun.setEnabled(false);
this.bPause.setEnabled(true);
this.bStop.setEnabled(true);
this.bPrint.setEnabled(false);
this.bExit.setEnabled(false);
// this.runner = new Thread(this);
//this.runner.start();
}
} //运行时的事件
public void setPSOParameters() //定义前面的setPSOParameters
{
this.psoPara.setInitialWeight(Double.valueOf(this.initialWeight).doubleValue());
this.psoPara.setPopulationSize(Integer.valueOf(this.populationSize).intValue());
this.psoPara.setMaximumPosition(Double.valueOf(this.positionMaximum).doubleValue());
this.psoPara.setMaximumVelocity(Double.valueOf(this.velocityMaximum).doubleValue());
this.psoPara.setXIndex(Integer.valueOf(this.xIndex).intValue());
this.psoPara.setYIndex(Integer.valueOf(this.yIndex).intValue());
this.psoPara.setDisplayStepSize(Integer.valueOf(this.displayStepSize).intValue());
this.psoPara.setMaximumGeneration(Integer.valueOf(this.iterationMaximum).intValue());
this.psoPara.setFunctionName(this.functionName);
this.psoPara.setFunctionDimension(Integer.valueOf(this.functionDimension).intValue());
}
private void psoPause()
{
if ((this.runner != null) && (this.runner.isAlive()))
{
if (this.pauseFlag == true)
{
this.pauseFlag = false;
this.runner.resume();
}
else
{
this.pauseFlag = true;
this.runner.suspend();
}
}
this.bSetParameter.setEnabled(false);
this.bRun.setEnabled(false);
this.bPause.setEnabled(true);
this.bStop.setEnabled(true);
this.bExit.setEnabled(false);
this.bPrint.setEnabled(false);
}
private void psoStop()
{
if ((this.runner != null) && (this.runner.isAlive())) {
this.runner.stop();
}
this.runDoneFlag = true;
this.bSetParameter.setEnabled(true);
this.bRun.setEnabled(true);
this.bPause.setEnabled(false);
this.bStop.setEnabled(false);
this.bExit.setEnabled(true);
this.bPrint.setEnabled(false);
}
public void itemStateChanged(ItemEvent paramItemEvent)
{
this.functionName = this.cFunctionName.getSelectedItem();
if (this.functionName.equals("landinggear"))
{
this.functionDimension = "7";
return;
}
if (this.functionName.equals("Bohachevsky"))
{
this.functionDimension = "2";
return;
}
if (this.functionName.equals("Colville"))
{
this.functionDimension = "4";
return;
}
if (this.functionName.equals("GoldsteinP"))
{
this.functionDimension = "2";
return;
}
if (this.functionName.equals("Easom"))
{
this.functionDimension = "2";
return;
}
if (this.functionName.equals("Floudas"))
{
this.functionDimension = "5";
return;
}
if (this.functionName.equals("Beale"))
{
this.functionDimension = "2";
return;
}
if (this.functionName.equals("Matyas"))
{
this.functionDimension = "2";
return;
}
if (this.functionName.equals("Zettl"))
{
this.functionDimension = "2";
return;
}
}
public void windowClosing(WindowEvent paramWindowEvent)
{
super.dispose(); }
public void windowOpened(WindowEvent paramWindowEvent) { }
public void windowIconified(WindowEvent paramWindowEvent) { }
public void windowDeiconified(WindowEvent paramWindowEvent) { }
public void windowClosed(WindowEvent paramWindowEvent) {
}
public void windowActivated(WindowEvent paramWindowEvent) {
int i = Integer.valueOf(this.displayStepSize).intValue();
if ((this.iterationCount <= i) || (this.iterationCount % i == 0)) if (this.runDoneFlag = true) return;
}
public void windowDeactivated(WindowEvent paramWindowEvent)
{
}
}