package edu.vt.marian.search; import java.util.*; import java.io.*; import edu.vt.marian.common.*; /** A Weighted Link Class Manager manages a particular class of weighted links: that is, links each of which have an associated Weight. @author Robert France @see LinkClassManager @see UnwtdLinkClassManager */ public class WtdLinkClassManager implements LinkClassManager { protected Debug debug; /** The class of links that this can manage. */ protected ClassID classID; /** Create a LinkClassManager for a particular class of weighted links. */ // I'm not sure these parameters are sufficient. public WtdLinkClassManager(ClassID linkClID, Debug d) { debug = d; classID = linkClID; } /** Create (or find in the local cache) a set of matches to description. @param description An abstract description of the links we're looking for: specifically, the link class (presumably this.classID), the direction, and a description of what is on one end. @return a WtdObjSet of nodes on the other end. */ public WtdObjSet match(LinkDesc description) { return( null ); } /** * Take a single node on one end of this link to all the nodes at the other * end. * * @param key The node as a WtdObj. * @param dir Whether key functions as source or sink. * @return The set of all nodes linked to key by instances of this link * class, weighted by link weights (if any) and key.wt(). */ public WtdObjSet keyNodeToTargetSet(WtdObj key, int dir) { return( null ); } /** * Take a weighted object set of nodes on one end of the links in this class * to all the nodes at the other end. *
* NOTE: Where two nodes in keySet are both linked to the same "target" * node, some function must be applied to compute the node's weight in the * combined set. The default for links is max(), but any implementing * LinkClassManager class may use any function that suits its semantics. * * @param key the node as a WtdObj. * @param dir Whether key functions as source or sink. * @return The set of all nodes linked to any node in keySet by instances * of this link class, weighted by link weights (if any) and key.wt(). */ public WtdObjSet keySetToTargetSet(WtdObjSet keySet, int dir) { // Create a new (or find an existing) UnwtdLinkSearcher and return it. long nodeClassSize; if (dir == LinkDesc.SOURCE_TO_SINK) nodeClassSize = numSinks(); else nodeClassSize = numSources(); WeightedSetSequencer seq = new WeightedSetSequencer( //**DEVEL: What is the real approximation here? -- RKF Nov00 keySet.approxSize()*nodeClassSize, debug); seq.addSets(keySet, new LinkSetMapping(this, dir, debug) ); return( new MaxUnionSearcher(seq, debug) ); } /** * Syntactic sugar on keyNodeToTargetSet(). */ public WtdObjSet sourceToSinks(WtdObj sourceNode) { return( keyNodeToTargetSet(sourceNode, LinkDesc.SOURCE_TO_SINK) ); } /** * Syntactic sugar on keySetToTargetSet(). */ public WtdObjSet sourcesToSinks(WtdObjSet sourceSet) { return( keySetToTargetSet(sourceSet, LinkDesc.SOURCE_TO_SINK) ); } /** * Syntactic sugar on keyNodeToTargetSet(). */ public WtdObjSet sinkToSources(WtdObj sinkNode) { return( keyNodeToTargetSet(sinkNode, LinkDesc.SINK_TO_SOURCE) ); } /** * Syntactic sugar on keySetToTargetSet(). */ public WtdObjSet sinksToSources(WtdObjSet sinkSet) { return( keySetToTargetSet(sinkSet, LinkDesc.SINK_TO_SOURCE) ); } /** * Return the number of class instances currently in the factory. * Syntactic sugar on super.classSize(). */ public long numLinks() { return( ReturnCodes.NOT_YET_IMPLEMENTED ); } /** * Return the number of unique source nodes currently in the factory. */ public long numSources() { return( ReturnCodes.NOT_YET_IMPLEMENTED ); } /** * Return the number of unique sink nodes currently in the factory. */ public long numSinks() { return( ReturnCodes.NOT_YET_IMPLEMENTED ); } /** * Return the average number of links in this class that impinge on * a source node currently (== numLinks / numSources). */ public double avgSourceDegree() { return( ((double) numLinks()) / ((double) numSources()) ); } /** * Return the average number of links in this class that impinge on * a sinknode currently (== numLinks / numSinks). */ public double avgSinkDegree() { return( ((double) numLinks()) / ((double) numSinks()) ); } /** * Return the number of class instances currently in the factory. */ public long classSize() { return( numLinks() ); } }