import java.util.*; public class NodeGeo extends Node implements Comparable { public static NodeGeo dst; // 目的地 public double x; // このノードの位置: x座標 public double y; // このノードの位置: y座標 public NodeGeo(int id,double x,double y) { super(id); this.x = x; this.y = y; } public double h_star() { // このノードから目的地までの直線距離 if (dst == null) return 0.0; double dx = dst.x - x; double dy = dst.y - y; return Math.sqrt(dx*dx+dy*dy); } public int compareTo(Object o) { // NodeGeo同士の比較に使うメソッド if (o instanceof NodeGeo) { NodeGeo t = (NodeGeo) o; double a = value + h_star(); double b = t.value + t.h_star(); return (a > b) ? 1 : ((a < b) ? (-1) : 0); } else { return super.compareTo(o); } } public String toString() { return "node#"+id+"[("+x+","+y+")," +((via==null)?"null":via.id)+","+value+"]"; } }