| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 753 人关注过本帖
标题:恳请各位高手帮忙解决一下问题
只看楼主 加入收藏
ainan118
Rank: 1
等 级:新手上路
帖 子:14
专家分:1
注 册:2009-8-6
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:9 
恳请各位高手帮忙解决一下问题
编译时,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)
  {
  }
  
              
  
  }
搜索更多相关主题的帖子: public import 
2009-08-06 16:44
freish
Rank: 6Rank: 6
等 级:贵宾
威 望:23
帖 子:1223
专家分:437
注 册:2007-6-1
收藏
得分:0 
Swarm这个类在里面定义的?

[url=http://shop63425653./]/cvbnm/a6/1d/f4/7dd1720119cf3b1dcfb570b467b24051.jpg" border="0" />[/url]
2009-08-06 16:53
ainan118
Rank: 1
等 级:新手上路
帖 子:14
专家分:1
注 册:2009-8-6
收藏
得分:0 
专门定义了一个 Swarm类 ,import 行吗?
2009-08-06 17:08
usbboy2009
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:39
专家分:183
注 册:2009-7-31
收藏
得分:0 
Swarm 类 是不是抽象类 有没有public修饰?
2009-08-06 18:08
ainan118
Rank: 1
等 级:新手上路
帖 子:14
专家分:1
注 册:2009-8-6
收藏
得分:0 
有的  
public class Swarm {   
    public    int swarmnum;
    public    int dimension;
    public    Particle[]    particle;
    public    float[]  groupposition;
    public    float   groupfitness;
                                   
    public long maxiteration;    //最大迭代次数  
        
    public long iteration = 0;   //迭代次数  
         
    public double cutoff;           //终止条件
      
    public int gbest = 0;            
         
    public double weight;               //权重
      
    public int run_no;               //运行的次数   
     
    public double maxruntime = 0.0;         //最大运行时间     
            
        
    public int popSize;                //群体大小  
        
        
   
         
        
    public Swarm(int dimension,int num,float vmax,float[] xmin,float[] xmax,float w)  
     
      
      {   
        particle  = new Particle[num];
        groupposition  = new float[dimension];
        this.dimension=dimension;
        swarmnum  =num;
        for(int i=0;i<num;i++)
           particle[i] = new Particle(dimension,xmin,xmax,w,vmax);   
               
           this.refreshbestposition(0);   
    }   
        
    public void movenext()
     {
     for(int i=0;i<swarmnum;i++)
     this.particle[i].stepone(this.groupposition);
     this.refreshbestposition(1);
     }
      
    public void refreshbestposition(int k)
    {
      int j=0;
      for(int m=0;m<swarmnum;m++)
        {
            if(particle[m].fitness>=particle[j].fitness)
                 j=m;
                  
                }     
          if(k==0)
          {
              for(int i=0;i<dimension;i++)
              this.groupposition[i]=particle[j].nowposition[i];
              this.groupfitness=particle[j].fitness;
               
           }
            
           else if(k==1)
           {
                 if(particle[j].fitness>=this.groupfitness)
                  
                   {
                        
                   for(int i=0;i<dimension;i++)
                     this.groupposition[i]=particle[j].nowposition[i];
                     this.groupfitness=particle[j].fitness;     
                        
                        
                   }
               
               
           }
            
           }  //end class
         
         
 
      
 
   
 
   
  }
   
   
   
 
 
 
2009-08-06 18:11
usbboy2009
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:39
专家分:183
注 册:2009-7-31
收藏
得分:0 
Swarm里的构造函数被重写了public Swarm(int dimension,int num,float vmax,float[] xmin,float[] xmax,float w)

所以调用时候 public Swarm swarm  = new Swarm(); 已经没有缺省构造函数了,除非自己在Swarm类里写个无参的
2009-08-06 18:15
ainan118
Rank: 1
等 级:新手上路
帖 子:14
专家分:1
注 册:2009-8-6
收藏
得分:0 
哦,是这样。


 如果调用     public Swarm swarm  = new Swarm(int dimension,int num,float vmax,float[] xmin,float[] xmax,float w) ;

为什么也不行呢?
 

要是在Swarm类里写个无参的,那么dimension num   vmax 这些数据怎么办啊,
2009-08-06 18:53
usbboy2009
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:39
专家分:183
注 册:2009-7-31
收藏
得分:20 
删除最前面的Swarm swarm = new Swarm();

在中间代码
Swram  swarm   = new  Swarm (this.psoPara.getFunctionDimension(), this.psoPara.getPopulationSize(),this.psoPara.getMaximumVelocity(),this.leftInitialRange,this.rightInitialRange,this.psoPara.getInitialWeight() );
前面加Swarm

我没仔细看代码中的实际参数是否类型匹配 你自己看下
Swarm(int , int , float, float, float, float )

[ 本帖最后由 usbboy2009 于 2009-8-6 20:47 编辑 ]
2009-08-06 20:43
yyjz
Rank: 1
等 级:新手上路
帖 子:26
专家分:9
注 册:2009-7-27
收藏
得分:0 
不懂 所以来这
2009-08-07 10:40
ainan118
Rank: 1
等 级:新手上路
帖 子:14
专家分:1
注 册:2009-8-6
收藏
得分:0 
请问   this.psoPara.setInitialWeight(Double.valueOf(this.initialWeight).doubleValue());   是什么意思,怎么转换成 float 数据呢?
2009-08-07 14:52
快速回复:恳请各位高手帮忙解决一下问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.036058 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved