Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional constraint generated during transformation of choice rules #282

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2017-2018, the Alpha Team.
/*
* Copyright (c) 2017-2020, the Alpha Team.
* All rights reserved.
*
* Additional changes made by Siemens.
Expand Down Expand Up @@ -79,7 +79,7 @@ public InputProgram apply(InputProgram inputProgram) {
for (ChoiceHead.ChoiceElement choiceElement : choiceHead.getChoiceElements()) {
// Create two guessing rules for each choiceElement.

// Construct common body to both rules.
// Construct body common to both rules and constraint.
Atom head = choiceElement.choiceAtom;
List<Literal> ruleBody = new ArrayList<>(rule.getBody());
ruleBody.addAll(choiceElement.conditionLiterals);
Expand All @@ -99,13 +99,19 @@ public InputProgram apply(InputProgram inputProgram) {

// Construct two guessing rules.
List<Literal> guessingRuleBodyWithNegHead = new ArrayList<>(ruleBody);
guessingRuleBodyWithNegHead.add(new BasicAtom(head.getPredicate(), head.getTerms()).toLiteral(false));
guessingRuleBodyWithNegHead.add(head.toLiteral(false));
additionalRules.add(new BasicRule(new NormalHead(negHead), guessingRuleBodyWithNegHead));

List<Literal> guessingRuleBodyWithHead = new ArrayList<>(ruleBody);
guessingRuleBodyWithHead.add(new BasicAtom(negPredicate, headTerms).toLiteral(false));
guessingRuleBodyWithHead.add(negHead.toLiteral(false));
additionalRules.add(new BasicRule(new NormalHead(head), guessingRuleBodyWithHead));

// Construct a constraint: complementary atoms may not be true simultaneously.
List<Literal> bodyOfConstraint = new ArrayList<>(ruleBody);
bodyOfConstraint.add(head.toLiteral());
bodyOfConstraint.add(negHead.toLiteral());
additionalRules.add(new BasicRule(null, bodyOfConstraint));

// TODO: when cardinality constraints are possible, process the boundaries by adding a constraint with a cardinality check.
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/test/resources/transform-test/choice-to-normal.1.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
_nred("1", N) :- node(N), not red(N).
red(N) :- node(N), not _nred("1", N).
:- node(N), red(N), _nred("1", N).
_ngreen("1", N) :- node(N), not green(N).
green(N) :- node(N), not _ngreen("1", N).
:- node(N), green(N), _ngreen("1", N).
_nblue("1", N) :- node(N), not blue(N).
blue(N) :- node(N), not _nblue("1", N).
:- node(N), blue(N), _nblue("1", N).