V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
yanyumihuang
V2EX  ›  问与答

粒子群算法的编码方式有哪些?

  •  
  •   yanyumihuang · Apr 30, 2022 · 896 views
    This topic created in 1464 days ago, the information mentioned may be changed or developed.

    在解决一个函数的最大值时碰见了问题,老师让用遗传算法和粒子群算法进行求解,我采用了浮点数方法进行编码,并写出了相应的代码。交上去后,老师说编码方式有不小的问题。遗传算法猜测可以用二进制来替换原来的浮点数编码,但粒子群我就不太清楚该怎么改了。本人是刚接触这个优化算法,老师也只是说编码方式有问题,搜了很多资料根本没有提到粒子群的编码方式,因此发帖求求大佬点醒 初始化粒子的位置

     public static float[] initData(){
            float[] data=new float[8];
            for (int i = 0; i < 8; i++) {
                data[i]= (float) (Math.random() * (GeneticAlgorithm.max - GeneticAlgorithm.min) + GeneticAlgorithm.min);
            }
            return data;
        }
    

    初始化粒子的速度

        public static float[] initVelocity(){
            float[] velocity=new float[8];
            for (int i = 0; i < 8; i++) {
                velocity[i]= (float) (Math.random() * (velocityMax - velocityMin) + velocityMin);
            }
            return velocity;
        }
    
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   971 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 23:41 · PVG 07:41 · LAX 16:41 · JFK 19:41
    ♥ Do have faith in what you're doing.