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

Scache - Cache structures for binary LV scores


Detailed Description

Author:
Michael Schulz
Date:
somewhen in 1998
A score cache serves much the same purpose as the score matrices in the edges of a constraint net, except that it can be used even if the constraint net has no edges in it. This simply means that the binary score of a pair of LVs will be computed when it is used for the first time rather than upon initializing the net.


Data Structures

struct  ScoreCacheStruct

Defines

#define DEBUG_SCORECACHE   0
#define indexOfPair(x, y)   ((x<y) ? (((y*(y-1))>>1)+x) : (((x*(x-1))>>1)+y))

Typedefs

typedef ScoreCacheStructScoreCache

Functions

void scDelete (ScoreCache cache)
Number scGetScore (ScoreCache cache, LevelValue a, LevelValue b)
void scInitialize ()
ScoreCache scNew (int noValues)
void scSetScore (ScoreCache cache, LevelValue a, LevelValue b, Number score)

Variables

Boolean scUseCache
Boolean scUseCache = FALSE


Define Documentation

#define DEBUG_SCORECACHE   0
 

debug flag Definition at line 41 of file scache.c.

#define indexOfPair x,
 )     ((x<y) ? (((y*(y-1))>>1)+x) : (((x*(x-1))>>1)+y))
 

determines the index of a given pair Definition at line 39 of file scache.c.

Referenced by scGetScore(), scNew(), and scSetScore().


Typedef Documentation

typedef ScoreCacheStruct* ScoreCache
 

Pointer to ScoreCacheStruct Definition at line 45 of file scache.h.

Referenced by scDelete(), scGetScore(), scNew(), and scSetScore().


Function Documentation

void scDelete ScoreCache  cache  ) 
 

free memory from a cache

This function deallocates a cache. Definition at line 88 of file scache.c.

References ScoreCacheStruct::data, and ScoreCache.

Referenced by cnDelete(), cnRenew(), comCompareAllLvPairs(), and comCompareWithContext().

Number scGetScore ScoreCache  cache,
LevelValue  a,
LevelValue  b
 

retrieve score from cache if available, else return -1.0

This function returns the mutual score for the LVs a and b from the score. If it is not yet known, -1 is returned. Definition at line 102 of file scache.c.

References ScoreCacheStruct::data, ScoreCacheStruct::hits, indexOfPair, ScoreCache, and ScoreCacheStruct::size.

Referenced by evalBinary().

void scInitialize  ) 
 

initialize the module Scache. It registers the module's CDG variables. Definition at line 216 of file scache.c.

References NULL, and scUseCache.

Referenced by cdgInitialize().

ScoreCache scNew int  size  ) 
 

return an initial score-cache

This function returns a pointer to a new cache. The fields count and hits are initialized to 0. All elements of the underlying Vector are set to -1. Definition at line 62 of file scache.c.

References ScoreCacheStruct::capacity, ScoreCacheStruct::count, ScoreCacheStruct::data, ScoreCacheStruct::hits, indexOfPair, ScoreCache, and ScoreCacheStruct::size.

Referenced by cnBuildFinal(), cnRenew(), comCompareAllLvPairs(), and comCompareWithContext().

void scSetScore ScoreCache  cache,
LevelValue  a,
LevelValue  b,
Number  score
 

store score in cache

This function registers a binary score in the cache. It behaves as follows:

  • If cache is NULL the function returns.
  • If either of the LVs still has its no set to -1, registerValue() is applied to it.
  • A unique index is computed from the fields no of both LVs.
  • The underlying Vector is resize if necessary.
  • score is entered in the corresponding cell.
Definition at line 137 of file scache.c.

References ScoreCacheStruct::capacity, CDG_DEBUG, CDG_ERROR, cdgPrintf(), ScoreCacheStruct::count, ScoreCacheStruct::data, indexOfPair, ScoreCache, and ScoreCacheStruct::size.

Referenced by evalBinary().


Variable Documentation

Boolean scUseCache
 

implements the CDG variable cache. If this flag is set, binary constraints are never evaluated twice on the same pair of LVs. The function evalBinary() will then simply call scGetScore() instead of evalConstraint().

This variable is exported because it's cheaper for the calling function to check a boolean variable than calling a cache function which does nothing again and again. Definition at line 53 of file scache.c.

Referenced by cmdIncrementalCompletion(), cmdStatus(), cnBuildFinal(), cnRenew(), comCompareAllLvPairs(), comCompareWithContext(), evalBinary(), and scInitialize().

Boolean scUseCache = FALSE
 

implements the CDG variable cache. If this flag is set, binary constraints are never evaluated twice on the same pair of LVs. The function evalBinary() will then simply call scGetScore() instead of evalConstraint().

This variable is exported because it's cheaper for the calling function to check a boolean variable than calling a cache function which does nothing again and again. Definition at line 53 of file scache.c.

Referenced by cmdIncrementalCompletion(), cmdStatus(), cnBuildFinal(), cnRenew(), comCompareAllLvPairs(), comCompareWithContext(), evalBinary(), and scInitialize().


CDG 0.95 (20 Oct 2004)