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类进行简要介 ...
随机推荐
- Eexcel批量设定单元格条件格式
最近在整理excel项目记录,觉得有些技巧还是值得拥有,记录备份下,以防将来使用: [工具/原料] excel(office或wps) [方法/步骤] 1.建立一个追踪表如下: 2.选择状态列,建立数 ...
- oracle sqlplus 格式化输出
1- show pagesize ###显示页行数 set pagesize 300 ###显示页行数为300 2- show linesize ###显示行宽度 set li ...
- ios - kvo观察者示例
首先创建Person分类 #import <Foundation/Foundation.h> @interface Person : NSObject @property (nonatom ...
- 如何使用JDBC链接数据库
1.加载数据库驱动 不同的数据库加载的驱动不一样 Class.forName(com.MySQL.jdbc.Driver) Class.forName(oracle.jdbc.driver.Oracl ...
- C正则库做DNS域名验证时的性能对比
C正则库做DNS域名验证时的性能对比 本文对C的正则库regex和pcre在做域名验证的场景下做评测. 验证DNS域名的正则表达式为: "^[0-9a-zA-Z_-]+(\\.[0-9a ...
- 下载VM12 虚拟机和安装kali
为什么现在才写这个-- 因为我在学校啊,学校的电脑还没有kali.好了我们开始. http://www.vmware.com/products/player/playerpro-evaluation ...
- url传参中文乱码
当使用url重定向传参的时候,比如: javascript:window.location.href='modifyBook.jsp?BName=<%=URLEncoder.encode(&qu ...
- Ajax跨域的几种方法以及每种方法的原理
js中几种实用的跨域方法原理详解 这里说的js跨域是指通过js在不同的域之间进行数据传输或通信,比如用ajax向一个不同的域请求数据,或者通过js获取页面中不同域的框架中(iframe)的数据.只要协 ...
- git基本配置
用户信息 你个人的用户名称和电子邮件地址,用户名可随意修改,git 用于记录是谁提交了更新,以及更新人的联系方式. $ git config --global user.name "Donl ...
- Fiddler的一些坑: !SecureClientPipeDirect failed: System.IO.IOException
手机的请求Fiddler可以捕捉,但是手机一直无法上网,在logs中看到的日志如下: !SecureClientPipeDirect failed: System.IO.IOException 由于远 ...