1 / 44
文档名称:

遗传蚂蚁算法【Java】.doc

格式:doc   大小:157KB   页数:44页
下载后只包含 1 个 DOC 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

遗传蚂蚁算法【Java】.doc

上传人:xxj16588 2018/5/1 文件大小:157 KB

下载得到文件列表

遗传蚂蚁算法【Java】.doc

文档介绍

文档介绍:遗传蚂蚁算法【Java】
【】
// ic Ant Algorithm
// Carl E. Bredlau

// from Koza, ic Programming_, MIT Press
// programmed modeled after sga. Thanks to the author.
package icAnt;
public class Ant implements Cloneable {
// An ant
// From the ant's point of view it only sees food. It does not know
// where on the board it is.
// For counting ants:
private static int antCount = 0;

int antID = 0; // which ant
Chromosome chromo;
int state = 0; // internal state;
int fitness = 1; // How good the ant is
int parent1 = -1; // "Parents" of the ant
int parent2 = -1;
int age = 0; // age of ant
int gene = -1; // where we swap or mutate
public Ant(int states) {
chromo = new Chromosome(states);
antID = antCount++;
}

// Ant moves:
public static final int MOVE = ; // move foward
public static final int LEFT = ; // turn left
public static final int RIGHT = ; // move right
public static final int NOP = ; // don't move
public int move(boolean sees_food) {
// depending upon the state and whether it sees food, change
// state and return what it will do.
int mem_loc = 2*state;
if (sees_food) { // move down one state if food is there...
mem_loc++;
}
state = [mem_loc].state;
return [mem_loc].action;
}
public void incFitness() {fitness++;}
public void walk (Board board, int numMoves) {
// Ant walks on the board to determine fitness
fitness = 1;
state = 0;
// Put ant on board
();
// ("Move: " + 0 + " State: " + state +
// " Fitness is " + fitness);
// (); // for testing.

for (int moves = 1; moves <= numMoves; moves++) {
int ant_move = move(()); // Ant moves or turns
int foodEaten = (ant_move);
if (foodEaten == ) incFitness();
// for testing...
// ("Move: " + moves + " State: " + state +
// " Fitness is " + fitn