001/** An interface defining the operations on a complete partial order (CPO). 002 003 Copyright (c) 1997-2013 The Regents of the University of California. 004 All rights reserved. 005 Permission is hereby granted, without written agreement and without 006 license or royalty fees, to use, copy, modify, and distribute this 007 software and its documentation for any purpose, provided that the above 008 copyright notice and the following two paragraphs appear in all copies 009 of this software. 010 011 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 012 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 013 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 014 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 015 SUCH DAMAGE. 016 017 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 018 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 019 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 020 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 021 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 022 ENHANCEMENTS, OR MODIFICATIONS. 023 024 PT_COPYRIGHT_VERSION_2 025 COPYRIGHTENDKEY 026 027 028 */ 029package ptolemy.graph; 030 031import java.util.Set; 032 033/////////////////////////////////////////////////////////////////// 034//// CPO 035 036/** 037 An interface defining the operations on complete partial order (CPO). 038 The definitions of these operations can be found in "Introduction to 039 Lattices and Order," Cambridge University Press, 1990, by B. A. Davey 040 and H. A. Priestley. Informal definitions are given in the code comments. 041 042 Each element in the CPO is represented by an Object. 043 For infinite CPOs, the result of some of the operations may be an 044 infinite set, in which case, the class implementing those operations 045 can throw an Exception. 046 047 @author Yuhong Xiong 048 @version $Id$ 049 @since Ptolemy II 0.2 050 @Pt.ProposedRating Green (yuhong) 051 @Pt.AcceptedRating Green (kienhuis) 052 */ 053public interface CPO<T extends Object> { 054 /////////////////////////////////////////////////////////////////// 055 //// public methods //// 056 057 /** Return the bottom element of this CPO. 058 * The bottom element is the element in the CPO that is lower than 059 * all the other elements. 060 * @return An Object representing the bottom element, or 061 * <code>null</code> if the bottom does not exist. 062 */ 063 public Object bottom(); 064 065 /** Compare two elements in this CPO. 066 * @param e1 An Object representing a CPO element. 067 * @param e2 An Object representing a CPO element. 068 * @return One of <code>CPO.LOWER, CPO.SAME, 069 * CPO.HIGHER, CPO.INCOMPARABLE</code>. 070 * @exception IllegalArgumentException If at least one of the 071 * specified Objects is not an element of this CPO. 072 */ 073 public int compare(Object e1, Object e2); 074 075 /** Compute the down-set of an element in this CPO. 076 * The down-set of an element is the subset consisting of 077 * all the elements lower than or the same as the specified element. 078 * @param e An Object representing an element in this CPO. 079 * @return An array of Objects representing the elements in the 080 * down-set of the specified element. 081 * @exception IllegalArgumentException If the specified Object is not 082 * an element in this CPO, or the resulting set is infinite. 083 */ 084 public Object[] downSet(Object e); // FIXME: return Set instead of array 085 086 /** Compute the greatest element of a subset. 087 * The greatest element of a subset is an element in the 088 * subset that is higher than all the other elements in the 089 * subset. 090 * @param subset A set of Objects representing the subset. 091 * @return An Object representing the greatest element of the subset, 092 * or <code>null</code> if the greatest element does not exist. 093 * @exception IllegalArgumentException If at least one Object in the 094 * specified array is not an element of this CPO. 095 */ 096 public Object greatestElement(Set<T> subset); 097 098 /** Compute the greatest lower bound (GLB) of two elements. 099 * The GLB of two elements is the greatest element in the CPO 100 * that is lower than or the same as both of the two elements. 101 * @param e1 An Object representing an element in this CPO. 102 * @param e2 An Object representing an element in this CPO. 103 * @return An Object representing the GLB of the two specified 104 * elements, or <code>null</code> if the GLB does not exist. 105 * @exception IllegalArgumentException If at least one of the 106 * specified Objects is not an element of this CPO. 107 */ 108 public Object greatestLowerBound(Object e1, Object e2); 109 110 /** Compute the greatest lower bound (GLB) of a subset. 111 * The GLB of a subset is the greatest element in the CPO that 112 * is lower than or the same as all the elements in the 113 * subset. 114 * @param subset A set of Objects representing the subset. 115 * @return An Object representing the GLB of the subset, or 116 * <code>null</code> if the GLB does not exist. 117 * @exception IllegalArgumentException If at least one Object 118 * in the specified array is not an element of this CPO. 119 */ 120 public T greatestLowerBound(Set<T> subset); 121 122 /** Test if this CPO is a lattice. 123 * A lattice is a CPO where the LUB and GLB of any pair of elements 124 * exist. 125 * @return True if this CPO is a lattice; 126 * <code>false</code> otherwise. 127 */ 128 public boolean isLattice(); 129 130 /** Compute the least element of a subset. 131 * The least element of a subset is an element in the 132 * subset that is lower than all the other element in the 133 * subset. 134 * @param subset A set of Objects representing the subset. 135 * @return An Object representing the least element of the subset, 136 * or <code>null</code> if the least element does not exist. 137 * @exception IllegalArgumentException If at least one Object in the 138 * specified array is not an element of this CPO. 139 */ 140 public Object leastElement(Set<T> subset); 141 142 /** Compute the least upper bound (LUB) of two elements. 143 * The LUB of two elements is the least element in the CPO 144 * that is greater than or the same as both of the two elements. 145 * @param e1 An Object representing an element in this CPO. 146 * @param e2 An Object representing an element in this CPO. 147 * @return An Object representing the LUB of the two specified 148 * elements, or <code>null</code> if the LUB does not exist. 149 * @exception IllegalArgumentException If at least one of the 150 * specified Objects is not an element of this CPO. 151 */ 152 public Object leastUpperBound(Object e1, Object e2); 153 154 /** Compute the least upper bound (LUB) of a subset. 155 * The LUB of a subset is the least element in the CPO that 156 * is greater than or the same as all the elements in the 157 * subset. 158 * @param subset A set of Objects representing the subset. 159 * @return An Object representing the LUB of the subset, or 160 * <code>null</code> if the LUB does not exist. 161 * @exception IllegalArgumentException If at least one Object 162 * in the specified array is not an element of this CPO. 163 */ 164 public T leastUpperBound(Set<T> subset); 165 166 /** Return the top element of this CPO. 167 * The top element is the element in the CPO that is higher than 168 * all the other elements. 169 * @return An Object representing the top element, or 170 * <code>null</code> if the top does not exist. 171 */ 172 public Object top(); 173 174 /** Compute the up-set of an element in this CPO. 175 * The up-set of an element is the subset consisting of 176 * all the elements higher than or the same as the specified element. 177 * @param e An Object representing an element in this CPO. 178 * @return An array of Objects representing the elements in the 179 * up-set of the specified element. 180 * @exception IllegalArgumentException If the specified Object is not 181 * an element of this CPO, or the resulting set is infinite. 182 */ 183 public Object[] upSet(Object e); // FIXME: return Set instead of array 184 185 /////////////////////////////////////////////////////////////////// 186 //// public variables //// 187 188 /** One of the return values of <code>compare</code>, indicating 189 * that the first element is higher than the second. 190 * @see #compare 191 */ 192 public static final int HIGHER = 1; 193 194 /** One of the return values of <code>compare</code>, indicating 195 * that the two elements are incomparable. 196 * @see #compare 197 */ 198 public static final int INCOMPARABLE = 2; 199 200 /** One of the return values of <code>compare</code>, indicating 201 * that the first element is lower than the second. 202 * @see #compare 203 */ 204 public static final int LOWER = -1; 205 206 /** One of the return values of <code>compare</code>, indicating 207 * that the two elements are the same. 208 * @see #compare 209 */ 210 public static final int SAME = 0; 211 212 /////////////////////////////////////////////////////////////////// 213 //// public inner classes //// 214 215 /** An enumeration type to represent the two different types of bounds 216 * that can be calculated on a set of nodes in a CPO; either 217 * a greatest lower bound or least upper bound. 218 */ 219 public static enum BoundType { 220 /** Represents the greatest lower bound. */ 221 GREATESTLOWER, 222 223 /** Represents the least upper bound. */ 224 LEASTUPPER 225 } 226}