File: CConcreteConceptProcessingOperatorPriorityStrategy.cpp

package info (click to toggle)
konclude 0.6.2~dfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 26,976 kB
  • ctags: 43,332
  • sloc: cpp: 250,898; xml: 54,573; makefile: 29; ansic: 3; sh: 3
file content (238 lines) | stat: -rw-r--r-- 8,083 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/*
 *		Copyright (C) 2013, 2014, 2015 by the Konclude Developer Team.
 *
 *		This file is part of the reasoning system Konclude.
 *		For details and support, see <http://konclude.com/>.
 *
 *		Konclude is free software: you can redistribute it and/or modify it under
 *		the terms of version 2.1 of the GNU Lesser General Public License (LGPL2.1)
 *		as published by the Free Software Foundation.
 *
 *		You should have received a copy of the GNU Lesser General Public License
 *		along with Konclude. If not, see <http://www.gnu.org/licenses/>.
 *
 *		Konclude is distributed in the hope that it will be useful,
 *		but WITHOUT ANY WARRANTY; without even the implied warranty of
 *		MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For more
 *		details, see GNU Lesser General Public License.
 *
 */

#include "CConcreteConceptProcessingOperatorPriorityStrategy.h"


namespace Konclude {

	namespace Reasoner {

		namespace Kernel {

			namespace Strategy {

				CConcreteConceptProcessingOperatorPriorityStrategy::CConcreteConceptProcessingOperatorPriorityStrategy() {
					priCount = 200;
					priorities = new double[priCount];
					symAccessPri = priorities+priCount/2;

					for (int i = 0; i < priCount; ++i) {
						priorities[i] = 0;
					}

					// The following priorities are similar to the FaCT++ standard IAOEFLG options and have the same meaning.

					// FaCT++ register "IAOEFLG" option:
					// Option 'IAOEFLG' define the priorities of different operations in TODO list. Possible values are 
					// 7-digit strings with only possible digit are 0-6. The digits on the places 1, 2, ..., 7 are for 
					// priority of Id, And, Or, Exists, Forall, LE and GE operations respectively. The smaller number means 
					// the higher priority. All other constructions (TOP, BOTTOM, etc) has priority 0.

					// The operations are ordered in a priority queue and are applied also from lower to highest priority.
					//symAccessPri[CCATOM]    = 2;
					//symAccessPri[CCAND]     = 3;
					//symAccessPri[CCOR]      = 7;
					//symAccessPri[CCSOME]    = 4;
					//symAccessPri[CCALL]     = 1;
					//symAccessPri[CCATLEAST] = 1;
					//symAccessPri[CCATMOST]  = 6;
					cint64 nextPriority = 14;


					symAccessPri[CCTOP]				= nextPriority;
					symAccessPri[-CCBOTTOM]			= nextPriority;
					symAccessPri[CCATOM]			= nextPriority;
					symAccessPri[-CCATOM]			= nextPriority;

					nextPriority = 13;

					symAccessPri[CCAND]				= nextPriority;
					symAccessPri[-CCOR]				= nextPriority;
					symAccessPri[CCSUB]				= nextPriority;
					symAccessPri[CCEQ]				= nextPriority;
					symAccessPri[CCIMPLTRIG]		= nextPriority;
					symAccessPri[CCBRANCHTRIG]		= nextPriority;
					symAccessPri[CCPBINDTRIG]		= nextPriority;
					symAccessPri[CCPBINDAND]		= nextPriority;
					symAccessPri[CCVARBINDTRIG]		= nextPriority;
					symAccessPri[CCVARBINDAND]		= nextPriority;
					symAccessPri[CCVARPBACKTRIG]	= nextPriority;
					symAccessPri[CCBACKACTIVTRIG]	= nextPriority;

					symAccessPri[CCOR]				= nextPriority;
					symAccessPri[-CCAND]			= nextPriority;
					symAccessPri[-CCEQ]				= nextPriority;
					symAccessPri[CCDATATYPE]		= nextPriority;
					symAccessPri[-CCDATATYPE]		= nextPriority;
					symAccessPri[CCDATALITERAL]		= nextPriority;
					symAccessPri[-CCDATALITERAL]	= nextPriority;
					symAccessPri[CCDATARESTRICTION] = nextPriority;
					symAccessPri[-CCDATARESTRICTION]= nextPriority;

					mDisjDelConsidPriOffset = -11.0;
					mDisjDelProcessPriOffset = -11.5;


					nextPriority = 12;

					symAccessPri[CCALL]				= nextPriority;
					symAccessPri[-CCSOME]			= nextPriority;
					symAccessPri[CCAQALL]			= nextPriority;
					symAccessPri[CCIMPLALL]			= nextPriority;
					symAccessPri[CCBRANCHALL]		= nextPriority;
					symAccessPri[CCIMPLAQALL]		= nextPriority;
					symAccessPri[CCBRANCHAQALL]		= nextPriority;
					symAccessPri[CCPBINDALL]		= nextPriority;
					symAccessPri[CCVARBINDALL]		= nextPriority;
					symAccessPri[CCVARBINDAQALL]	= nextPriority;
					symAccessPri[CCVARPBACKAQALL]	= nextPriority;
					symAccessPri[CCVARPBACKALL]		= nextPriority;

					nextPriority = 11;

					symAccessPri[CCAQAND]			= nextPriority;
					symAccessPri[CCIMPLAQAND]		= nextPriority;
					symAccessPri[CCBRANCHAQAND]		= nextPriority;
					symAccessPri[CCPBINDAQAND]		= nextPriority;
					symAccessPri[CCVARBINDAQAND]	= nextPriority;
					symAccessPri[CCVARPBACKAQAND]	= nextPriority;

					nextPriority = 10;

					symAccessPri[CCAQCHOOCE]		= nextPriority;
					symAccessPri[-CCAQCHOOCE]		= nextPriority;

					nextPriority = 9;

					symAccessPri[CCIMPL]			= nextPriority;
					symAccessPri[CCBRANCHIMPL]		= nextPriority;
					symAccessPri[CCPBINDIMPL]		= nextPriority;
					symAccessPri[CCPBINDVARIABLE]	= nextPriority;
					symAccessPri[CCPBINDCYCLE]		= nextPriority;
					symAccessPri[CCVARBINDJOIN]		= nextPriority;
					symAccessPri[CCVARBINDVARIABLE]	= nextPriority;
					symAccessPri[CCBACKACTIVIMPL]	= nextPriority;
					symAccessPri[CCVARBINDIMPL]		= nextPriority;

					nextPriority = 8;
					symAccessPri[CCSELF]			= nextPriority;
					symAccessPri[-CCSELF]			= nextPriority;
					symAccessPri[CCVALUE]			= nextPriority;
					symAccessPri[-CCVALUE]			= nextPriority;

					// intermediately processing limit

					nextPriority = 7;

					symAccessPri[CCNOMINAL]			= nextPriority;
					symAccessPri[-CCNOMINAL]		= nextPriority;


					nextPriority = 6;

					symAccessPri[CCPBINDGROUND]		= nextPriority;
					symAccessPri[CCVARBINDGROUND]	= nextPriority;
					symAccessPri[-CCPBINDGROUND]	= nextPriority;
					symAccessPri[-CCVARBINDGROUND]	= nextPriority;

					nextPriority = 5;

					symAccessPri[CCATLEAST]			= nextPriority;
					symAccessPri[-CCATMOST]			= nextPriority;

					nextPriority = 4;

					symAccessPri[CCSOME]			= nextPriority;
					symAccessPri[-CCALL]			= nextPriority;
					symAccessPri[CCAQSOME]			= nextPriority;

					// deterministic processing limit

					nextPriority = 3;

					symAccessPri[CCATMOST]			= nextPriority;
					symAccessPri[-CCATLEAST]		= nextPriority;

					nextPriority = 2;

					// disjunctions + processing offsets






				}


