// SearchApplet.java
//
// This class is an abstract class for defining search
// algorithm classes.
//
// Copyright Mark Watson, 1998. Open Source and Open Content.
//
import java.awt.*;
import java.awt.event.*;
import java.util.Vector;
abstract public class SearchApplet extends java.applet.Applet {
public void init() {
String width = getParameter("pwidth");
if (width == null) {
xSizePixels = 80;
} else {
xSizePixels = Integer.valueOf(width).intValue();
}
String height = getParameter("pheight");
if (height == null) {
ySizePixels = 80;
} else {
ySizePixels = Integer.valueOf(height).intValue();
}
System.out.println("width=" + xSizePixels + ", height=" + ySizePixels);
setLayout(null);
startChoice = new Choice();
goalChoice = new Choice();
for (int i=0; i x_max) x_max = x;
if (y < y_min) y_min = y;
if (y > y_max) y_max = y;
}
public String getNodeName(int index) {
try {
return nodeNames[index];
} catch (Exception e) {
System.out.println("Error in getNodeName: " + e);
}
return "no name"; // error condition
}
public float getNodeX(int index) {
try {
return node_x[index];
} catch (Exception e) {
System.out.println("Error in getNodePosition: " + e);
}
return 0.0f; // error condition
}
public float getNodeY(int index) {
try {
return node_y[index];
} catch (Exception e) {
System.out.println("Error in getNodePosition: " + e);
}
return 0.0f; // error condition
}
public float getPathLength(int index) { // currently unsued - for adding heuristics
return lengths[index];
}
public void addLink(int node1, int node2) {
link_1[numLinks] = node1;
link_2[numLinks] = node2;
float dist_squared =
(node_x[node1] - node_x[node2]) * (node_x[node1] - node_x[node2]) +
(node_y[node1] - node_y[node2]) * (node_y[node1] - node_y[node2]);
lengths[numLinks] = (float)Math.sqrt(dist_squared);
numLinks++;
}
public void addLink(String name1, String name2) {
int index1 = -1, index2 = -1;
for (int i=0; i
Back to main page