Skip to content
Snippets Groups Projects
Commit a297e2e3 authored by Jonas Blatt's avatar Jonas Blatt :ant:
Browse files

Add PartialReductionVerification verifier

parent d1fd2745
No related branches found
No related tags found
No related merge requests found
...@@ -33,7 +33,10 @@ public class BiCreaterAppend extends AbstractBoundaryBiCreater<AbstractGrowingBo ...@@ -33,7 +33,10 @@ public class BiCreaterAppend extends AbstractBoundaryBiCreater<AbstractGrowingBo
if (b1 instanceof BooleanBoundary) { if (b1 instanceof BooleanBoundary) {
return createrBoolean((BooleanBoundary) b1, (BooleanBoundary) b2); return createrBoolean((BooleanBoundary) b1, (BooleanBoundary) b2);
} }
if (b1 instanceof IntegerBoundary || b1 instanceof LongBoundary) { if (b1 instanceof IntegerBoundary) {
return createrInt(b1, b2);
}
if (b1 instanceof LongBoundary) {
return createrLong(b1, b2); return createrLong(b1, b2);
} }
if (b1.getUpperBound().equals(b2.getLowerBound()) if (b1.getUpperBound().equals(b2.getLowerBound())
...@@ -57,6 +60,34 @@ public class BiCreaterAppend extends AbstractBoundaryBiCreater<AbstractGrowingBo ...@@ -57,6 +60,34 @@ public class BiCreaterAppend extends AbstractBoundaryBiCreater<AbstractGrowingBo
return Optional.empty(); return Optional.empty();
} }
private Optional<AbstractGrowingBoundary> createrInt(
AbstractGrowingBoundary b1, AbstractGrowingBoundary b2) {
int b1L = (int) b1.getLowerBound();
int b1U = (int) b1.getUpperBound();
int b2L = (int) b1.getLowerBound();
int b2U = (int) b1.getUpperBound();
if (b1U + 1 == b2L
&& b1.getUpperBoundType() == INCLUSIVE
&& b2.getLowerBoundType() == INCLUSIVE) {
return Optional.of(
b1.getCopy(
b1.getLowerBound(),
b2.getUpperBound(),
b1.getLowerBoundType(),
b2.getUpperBoundType()));
} else if (b2U + 1 == b1L
&& b2.getUpperBoundType() == INCLUSIVE
&& b1.getLowerBoundType() == INCLUSIVE) {
return Optional.of(
b1.getCopy(
b2.getLowerBound(),
b1.getUpperBound(),
b2.getLowerBoundType(),
b1.getUpperBoundType()));
}
return Optional.empty();
}
private Optional<AbstractGrowingBoundary> createrLong( private Optional<AbstractGrowingBoundary> createrLong(
AbstractGrowingBoundary b1, AbstractGrowingBoundary b2) { AbstractGrowingBoundary b1, AbstractGrowingBoundary b2) {
long b1L = (long) b1.getLowerBound(); long b1L = (long) b1.getLowerBound();
......
...@@ -39,11 +39,11 @@ public class BiCreaterBetween extends AbstractBoundaryBiCreater<AbstractGrowingB ...@@ -39,11 +39,11 @@ public class BiCreaterBetween extends AbstractBoundaryBiCreater<AbstractGrowingB
&& !b2.getUpperBound().equals(b1.getLowerBound())) { && !b2.getUpperBound().equals(b1.getLowerBound())) {
return Optional.empty(); return Optional.empty();
} }
if (b1 instanceof DoubleBoundary || b1 instanceof IntegerBoundary) { if (b1 instanceof IntegerBoundary) {
long b1L = (long) b1.getLowerBound(); int b1L = (int) b1.getLowerBound();
long b1U = (long) b1.getUpperBound(); int b1U = (int) b1.getUpperBound();
long b2L = (long) b1.getLowerBound(); int b2L = (int) b1.getLowerBound();
long b2U = (long) b1.getUpperBound(); int b2U = (int) b1.getUpperBound();
if (b1U + 1 == b2L if (b1U + 1 == b2L
&& b1.getUpperBoundType() == INCLUSIVE && b1.getUpperBoundType() == INCLUSIVE
&& b2.getLowerBoundType() == INCLUSIVE && b2.getLowerBoundType() == INCLUSIVE
...@@ -53,6 +53,20 @@ public class BiCreaterBetween extends AbstractBoundaryBiCreater<AbstractGrowingB ...@@ -53,6 +53,20 @@ public class BiCreaterBetween extends AbstractBoundaryBiCreater<AbstractGrowingB
return Optional.empty(); return Optional.empty();
} }
} }
if (b1 instanceof DoubleBoundary) {
long b1L = (long) b1.getLowerBound();
long b1U = (long) b1.getUpperBound();
long b2L = (long) b1.getLowerBound();
long b2U = (long) b1.getUpperBound();
if (b1U + 1 == b2L
&& b1.getUpperBoundType() == INCLUSIVE
&& b2.getLowerBoundType() == INCLUSIVE
|| b2U + 1 == b1L
&& b2.getUpperBoundType() == INCLUSIVE
&& b1.getLowerBoundType() == INCLUSIVE) {
return Optional.empty();
}
}
if (b1.getLowerBound().compareTo(b2.getUpperBound()) < 0) { if (b1.getLowerBound().compareTo(b2.getUpperBound()) < 0) {
return Optional.of( return Optional.of(
b1.getCopy( b1.getCopy(
......
...@@ -69,7 +69,7 @@ public class VDmnFunctions { ...@@ -69,7 +69,7 @@ public class VDmnFunctions {
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
public boolean differentConclusions(List<VDmnRule> rules) { public static boolean differentConclusions(List<VDmnRule> rules) {
if (rules.size() == 0) { if (rules.size() == 0) {
return false; return false;
} }
...@@ -82,7 +82,7 @@ public class VDmnFunctions { ...@@ -82,7 +82,7 @@ public class VDmnFunctions {
return false; return false;
} }
public boolean differentConclusions(VDmnRule oneRule, VDmnRule otherRule) { public static boolean differentConclusions(VDmnRule oneRule, VDmnRule otherRule) {
if (oneRule.getDmnOutputValues().size() != otherRule.getDmnOutputValues().size()) { if (oneRule.getDmnOutputValues().size() != otherRule.getDmnOutputValues().size()) {
return true; return true;
} }
...@@ -98,23 +98,25 @@ public class VDmnFunctions { ...@@ -98,23 +98,25 @@ public class VDmnFunctions {
return false; return false;
} }
public List<List<VDmnRule>> getRuleClustersWithIdenticalOutput( public static List<List<VDmnRule>> getRuleClustersWithIdenticalOutput(
VDmnDecisionTable dmnDecisionTable) { VDmnDecisionTable dmnDecisionTable) {
List<List<VDmnRule>> clusters = new ArrayList<>(); List<List<VDmnRule>> clusters = new ArrayList<>();
List<VDmnRule> remainingRules = new ArrayList<>(dmnDecisionTable.getRules()); List<VDmnRule> remainingRules = new ArrayList<>(dmnDecisionTable.getRules());
for (int i = 0; i < remainingRules.size(); i++) { for (int i = 0; i < remainingRules.size(); i++) {
List<VDmnRule> newCluster = new ArrayList<>(); List<VDmnRule> newCluster = new ArrayList<>();
newCluster.add(remainingRules.get(i)); if (remainingRules.get(i) != null) {
remainingRules.set(i, null); newCluster.add(remainingRules.get(i));
for (int u = i + 1; u < remainingRules.size(); u++) { remainingRules.set(i, null);
if (remainingRules.get(u) != null for (int u = i + 1; u < remainingRules.size(); u++) {
&& !differentConclusions(newCluster.get(0), remainingRules.get(u))) { if (remainingRules.get(u) != null
newCluster.add(remainingRules.get(u)); && !differentConclusions(newCluster.get(0), remainingRules.get(u))) {
remainingRules.set(u, null); newCluster.add(remainingRules.get(u));
remainingRules.set(u, null);
}
}
if (newCluster.size() > 1) {
clusters.add(newCluster);
} }
}
if (newCluster.size() > 1) {
clusters.add(newCluster);
} }
} }
return clusters; return clusters;
......
package de.unikoblenz.fgbks.core.dmn.verification.verifier.impl; package de.unikoblenz.fgbks.core.dmn.verification.verifier.impl;
import static de.unikoblenz.fgbks.base.utils.boundary.bicreater.BoundaryBiCreaterType.COMBINE;
import static de.unikoblenz.fgbks.base.utils.boundary.checker.BoundaryCheckType.IS_EQUAL;
import de.unikoblenz.fgbks.core.dmn.domain.vdmn.VDmnDecision;
import de.unikoblenz.fgbks.core.dmn.domain.vdmn.VDmnDecisionTable;
import de.unikoblenz.fgbks.core.dmn.domain.vdmn.VDmnInputColumn;
import de.unikoblenz.fgbks.core.dmn.domain.vdmn.VDmnInputValue;
import de.unikoblenz.fgbks.core.dmn.domain.vdmn.VDmnRule;
import de.unikoblenz.fgbks.core.dmn.domain.vdmn.utils.VDmnFunctions;
import de.unikoblenz.fgbks.core.dmn.verification.result.VerificationResultEntry.VerificationClassification;
import de.unikoblenz.fgbks.core.dmn.verification.result.VerificationResultEntryElement;
import de.unikoblenz.fgbks.core.dmn.verification.verifier.AbstractVerifier; import de.unikoblenz.fgbks.core.dmn.verification.verifier.AbstractVerifier;
import de.unikoblenz.fgbks.core.dmn.verification.verifier.DmnVerifier; import de.unikoblenz.fgbks.core.dmn.verification.verifier.DmnVerifier;
import de.unikoblenz.fgbks.core.dmn.verification.verifier.config.DefaultConfiguration; import de.unikoblenz.fgbks.core.dmn.verification.verifier.config.DefaultConfiguration;
import de.unikoblenz.fgbks.core.dmn.verification.verifier.types.PartialReductionVerification; import de.unikoblenz.fgbks.core.dmn.verification.verifier.types.PartialReductionVerification;
import java.util.ArrayList;
import java.util.List;
@DmnVerifier( @DmnVerifier(
verifierType = PartialReductionVerification.class, verifierType = PartialReductionVerification.class,
...@@ -11,5 +24,79 @@ import de.unikoblenz.fgbks.core.dmn.verification.verifier.types.PartialReduction ...@@ -11,5 +24,79 @@ import de.unikoblenz.fgbks.core.dmn.verification.verifier.types.PartialReduction
public class PartialReductionVerifier extends AbstractVerifier { public class PartialReductionVerifier extends AbstractVerifier {
@Override @Override
protected void doVerification() {} protected void doVerification() {
for (VDmnDecision decision : dmnObjectContainer.getVDmnDefinition().getDmnDecisions()) {
findPartialReduction(decision.getDmnDecisionTable());
}
}
private void findPartialReduction(VDmnDecisionTable dmnDecisionTable) {
List<List<VDmnRule>> identicalOutputCluster = VDmnFunctions
.getRuleClustersWithIdenticalOutput(dmnDecisionTable);
List<VDmnInputColumn> inColumns = dmnDecisionTable.getInputColumns();
identicalOutputCluster.stream() // do: parallelStream() ?
.forEach(c -> findPartialReduction(inColumns, 0, c, false));
}
private void findPartialReduction(List<VDmnInputColumn> inColumns, int i,
List<VDmnRule> clusterRules,
boolean hasCombination) {
if (i == inColumns.size()) {
if (hasCombination) {
clusterRules.forEach(
rule ->
vreFactory.addElement(
VerificationResultEntryElement.create(inColumns.get(0).getDmnDecisionTable())
.withIdentifier(rule.getRuleId())));
vreFactory.addToEntry(VerificationClassification.WARNING, "PartialReduction");
}
} else {
List<VDmnInputValue> rules = VDmnFunctions
.getColumnValuesInRules(inColumns.get(i), clusterRules);
List<List<VDmnRule>> nClusters = new ArrayList<>();
List<Boolean> combinationCluster = new ArrayList<>();
for (int i1 = 0; i1 < rules.size(); i1++) {
VDmnInputValue currentRule = rules.get(i1);
// 1. Find combinations
if (!hasCombination) {
for (int i2 = i1 + 1; i2 < rules.size(); i2++) {
VDmnInputValue currentRuleInner = rules.get(i2);
if (currentRule != currentRuleInner) {
if (currentRule
.getBoundary()
.createBi(COMBINE, currentRuleInner.getBoundary())
.isPresent()) {
List<VDmnRule> cluster = new ArrayList<>();
cluster.add(currentRule.getDmnRule());
cluster.add(currentRuleInner.getDmnRule());
nClusters.add(cluster);
combinationCluster.add(true);
}
}
}
}
// 2. Find equal values
for (int i2 = i1 + 1; i2 < rules.size(); i2++) {
VDmnInputValue currentRuleInner = rules.get(i2);
if (currentRule != currentRuleInner) {
if (currentRule.getBoundary().checkWith(IS_EQUAL, currentRuleInner.getBoundary())) {
List<VDmnRule> cluster = new ArrayList<>();
cluster.add(currentRule.getDmnRule());
cluster.add(currentRuleInner.getDmnRule());
nClusters.add(cluster);
combinationCluster.add(false);
}
}
}
}
// nex col
for (int x = 0; x < combinationCluster.size(); x++) {
if (nClusters.get(x).size() > 1) {
findPartialReduction(
inColumns, i + 1, nClusters.get(x), combinationCluster.get(x) || hasCombination);
}
}
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment