/* * * $Author: work $ * $Revision: 1.12 $ * $Log: ASMattributes.java,v $ * Revision 1.12 2000-03-31 18:40:53-06 work * replaced * columnNumberOfFirstRowUnit * with * invertedRowNumberOfLastColumnUnit * * Revision 1.11 2000-03-31 03:40:14-06 work * implemented hashCode() * * Revision 1.10 2000-03-31 03:21:26-06 work * implemented correct equals() * * Revision 1.9 2000-03-31 03:13:53-06 work * implemented clone() * * Revision 1.8 2000-03-31 01:16:53-06 work * fixed typo * * Revision 1.7 2000-03-31 01:14:56-06 work * change columnOfFirstRowUnit to * invertedRowNumberOfLastColumnUnit * * Revision 1.6 2000-03-30 04:42:41-06 work * tidied up greaterThan method * * Revision 1.5 2000-03-30 04:39:56-06 work * now inheriting from SortableObject * and has greaterThan method * * Revision 1.4 2000-03-29 22:05:21-06 work * condensed toString printout version * * Revision 1.3 2000-03-29 21:52:02-06 work * first draft (corrected), compiles clean * * Revision 1.2 2000-03-29 21:50:24-06 work * first draft * * Revision 1.1 2000-03-29 21:38:00-06 work * Initial revision * */ /* * Copyright (C) 2000 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ import java.util.*; import java.io.*; final class ASMattributes extends SortableObject implements Cloneable, Serializable { public final int dimension; public final int invertedRowNumberOfLastColumnUnit; public final int numberOfMinusOnes; public final int inversionNumber; // 1<<8 = 256, which is larger than any of the above attributes // for an ASM of computationally feasible size static final int radix = 1<<8; // constructor ASMattributes( int n, int k, int m, int p ) { dimension = n; invertedRowNumberOfLastColumnUnit = k; numberOfMinusOnes = m; inversionNumber = p; } public Object clone() { return new ASMattributes( dimension, invertedRowNumberOfLastColumnUnit, numberOfMinusOnes, inversionNumber ); } public int hashCode() { return ((dimension*radix + invertedRowNumberOfLastColumnUnit)*radix + numberOfMinusOnes)*radix + inversionNumber; } public boolean equals( Object other ) { ASMattributes a = (ASMattributes) other; return( (dimension == a.dimension) && (invertedRowNumberOfLastColumnUnit == a.invertedRowNumberOfLastColumnUnit) && (numberOfMinusOnes == a.numberOfMinusOnes) && (inversionNumber == a.inversionNumber) ); } public String toString() { return "n="+dimension+ " k="+invertedRowNumberOfLastColumnUnit+ " m="+numberOfMinusOnes+ " p="+inversionNumber; /* s = "Dimension (n) = " + dimension + "\n"; s += "Inverted row number of last column unit (k) = " + invertedRowNumberOfLastColumnUnit + "\n"; s += "Number of -1's (m) = " + numberOfMinusOnes + "\n"; s += "Inversion number (p) = " + inversionNumber + "\n"; return s; */ } public boolean greaterThan( SortableObject y ) { int sum = 0; int d3 = dimension-((ASMattributes) y).dimension; int d2 = invertedRowNumberOfLastColumnUnit-((ASMattributes) y).invertedRowNumberOfLastColumnUnit; int d1 = numberOfMinusOnes-((ASMattributes) y).numberOfMinusOnes; int d0 = inversionNumber-((ASMattributes) y).inversionNumber; sum += d3>0?1<<3:0; sum -= d3<0?1<<3:0; sum += d2>0?1<<2:0; sum -= d2<0?1<<2:0; sum += d1>0?1<<1:0; sum -= d1<0?1<<1:0; sum += d0>0?1<<0:0; sum -= d0<0?1<<0:0; return sum>0; } }