-
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
Partial up-front evaluation of stratifiable program parts - issue #75 #207
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…ged package private stuff in RuleGrondingOrder to public
…o NormalRule, renamed Rule to BasicRule
…formations ###### Program refactoring - `Program`: renamed to `AbstractProgram<R extends AbstractRule<? extends Head>>` and made immutable (immutability doesn't apply to InlineDirectives) - new type `InputProgram extends AbstractProgram<BasicRule>`: the most general type of program, returned by the parser, rules can contain any constructs allowed by the parser - new type `NormalProgram extends AbstractProgram<NormalRule>`: A program that has only rules with normal heads (`NormalHead` introduced as new Head subtype) - new type `InternalProgram extends AbstractProgram<InternalRule>`: A program that is completely transformed and ready to be passed to the grounder and solver (replaces `ProgramAnalysis`, allows no aggregate literals and only normal rule heads) Above changes were made in order to properly reflect "transformation stages" while performing program transformations and to have a compile-time guarantee that the grounder/solver only ever see programs that underwent the necessary preprocessing. Programs are now (mostly) immutable, thereby making debugging easier - before/after comparisons for program transformations are quite easy now. Note that Atoms, Literals and InlineDirectives should also be made immutable to properly guarantee immutability of programs. ###### Rule refactoring - `Rule` renamed to `AbstractRule<H extends Head>` and made immutable (immutability does not apply to Literals) - new type `BasicRule extends AbstractRule<Head>`: rules as they are returned by the parser, any types of heads possible, any kind of literals in body - new type `NormalRule extends AbstractRule<NormalHead>`: rules that have a normal head - `NonGroundRule` renamed to `InternalRule extends NormalRule`: rules that are ready to be passed to the grounder The changes to rules reflect the abovementioned changes to programs and serve the same purpose ###### Refinements in program transformations - made `ProgramTransformation`abstract and added type params, signature is now `ProgramTransformation<I extends AbstractProgram<?>, O extends AbstractProgram<?>` in order to properly reflect input- and output-contracts for individual transformations - adapted transformations to no longer transform a (now immutable) program in place, but return new program instances - changed `IntervalTermToIntervalAtom` and `VariableEqualityRemoval` to only work on `NormalProgram`s
- DepthFirstSearchHelper renamed to DepthFirstSearchAlgorithm. - DfsResult moved as inner class into DepthFirstSearchAlgorithm. - Enhanced comments, removed this.'s, clarified variable names, made variable declarations more local.
Merged
- DfsResult now really contains nodes reachable from root nodes.
- Rename into StronglyConnectedComponentsAlgorithm, make methods static. - Move SccResult inside StronglyConnectedComponentsAlgorithm. - Simplify component extraction from DfsResult.
interface static, removed this.s.
- Changed the stratification to yield one stratum per component, using DFS for finding a topological ordering and marking unstratifiable components. - Renamed ComponentGraphTest to StratificationAlgorithmTest as this is what is tested there, adapted tests to new StratificationAlgorithm. - Adapted StratifiedEvaluation to new result of StratificationAlgorithm.
- Streamlined construction of output facts, removed duplicates check.
- Removed ignored test from DependencyGraphTest. - Inlined components-test.asp and removed it.
Pr207 polishing
# Conflicts: # src/main/java/at/ac/tuwien/kr/alpha/common/program/AnalyzedProgram.java # src/main/java/at/ac/tuwien/kr/alpha/common/program/InternalProgram.java # src/main/java/at/ac/tuwien/kr/alpha/grounder/NaiveGrounder.java # src/main/java/at/ac/tuwien/kr/alpha/grounder/transformation/StratifiedEvaluation.java
Stratification suggestions
AntoniusW
approved these changes
Oct 1, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Stratified Evaluation
Evaluates the stratifiable program part that only depends on facts up-front before the resulting, simplified, program is passed to the grounder. Stratified evaluation is implemented as a program transformation. Solved (i.e. fully evaluated) rules are removed from the program, atoms derived during stratified evaluation are added to the program as facts.
Added command line flags
-nse,--disable-stratified-eval
disables stratified up-front evaluation, i.e. the input program gets passed to the grounder right after normalization-pp,--write-preproc <target>
writes the normalized (and partially evaluated) program to the file attarget
-dg,--depgraph <target>
writes the input program's dependency graph to the file attarget
in dot (graphviz) format-cg,--compgraph <target>
writes the input program's component graph to the file attarget
in dot (graphviz) formatRefactorings
Atom
is now an abstract class rather than an interfaceAbstractRule
as common superclass for all types of rulesAbstractProgram
as common superclass for all types of programsprogram.accumulate(...)
with buildersInputProgram
for parse result, may contain choices, aggregates etc,NormalProgram
for a program without choice heads,InternalProgram
: required input type for grounder, does not permit choice heads and aggregate literals;AnalyzedProgram
: subclass ofInternalProgram
, stores dependency and component graphs, input type for stratified evaluator