				CConcreteConceptProcessingOperatorPriorityStrategy::~CConcreteConceptProcessingOperatorPriorityStrategy() {
					delete [] priorities;
				}

				double CConcreteConceptProcessingOperatorPriorityStrategy::getPriorityOffsetForDisjunctionDelayedConsidering(CConceptDescriptor *conceptDescriptor, CIndividualProcessNode *individual) {
					return mDisjDelConsidPriOffset;
				}

				double CConcreteConceptProcessingOperatorPriorityStrategy::getPriorityOffsetForDisjunctionDelayedProcessing(CConceptDescriptor *conceptDescriptor, CIndividualProcessNode *individual) {
					return mDisjDelProcessPriOffset;
				}


				CConceptProcessPriority CConcreteConceptProcessingOperatorPriorityStrategy::getPriorityForConcept(CConceptDescriptor *conceptDescriptor, CIndividualProcessNode *individual) {
					qint64 cCode = conceptDescriptor->getData()->getOperatorCode();
					bool negated = false;
					if (conceptDescriptor->isNegated()) {
						cCode *= -1;
						negated = true;
					}
					double priority = 0;
					priority = symAccessPri[cCode];

					CSortedNegLinker<CConcept *> *opConLinkerIt = conceptDescriptor->getData()->getOperandList();
					if (cCode == CCATMOST) {
						qint64 param = conceptDescriptor->getData()->getParameter();
						param = param - 1*negated;
						if (param <= 1 && !opConLinkerIt) {
							priority = 5.5;
						} else {
							double priorityOffset = (exp(-param / 1000.)) * 0.5;
							priority += priorityOffset;
						}
					} else if (cCode == CCATLEAST) {
						qint64 param = conceptDescriptor->getData()->getParameter();
						param = param + 1*negated;
						if (param <= 2 && !opConLinkerIt) {
							priority = 5.0;
						} else {
							double priorityOffset = (1. - exp(-param / 1000.)) * 0.5;
							priority += priorityOffset;
						}
					}
					return CConceptProcessPriority(priority);
				}

			}; // end namespace Strategy

		}; // end namespace Kernel

	}; // end namespace Reasoner

}; // end namespace Konclude