23.08.2015 Views

Here - Agents Lab - University of Nottingham

Here - Agents Lab - University of Nottingham

Here - Agents Lab - University of Nottingham

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

epresentation. The cache simply acts as a filter: if a query is a cache hit the results areimmediately returned by the cache; if a query is a cache miss, the query is delegated tothe knowledge representation and the results stored in the cache, before being returnedto the agent program.The use <strong>of</strong> a cache requires an extension <strong>of</strong> the KRT interface with a cache operationlookup to lookup entries, an operation put to put entries into the cache, and anoperation clear to clear the cache again. The basic approach can be implemented asshown in the algorithm below.Listing 1.1: Query Cache1 % Query Phase2 clear(cache)3 FOR EACH query Q i DO4 IF lookup(Q i , answer, cache)5 THEN return(answer)6 ELSE DO7 answer = query(Q i , beliefbase)8 put(Q i :answer, cache)9 return(answer)10 ENDDO11 ENDDOOf course, by only storing the query results, it is not possible to detect when cacheentries are invalidated, so the cache needs to be cleared at the start <strong>of</strong> each query phase inan update cycle and rebuilt from scratch. In addition, when compiling an agent program,care is required to ensure that differences in variable names are resolved so that similarqueries are retrieved from the cache instead <strong>of</strong> being recomputed. For example, thequeries q(X, Y ) and q(A, B) which represent the same query but use different variablesshould not result in a cache miss.The cache can be implemented by a hash table. Given Observation 2, the size <strong>of</strong> thehash table can be tuned to optimal size after one or two cycles. By implementing thecache as a hash table, the insertion costs c ins <strong>of</strong> an entry are constant and the evaluationcosts <strong>of</strong> performing a query a second time are equal to the lookup costs, i.e. a constantc hit that represents the cost for a cache hit. This results in the following performancemodel, adapted from the model in Section 2:It follows that wheneverK · (c qry + c ins ) + N · c hit + U · c upd (2)c qry >KN − K · c ins +NN − K · c hit (3)it is beneficial to implement a cache. That is, the cache increases performance wheneverthe average query cost is greater than the average lookup cost <strong>of</strong> a query plus the averageinsertion cost times the proportion <strong>of</strong> unique to non-unique queries (for N > K). Asexpected, the larger the average number <strong>of</strong> times n a query is performed in a single128

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!