JavaACOFramework的各个类介绍(part3 : Ant4ACS类)
package aco.ant; import java.util.ArrayList; import sys.Settings;
import util.PseudoRandom;
import aco.ACO; public class Ant4ACS extends Ant4AS { /** 进行Exploitation的概率 */
protected double Q0 = Settings.Q0; /** 信息素挥发的概率*/
protected double P = Settings.P; public Ant4ACS(ACO aco) {
super(aco);
}
/*实现了父类的explore操作的接口*/
@Override
public void explore() {
while (!nodesToVisit.isEmpty()) {
int nextNode = -1; if (PseudoRandom.randDouble(0, 1) <= Q0) {
nextNode = doExploitation(currentNode);//Exploitation操作
} else {
nextNode = doExploration(currentNode);//Exploration操作
} localUpdateRule(currentNode, nextNode);//挥发连接当前节点和下一个节点边的信息素 // Save next node
tour.add(new Integer(nextNode));//将下一个节点存入蚂蚁的路径列表
path[currentNode][nextNode] = 1;//将当前节点与下一节点间的边标记为已访问过
path[nextNode][currentNode] = 1;//将下一节点与当前节点间的边标记为已访问过 aco.p.updateTheMandatoryNeighborhood(this);//更新邻域 currentNode = nextNode;//将下一节点作为当前节点
}
}
/* 信息素挥发 */
protected void localUpdateRule(int i, int j) {
double evaporation = (1.0 - P) * aco.getTau(i, j);
double deposition = P * aco.p.getT0(); aco.setTau(i, j, evaporation + deposition);
aco.setTau(j, i, evaporation + deposition);
}
/*该操作选择和当前节点i相邻的所有未被访问过的节点中tij * nij值最高的节点作为下一个节点*/
protected int doExploitation(int i) {
int nextNode = -1;
double maxValue = Double.MIN_VALUE; // Update the sum
for (Integer j : nodesToVisit) {
if (aco.getTau(i, j) == 0.0) {
throw new RuntimeException("tau == 0.0");
} double tij = aco.getTau(i, j);
double nij = Math.pow(aco.p.getNij(i, j), BETA);
double value = tij * nij; if(value > maxValue){
maxValue = value;
nextNode = j;
}
} if (nextNode == -1) {
throw new RuntimeException("nextNode == -1");
} nodesToVisit.remove(new Integer(nextNode)); return nextNode;
} @Override
/*实现父类的clone接口,复制蚂蚁*/
public Ant clone() {
Ant ant = new Ant4ACS(aco);
ant.id = id;
ant.currentNode = currentNode;
ant.tourLength = tourLength;
ant.tour = new ArrayList<Integer>(tour);
ant.path = path.clone();
return ant;
}
}
JavaACOFramework的各个类介绍(part3 : Ant4ACS类)的更多相关文章
- istringstream、ostringstream、stringstream 类介绍 和 stringstream类 clear函数的真正用途
istringstream.ostringstream.stringstream 类介绍 和 stringstream类 clear函数的真正用途 来源: http://blog.csdn.net/T ...
- JavaACOFramework的各个类介绍(part1 : Ant类)
public abstract class Ant extends Observable implements Runnable { public static int ANT_ID = 1; // ...
- JavaACOFramework的各个类介绍(part2 : Ant4AS类)
package aco.ant; import java.util.ArrayList; import util.RouletteWheel;//引入轮盘类 import aco.ACO;//引入蚁群 ...
- SimpleDateFormat类介绍和 DateFormat类的format方法和parse方法
使用 SimpleDateFormat格式化日期 SimpleDateFormat 是一个以语言环境敏感的方式来格式化和分析日期的类.SimpleDateFormat 允许你选择任何用户自定义日期时间 ...
- CYQ.Data.Orm.DBFast 新增类介绍(含类的源码及新版本配置工具源码)
前言: 以下功能在国庆期就完成并提前发布了,但到今天才有时间写文介绍,主要是国庆后还是选择就职了,悲催的是上班的地方全公司都能上网,唯独开发部竟不让上网,是个局域网. 也不是全不能上,房间里有三台能上 ...
- Bullet核心类介绍(Bullet 2.82 HelloWorld程序及其详解,附程序代码)
实验平台:win7,VS2010 先上结果截图: 文章最后附有生成该图的程序. 1. 刚体模拟原理 Bullet作为一个物理引擎,其任务就是刚体模拟(还有可变形体模拟).刚体模拟,就是要计算预测物体的 ...
- MediaRecorder类介绍
audiocallbackvideojavadescriptorencoding 目录(?)[+] 找到个MediaRecorder类介绍和大家分享一下. Mediarecorder类在官网的介绍和在 ...
- Object类介绍
一.Object类介绍
- C#文件读写常用类介绍
首先要熟悉.NET中处理文件和文件夹的操作.File类和Directory类是其中最主要的两个类.了解它们将对后面功能的实现提供很大的便利. 本节先对和文件系统相关的两个.NET类进行简要介 ...
随机推荐
- SpringMVC常用配置-文件上传-基于Servlet 3.0
[2] http://www.cnblogs.com/weilu2/p/springmvc_MultipartConfigElement_tomcat_webapps_work.html
- haproxy学习之https配置
haproxy学习之https配置 原文 http://www.cnblogs.com/ilanni/p/4941056.html 如何配置https,以及https在实际生产环境中的应用. ...
- __attribute__
转来的: http://www.cnblogs.com/astwish/p/3460618.html __attribute__ 你知多少? GNU C 的一大特色就是__attribute__ 机制 ...
- PHP获取某个表与其他表的关联关系算法
如图 电影movie有多个附表,如果通过movie表来找出多个与之关联的表. 本算法规则: 外键写法必须是X_id; A与B 1对多关系,中间表表名必须是A_B,且A_B,必须包含A_id,B_id外 ...
- C#下没有注册类 (异常来自 HRESULT:0x80040154 (REGDB_E_CLASSNOTREG))
C#下没有注册类 (异常来自 HRESULT:0x80040154 (REGDB_E_CLASSNOTREG)) 原因:没有原生支持64位,而是以32位兼容方式运行 解决办法:在项目属性里设置“生成” ...
- HDU 5063 Operation the Sequence(仔细审题)
http://acm.hdu.edu.cn/showproblem.php?pid=5063 题目大意: 题目意思还是比较简单.所以就不多少了.注意这句话,对解题有帮助. Type4: Q i que ...
- eclipse for java developer和eclipse for java ee developer的区别
eclipse是基于插件机制的软件,插件本身是不能启动和操作的,它们需要一个环境,eclipse使用osgi r4规范实现了这个环境. osgi是java动态模块化的规范,该规范不光要让java程序模 ...
- python 在最后一行追加
2.文本文件的写入 import fileinput file = open("D:\\test.txt", encoding="utf-8",mode=&qu ...
- git 常用命令粗略总结
本文版权归cxun所有,如有转载请注明出处与本文链接,谢谢!原文地址:http://www.cnblogs.com/cxun/p/5630190.html git的功能很强大,但是其实很简单,用来用去 ...
- 敏捷项目开源管理软件ScrumBasic(2)- 多项目支持
1.加入Project对象模型 public class Project { [Key] [MaxLength(32)] public string ID { get; set; } public s ...