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

Partial up-front evaluation of stratifiable program parts - issue #75 #207

Merged
merged 240 commits into from
Oct 1, 2020

Conversation

madmike200590
Copy link
Collaborator

@madmike200590 madmike200590 commented Nov 20, 2019

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 at target
  • -dg,--depgraph <target> writes the input program's dependency graph to the file at target in dot (graphviz) format
  • -cg,--compgraph <target> writes the input program's component graph to the file at target in dot (graphviz) format

Refactorings

  • Atom is now an abstract class rather than an interface
  • AbstractRule as common superclass for all types of rules
  • AbstractProgram as common superclass for all types of programs
  • program types immutable, replaced program.accumulate(...) with builders
  • new program types: InputProgram 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 of InternalProgram, stores dependency and component graphs, input type for stratified evaluator

…ged package private stuff in RuleGrondingOrder to public
…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
AntoniusW and others added 12 commits September 19, 2020 00:48
- DfsResult now really contains nodes reachable from root nodes.
- Rename into StronglyConnectedComponentsAlgorithm, make methods static.
- Move SccResult inside StronglyConnectedComponentsAlgorithm.
- Simplify component extraction from DfsResult.
- 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.
# 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
@madmike200590 madmike200590 linked an issue Oct 1, 2020 that may be closed by this pull request
@AntoniusW AntoniusW merged commit 7788331 into alpha-asp:master Oct 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants