Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Related Pages

constraintnet.h

00001 /* 00002 * Copyright (C) 1997-2004 The CDG Team <cdg@nats.informatik.uni-hamburg.de> 00003 * 00004 * This file is free software; as a special exception the author gives 00005 * unlimited permission to copy and/or distribute it, with or without 00006 * modifications, as long as this notice is preserved. 00007 * 00008 * This program is distributed in the hope that it will be useful, but 00009 * WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 00010 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00011 * 00012 * $Id: constraintnet.h,v 1.65 2004/09/01 13:48:19 micha Exp $ 00013 */ 00014 00015 /* --------------------------------------------------------------------------- 00016 * @addtogroup Constraintnet 00017 * @{ 00018 */ 00019 00020 #ifndef CONSTRAINTNET_H 00021 #define CONSTRAINTNET_H 00022 00023 /* ---------------------------------------------------------------------- */ 00024 #include <blah.h> 00025 #include "input.h" 00026 #include "scorematrix.h" 00027 #include "lexemgraph.h" 00028 #include "scache.h" 00029 00030 /* ---------------------------------------------------------------------- 00031 * The types of a constraintnet edge 00032 */ 00033 typedef enum { 00034 cnEdgesOn, 00035 cnEdgesOff, 00036 cnEdgesFew, 00037 cnEdgesAll 00038 } CnEdgesType; 00039 00040 00041 /* ---------------------------------------------------------------------- 00042 * The constraint net. 00043 */ 00044 typedef struct { 00045 String id; /**< A unique identifier for the net. 00046 Each net created by the system 00047 is labeled as net <i>n</i>, where <i>n</i> 00048 is the current value of cnCounter. */ 00049 LexemGraph lexemgraph; /**< Points to the enriched word graph used 00050 in constructing the net. */ 00051 Vector values; /**< Vector of LevelValues */ 00052 Vector nodes; /**< Vector of ConstraintNode */ 00053 Vector edges; /**< Vector of ConstraintEdge */ 00054 Array isBuilt; /**< have LVs for wordx-->wordy been built? */ 00055 Agenda searchagenda; /**< Agenda for searching, it is used 00056 by netsearch() */ 00057 int totalNumberOfValues; /**< Holds the total number of LVs in the 00058 constraint net. It should always be equal 00059 to vectorSize(net->values). */ 00060 List parses; /**< Contains all structures of type Parse 00061 found by any solution method. */ 00062 ScoreCache cache; /**< Holds the cache used to hold the results 00063 of binary constraint evaluations. (This 00064 cache only exists if scUseCache was set 00065 when creating the net.) */ 00066 int evalUnary; /**< Counting unary evaluations */ 00067 int statUnary; /**< Counting unary statistics */ 00068 int evalBinary; /**< Counting binary evaluations */ 00069 Vector lvTotals; /**< Records how many LVs the net contained 00070 at each successive step in its history. 00071 This is only used by incrementalcompletion. */ 00072 } ConstraintNetStruct; 00073 typedef ConstraintNetStruct *ConstraintNet; 00074 /**< Pointer to the ConstraintNetStruct */ 00075 00076 /* The Array isBuilt holds information on whether LVs that connect modifier 00077 x to modifiee y on level n have already been built or not. The 00078 modifiee NIL is encoded as lg->max+1, and NONSPEC as lg->max+2. */ 00079 00080 #ifndef SWIG 00081 /* ---------------------------------------------------------------------- 00082 * Models a node in a constraint net 00083 */ 00084 typedef struct { 00085 ConstraintNet net; /**< corresponding constraint net */ 00086 Level level; /**< points to the level for which 00087 a constraint node was built. */ 00088 GraphemNode gn; /**< corresponding grapheme node */ 00089 Vector values; /**< holds shallow copies of all LVs 00090 that may be used to bind this constraint 00091 node. */ 00092 int totalNumberOfValues; /**< number of level values */ 00093 int noValidValues; /**< number of not yet deleted LVs */ 00094 } ConstraintNodeStruct; 00095 00096 /** 00097 * Pointer to the ConstraintNodeStruct 00098 */ 00099 typedef ConstraintNodeStruct *ConstraintNode; 00100 00101 00102 /* ---------------------------------------------------------------------- 00103 * Models an edge between the two constraint nodes 00104 * \b start and \b stop. These two fields are shallow copies of 00105 * the nodes in the corresponding constraint net. 00106 */ 00107 typedef struct ConstraintEdgeStruct { 00108 ConstraintNode start; /**< start node */ 00109 ConstraintNode stop; /**< end node */ 00110 struct ConstraintEdgeStruct *reverse; /**< points to the inverse 00111 of the edge itself. */ 00112 ScoreMatrix scores; /**< holds all binary scores calculated 00113 for pairs of LVs from the two nodes */ 00114 Boolean *m; /**< flag whether <x,a> is already processed */ 00115 Vector *prevSupport; /**< used by module arcconsistency */ 00116 Vector *nextSupport; /**< used by module arcconsistency */ 00117 Vector *s; /**< used by module arcconsistency */ 00118 int *counter; /**< counts support */ 00119 Boolean *isMarked; /**< flag for marking, obsolete? */ 00120 } ConstraintEdgeStruct; 00121 00122 /** 00123 * Pointer to the ConstraintEdgeStruct 00124 */ 00125 typedef ConstraintEdgeStruct *ConstraintEdge; 00126 00127 /* ---------------------------------------------------------------------- 00128 * This serves merely merely to pair a constraint node and an LV. 00129 */ 00130 typedef struct { 00131 ConstraintNode node; /**< constraint node */ 00132 LevelValue value; /**< level value */ 00133 } NodeBindingStruct; 00134 00135 /** 00136 * Pointer to the NodeBindingStruct 00137 */ 00138 typedef NodeBindingStruct *NodeBinding; 00139 #endif 00140 00141 /* ---------------------------------------------------------------------- 00142 * Holds information about a constraint violated by a 00143 * solution. 00144 */ 00145 typedef struct { 00146 Constraint constraint; /**< violated constraint */ 00147 Number penalty; /**< holds the penalty of this particular 00148 instance of \b constraint (recall that a 00149 constraint declaration specifies an entire 00150 set of constraints, possibly with variable 00151 penalties). */ 00152 int nodeBindingIndex1; /**< holds the position of the LV causing 00153 the conflict, as calculated by 00154 lvIndex(). */ 00155 LevelValue lv1; /**< first node binding */ 00156 int nodeBindingIndex2; /**< holds the position of the LV causing 00157 the conflict, as calculated by 00158 lvIndex(). */ 00159 LevelValue lv2; /**< second node binding, maybe empty */ 00160 } ConstraintViolationStruct; 00161 00162 /** 00163 * Pointer to the ConstraintViolationStruct 00164 */ 00165 typedef ConstraintViolationStruct *ConstraintViolation; 00166 00167 /* ---------------------------------------------------------------------- */ 00168 00169 #ifndef SWIG 00170 extern int cnCounter; /* FIXME: shouldn't this be static inside constraintnet.c */ 00171 #endif 00172 00173 #ifdef SWIG 00174 #ifdef OLD_SWIG 00175 %readwrite; 00176 #else 00177 %mutable; 00178 #endif 00179 #endif 00180 /* pointer to most recently created constraint net */ 00181 extern ConstraintNet cnMostRecentlyCreatedNet; 00182 #ifdef SWIG 00183 #ifdef OLD_SWIG 00184 %readonly; 00185 #else 00186 %immutable; 00187 #endif 00188 #endif 00189 00190 /* this replaces both cnSuppressEdgesFlag and cnFewEdgesFlag */ 00191 extern CnEdgesType cnEdgesFlag; 00192 00193 /* If TRUE, the deleted levelvalues are printed too. */ 00194 extern Boolean cnShowDeletedFlag; 00195 00196 /* If TRUE, construct NONSPEC levelvalues in constraint nets. */ 00197 extern Boolean cnUseNonSpec; 00198 00199 /* 00200 * Fraction of all levelvalues in one domain that are deleted based 00201 * only on the unary score. A factor of 1.0 means keep all values. 00202 */ 00203 extern Number cnUnaryPruningFraction; 00204 00205 /* 00206 * initial sortation of constraintnodes in constraintnets 00207 * (relevant in netsearch) 00208 * 0 no sorting of constraintnodes 00209 * 1 sort nodes by level->prio 00210 * 2 sort nodes by increasing domain size (i. e. small domains first) 00211 */ 00212 extern int cnSortNodesMethod; 00213 00214 /* ---------------------------------------------------------------------- */ 00215 00216 /* 00217 * Looks for a constraint net with id ID and return it or NULL if 00218 * it can't find the net in inputCurrentGrammar. 00219 */ 00220 extern ConstraintNet cnFindNet(String id); 00221 00222 #ifndef SWIG 00223 extern ConstraintNet cnBuildInit(); 00224 extern ConstraintNet cnBuildFinal(ConstraintNet net, Boolean buildLVs); 00225 extern ConstraintNet cnBuild(Lattice lat, Boolean buildLVs); 00226 extern void cnDelete(ConstraintNet net); 00227 extern void cnDeleteNode(ConstraintNode cn); 00228 extern void cnDeleteEdge(ConstraintEdge cn); 00229 extern void cnDeleteBinding(NodeBinding nb); 00230 extern void cnPrint(long unsigned int mode, ConstraintNet net); 00231 extern void cnPrintNode(long unsigned int mode, ConstraintNode cn); 00232 extern void cnPrintEdge(long unsigned int mode, ConstraintEdge e); 00233 extern void cnBuildLevelValues(ConstraintNode node, Level level, GraphemNode modifier, GraphemNode modifiee); 00234 extern Boolean cnBuildTriple(ConstraintNet net, int a, int b, int levelno); 00235 extern Boolean cnBuildIter(ConstraintNet net, GraphemNode gn, Boolean buildLVs); 00236 extern Boolean cnBuildNodes(ConstraintNet net, Boolean buildLVs); 00237 extern void cnBuildEdges(ConstraintNet net); 00238 extern void cnBuildLv(ConstraintNode node, List modifiers, 00239 Level level, String label, List modifiees); 00240 extern Boolean cnRenew(ConstraintNet net); 00241 extern Boolean cnIsStartNode(ConstraintNode n); 00242 extern Boolean cnIsEndNode(ConstraintNode n); 00243 extern Boolean cnCompareViolation(ConstraintViolation a, 00244 ConstraintViolation b); /* TODO: never used */ 00245 extern Boolean cnConnectedByArc(ConstraintNode a, ConstraintNode b); 00246 extern void cnPrintInfo(ConstraintNet net); 00247 extern void cnUnaryPruning(ConstraintNode node); 00248 extern int cnOptimizeNet(ConstraintNet net); 00249 extern int cnOptimizeNode(ConstraintNet net, ConstraintNode node); 00250 extern void cnSortNodes(ConstraintNet net); 00251 extern void cnSortLVs(ConstraintNet net); 00252 extern void cnPrintParses(ConstraintNet net); 00253 extern ConstraintNode cnFindNode(ConstraintNet net, LevelValue lv); 00254 00255 extern ConstraintViolation cvNew(Constraint c, LevelValue lva, LevelValue lvb); 00256 extern void cvDelete(ConstraintViolation cv); 00257 extern void cvAnalyse(ConstraintViolation cv, Vector context); 00258 extern void cvPrint(unsigned long mode, ConstraintViolation cv); 00259 extern Boolean cvContains(List conflicts, ConstraintViolation cv); 00260 extern ConstraintViolation cvClone(ConstraintViolation cv); 00261 extern Boolean cvCompare(ConstraintViolation a, ConstraintViolation b); 00262 extern Boolean cvCompareNatural(ConstraintViolation a, ConstraintViolation b); 00263 extern void cnPrintActiveLVs(ConstraintNet net); 00264 extern void cnUndeleteAllLVs(ConstraintNet net); 00265 extern void cnDeleteAllLVs(ConstraintNet net); 00266 extern Boolean cnBuildUpdateArcs(ConstraintNet net, List listArcs); 00267 extern GraphemNode cnGetGraphemNodeFromArc(ConstraintNet net, Arc arc); 00268 00269 extern void cnInitialize(); 00270 extern void cnCallback(String name, float *var); 00271 #endif 00272 00273 extern Lattice cnGetLattice(ConstraintNet cn); 00274 00275 /* ---------------------------------------------------------------------- */ 00276 #endif /* don't insert anything after this #endif */ 00277 /** @} */

CDG 0.95 (20 Oct 2004)