package pso;
import java.util.ArrayList;
import java.util.List;
public class Particle {
//限制界限
final List<Double> min;
final List<Double> max;
List<Double> maxVelocity;
final int dimensions;
final int maxGeneration;
String name;
List<Double> velocity;
List<Double> coordinate;
double score;
int generation;
//加速系数
double c1;
double c2;
//惯性系数
double w;
List<Double> bestCoordinate;
double bestScore;
//产生了本粒子新的最优解,返回true
boolean getScore(){
score = Problem.function4(coordinate,dimensions);
boolean flag = score > bestScore;
if (flag){
bestScore = score;
bestCoordinate = new ArrayList<>(coordinate);
}
return flag;
}
void update(Particle bestParticle){
generation++;
updateVelocity(bestParticle.bestCoordinate);
updateCoordinate();
updateWeight();
getScore();
}
void updateWeight() {
w -= (0.5/maxGeneration);
}
void updateVelocity(List<Double> pg){
double newV = 0.0;
for (int i = 0; i < dimensions; i++) {
double r1 = Math.random();
double r2 = Math.random();
newV = w*velocity.get(i);
newV += r1*c1*(bestCoordinate.get(i)-coordinate.get(i));
newV += r2*c2*(pg.get(i)-coordinate.get(i));
//不能超速
if(newV > maxVelocity.get(i))
newV = maxVelocity.get(i);
if(newV < -maxVelocity.get(i))
newV = -maxVelocity.get(i);
velocity.set(i,newV);
}
}
void updateCoordinate(){
double newX = 0.0;
for (int i = 0; i < dimensions; i++) {
newX = coordinate.get(i) + velocity.get(i);
//不能越界
if(newX > max.get(i))
newX = max.get(i);
if(newX < min.get(i))
newX = min.get(i);
coordinate.set(i,newX);
}
}
void initialCoordinate(){
coordinate = new ArrayList<>();
for (int i = 0; i < dimensions; i++) {
double d = (max.get(i)- min.get(i))*Math.random() + min.get(i);
coordinate.add(d);
}
}
void initialVelocity(){
velocity = new ArrayList<>();
for (int i = 0; i < dimensions; i++) {
double d = 2*(maxVelocity.get(i))*Math.random()-maxVelocity.get(i);
velocity.add(d);
}
}
public Particle(List<Double> min, List<Double> max, List<Double> maxVelocity, int dimensions, int maxGeneration, double c1, double c2, double w,String name) {
this.min = min;
this.max = max;
this.maxVelocity = maxVelocity;
this.dimensions = dimensions;
this.maxGeneration = maxGeneration;
this.c1 = c1;
this.c2 = c2;
this.w = w;
this.name = name;
generation = 0;
initialCoordinate();
initialVelocity();
getScore();
bestScore = score;
bestCoordinate = new ArrayList<>(coordinate);
}
//绘图用的
public Particle(String name, List<Double> velocity, List<Double> coordinate, double score) {
this.min = null;
this.max = null;
this.dimensions = 0;
this.maxGeneration = 0;
this.name = name;
this.velocity = new ArrayList<>(velocity);
this.coordinate = new ArrayList<>(coordinate);
this.score = score;
}
@Override
public String toString() {
return "Particle{" +
"name='" + name + '\'' +
", velocity=" + velocity +
", coordinate=" + coordinate +
", score=" + score +
// ", generation=" + generation +
// ", bestCoordinate=" + bestCoordinate +
// ", bestScore=" + bestScore +
"}\n";
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
基于Java实现粒子群PSO算法优化改进(源码).rar
共35个文件
class:15个
java:14个
xml:5个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 2 下载量 97 浏览量
2023-03-22
16:35:20
上传
评论 2
收藏 35KB RAR 举报
温馨提示
1、资源内容:基于Java实现粒子群PSO算法优化改进(源码).rar 2、适用人群:计算机,电子信息工程、数学等专业的学习者,作为“参考资料”参考学习使用。 3、解压说明:本资源需要电脑端使用WinRAR、7zip等解压工具进行解压,没有解压工具的自行百度下载即可。 4、免责声明:本资源作为“参考资料”而不是“定制需求”,代码只能作为参考,不能完全复制照搬。不一定能够满足所有人的需求,需要有一定的基础能够看懂代码,能够自行调试代码并解决报错,能够自行添加功能修改代码。由于作者大厂工作较忙,不提供答疑服务,如不存在资源缺失问题概不负责,谢谢理解。
资源推荐
资源详情
资源评论
收起资源包目录
基于Java实现粒子群PSO算法优化改进(源码).rar (35个子文件)
基于Java实现粒子群PSO算法优化改进(源码)
src
pso
DrawSee.java 607B
TestAA.java 2KB
TestDetail.java 2KB
ParticleGroupCAS.java 931B
TestTogther.java 3KB
ParticleGroup.java 2KB
ParticleGroupAA.java 1KB
ParticleCAS.java 2KB
ParticleAA.java 2KB
TestCAS.java 2KB
Particle.java 4KB
ParticalPanel.java 2KB
Test.java 1KB
Problem.java 2KB
out
production
pso
pso
Test.class 3KB
ParticleGroupAA.class 2KB
Problem.class 2KB
ParticleGroup.class 2KB
TestAA.class 3KB
ParticleCAS.class 3KB
Particle.class 4KB
ParticleGroup$1.class 909B
ParticalPanel.class 3KB
TestDetail.class 3KB
ParticleAA.class 3KB
TestCAS.class 3KB
ParticleGroupCAS.class 506B
TestTogther.class 3KB
DrawSee.class 914B
.idea
uiDesigner.xml 9KB
runConfigurations.xml 337B
vcs.xml 180B
misc.xml 273B
modules.xml 246B
pso.iml 423B
共 35 条
- 1
资源评论
- 知识分享达人2023-08-27资源内容详实,描述详尽,解决了我的问题,受益匪浅,学到了。
- 2301_765381482023-04-20资源内容总结的很到位,内容详实,很受用,学到了~
Matlab仿真实验室
- 粉丝: 2w+
- 资源: 2180
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功