aboutsummaryrefslogtreecommitdiffstats
path: root/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/builder/LogicSolver.xtend
blob: fa277dbf7e198e66d0d21c159c7e592fc235bab6 (plain) (blame)
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
239
package hu.bme.mit.inf.dslreasoner.logic.model.builder

import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem
import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.LogicResult
import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.ModelResult
import hu.bme.mit.inf.dslreasoner.workspace.ReasonerWorkspace
import java.util.List
import java.util.SortedSet
import java.util.TreeSet
import com.google.thirdparty.publicsuffix.PublicSuffixPatterns
import javax.xml.ws.soap.AddressingFeature.Responses
import java.util.Collection

abstract class LogicReasoner {
	def abstract LogicResult solve(LogicProblem problem, LogicSolverConfiguration configuration,
		ReasonerWorkspace workspace) throws LogicReasonerException

	def abstract List<? extends LogicModelInterpretation> getInterpretations(ModelResult modelResult)
}

public class LogicReasonerException extends Exception {
	new(String message, Exception cause) {
		super(message, cause)
	}

	new(Exception cause) {
		super("The reasoner has failed", cause)
	}

	new(String message) {
		super(message)
	}
}

/**
 * Creates an interval. If the lowerLimit is greater than the upperLimit, the values will be swapped.
 */
class IntegerInterval {
	private var int lowerLimit;
	private var int upperLimit;

	new(int lowerLimit, int upperLimit) {
		if (lowerLimit <= upperLimit) {
			this.lowerLimit = lowerLimit;
			this.upperLimit = upperLimit;
		} else {
			this.upperLimit = lowerLimit;
			this.lowerLimit = upperLimit;
		}
	}

	def boolean equals(IntegerInterval interval) {
		if (interval.lowerLimit == this.lowerLimit && interval.upperLimit == this.upperLimit)
			return true
		return false
	}

	def public int getLowerLimit() {
		return lowerLimit;
	}

	def public int getUpperLimit() {
		return upperLimit;
	}

	def public void setLimits(int lowerLimit, int upperLimit) {
		if (lowerLimit <= upperLimit) {
			this.lowerLimit = lowerLimit;
			this.upperLimit = upperLimit;
		} else {
			this.upperLimit = lowerLimit;
			this.lowerLimit = upperLimit;
		}
	}
}

/**
 * Creates a range which represents the minimum and maximum length allowed for Strings. 
 * If the input for minimumLength is lower than 0, then the minimumLength will be set to 0.
 * If the input for maximumLength is lower than 0, then the maximumLength will be set to 0.
 * If minimumLength is greater than maximumLength, the values will be swapped
 */
class StringLengthInterval {
	private var int minimumLength;
	private var int maximumLength;

	new(int minimumLength, int maximumLength) {
		if (minimumLength < 0) {
			this.minimumLength = 0
		} else if (maximumLength < 0) {
			this.maximumLength = 0
		} else if (minimumLength >= maximumLength) {
			this.maximumLength = minimumLength;
			this.minimumLength = maximumLength;
		} else {
			this.maximumLength = maximumLength;
			this.minimumLength = minimumLength;
		}
	}

	def boolean equals(StringLengthInterval interval) {
		if (interval.minimumLength == this.minimumLength && interval.maximumLength == this.maximumLength)
			return true
		return false
	}

	def public int getMinimumLength() {
		return minimumLength;
	}

	def public int getMaximumLength() {
		return maximumLength;
	}

	def public void setLimits(int minimumLength, int maximumLength) {
		if (minimumLength < 0) {
			this.minimumLength = 0
		} else if (maximumLength < 0) {
			this.maximumLength = 0
		} else if (minimumLength >= maximumLength) {
			this.maximumLength = minimumLength;
			this.minimumLength = maximumLength;
		} else {
			this.maximumLength = maximumLength;
			this.minimumLength = minimumLength;
		}
	}
}

abstract class LogicSolverConfiguration {
	public static val Unlimited = -1;
	public static val String UndefinedPath = null

	/** The URI string to the independent solver application */
	public String solverPath = UndefinedPath
	/** Max runtime limit in seconds. */
	public int runtimeLimit = Unlimited
	/** Max runtime limit in seconds. */
	public int memoryLimit = Unlimited

	public var TypeScopes typeScopes = new TypeScopes;
	public var SolutionScope solutionScope = new SolutionScope
}

/**
 * Defines the the size of the generated models. Constant <code>Unlimited</code> defines no upper limit to the type.
 */
public class TypeScopes {
	public static val Unlimited = -1;
	public var boolean ignoreIdDuringGeneration = true

	/**
	 * The domain of integers from which we can choose
	 */
	public var IntegerInterval intervalOfIntegers
	/**
	 * The maximal and minimal length of strings
	 */
	public var StringLengthInterval intervalOfStrings
	/**
	 * A set containing the integers that can be used to solve the problem.
	 */
	public TreeSet<Integer> allIntegers = new TreeSet<Integer> {
		override boolean add(Integer element) {
			if (element < intervalOfIntegers.lowerLimit || element > intervalOfIntegers.upperLimit) {
				return false
			} else {
				return super.add(element)
			}
		}

		override boolean addAll(Collection<? extends Integer> collectionToAdd) {
			var boolean hasBeenModified = false
			for (element : collectionToAdd) {
				hasBeenModified = this.add(element);
			}
			return hasBeenModified
		}

	}

	/**
	 * A set containing the strings that can be used to solve the problem.
	 */
	public TreeSet<String> allStrings = new TreeSet<String> {
		override boolean add(String string) {
			if (string.length < intervalOfStrings.minimumLength || string.length > intervalOfStrings.maximumLength) {
				return false
			} else {
				return super.add(string)
			}
		}

		override boolean addAll(Collection<? extends String> collectionToAdd) {
			var boolean hasBeenModified = false
			for (element : collectionToAdd) {
				if (!(element.length < intervalOfStrings.minimumLength ||
					element.length > intervalOfStrings.maximumLength)) {
					hasBeenModified = super.add(element);
				}
			}
			return hasBeenModified
		}
	}

	/**
	 * A set containing the doubles that can be used to solve the problem.
	 */
	public TreeSet<Double> allDoubles = new TreeSet<Double>
	/**
	 * Sets the number of Strings that has to be used to solve the problem.
	 */
	public var numberOfUseableStrings = Unlimited
	/**
	 * Sets the number of Integers that has to be used to solve the problem.
	 */
	public var numberOfUseableIntegers = Unlimited
	/**
	 * Defines a limit for integers in the logic problem.
	 */
	public var maxIntScope = Unlimited
	/**
	 * Defines the minimal number of newly added elements. Default value is 0.
	 */
	public var minNewElements = 0
	/**
	 * Defines the maximal number of newly added elements. Default value is <code>TypeScopes.Unlimited</code>.
	 */
	public var maxNewElements = Unlimited
}

/**
 * Defines the required number of solutions for the problem.
 * Constant <code>All</code> defines that all solution for the problem is requested.
 */
public class SolutionScope {
	public static val All = -1;
	public var numberOfRequiredSolution = 1
}