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类进行简要介 ...
随机推荐
- Spring操作指南-AOP基本示例(基于注解)
- 构造函数this和base的区别
构造函数this和base的区别: this:调用的是本身,不能调用父类和子类的 base:调用父类的,不能调用本身的,但别人继承,可以调用 从中也可以得出另外个结果构造函数的运行过程 先从基类开始构 ...
- 使用mybatis-generator自动生成映射配置
使用mybatis时,编写实体类与数据库的映射是一项繁琐的工作,很容易出错,而mybatis-generator工具很好地解决了这个问题. 一.工具下载与配置 下载地址:① https://gith ...
- jQuery工具函数(转)
原文地址:http://www.cnblogs.com/kissdodog/archive/2012/12/27/2835561.html 作者:逆心 ------------------------ ...
- R12.2.6 installation failed with - Unable to rename database
报错信息: 日志信息:/data/ebsdb/VIS/12.1.0/appsutil/log/VIS_ebstest/12222150.log Phase 3 Rename Database Exec ...
- 用SQL命令查看Mysql数据库大小
要想知道每个数据库的大小的话,步骤如下: 1.进入information_schema 数据库(存放了其他的数据库的信息) use information_schema; 2.查询所有数据的大小: s ...
- Fatal error: Call to undefined function curl_init()问题
最近分别在win7和Win8.win10 上分别安装php 高版本!都遇到了这个问题! 一.win7系统, apache2.2/apache2.4, php5.2升级到5.4. 这个比较容易: 1. ...
- Linux 安装记录
######ubuntu-16.04.1-desktop-amd64 ||| Unity desktop Environment, NOT !!! ######deepin-15.3-amd64.is ...
- CMD命令大全
有关某个命令的详细信息,请键入 HELP 命令名 ASSOC 显示或修改文件扩展名关联. AT 计划在计算机上运行的命令和程序. ATTRIB 显示或更改文件属性. BREAK 设置或清除扩展式 CT ...
- 补全Gemfile缺少到javascript gem
如果缺少某个gem,查看并修改Gemfile文件 第一步要先修改源 source 'https://ruby.taobao.org' 下面补全这两个gem gem 'execjs' gem 'ther ...