Main Page   Packages   Class Hierarchy   Compound List   File List   Compound Members  

ChunkDist.java

00001 /*
00002  *  Copyright 2006-2007 Columbia University.
00003  *
00004  *  This file is part of MEAPsoft.
00005  *
00006  *  MEAPsoft is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License version 2 as
00008  *  published by the Free Software Foundation.
00009  *
00010  *  MEAPsoft is distributed in the hope that it will be useful, but
00011  *  WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *  General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with MEAPsoft; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00018  *  02110-1301 USA
00019  *
00020  *  See the file "COPYING" for the text of the license.
00021  */
00022 
00023 package com.meapsoft;
00024 
00025 import java.io.Serializable;
00026 import java.util.Comparator;
00027 
00037 public abstract class ChunkDist implements Serializable, Comparator
00038 {
00039     public Chunk targetChunk = null;
00040     public ChunkDist next;
00041     // only compute distance based on these feature dimensions
00042     public int[] featdim;  
00043     
00044     public ChunkDist() 
00045     { 
00046         next = null;  
00047         featdim = null; 
00048     }
00049 
00050     public ChunkDist(ChunkDist next) 
00051     {
00052         this.next = next;
00053     }
00054 
00055     public ChunkDist(int[] fd) 
00056     {
00057         this();
00058         featdim = fd;
00059     }
00060 
00061     public ChunkDist(ChunkDist next, int[] fd) 
00062     {
00063         this.next = next;
00064         featdim = fd;
00065     }
00066 
00070     public double distance(Chunk c1, Chunk c2) 
00071     {
00072         if(next != null)
00073             return next.distance(c1, c2);
00074         return 0;
00075     }
00076 
00082     public void setTarget(Chunk t)
00083     {
00084         targetChunk = t;
00085     }
00086 
00090     public int compare(Object o1, Object o2) throws ClassCastException
00091     {
00092         Chunk c1 = (Chunk)o1;
00093         Chunk c2 = (Chunk)o2;
00094         
00095         // compare distances separate target vector (usually the origin)
00096         double d1 = distance(c1, targetChunk); 
00097         double d2 = distance(c2, targetChunk); 
00098 
00099         double comp = d1-d2;
00100         //System.out.println(d1 + "-" + d2 + " = " + (comp));
00101 
00102         if(comp > 0)
00103             return 1;
00104         else if(comp < 0)
00105             return -1;
00106         // Fall back to Chunk.compareTo if they are the same
00107         // distance from target (I don't expect this to happen
00108         // often...)
00109         else if(comp == 0)
00110             return c1.compareTo(c2);
00111 
00112         // this should never happen, but the glorious sun compiler requires it.
00113         return(0);
00114     }
00115 
00116     public boolean equals(Object obj)
00117     {
00118         return this == obj; 
00119     }
00120 }

Generated on Tue Feb 6 19:02:24 2007 for MEAPsoft by doxygen1.2.18