pddl4j icon indicating copy to clipboard operation
pddl4j copied to clipboard

Instantiated action has wrong effects

Open o-fir opened this issue 9 months ago • 0 comments

For the action (do_decontaminate env1 c1) of type

(:action do_decontaminate
		:parameters (?env - environment ?c - contamination)
		:precondition (and 
			(contaminated ?env ?c)	
		)
		:effect (and
			(not(contaminated ?env ?c))
		)
	)

the positive effects include (contaminated env1 c1)

Code to display effects of all actions:

 for (int i = 0; i < problem.getTasks().size(); i++) {
                Task t = problem.getTasks().get(i);
                if (t.isPrimtive()) {
                    Action ac = problem.getActions().get(i);
                    BitVector pos = ac.getUnconditionalEffect().getPositiveFluents();
                    BitVector neg = ac.getUnconditionalEffect().getNegativeFluents();
                    System.out.println("ACTION: " + PrintFunctions.taskToString(i, problem));

                    for (int g = pos.nextSetBit(0); g >= 0; g = pos.nextSetBit(g + 1)) {
                        System.out.println("+++ " + PrintFunctions.predicateToString(g, problem));
                    }
                    for (int g = neg.nextSetBit(0); g >= 0; g = neg.nextSetBit(g + 1)) {
                        System.out.println("--- " + PrintFunctions.predicateToString(g, problem));
                    }
                }
            }



    public static String predicateToString(int index, Problem problem) {
        Fluent f = problem.getFluents().get(index);
        String tmp = "";
        tmp += problem.getPredicateSymbols().get(f.getSymbol()) + "(";

        for (Integer i : f.getArguments()) {
            tmp += problem.getConstantSymbols().get(i) + ", ";
        }
        tmp += ")";
        return tmp;
    }

DOMAIN:

; problem is performing experiments
; experiments are performed in the lab by 2 scientists, after which lab equipment must be rearranged by 1 scientist
; labs are accessed via ports
; a new person can't enter a lab, if there is already someone inside.
; only one person can enter via port

(define (domain quarantine)
	(:requirements :hierarchy :negative-preconditions :equality :typing :method-preconditions)

	(:types
		contamination
		subject
		environment
		experiment
		decontamination-procedure
	)

	(:predicates
		(assigned ?e - experiment ?env - environment)
		(contaminated ?e - environment ?c - contamination)
		(carrier ?s - subject ?c - contamination)
		(decontamination-type ?d - decontamination-procedure ?c - contamination)
		(experiment-type ?e - experiment ?c - contamination)
	)

	(:task perform_experiment
		:parameters (?e - experiment)
	)

	(:task contaminate
		:parameters (?env - environment ?c - contamination)
	)

	(:task decontaminate
		:parameters (?env - environment ?c - contamination)
	)

	(:method m0_perform_experiment
		:parameters (?e - experiment ?c - contamination ?env - environment)
		:task (perform_experiment ?e)
		:precondition (and
			(experiment-type ?e ?c)
		)
		:ordered-subtasks (and
			(contaminate ?env ?c)
			(do_experiment ?e ?env ?c)
			(decontaminate ?env ?c)
		)
	)


	(:method m0_contaminate
		:parameters (?env - environment ?c - contamination)
		:task (contaminate ?env ?c)
		:precondition (and
			(not(contaminated ?env ?c))
		)
		:ordered-subtasks (and
			(do_contaminate ?env ?c)
		)
	)
	(:method m1_contaminate
		:parameters (?env - environment ?c - contamination)
		:task (contaminate ?env ?c)
		:precondition (and
			(contaminated ?env ?c)
		)
		:ordered-subtasks (and
			(nop)
		)
	)
	(:method m0_decontaminate
		:parameters (?env - environment ?c - contamination ?d - decontamination-procedure)
		:task (decontaminate ?env ?c)
		:precondition (and
			(contaminated ?env ?c)
			(decontamination-type ?d ?c)
		)
		:ordered-subtasks (and
			(do_clear_environment ?env)
			(do_initiate_decontamination ?env ?d)
			(do_decontaminate ?env ?c)
		)
	)
	(:method m1_decontaminate
		:parameters (?env - environment ?c - contamination)
		:task (decontaminate ?env ?c)
		:precondition (and
			(not(contaminated ?env ?c))
		)
		:ordered-subtasks (and
			(nop)
		)
	)

	(:action do_experiment
		:parameters (?e - experiment ?env - environment ?c - contamination)
		:precondition (and 
			(contaminated ?env ?c)
			(experiment-type ?e ?c)
		)
		:effect (and
		)
	)

	(:action do_contaminate
		:parameters (?env - environment ?c - contamination)
		:precondition (and )
		:effect (and
			(contaminated ?env ?c)
		)
	)

	(:action do_clear_environment
		:parameters (?env - environment)
		:precondition (and )
		:effect (and
		)
	)

	(:action do_initiate_decontamination
		:parameters (?env - environment ?d - decontamination-procedure)
		:precondition (and )
		:effect (and
		)
	)

	(:action do_decontaminate
		:parameters (?env - environment ?c - contamination)
		:precondition (and 
			(contaminated ?env ?c)	
		)
		:effect (and
			(not(contaminated ?env ?c))
		)
	)


	(:action nop
  	:parameters ()
  	:precondition ()
  	:effect ())
)

PROBLEM:

; num_oven: 2
; num_brick: 4
; num_temp: 2

(define
   (problem pfile0)
   (:domain quarantine)
   (:objects
      c1 - contamination
      e1 e2 e3 - experiment
      env1 - environment
      d1 - decontamination-procedure
   )

   (:htn
      :parameters ()
      :subtasks (and
         (task0 (perform_experiment e1))
         (task1 (perform_experiment e2))
         (task2 (perform_experiment e3))
      )
   )

   (:init
      (experiment-type e1 c1)
      (experiment-type e2 c1)
      (experiment-type e3 c1)
      (decontamination-type d1 c1)
   )
)

o-fir avatar Sep 07 '23 10:09 o-fir