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

  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的各个类介绍(part3 : Ant4ACS类)

    package aco.ant; import java.util.ArrayList; import sys.Settings; import util.PseudoRandom; import a ...

  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. highcharts 插件问题

    Uncaught TypeError: $(...).highcharts is not a function 解决方法: $('#container').highcharts({ colors: [ ...

  2. spark 基本操作

    读取文件的数据 使用的数据:https://codeload.github.com/xsankar/fdps-v3/zip/master 读取单个文件的数据 case class Employee(E ...

  3. EXC_ARM_DA_ALIGN

    ios 版本上的问题  armv7  ipad2 int64 t = *(int64*)pBuff; 如果pBuff不是8字节对齐的地址就 crash 变通的方法是通过memcpy __sync_fe ...

  4. 安装redis

    第一步 下载 第二步 解压 .tar.gz 第三步 make cd redis- make 第四步  启动试一下 src/redis-server 好了 :C Jan ::13.501 # Warni ...

  5. hp安装oracle报错解决

    hpux上安装oracle 11gR2刚开始报错:集群验证框架内部发生了错误 解决办法http://www.it165.net/database/html/201509/14181.html 将文件后 ...

  6. grunt 入门学习

    前端工作流,Grunt上手指南 Posted@2013-04-20 7:15 a.m. CategoriesGrunt ,  javascript 我想先花点时间回忆一下作为一个前端需要做的工作(Lo ...

  7. 使用JFinal的第一个项目出现的问题(The return type is incompatible with JspSourceDependent.getDependants())

    四月 08, 2016 4:35:34 下午 org.apache.catalina.core.ApplicationDispatcher invoke严重: Servlet.service() fo ...

  8. ios下fixed回复框bug的解决方案

    前几天做一个移动端的页面,要加个像微信那样附着在底部的回复框,按照做PC端网页的思路,首先是用fixed,在安卓上测了一下是好的,结果到朋友的iphone6p上就不行了,点击输入框之后它总会跳到屏幕中 ...

  9. git config 配置

    1. git config简介 我们知道config是配置的意思,那么git config命令就是对git进行一些配置.而配置一般都是写在配置文件里面,那么git的配置文件在哪里呢?互动一下,先问下大 ...

  10. iOS 推送小记

    ios做推送功能时,最烦得就是各种证书的问题,以前自己做的时候经常要反复搞那些证书搞好几遍才能成功,现在发现归根到底都是appid这个东西搞错了,做个笔记记下来,以免忘了. 首先是程序里面注册推送的变 ...