alpha-asp / Alpha

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

IntervalTermRewriting fails on ExternalAtoms #277

Closed madmike200590 closed 3 years ago

madmike200590 commented 3 years ago

Following code throws an exception in interval rewriting:

parse_area_parse_input(AREA, INPUT) :-
    parse_area_parts(AREA, PARTS),
    &array_idx_value[PARTS, 0..MAX_IDX](INPUT),
    &array_length[PARTS](PARTS_LEN),
    MAX_IDX = PARTS_LEN - 1.

Error is:

Exception in thread "main" java.lang.UnsupportedOperationException: Editing term list is not supported for external atoms!
    at at.ac.tuwien.kr.alpha.common.atoms.ExternalAtom.withTerms(ExternalAtom.java:135)
    at at.ac.tuwien.kr.alpha.grounder.transformation.IntervalTermToIntervalAtom.rewriteLiteral(IntervalTermToIntervalAtom.java:106)
    at at.ac.tuwien.kr.alpha.grounder.transformation.IntervalTermToIntervalAtom.rewriteIntervalSpecifications(IntervalTermToIntervalAtom.java:66)
    at at.ac.tuwien.kr.alpha.grounder.transformation.IntervalTermToIntervalAtom.apply(IntervalTermToIntervalAtom.java:143)
    at at.ac.tuwien.kr.alpha.grounder.transformation.NormalizeProgramTransformation.apply(NormalizeProgramTransformation.java:36)
    at at.ac.tuwien.kr.alpha.api.Alpha.normalizeProgram(Alpha.java:124)
    at at.ac.tuwien.kr.alpha.api.Alpha.solve(Alpha.java:159)
    at at.ac.tuwien.kr.alpha.api.Alpha.solve(Alpha.java:151)

Cause seems to be that IntervalTermToIntervalAtom (correctly) tries to rewrite the interval in &array_idx_value[PARTS, 0..MAX_IDX](INPUT) but fails to do so since ExternalAtoms throw an exception in withTerms. I cannot think of a good reason for that, so the fix should be to adapt ExternalAtoms withTerms to use the default implementation from BasicAtom.

madmike200590 commented 3 years ago

After some more thinking and discussion with @AntoniusW: Fix this by extending getTerms to give all terms and adapt withTerms accordingly