Debian Codegraph @

FaCT++.Python/lib/Kernel/tAxiomSet.cpp

raw symbols SCIP
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 #include "tAxiomSet.h"
21
22 #include "logging.h"
23 #include "dlTBox.h"
24
25 /// d'tor
26 TAxiomSet :: ~TAxiomSet()
27 {
28 for ( auto& axiom: Accum )
29 delete axiom;
30 }
31
32 bool
33 TAxiomSet :: split ( const TAxiom* p )
34 {
35 AxiomCollection Splitted, Kept, Unneeded;
36 if ( !p->split(Splitted) ) // nothing to split
37 return false;
38
39 bool fail = false;
40 for ( auto& axiom: Splitted )
41 {
42 // axiom is a copy of a processed one: fail to do split
43 if ( axiom->isCyclic() )
44 {
45 fail = true;
46 break;
47 }
48 // axiom is a copy of a new one: skip it
49 if ( copyOfExisting(axiom) )
50 Unneeded.push_back(axiom);
51 else // new axiom: keep it
52 Kept.push_back(axiom);
53 }
54 // if fail to split: delete all the axioms
55 if ( fail )
56 {
57 for ( auto& axiom: Splitted )
58 delete axiom;
59 return false;
60 }
61 // no failure: delete all the unneeded axioms, add all kept ones
62 for ( auto& axiom: Unneeded )
63 delete axiom;
64 for ( auto& axiom: Kept )
65 insertGCI(axiom);
66 return true;
67 }
68
69 size_t TAxiomSet :: absorb ( void )
70 {
71 // absorbed- and unabsorbable GCIs
72 AxiomCollection Absorbed, GCIs;
73
74 // we will change Accum (via split rule), so indexing and compare with size
75 for ( size_t curAxiom = 0; curAxiom < Accum.size(); ++curAxiom )
76 {
77 # ifdef RKG_DEBUG_ABSORPTION
78 std::cout << "\nProcessing (" << curAxiom << "):";
79 # endif
80 TAxiom* ax = Accum[curAxiom];
81 if ( absorbGCI(ax) )
82 Absorbed.push_back(ax);
83 else
84 GCIs.push_back(ax);
85 }
86
87 // clear absorbed and remove them from Accum
88 for ( auto& axiom: Absorbed )
89 delete axiom;
90 Accum.swap(GCIs);
91
92 #ifdef RKG_DEBUG_ABSORPTION
93 std::cout << "\nAbsorption done with " << Accum.size() << " GCIs left\n";
94 #endif
95 PrintStatistics();
96 return size();
97 }
98
99 bool TAxiomSet :: absorbGCI ( const TAxiom* p )
100 {
101 Stat::SAbsAction();
102
103 for ( const auto& action: ActionVector )
104 if ( (this->*action)(p) )
105 return true;
106
107 #ifdef RKG_DEBUG_ABSORPTION
108 std::cout << " keep as GCI";
109 #endif
110
111 return false;
112 }
113
114 bool TAxiomSet :: initAbsorptionFlags ( const std::string& flags )
115 {
116 ActionVector.clear();
117 for ( const auto& ch: flags )
118 switch ( ch )
119 {
120 case 'B': ActionVector.push_back(&TAxiomSet::absorbIntoBottom); break;
121 case 'T': ActionVector.push_back(&TAxiomSet::absorbIntoTop); break;
122 case 'E': ActionVector.push_back(&TAxiomSet::simplifyCN); break;
123 case 'C': ActionVector.push_back(&TAxiomSet::absorbIntoConcept); break;
124 case 'N': ActionVector.push_back(&TAxiomSet::absorbIntoNegConcept); break;
125 case 'f': ActionVector.push_back(&TAxiomSet::simplifySForall); break;
126 case 'F': ActionVector.push_back(&TAxiomSet::simplifyForall); break;
127 case 'R': ActionVector.push_back(&TAxiomSet::absorbIntoDomain); break;
128 case 'S': ActionVector.push_back(&TAxiomSet::split); break;
129 default: return true;
130 }
131
132 if ( LLM.isWritable(llAlways) )
133 LL << "Init absorption order as " << flags << "\n";
134
135 return false;
136 }
137
138 void TAxiomSet :: PrintStatistics ( void ) const
139 {
140 if ( Stat::SAbsAction::objects_created == 0 || !LLM.isWritable(llAlways) )
141 return;
142
143 LL << "\nAbsorption dealt with "
144 << Stat::SAbsInput::objects_created << " input axioms\nThere were made "
145 << Stat::SAbsAction::objects_created << " absorption actions, of which:";
146 if ( Stat::SAbsRepCN::objects_created )
147 LL << "\n\t" << Stat::SAbsRepCN::objects_created << " concept name replacements";
148 if ( Stat::SAbsRepForall::objects_created )
149 LL << "\n\t" << Stat::SAbsRepForall::objects_created << " universals replacements";
150 if ( Stat::SAbsSplit::objects_created )
151 LL << "\n\t" << Stat::SAbsSplit::objects_created << " conjunction splits";
152 if ( Stat::SAbsBApply::objects_created )
153 LL << "\n\t" << Stat::SAbsBApply::objects_created << " BOTTOM absorptions";
154 if ( Stat::SAbsTApply::objects_created )
155 LL << "\n\t" << Stat::SAbsTApply::objects_created << " TOP absorptions";
156 if ( Stat::SAbsCApply::objects_created )
157 LL << "\n\t" << Stat::SAbsCApply::objects_created << " concept absorption with "
158 << Stat::SAbsCAttempt::objects_created << " possibilities";
159 if ( Stat::SAbsNApply::objects_created )
160 LL << "\n\t" << Stat::SAbsNApply::objects_created << " negated concept absorption with "
161 << Stat::SAbsNAttempt::objects_created << " possibilities";
162 if ( Stat::SAbsRApply::objects_created )
163 LL << "\n\t" << Stat::SAbsRApply::objects_created << " role domain absorption with "
164 << Stat::SAbsRAttempt::objects_created << " possibilities";
165 if ( !Accum.empty() )
166 LL << "\nThere are " << Accum.size() << " GCIs left";
167 }