JavaACOFramework的各个类介绍(part2 : Ant4AS类)
package aco.ant; import java.util.ArrayList; import util.RouletteWheel;//引入轮盘类
import aco.ACO;//引入蚁群类 /**
* The AS Ant Class
*
* @author Thiago Nascimento
* @since 2014-07-27
* @version 1.0
*/
public class Ant4AS extends Ant { /*父类的构造函数*/
public Ant4AS(ACO aco) {
super(aco);
}
/*实现父类的explore结口,完成构造路径的工作*/
@Override
public void explore() {
while (!nodesToVisit.isEmpty()) {
int nextNode = doExploration(currentNode);//找到下一个访问的节点 //Save next node
tour.add(new Integer(nextNode));//将下一个节点的编号加入路径
path[currentNode][nextNode] = 1;//将标志位矩阵中当前节点与下一节点间的边的访问标志置为1
path[nextNode][currentNode] = 1;//将标志位矩阵中下一节点与当前节点间的边的访问标志置为1 aco.p.updateTheMandatoryNeighborhood(this);//更新领域 currentNode = nextNode;//把下一节点作为当前节点
}
} /**
* 返回下一个访问节点的编号
*
* @param i :当前节点的编号
* @return 下一节点的编号,该函数是利用轮盘赌的方法选择下一个要访问的节点
*/
protected int doExploration(int i) {
int nextNode = -1;
double sum = 0.0; // Update the sum
for (Integer j : nodesToVisit) {
if (aco.getTau(i, j) == 0.0) {
throw new RuntimeException("tau == 0.0");
} double tij = Math.pow(aco.getTau(i, j), ALPHA);
double nij = Math.pow(aco.p.getNij(i, j), BETA);
sum += tij * nij;
} if (sum == 0.0) {
throw new RuntimeException("sum == 0.0");
} double[] probability = new double[aco.p.getNodes()];
double sumProbability = 0.0; for (Integer j : nodesToVisit) {
double tij = Math.pow(aco.getTau(i, j), ALPHA);
double nij = Math.pow(aco.p.getNij(i, j), BETA);
probability[j] = (tij * nij) / sum;
sumProbability += probability[j];
} // Select the next node by probability
nextNode = RouletteWheel.select(probability, sumProbability); if (nextNode == -1) {
throw new RuntimeException("nextNode == -1");
} nodesToVisit.remove(new Integer(nextNode)); return nextNode;
} @Override 实现父类的clone接口,复制ant对象
public Ant clone() {
Ant ant = new Ant4AS(aco);
ant.id = id;
ant.currentNode = currentNode;
ant.tourLength = tourLength;
ant.tour = new ArrayList<Integer>(tour);
ant.path = path.clone();
return ant;
}
}
JavaACOFramework的各个类介绍(part2 : Ant4AS类)的更多相关文章
- 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的各个类介绍(part3 : Ant4ACS类)
package aco.ant; import java.util.ArrayList; import sys.Settings; import util.PseudoRandom; import a ...
- 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类进行简要介 ...
随机推荐
- 使用NUGet自动下载(还原)项目中使用的包
签出完整项目后,在解决方案名称上点右键,选择"启用NuGet程序包还原",如下图: 出现询问,当然要点是:是 当完成后,会发现在解决方案中,多出".nuget" ...
- Web自动化测试工具调研
背景 Web自动化测试越来越被重视, 因为现在Web已经是工程化的状态. 如何通过工具测试, 保证Web开发的质量,提升开发效率,是Web工具的诞生的来由. Web测试分为以下几个方面: 1. 界面测 ...
- 搭建git for windows服务器
文档出处 :http://blog.csdn.net/code_style/article/details/38764203 http://blog.csdn.net/aaron_luchen/art ...
- C++之路进阶codevs1269(匈牙利游戏)
1269 匈牙利游戏 2012年CCC加拿大高中生信息学奥赛 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description ...
- NLog路由规则和上下文信息
NLog配置路由规则和上下文信息 rules: 规则节点 logger:一个路由规则 <rules> <!--<logger name="*" writeT ...
- jQuery Scroll Follow
Overview Scroll Follow is a simple jQuery plugin that enables a DOM object to follow the page as the ...
- 【Arduino】旋转编码器的Arduino使用方法
以前用CRT显示器的时候,调整显示器的时候用一个圆盘转动和点击的方法就可以实现选择菜单和修改设置项的值,比多个按钮的方式方便很多. 鼠标滚轮也是这种操作方法,旋转+点击,只是方向不同.最近在网上买了旋 ...
- Qt中使用Windows API
在Windows平台上进行开发,不可避免与Windows API打交道,Qt中使用的时候要添加对应API的头文件和链接lib文件,另外使用的Windows API的代码部分要使用#ifdef Q_O ...
- android 布局学习
各种layout用到的一些重要属性 第一类:属性值为true或false android:layout_centerHrizontal 水平居中 android:layout_centerVertic ...
- Node判断文件是否链接
通过fs.stat(), fs.lstate() and fs.fstate()都可以得到fs.Stats对象, 其中stats.isSymbolicLink()方法用来判断是否链接, 然而一直都不成 ...