Open AntoniusW opened 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.
I created some issues that were uncovered in #274: #302, #303, #304.
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 ofArrayList<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.
One more: Allow configuration of packages to be scanned for external predicates.
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.
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).
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.
Moving a TODO here:
class BasicLiteralImpl extends AbstractLiteral implements BasicLiteral
// TODO could we parameterize Literal with Atom type?
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:
BinaryNoGoodPropagationEstimation
.BasicSubstitution
.Refactoring required:
Alpha#getConfig
is never used and can be removed.AnswerSetQuery#forPredicate(Predicate)
and the interface contains superfluouspublic
modifiers.ProgramParser#parse(Map<String, PredicateInterpretation> externalPredicateDefinitions, Path... programSources)
is the sole overloadedparse
method where external predicates is the first parameter (probably due to varargsPath...
). This should be in line and varargs avoided with aPath[]
array as first parameter.Refactoring suggestions:
NormalProgram
from API and keep it only in core.NormalProgram
is contained inDebugSolvingContext
and written inMain.java
but anASPCore2Program
would suffice there.java.util.function.Predicate<Predicate> filter
andAnswerSetPredicateFilter
may be more telling.AnswerSet
could support methodMap<Predicate,SortedSet<Atom>> getInstances()
while method#getPredicateInstances
could be renamed to#getInstancesOfPredicate(Predicate)
.ComparisonOperator
should probably be replaced with an enum in API and just state the standard operations. There should to be no need for arbitrary comparison operators. Additionally,ComparisonOperators
replaced a switching of the type of operator with sub-classing, spreading the behaviour ofComparisonOperator#compare
over six classes -- a simple switch in one place probably is much more understandable and avoids a lot of boilerplate. Additionally, inAggregateLiteralSplitting
an if-else-if chain could be replaced with a switch on the enum (again).MinusTerm
ofArithmeticTermImpl
seems superfluous.Atom
andLiteral
hierarchies (not all interface methods make sense on every atom or literal). This should also consider dissolvingVariableNormalizableAtom
as its only method is implemented by all atom implementations. Consider whether a generic form of literalLiteral<SpecificAtomType>
makes sense.BasicSubstitution
really should be in commons and not just in core and available through a factory in commons. Some methods ofSubstitution
may have better names.AbstractProgram
should implementProgram
.Predicate#isInternal
andPredicate#isSolverInternal
likely should not be in API as their names already suggest.ComponentGraph#SCCComponent
are not named very intuitively.DependencyGraph
is actually a predicate-dependency graph, this should be reflected in its name. Furthermore,DependencyGraph#Node#getLabel
is only an alternative name forNode#getPredicate#toString
and probably can be removed.Unifier
currently extendsSubstitution
, but maybe should be the other way round asSubstitution
is actually only for grounding substitutions and unifier is a substitution that allows mappings to variables, not just ground terms. AsSubstitution#eval
is used at the core of all grounding, care must be taken to not impact performance negatively with those changes.Predicate
really needs methodsisInternal()
andisSolverInternal()
.AggregateElement
represents.Atom#substitute
methods, also document them.AnswerSetQuery
allows to set filters but lacks the most important one, namely whichPredicate
this query is applied to. This is currently based in the factory method to construct a query, but would make more sense in place where all other conditions for the query are set.DisjunctiveHead
or implement a rewriting in case input program is head-cycle-free.Literals#fromAtom
is a duplicate ofAtom#toLiteral
functionality and remove if so.at.ac.tuwien.kr.alpha.commons.substitutions.Instance
from api/commons view and move to core.TODO
comments in code.Terms#renameTerms
is mis-named as it callsnormalizeVariables
which in turn renames only variable terms.Terms#evaluateGroundTerm
to make clear that this is arithmetic evaluation yielding integers.Terms#new..Term
vsPredicate#getPredicate
vsAtoms#new..Atom
vsLiterals#fromAtom
. Previously most of these used a#getInstance
naming.CompiledRule
andCompiledProgram
exists since both are in alpha-core where their only implementationsInternalRule
andInternalProgram
also exist. It seems that both interfaces can be deleted.BridgedGrounder
andBridge
architecture of the grounder could be removed, since it is not in use any longer and Alpha nowadays has its own mechanism for external predicates.RuleGroundingOrder
andRuleGroundingInfo
can be reverted as this is pretty internal information and only used in the core.core.Programs
provides one single helper method (of 2 lines of code) that is only used in one test, maybe the class should be inlined completely.[Interface]Impl
andBasic[Interface]
but we also have interfaces namedBasicAtom
which gives rise toBasicAtomImpl
.AtomCounter
should count atom types based on theirString
representation or onClass
objects.parseAndPreprocess
function, it looks like this could be shared among those tests.ASPCore2Program
whose sole implementation isInputProgram
, which is not obvious from the naming.Improve/Complete documentation in: