| 1 | /* This file is part of the FaCT++ DL reasoner |
| 2 | Copyright (C) 2003-2015 Dmitry Tsarkov and The University of Manchester |
| 3 | Copyright (C) 2015-2017 Dmitry Tsarkov |
| 4 | |
| 5 | This library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2.1 of the License, or (at your option) any later version. |
| 9 | |
| 10 | This library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with this library; if not, write to the Free Software |
| 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #ifndef MODELCACHEINTERFACE_H |
| 21 | #define MODELCACHEINTERFACE_H |
| 22 | |
| 23 | #include "globaldef.h" |
| 24 | #include "logging.h" |
| 25 | |
| 26 | /// status of model cache or merge operation |
| 27 | enum modelCacheState |
| 28 | { |
| 29 | csInvalid, ///> clash in model/merging fails because of direct contradiction; |
| 30 | csValid, ///> valid model/success in merging; |
| 31 | csFailed, ///> incorrect model/merging fails because of incompleteness of procedure; |
| 32 | csUnknown ///> untested model cache. |
| 33 | }; |
| 34 | |
| 35 | /// create united status for 2 given statuses |
| 36 | inline modelCacheState mergeStatus ( modelCacheState s1, modelCacheState s2 ) |
| 37 | { |
| 38 | // if one of caches is definitely UNSAT, then merge will be the same |
| 39 | if ( s1 == csInvalid || s2 == csInvalid ) |
| 40 | return csInvalid; |
| 41 | // if one of caches is unsure then result will be the same |
| 42 | if ( s1 == csFailed || s2 == csFailed ) |
| 43 | return csFailed; |
| 44 | // if one of caches is not inited, than result would be the same |
| 45 | if ( s1 == csUnknown || s2 == csUnknown ) |
| 46 | return csUnknown; |
| 47 | else // valid+valid = valid |
| 48 | return csValid; |
| 49 | } |
| 50 | |
| 51 | /// interface for general model caching. |
| 52 | class modelCacheInterface |
| 53 | { |
| 54 | protected: // members |
| 55 | /// flag to show that model contains nominals |
| 56 | bool hasNominalNode; |
| 57 | |
| 58 | protected: // methods |
| 59 | /// log a particular implementation of a cache entry |
| 60 | virtual void logCacheEntryImpl ( void ) const = 0; |
| 61 | |
| 62 | public: // interface |
| 63 | /// Create cache model with given presence of nominals |
| 64 | explicit modelCacheInterface ( bool flagNominals ) : hasNominalNode{flagNominals} {} |
| 65 | /// empty d'tor |
| 66 | virtual ~modelCacheInterface() = default; |
| 67 | |
| 68 | /// check whether both models have nominals; in this case, merge is impossible |
| 69 | bool hasNominalClash ( const modelCacheInterface* p ) const |
| 70 | { return hasNominalNode && p->hasNominalNode; } |
| 71 | /// update knowledge about nominals in the model after merging |
| 72 | void updateNominalStatus ( const modelCacheInterface* p ) { hasNominalNode |= p->hasNominalNode; } |
| 73 | |
| 74 | // mergeable part |
| 75 | |
| 76 | /// Check the model cache internal state. |
| 77 | virtual modelCacheState getState ( void ) const = 0; |
| 78 | /// check whether two caches can be merged; @return state of "merged" model |
| 79 | virtual modelCacheState canMerge ( const modelCacheInterface* p ) const = 0; |
| 80 | |
| 81 | /// get type of cache (deep or shallow) |
| 82 | virtual bool shallowCache ( void ) const { return true; } |
| 83 | /// log this cache entry (with given level) |
| 84 | void logCacheEntry ( unsigned int level ) const |
| 85 | { |
| 86 | if ( LLM.isWritable(level) ) |
| 87 | logCacheEntryImpl(); |
| 88 | } |
| 89 | }; // modelCacheInterface |
| 90 | |
| 91 | #endif |