| 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 PRIORITYMATRIX_H |
| 21 | #define PRIORITYMATRIX_Hcxx . . $ `Kernel/PriorityMatrix.h:21:9`! |
| 22 | |
| 23 | #include "eFaCTPlusPlus.h"cxx . . $ `<file>/Kernel/eFaCTPlusPlus.h`/ |
| 24 | #include "dlVertex.h"cxx . . $ `<file>/Kernel/dlVertex.h`/ // DagTag |
| 25 | #include "logging.h"cxx . . $ `<file>/Kernel/logging.h`/ |
| 26 | |
| 27 | typedef unsigned short int ToDoListIndexcxx . . $ ToDoListIndex#; |
| 28 | |
| 29 | /// number of regular options (o- and NN-rules are not included) |
| 30 | constexpr ToDoListIndexcxx . . $ ToDoListIndex# nRegularOpscxx . . $ nRegularOps. = 7; |
| 31 | /// priority index for o- and ID operations (note that these ops have the highest priority) |
| 32 | constexpr ToDoListIndexcxx . . $ ToDoListIndex# iIdcxx . . $ iId. = nRegularOpscxx . . $ nRegularOps.+1; |
| 33 | /// priority index for <= operation in nominal node |
| 34 | constexpr ToDoListIndexcxx . . $ ToDoListIndex# iNNcxx . . $ iNN. = nRegularOpscxx . . $ nRegularOps.+2; |
| 35 | |
| 36 | /// Auxiliary class to get priorities on operations |
| 37 | class ToDoPriorMatrixcxx . . $ ToDoPriorMatrix# |
| 38 | { |
| 39 | protected: // members |
| 40 | // regular operation indexes |
| 41 | ToDoListIndexcxx . . $ ToDoListIndex# iAndcxx . . $ ToDoPriorMatrix#iAnd. = nRegularOpscxx . . $ nRegularOps., |
| 42 | iOrcxx . . $ ToDoPriorMatrix#iOr. = nRegularOpscxx . . $ nRegularOps., |
| 43 | iExistscxx . . $ ToDoPriorMatrix#iExists. = nRegularOpscxx . . $ nRegularOps., |
| 44 | iForallcxx . . $ ToDoPriorMatrix#iForall. = nRegularOpscxx . . $ nRegularOps., |
| 45 | iLEcxx . . $ ToDoPriorMatrix#iLE. = nRegularOpscxx . . $ nRegularOps., |
| 46 | iGEcxx . . $ ToDoPriorMatrix#iGE. = nRegularOpscxx . . $ nRegularOps.; |
| 47 | |
| 48 | public: // interface |
| 49 | /// init priorities via given string OPTIONS |
| 50 | void initPrioritiescxx . . $ ToDoPriorMatrix#initPriorities(32373b8560f77290). ( const stdcxx . . $ std/::stringcxx . . $ std/string#& options, const char* optionName ); |
| 51 | /// get an index corresponding given Op, Sign and NominalNode |
| 52 | ToDoListIndexcxx . . $ ToDoListIndex# getIndexcxx . . $ ToDoPriorMatrix#getIndex(a85f1ffef8419fb8). ( DagTagcxx . . $ DagTag# Op, bool Sign, bool NominalNode ) const; |
| 53 | }; // ToDoPriorMatrix |
| 54 | |
| 55 | inline void ToDoPriorMatrixcxx . . $ ToDoPriorMatrix# :: initPrioritiescxx . . $ ToDoPriorMatrix#initPriorities(32373b8560f77290). ( const stdcxx . . $ std/::stringcxx . . $ std/string#& options, const char* optionName ) |
| 56 | { |
| 57 | // check for correctness |
| 58 | if ( options.sizecxx . . $ std/__cxx11/basic_string#size(48278e53df7b52a5). () != 7 ) |
| 59 | throw EFaCTPlusPluscxx . . $ EFaCTPlusPlus# ( "ToDo List option string should have length 7" ); |
| 60 | |
| 61 | // get int priority value out of a char |
| 62 | auto char2int = [] (const char c) { return static_cast<ToDoListIndexcxx . . $ ToDoListIndex#>(c - '0'); }; |
| 63 | |
| 64 | // init values by symbols loaded |
| 65 | iAndcxx . . $ ToDoPriorMatrix#iAnd. = char2int(cxx . . $ ToDoPriorMatrix#initPriorities(32373b8560f77290).$anonymous_type_0#`operator()`(b7102e242635955f).options[cxx . . $ std/__cxx11/basic_string#`operator[]`(fe0a407a03ea4a2d).1]); |
| 66 | iOrcxx . . $ ToDoPriorMatrix#iOr. = char2int(cxx . . $ ToDoPriorMatrix#initPriorities(32373b8560f77290).$anonymous_type_0#`operator()`(b7102e242635955f).options[cxx . . $ std/__cxx11/basic_string#`operator[]`(fe0a407a03ea4a2d).2]); |
| 67 | iExistscxx . . $ ToDoPriorMatrix#iExists. = char2int(cxx . . $ ToDoPriorMatrix#initPriorities(32373b8560f77290).$anonymous_type_0#`operator()`(b7102e242635955f).options[cxx . . $ std/__cxx11/basic_string#`operator[]`(fe0a407a03ea4a2d).3]); |
| 68 | iForallcxx . . $ ToDoPriorMatrix#iForall. = char2int(cxx . . $ ToDoPriorMatrix#initPriorities(32373b8560f77290).$anonymous_type_0#`operator()`(b7102e242635955f).options[cxx . . $ std/__cxx11/basic_string#`operator[]`(fe0a407a03ea4a2d).4]); |
| 69 | iLEcxx . . $ ToDoPriorMatrix#iLE. = char2int(cxx . . $ ToDoPriorMatrix#initPriorities(32373b8560f77290).$anonymous_type_0#`operator()`(b7102e242635955f).options[cxx . . $ std/__cxx11/basic_string#`operator[]`(fe0a407a03ea4a2d).5]); |
| 70 | iGEcxx . . $ ToDoPriorMatrix#iGE. = char2int(cxx . . $ ToDoPriorMatrix#initPriorities(32373b8560f77290).$anonymous_type_0#`operator()`(b7102e242635955f).options[cxx . . $ std/__cxx11/basic_string#`operator[]`(fe0a407a03ea4a2d).6]); |
| 71 | |
| 72 | // correctness checking |
| 73 | if ( iAndcxx . . $ ToDoPriorMatrix#iAnd. >= nRegularOpscxx . . $ nRegularOps. || |
| 74 | iOrcxx . . $ ToDoPriorMatrix#iOr. >= nRegularOpscxx . . $ nRegularOps. || |
| 75 | iExistscxx . . $ ToDoPriorMatrix#iExists. >= nRegularOpscxx . . $ nRegularOps. || |
| 76 | iForallcxx . . $ ToDoPriorMatrix#iForall. >= nRegularOpscxx . . $ nRegularOps. || |
| 77 | iGEcxx . . $ ToDoPriorMatrix#iGE. >= nRegularOpscxx . . $ nRegularOps. || |
| 78 | iLEcxx . . $ ToDoPriorMatrix#iLE. >= nRegularOpscxx . . $ nRegularOps. ) |
| 79 | throw EFaCTPlusPluscxx . . $ EFaCTPlusPlus# ( "ToDo List option out of range" ); |
| 80 | |
| 81 | // inform about used rules order |
| 82 | if ( LLMcxx . . $ LLM..isWritablecxx . . $ LeveLogger#isWritable(8de63fdb265b07c1).(llAlwayscxx . . $ llAlways.) ) |
| 83 | LLcxx . . $ LL. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\nInit " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). optionName <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " = " <<cxx . . $ std/basic_ostream#`operator<<`(9f4dd0ebeeaaa173). iAndcxx . . $ ToDoPriorMatrix#iAnd. <<cxx . . $ std/basic_ostream#`operator<<`(9f4dd0ebeeaaa173). iOrcxx . . $ ToDoPriorMatrix#iOr. <<cxx . . $ std/basic_ostream#`operator<<`(9f4dd0ebeeaaa173). iExistscxx . . $ ToDoPriorMatrix#iExists. <<cxx . . $ std/basic_ostream#`operator<<`(9f4dd0ebeeaaa173). iForallcxx . . $ ToDoPriorMatrix#iForall. <<cxx . . $ std/basic_ostream#`operator<<`(9f4dd0ebeeaaa173). iLEcxx . . $ ToDoPriorMatrix#iLE. <<cxx . . $ std/basic_ostream#`operator<<`(9f4dd0ebeeaaa173). iGEcxx . . $ ToDoPriorMatrix#iGE.; |
| 84 | } |
| 85 | |
| 86 | inline ToDoListIndexcxx . . $ ToDoListIndex# ToDoPriorMatrixcxx . . $ ToDoPriorMatrix# :: getIndexcxx . . $ ToDoPriorMatrix#getIndex(a85f1ffef8419fb8). ( DagTagcxx . . $ DagTag# Op, bool Sign, bool NominalNode ) const |
| 87 | { |
| 88 | switch ( Op ) |
| 89 | { |
| 90 | case dtAndcxx . . $ dtAnd.: |
| 91 | return (Sign?iAndcxx . . $ ToDoPriorMatrix#iAnd.:iOrcxx . . $ ToDoPriorMatrix#iOr.); |
| 92 | |
| 93 | case dtForallcxx . . $ dtForall.: |
| 94 | case dtIrrcxx . . $ dtIrr.: // process local (ir-)reflexivity as a FORALL |
| 95 | return (Sign?iForallcxx . . $ ToDoPriorMatrix#iForall.:iExistscxx . . $ ToDoPriorMatrix#iExists.); |
| 96 | |
| 97 | case dtProjcxx . . $ dtProj.: // it should be the lowest priority but now just OR's one |
| 98 | case dtChoosecxx . . $ dtChoose.: // probably should be highest branching one |
| 99 | return iOrcxx . . $ ToDoPriorMatrix#iOr.; |
| 100 | |
| 101 | case dtLEcxx . . $ dtLE.: |
| 102 | return (Sign?(NominalNode?iNNcxx . . $ iNN.:iLEcxx . . $ ToDoPriorMatrix#iLE.):iGEcxx . . $ ToDoPriorMatrix#iGE.); |
| 103 | |
| 104 | case dtDataTypecxx . . $ dtDataType.: |
| 105 | case dtDataValuecxx . . $ dtDataValue.: |
| 106 | case dtDataExprcxx . . $ dtDataExpr.: |
| 107 | case dtNNcxx . . $ dtNN.: |
| 108 | case dtTopcxx . . $ dtTop.: // no need to process these ops |
| 109 | return nRegularOpscxx . . $ nRegularOps.; |
| 110 | |
| 111 | case dtPSingletoncxx . . $ dtPSingleton.: |
| 112 | case dtPConceptcxx . . $ dtPConcept.: // no need to process neg of PC |
| 113 | return (Sign?iIdcxx . . $ iId.:nRegularOpscxx . . $ nRegularOps.); |
| 114 | |
| 115 | case dtNSingletoncxx . . $ dtNSingleton.: |
| 116 | case dtNConceptcxx . . $ dtNConcept.: // both NC and neg NC are processed |
| 117 | return iIdcxx . . $ iId.; |
| 118 | |
| 119 | default: // safety check |
| 120 | fpp_unreachablecxx . . $ `Kernel/fpp_assert.h:49:9`!(); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | #endif |