-
Notifications
You must be signed in to change notification settings - Fork 10
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
Full aggregate support #268
Full aggregate support #268
Conversation
…full_aggregate_support
Codecov Report
@@ Coverage Diff @@
## master #268 +/- ##
============================================
+ Coverage 77.69% 78.12% +0.42%
- Complexity 2362 2465 +103
============================================
Files 179 187 +8
Lines 7896 8127 +231
Branches 1383 1418 +35
============================================
+ Hits 6135 6349 +214
- Misses 1333 1344 +11
- Partials 428 434 +6
Continue to review full report at Codecov.
|
…" literal splitting and operator normalization
Co-authored-by: Antonius Weinzierl <AntoniusW@users.noreply.github.com>
Co-authored-by: Antonius Weinzierl <AntoniusW@users.noreply.github.com>
Co-authored-by: Antonius Weinzierl <AntoniusW@users.noreply.github.com>
Co-authored-by: Antonius Weinzierl <AntoniusW@users.noreply.github.com>
…0590/Alpha into full_aggregate_support
Thanks for the feedback! All taken care of, except for very few cases where I think my initial solution was better than the suggested change (see respective comments). Please take another look! |
@madmike200590 what is the current status here? I see some conflicts due to recent changes in master and we had the discussion about negative weights, which in principle can be accommodated but incur a quite hefty performance drawback. My suggestion, for the time being, is to add a commandline flag for whether aggregates should be rewritten such that negative weights are allowed or not. Default should be no negative weights in aggregates and throwing an exception once they are encountered, where the exception hints at turning the commandline flag on if one really wants negative weights. What are your thoughts? |
Conflicts are fixed, latest changes from master merged. On the negative integer question, as per our dicussion, I implemented the correct handling of negative values as the default behavior now. Cmdline-switch for lightweight version only supporting positive integers will be done by end of this week. |
…configurations for simplified rerwritings in regression tests
@AntoniusW This is now (finally!) finished. Support for negative integers in sum elements can be disabled using the |
Co-authored-by: Antonius Weinzierl <AntoniusW@users.noreply.github.com>
src/test/java/at/ac/tuwien/kr/alpha/solver/RegressionTestConfigProvider.java
Outdated
Show resolved
Hide resolved
…gProvider.java Co-authored-by: Antonius Weinzierl <AntoniusW@users.noreply.github.com>
Full Aggregate Support
This PR adds support for
X = #count{N : thing(N)}.
min
andmax
X < #sum{...} < Y
Implementation
As before, aggregates are supported by rewriting aggregate literals to aggregate-free sub-programs. The basic workflow for this is implemented in
AggregateRewriting
:count
andsum
, all aggregate literals are rewritten into versions that only use=
and<=
as operators.Aggregate Literal Splitting
This process step transforms aggregate literals that have both a lower- and upper-bound operator into two literals with only lower-bound operators while preserving semantics.
For positive literals, this is straight-forward - the lower-bound operator stays unchanged, and a second instance of the literal is added to the rule where the former upper-bound term is used as lower-bound term and the operator "turned" accordingly, e.g.
is transformed into
Slightly more effort is needed for negated aggregate literals. Since the semantics of the literal
not X <op1> <aggr> <op2> Y
isNOT (X <op1> <aggr> AND <aggr> <op2> Y)
, and therefore after applying DeMorgan's rule:NOT (X <op1> <aggr>) OR NOT (<aggr> <op2> Y)
, this cannot be directly represented in one rule (since ASP does not support disjunction within rule bodies). Rules containing negated aggregate literals with two operators therefore need to be split into separate rules, e.g:is transformed into
For rules with more than one aggregate literal, the splitting process happens recursively until there are no rules with un-split literals left.
Aggregate Operator Normalization
In order to keep the actual rewriting logic for the respective aggregate functions simple, aggregate literals that use the
count
orsum
function are transformed such that only=
and<=
are used for comparisons. The transformation works according to the following equivalencies:X < #aggr{...} <==> XP <= #aggr{...}, XP = X + 1
X != #aggr{...} <==> not X = #aggr{...}
X > #aggr{...} <==> not X <= #aggr{...}
X >= #aggr{...} <==> not XP <= #aggr{...}, XP = X + 1
not X < #aggr{...} <==> not XP <= #aggr{...}, XP = X + 1
not X != #aggr{...} <==> X = #aggr{...}
not X > #aggr{...} <==> X <= #aggr{...}
not X >= #aggr{...} <==> XP <= #aggr{...}, XP = X + 1
For details on the semantics involved, see the ASP Core2 Standard.
Aggregate Encoding
After aggregate literals are split and their operators normalized, the final step is to substitute the aggregate literals in rule bodies with generated standard literals and add the appropriate sub-programs that define rules deriving said literals. This process is implemented in
AggregateRewriting
.#count/#sum
The encodings for both
count
andsum
aggregates work on the same basic principle:X <= #aggr{...}
are encoded by way of counting (or adding up) starting from zero and checking if the resulting intermediate results exceed the value ofX
thereby makingX
a lower bound for#aggr{...}
.X = #aggr{...}
that assign a value to a variable make use of the variant for the "<= scenario
". Every potential count (or sum) that is a lower bound on the actual value is calculated and the greatest resulting lower bound is returned as the actual count/sum.Example
The program
is rewritten to
#min/#max
Encodings for
min
andmax
aggregates are very similar. Both define a "less_than
" relation over the respective element tuples and designate the element that has no smaller (min) or greater (max) element as result.Example
The program
is rewritten to