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类)的更多相关文章

  1. istringstream、ostringstream、stringstream 类介绍 和 stringstream类 clear函数的真正用途

    istringstream.ostringstream.stringstream 类介绍 和 stringstream类 clear函数的真正用途 来源: http://blog.csdn.net/T ...

  2. JavaACOFramework的各个类介绍(part1 : Ant类)

    public abstract class Ant extends Observable implements Runnable { public static int ANT_ID = 1; // ...

  3. JavaACOFramework的各个类介绍(part2 : Ant4AS类)

    package aco.ant; import java.util.ArrayList; import util.RouletteWheel;//引入轮盘类 import aco.ACO;//引入蚁群 ...

  4. SimpleDateFormat类介绍和 DateFormat类的format方法和parse方法

    使用 SimpleDateFormat格式化日期 SimpleDateFormat 是一个以语言环境敏感的方式来格式化和分析日期的类.SimpleDateFormat 允许你选择任何用户自定义日期时间 ...

  5. CYQ.Data.Orm.DBFast 新增类介绍(含类的源码及新版本配置工具源码)

    前言: 以下功能在国庆期就完成并提前发布了,但到今天才有时间写文介绍,主要是国庆后还是选择就职了,悲催的是上班的地方全公司都能上网,唯独开发部竟不让上网,是个局域网. 也不是全不能上,房间里有三台能上 ...

  6. Bullet核心类介绍(Bullet 2.82 HelloWorld程序及其详解,附程序代码)

    实验平台:win7,VS2010 先上结果截图: 文章最后附有生成该图的程序. 1. 刚体模拟原理 Bullet作为一个物理引擎,其任务就是刚体模拟(还有可变形体模拟).刚体模拟,就是要计算预测物体的 ...

  7. MediaRecorder类介绍

    audiocallbackvideojavadescriptorencoding 目录(?)[+] 找到个MediaRecorder类介绍和大家分享一下. Mediarecorder类在官网的介绍和在 ...

  8. Object类介绍

    一.Object类介绍

  9. C#文件读写常用类介绍

    首先要熟悉.NET中处理文件和文件夹的操作.File类和Directory类是其中最主要的两个类.了解它们将对后面功能的实现提供很大的便利.      本节先对和文件系统相关的两个.NET类进行简要介 ...

随机推荐

  1. CentOS 系统目录解析

    CentOS 系统目录解析 http://mp.weixin.qq.com/s?__biz=MzAxOTAzMzEzNg==&mid=202463614&idx=2&sn=51 ...

  2. 可爱的Python_课后习题_CDay−4 可用的首个Python 脚本

    读取文件cdays−4-test.txt 内容,去除空行和注释行后,以行为单位进行排序,并将结果输出为cdays−4-result.txt. cdays−4-test.txt的内容 #some wor ...

  3. jQuery源代码学习之九—jQuery事件模块

    jQuery事件系统并没有将事件坚挺函数直接绑定在DOM元素上,而是基于事件缓存模块来管理监听函数的. 二.jQuery事件模块的代码结构 //定义了一些正则 // // //jQuery事件对象 j ...

  4. HDU 5063 Operation the Sequence(仔细审题)

    http://acm.hdu.edu.cn/showproblem.php?pid=5063 题目大意: 题目意思还是比较简单.所以就不多少了.注意这句话,对解题有帮助. Type4: Q i que ...

  5. Mybatis传多个参数(三种解决方案)

    http://blog.csdn.net/liangyihuai/article/details/49965869 (zhuan)

  6. Javascript 中判断对象为空

    发现了一个巧妙的实现: 需要检查一个对象(Object)是否为空,即不包含任何元素.Javascript 中的对象就是一个字典,其中包含了一系列的键值对(Key Value Pair).检查一个对象是 ...

  7. nodejs cookie管理

    Cookie 管理 我们可以使用中间件向 Node.js 服务器发送 cookie 信息,以下代码输出了客户端发送的 cookie 信息: // express_cookie.js 文件 var ex ...

  8. 5.3监听请求:使用eclipse的tcp/ip工具(端口转换)

    1.改用wsdl文件生成响应文件 运行浏览器输入发布的地址,获得wsdl源码保存在项目路径下, 2.创建接口转换器,window-property-tcpip 客户端执行结果:

  9. [原创] Gradle DSL method not found: 'android()' 和 buildToolsVersion is not specified 的解决办法。

    今天在用Android Studio 2.0 打开别人的较早版本生成的工程时, 提示: Gradle DSL method not found: 'android()'. 解决办法为,打开根目录下面的 ...

  10. ArcGIS10.1 发布气温插值GP服务

    首先通过ModelBuilder 工具 构建模型 然后通过模块右键 设置输入参数 或者直接将一个模块设为输入参数 在输出模块的右键属性上 可以设置lyr文件用于渲染 设置数据添加到显示用于不是发布的时 ...