/*
Copyright 2006 by Sean Luke
Licensed under the Academic Free License version 3.0
See the file "LICENSE" for more information
*/
package ec.app.edge;
import ec.util.*;
import java.io.*;
import java.util.*;
import java.util.zip.*;
import ec.*;
import ec.gp.*;
import ec.gp.koza.*;
import ec.simple.*;
/*
* Edge.java
*
* Created: Mon Nov 1 15:46:19 1999
* By: Sean Luke
*/
/**
* Edge implements the Symbolic Edge problem.
*
Parameters
base.data
classname, inherits or == ec.app.edge.EdgeData
(the class for the prototypical GPData object for the Edge problem)
Parameter bases
base.data
species (the GPData object)
*
* @author Sean Luke
* @version 1.0
*/
public class Edge extends GPProblem implements SimpleProblemForm
{
private static final long serialVersionUID = 1;
public static final String P_GENERALIZE = "generalize";
public static final String P_ALLPOS = "allpos";
public static final String P_ALLNEG = "allneg";
public static final String P_TESTPOS = "testpos";
public static final String P_TESTNEG = "testneg";
public static final String P_MAXTEST = "maxtest";
public static final int MIN_ARRAY_SIZE = 64;
// reading states (BAD is initial state)
public static final int BAD = 0;
public static final int READING0 = 1;
public static final int READING1 = 2;
public static final int EPSILON = 3;
// building graph
public boolean[] start;
public boolean[] accept;
public int numNodes;
public int[] from;
public int[] to;
public int[] reading;
public int numEdges;
// adjacency lists
public int[][] reading1;
public int[] reading1_l;
public int[][] reading0;
public int[] reading0_l;
public int[][] epsilon;
public int[] epsilon_l;
// positive test
public boolean[][] posT;
// negative test
public boolean[][] negT;
// positive all
public boolean[][] posA;
// negative all
public boolean[][] negA;
// testing
public boolean[] state1;
public boolean[] state2;
// generalize?
public boolean generalize;
// we don't need to copy any of our arrays, they're null until
// we actually start using them.
public static String fill(int num, char c)
{
char[] buf = new char[num];
for(int x=0;x ";
if (reading0_l[x]>0)
{
str += "(0:";
for(int y=0;y0 ? "," : "") + String.valueOf(reading0[x][y]));
str += ") ";
}
if (reading1_l[x]>0)
{
str += "(1:";
for(int y=0;y0 ? "," : "") + String.valueOf(reading1[x][y]));
str += ") ";
}
if (epsilon_l[x]>0)
{
str += "(e:";
for(int y=0;y0 ? "," : "") + String.valueOf(epsilon[x][y]));
str += ")";
}
str += "\n";
}
return str;
}
public boolean[][] restrictToSize(int size, boolean[][]cases, EvolutionState state, int thread)
{
int csize = cases.length;
if (csize < size) return cases;
Hashtable hash = new Hashtable();
for(int x=0;xbb.length) return 1;
return 0;
}
});
return newcases;
}
// public boolean[][] slurp(final File f) throws IOException
public boolean[][] slurp(final InputStream f) throws IOException
{
//LineNumberReader r = new LineNumberReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(f))));
LineNumberReader r = new LineNumberReader(new InputStreamReader(new GZIPInputStream(f)));
String bits;
Vector v = new Vector();
while((bits=r.readLine())!=null)
{
bits = bits.trim();
int len = bits.length();
if (len==0) continue; // empty line
if (bits.charAt(0)=='#') continue; // comment
if (bits.equalsIgnoreCase("e"))
v.addElement(new boolean[0]);
else
{
boolean[] b = new boolean[len];
for(int x=0;x0)
{
// Need to restrict
state.output.message("Restricting to <= " + restriction + " Unique Examples");
posT = restrictToSize(restriction,posT,state,0);
}
state.output.message("");
printBits(state,posT);
state.output.message("");
state.output.message("Reading Negative Training Examples");
try { negT = slurp(tn); }
catch(IOException e) { state.output.error(
"IOException reading file (here it is)\n" + e, base.push(P_TESTNEG)); }
if ((restriction = state.parameters.getInt(
base.push(P_MAXTEST),null,1))>0)
{
// Need to restrict
state.output.message("Restricting to <= " + restriction + " Unique Examples");
negT = restrictToSize(restriction,negT,state,0);
}
state.output.message("");
printBits(state,negT);
state.output.message("");
state.output.exitIfErrors();
}
public boolean test(final boolean[] sample)
{
final boolean STATE_1 = false;
// final boolean STATE_2 = true;
boolean st = STATE_1;
// set initial state
for(int x=0;x
Ads help maintain this website.