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

[BUG] Negative effects are grounded as positive #119

Open
o-fir opened this issue Jul 11, 2024 · 3 comments
Open

[BUG] Negative effects are grounded as positive #119

o-fir opened this issue Jul 11, 2024 · 3 comments

Comments

@o-fir
Copy link

o-fir commented Jul 11, 2024

Using PDDL4J from DEVEL branch. Latest build.

Given a definition of a close_door action like this:

(:action close_door
		:parameters (?cd_rv - Regular_Vehicle)
		:precondition 
			(and
				(Door_Open ?cd_rv)
			)
		:effect
			(and
				(not (Door_Open ?cd_rv))
			)
	)

a grounded action (close_door flugzeug) has (door_open flugzeug) in its positive preconditions instead of negative.

Domain (UM-Translog) and problem are attached below.
domainTranslog.txt
p02.txt

@o-fir
Copy link
Author

o-fir commented Aug 7, 2024

After enabling the logger, I can safely say that the problem is somewhere in the problem.instantiate() from DefaultProblem.java

    public final void instantiate() {
        this.initialization();
        this.preinstantiation();
        this.instantiation();
        this.postinstantiation();
        this.finalization();
    }

this.initialization() is correct, because the logger prints:

Action close_door
Instantiations:
?X0 - Regular_Vehicle : ?
Preconditions:
(Door_Open ?X0)
Effects:
(not (Door_Open ?X0))

There are no problems at the end of this.instantiation() either, since logger prints:

Action close_door
Instantiations:
?X0 - Regular_Vehicle : Flugzeug
Preconditions:
(Door_Open Flugzeug)
Effects:
(not (Door_Open Flugzeug))

Similarly, in this.postinstantiation() when logger outputs actions simplified based on ground inertia:

Action close_door
Instantiations:
?X0 - Regular_Vehicle : Flugzeug
Preconditions:
(Door_Open Flugzeug)
Effects:
(not (Door_Open Flugzeug))

However, during this.finalization(), the close_door action is wrong:

Action close_door
Instantiations:
?X0 - Regular_Vehicle : Flugzeug
Preconditions:
(and (Door_Open Flugzeug))
Effects:
(and (Door_Open Flugzeug))

I will check if there's a bug in finalizeActions() called inside finalization()


finalizeActions() from FinalizedProblem.java applies 2 functions on each instantiated action (IntAction):

  1. IntAction normalizeAction()
  2. Action finalizeAction()

After normalizing close_door, its effects are (not (15 0)).
After calling finalizeAction() on normalized close_door, the effects (now bitvector) are as follows:

** Positive fluents **
{12}
** Negative fluents **
{}

@o-fir
Copy link
Author

o-fir commented Aug 7, 2024

I believe I have found the source of a bug:
This block in function finalizeAction inside problem.FinalizedProblem.java.

// Initialize the effects of the action
        final LinkedList<Expression<Integer>> effects = new LinkedList<>();
        if (action.getEffects().getConnector().equals(Connector.ATOM)) {
            effects.add(action.getEffects());
        } else {
            effects.addAll(action.getEffects().getChildren());
        }

Recall that close_door resembles this:

(:action close_door
  :parameters (?X0 - REGULAR_VEHICLE)
  :precondition
  (door_open ?X0)
  :effect
  (and
    (not (door_open ?X0)))
)

action.getEffects() is (not (15 0)) with connector NOT. Because connector is not ATOM, we end up using this case effects.addAll(action.getEffects().getChildren()); and effects are populated with (15 0) with connector ATOM. In other words, connector NOT` is thrown away.

To test this assumption I have changed the domain definition to this, where negative effect is duplicated:

(:action close_door
		:parameters (?cd_rv - Regular_Vehicle)
		:precondition 
			(and
				(Door_Open ?cd_rv)
			)
		:effect
			(and
				(not (Door_Open ?cd_rv))
				(not (Door_Open ?cd_rv))
			)
	)

And the problem gets grounded properly

@o-fir
Copy link
Author

o-fir commented Aug 7, 2024

As a solution I propose changing the block from this

        if (action.getEffects().getConnector().equals(Connector.ATOM)) {
            effects.add(action.getEffects());
        } else {
            effects.addAll(action.getEffects().getChildren());
        }

to this

        if (action.getEffects().getConnector().equals(Connector.AND)) {
            effects.addAll(action.getEffects().getChildren());
        } else {
            effects.add(action.getEffects());
        }

I will do some tests and if everything works out I will prepare a merge.

@o-fir o-fir changed the title Negative effects are grounded as positive [BUG] Negative effects are grounded as positive Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant