public abstract class Ant extends Observable implements Runnable {

     public static int ANT_ID = 1; // ANT_ID是蚂蚁的身份标识起始位,设置为1

     /** Importance of trail */
public static final int ALPHA = Settings.ALPHA;// ALPHA是计算转移概率p时设的参数之一(见蚁群算法简介) /** Importance of heuristic evaluate */
public static final int BETA = Settings.BETA;//BETA是计算转移概率p时用户设定的参数之一 /** Identifier */
public int id = ANT_ID++; //id是每个蚂蚁的身份标识,不能重复 public ACO aco; // ACO是蚁群算法类,代表蚂蚁采用什么样的策略来搜索,具体将在ACO类里详细介绍 public List<Integer> tour; // tour是个整型数组,它存放着蚂蚁走过的每个节点编号 /** The Current Node */
public int currentNode; // currentNode是蚂蚁当前所在的节点编号 public int[][] path;//path是个整型标志位矩阵,用来记录两个节点间的边是否被蚂蚁访问过 public List<Integer> nodesToVisit;//一个整型列表,记录蚂蚁从当前节点出发可通过一步到达的节点编号 public double tourLength;//蚂蚁创建路径的总长度 /*构造方法 */
public Ant(ACO aco) {
this.aco = aco;
reset();
}
/*将蚂蚁的所有属性恢复出厂设置*/
public void reset(){
this.currentNode = -1;
this.tourLength = 0;
this.nodesToVisit = new ArrayList<Integer>();
this.tour = new ArrayList<Integer>();
this.path = new int[aco.p.getNodes()][aco.p.getNodes()];
} /*重写了父类的run方法,父类主要用来实现多线程编程*/
@Override
public void run() {
init(); //初始化
explore();//构造路径
setChanged();
notifyObservers(this);//通知监听器线程结束
} /*初始化:在问题包含的节点中随机选取一个作为蚂蚁搜索的起点,把改点加到路径中,根据问题的不同设定邻域的范围 */
public void init(){
reset();
this.currentNode = PseudoRandom.randInt(0, aco.p.getNodes() - 1);
this.tour.add(new Integer(currentNode));
this.aco.p.initializeTheMandatoryNeighborhood(this);
}
/*输出蚂蚁的编号和路径的总长度*/
@Override
public String toString() {
return "Ant " + id + " " + tour+" "+tourLength;
} /**
* 构造路径,只提供接口,具体由继承Ant类的子类实现
*/ public abstract void explore(); /**
* 复制蚂蚁,等待继承Ant类的子类实现
*/
public abstract Ant clone();
}

JavaACOFramework的各个类介绍(part1 : Ant类)的更多相关文章

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

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

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

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

  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. spring中常用工具类介绍

    http://www.cnblogs.com/langtianya/p/3875103.html 文件资源操作     Spring 定义了一个 org.springframework.core.io ...

  8. MediaRecorder类介绍

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

  9. Object类介绍

    一.Object类介绍

随机推荐

  1. linux常用工具链接

    http://linuxtools-rst.readthedocs.io/zh_CN/latest/tool/lsof.html

  2. Jquery操作select,左右移动,双击移动 取到所有option的值

    $(function () { function MoveItem(fromId, toId) { $("#" + fromId + " option:selected& ...

  3. 获取设备的mac地址和IP地址(android6.0以上专用)

    /** * 获取设备HardwareAddress地址 * @return */public static String getMachineHardwareAddress(){ Enumeratio ...

  4. Mysql 数据库中所有列名为某个值的 sql 语句

    SELECT DISTINCT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME IN ('columnname') AND T ...

  5. python staticmethod and classmethod方法

    静态方法无绑定,和普通函数使用方法一样,只是需要通过类或者实例来调用.没有隐性参数. 实例方法针对的是实例,类方法针对的是类,他们都可以继承和重新定义,而静态方法则不能继承,可以认为是全局函数. #h ...

  6. NODEJS 在Centos下面的自动启动

    直接上代码 #!/bin/sh ## chkconfig: 345 99 10# description: Node.js /home/cekimy/index.js# . /etc/rc.d/ini ...

  7. http 中定义的八种请求的介绍

    在http1.1协议中,共定义了8种可以向服务器发起的请求(这些请求也叫做方法或动作),本文对这八种请求做出简要的介绍: 1.PUT:put的本义是推送 这个请求的含义就是推送某个资源到服务器,相当于 ...

  8. 【数学】Jersey Politics

                                                            Jersey Politics Time Limit: 1000MS   Memory ...

  9. String.Join的巧用

    String.Join大大的方便了我们拼接字符串的处理. 1.普通用法:指定元素间的拼接符号 var ids = new List<int>(); for (int i = 0; i &l ...

  10. Windows Azure 将正式更名为 Microsoft Azure

    微软的公共云平台在2014年4月3日正式从Windows Azure 更名为Microsoft Azure. windows azure是二级产品名,microsoft azure是一级产品名,和mi ...