/*
Copyright 2006 by Sean Luke
Licensed under the Academic Free License version 3.0
See the file "LICENSE" for more information
*/
package ec.app.ant;
import ec.app.ant.func.*;
import ec.util.*;
import ec.*;
import ec.gp.*;
import ec.gp.koza.*;
import java.io.*;
import java.util.*;
import ec.simple.*;
/*
* Ant.java
*
* Created: Mon Nov 1 15:46:19 1999
* By: Sean Luke
*/
/**
* Ant implements the Artificial Ant problem.
*
Parameters
base.data
classname, inherits or == ec.gp.GPData
(the class for the prototypical GPData object for the Ant problem)
base.file
String
(filename of the .trl file for the Ant problem)
base.turns
int >= 1
(maximal number of moves the ant may make)
Parameter bases
base.data
species (the GPData object)
*
* @author Sean Luke
* @version 1.0
*/
public class Ant extends GPProblem implements SimpleProblemForm
{
public static final String P_FILE = "file";
public static final String P_MOVES = "moves";
// map point descriptions
public static final int ERROR = 0;
public static final int FOOD = -1;
public static final int EMPTY = 1;
public static final int TRAIL = 2;
public static final int ATE = 3;
// orientations
public static final int O_UP = 0;
public static final int O_LEFT = 1;
public static final int O_DOWN = 2;
public static final int O_RIGHT = 3;
// maximum number of moves
public int maxMoves;
// how much food we have
public int food;
// our map
public int map[][];
// store the positions of food so we can reset our map
// don't need to be deep-cloned, they're read-only
public int foodx[];
public int foody[];
// map[][]'s bounds
public int maxx;
public int maxy;
// our position
public int posx;
public int posy;
// how many points we've gotten
public int sum;
// our orientation
public int orientation;
// how many moves we've made
public int moves;
// print modulo for doing the abcdefg.... thing at print-time
public int pmod;
public Object clone()
{
Ant myobj = (Ant) (super.clone());
myobj.map = new int[map.length][];
for(int x=0;x0");
// load our file
//File filename = state.parameters.getFile(base.push(P_FILE),null);
//if (filename==null)
// state.output.fatal("Ant trail file name not provided.");
InputStream str = state.parameters.getResource(base.push(P_FILE), null);
if (str == null)
state.output.fatal("Error loading file or resource", base.push(P_FILE), null);
food = 0;
LineNumberReader lnr = null;
try
{
lnr =
//new LineNumberReader(new FileReader(filename));
new LineNumberReader(new InputStreamReader(str));
StringTokenizer st = new StringTokenizer(lnr.readLine()); // ugh
maxx = Integer.parseInt(st.nextToken());
maxy = Integer.parseInt(st.nextToken());
map = new int[maxx][maxy];
int y;
for(y=0;y
Ads help maintain this website.