diff options
author | 2017-06-10 19:05:05 +0200 | |
---|---|---|
committer | 2017-06-10 19:05:05 +0200 | |
commit | 60f01f46ba232ed6416054f0a6115cb2a9b70b4e (patch) | |
tree | 5edf8aeb07abc51f3fec63bbd15c926e1de09552 /Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/util/LogicProblemBuilder_AdvancedConstructs.xtend | |
parent | Initial commit, migrating from SVN (diff) | |
download | VIATRA-Generator-60f01f46ba232ed6416054f0a6115cb2a9b70b4e.tar.gz VIATRA-Generator-60f01f46ba232ed6416054f0a6115cb2a9b70b4e.tar.zst VIATRA-Generator-60f01f46ba232ed6416054f0a6115cb2a9b70b4e.zip |
Migrating Additional projects
Diffstat (limited to 'Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/util/LogicProblemBuilder_AdvancedConstructs.xtend')
-rw-r--r-- | Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/util/LogicProblemBuilder_AdvancedConstructs.xtend | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/util/LogicProblemBuilder_AdvancedConstructs.xtend b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/util/LogicProblemBuilder_AdvancedConstructs.xtend new file mode 100644 index 00000000..3db0e2a6 --- /dev/null +++ b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/util/LogicProblemBuilder_AdvancedConstructs.xtend | |||
@@ -0,0 +1,71 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.util | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicProblemBuilder | ||
4 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.IfThenElse | ||
5 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Term | ||
6 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Variable | ||
7 | import java.util.ArrayList | ||
8 | import java.util.Collection | ||
9 | import java.util.List | ||
10 | import java.util.Map | ||
11 | |||
12 | class LogicProblemBuilder_AdvancedConstructs { | ||
13 | val extension LogicProblemBuilder builder; | ||
14 | public new(LogicProblemBuilder builder) { | ||
15 | this.builder = builder | ||
16 | } | ||
17 | |||
18 | def public FunctionDefinitionBody(Iterable<Variable> variables, Map<List<Term>,Term> parametersToValue, Term other) { | ||
19 | val variableList = variables.toList | ||
20 | val entryList = parametersToValue.entrySet.toList | ||
21 | |||
22 | // Size = 0 | ||
23 | if(entryList.empty && other === null) { | ||
24 | throw new IllegalArgumentException('''No possible value is specified!''') | ||
25 | // Size = 1 | ||
26 | } else if(entryList.size == 1 && other === null) { | ||
27 | return entryList.head.value | ||
28 | // Size = 1 | ||
29 | } else if(entryList.empty && !(other === null)) { | ||
30 | return other | ||
31 | // Size > 1 | ||
32 | }else { | ||
33 | // Transforming values to IF-Then-Else structures | ||
34 | /**The number of IF-THEN-ELSE structures needed*/ | ||
35 | var int iteNumber | ||
36 | if(other === null) iteNumber = entryList.size-1 | ||
37 | else iteNumber = entryList.size | ||
38 | |||
39 | val ites = new ArrayList<IfThenElse>(iteNumber) | ||
40 | for (element : 0 ..< iteNumber) { | ||
41 | ites += ITE( | ||
42 | entryList.get(element).key.substitutionIsEqual(variableList), | ||
43 | entryList.get(element).value, | ||
44 | null) | ||
45 | } | ||
46 | |||
47 | // Linking the IF-Then-Else structures to a chain | ||
48 | for (optionIndex : 1 ..< ites.size) { | ||
49 | val prev = ites.get(optionIndex - 1) | ||
50 | val next = ites.get(optionIndex) | ||
51 | prev.ifFalse = next | ||
52 | } | ||
53 | |||
54 | if(other === null) ites.last.ifFalse = entryList.last.value | ||
55 | else ites.last.ifFalse = other | ||
56 | |||
57 | // return the head of the chain | ||
58 | return ites.head | ||
59 | } | ||
60 | } | ||
61 | |||
62 | def public RelationDefinitionBody(Iterable<Variable> variables, Collection<List<Term>> elements) { | ||
63 | val variableList = variables.toList | ||
64 | return elements.map[row | row.substitutionIsEqual(variableList)].Or | ||
65 | } | ||
66 | |||
67 | def private substitutionIsEqual(List<Term> substitution, List<Variable> variables) { | ||
68 | val parameterIndexes = 0..<variables.size | ||
69 | return And(parameterIndexes.map[index | substitution.get(index) == variables.get(index)]) | ||
70 | } | ||
71 | } \ No newline at end of file | ||