alpha-asp / Alpha

A lazy-grounding Answer-Set Programming system
BSD 2-Clause "Simplified" License
58 stars 10 forks source link

Modularized code quality needs improvement. #300

Open AntoniusW opened 3 years ago

AntoniusW commented 3 years ago

Here we track code quality issues that became visible due to the modularization. The goal is to fix those issues after the basic modularization has been merged into master, as addressing all of them before merging would significantly increase the scope of changes already in PR #274. The lists here will be expanded during code review and modified according to ongoing discussions.

Documentation missing:

Refactoring required:

Refactoring suggestions:

Improve/Complete documentation in:

lorenzleutgeb commented 3 years ago

Because the following involves benchmarking, it might warrant a separat issue, but nevertheless, I uncovered it during the review for #274, so here we go:

C:\Users\lorenz\src\github.com\alpha-asp\Alpha\alpha-core\src\main\java\at\ac\tuwien\kr\alpha\core\solver\NoGoodStoreAlphaRoaming.java:78: warning: [rawtypes] found raw type: ArrayList
    private ArrayList<WatchedNoGood>[] watches = new ArrayList[0];
                                                     ^
  missing type arguments for generic class ArrayList<E>
  where E is a type-variable:
    E extends Object declared in class ArrayList
C:\Users\lorenz\src\github.com\alpha-asp\Alpha\alpha-core\src\main\java\at\ac\tuwien\kr\alpha\core\solver\NoGoodStoreAlphaRoaming.java:80: warning: [rawtypes] found raw type: ArrayList
    private ArrayList<WatchedNoGood>[] watchesAlpha = new ArrayList[0];
                                                          ^
  missing type arguments for generic class ArrayList<E>
  where E is a type-variable:
    E extends Object declared in class ArrayList
C:\Users\lorenz\src\github.com\alpha-asp\Alpha\alpha-core\src\main\java\at\ac\tuwien\kr\alpha\core\solver\NoGoodStoreAlphaRoaming.java:105: warning: [rawtypes] found raw type: ArrayList
        watches = new ArrayList[0];
                      ^
  missing type arguments for generic class ArrayList<E>
  where E is a type-variable:
    E extends Object declared in class ArrayList
C:\Users\lorenz\src\github.com\alpha-asp\Alpha\alpha-core\src\main\java\at\ac\tuwien\kr\alpha\core\solver\NoGoodStoreAlphaRoaming.java:106: warning: [rawtypes] found raw type: ArrayList
        watchesAlpha = new ArrayList[0];
                           ^
  missing type arguments for generic class ArrayList<E>
  where E is a type-variable:
    E extends Object declared in class ArrayList

These warnings can be avoided by using ArrayList<ArrayList<WatchedNoGood>> instead of ArrayList<WatchedNoGood>[]. It's not obvious how the two variants differ in performance, so I'd ask for benchmarking, but at the same time I conjecture that the impact would be neglegible.

lorenzleutgeb commented 3 years ago

I created some issues that were uncovered in #274: #302, #303, #304.

AntoniusW commented 3 years ago

Because the following involves benchmarking, it might warrant a separat issue, but nevertheless, I uncovered it during the review for #274, so here we go:

C:\Users\lorenz\src\github.com\alpha-asp\Alpha\alpha-core\src\main\java\at\ac\tuwien\kr\alpha\core\solver\NoGoodStoreAlphaRoaming.java:78: warning: [rawtypes] found raw type: ArrayList
  private ArrayList<WatchedNoGood>[] watches = new ArrayList[0];
                                                   ^
  missing type arguments for generic class ArrayList<E>
  where E is a type-variable:
    E extends Object declared in class ArrayList
...

These warnings can be avoided by using ArrayList<ArrayList<WatchedNoGood>> instead of ArrayList<WatchedNoGood>[]. It's not obvious how the two variants differ in performance, so I'd ask for benchmarking, but at the same time I conjecture that the impact would be neglegible.

Agreed, this should not be changed without benchmarking. Since access to watches is at the core of propagation, this is (part of) the code that runs millions of times per second. Arrays have a small advantage over ArrayLists, namely that the array (in theory) needs only one memory access to get the desired data, while the ArrayList is an object that stores a reference to an array, hence there are two memory accesses required to get the data. Since the outer list is accessed randomly (while the inner one will be walked sequentially), I conjecture that changing the outer to an ArrayList might slow down propagation. But at the moment, I also do not have solid data for that behaviour with the current solver. For the moment a separate issue might be advised.

lorenzleutgeb commented 3 years ago

One more: Allow configuration of packages to be scanned for external predicates.

madmike200590 commented 2 years ago

alpha-api/src/main/java/at/ac/tuwien/kr/alpha/api/StatisticsReportingSolver.java needs full documentation.

@AntoniusW could you please take care of this? I lack the level of detailed expertise in our DefaultSolver to properly document the collected statistics.

madmike200590 commented 2 years ago

alpha-api/src/main/java/at/ac/tuwien/kr/alpha/api/config/BinaryNoGoodPropagationEstimationStrategy.java should be more detailed with information from BinaryNoGoodPropagationEstimation.

The current javadoc for both of these is not approachable to users without in-depth knowledge of ASP solver architecture. Any API user wanting to use anything other than default settings here will have to read some research papers as well as sources of the alpha-core module, so I'm at a loss on what to put into the javadoc here (especially since I'm not completely sure this should even be public API).

madmike200590 commented 2 years ago

Interface lacks method AnswerSetQuery#forPredicate(Predicate) and the interface contains superfluous public modifiers.

AnswerSetQuery#forPredicate(Predicate) is a static factory method that does not make sense in an interface definition.

lorenzleutgeb commented 2 years ago

Moving a TODO here:

class BasicLiteralImpl extends AbstractLiteral implements BasicLiteral
// TODO could we parameterize Literal with Atom type?