Repository: plaans/aries (language: python)

Issue:
Support having variables with an empty initial domain
The planner currently does not support problems where some unused variables have an empty initial domain.

Test case provided in  #27 


Discussion / hints:

Fix patch:
diff --git a/model/src/model.rs b/model/src/model.rs
index b02dddfb..995e5c79 100644
--- a/model/src/model.rs
+++ b/model/src/model.rs
@@ -272,11 +272,20 @@ impl<Lbl: Label> Model<Lbl> {
             self.shape.set_type(dvar, Type::Sym(tpe));
             SVar::new(dvar, tpe)
         } else {
-            // no instances for this type, make a variable with empty domain
-            //self.discrete.new_var(1, 0, label)
-            panic!(
-                "Variable with empty symbolic domain (note that we do not properly handle optionality in this case)"
-            );
+            // no instances for this type, we should create a variable with an empty domain which is only allowed for optional variable
+            println!("WARNING: workaround for empty domain of optional vars (Github Issue #28)");
+            let p = if let Some(presence) = presence {
+                // this is an optional variable, force it to be absent
+                self.state
+                    .set(!presence, Cause::Decision) // TODO: fix decision cause
+                    .expect("An optional but necessarily present variable has an empty integer domain.");
+                // create a a variable with arbitrary domain (which will never be used as is forced to be absent)
+                self.state.new_optional_var(0, 0, presence)
+            } else {
+                // non-optional variable, break on assumption of non-empty domain in the model
+                panic!("Variable with empty symbolic domain.");
+            };
+            SVar::new(p, tpe)
         }
     }
 


Test patch:
diff --git a/problems/hddl/tests/empty-dom.dom.hddl b/problems/hddl/tests/empty-dom.dom.hddl
new file mode 100644
index 00000000..621a1e72
--- /dev/null
+++ b/problems/hddl/tests/empty-dom.dom.hddl
@@ -0,0 +1,42 @@
+(define (domain MinehuntingLocal)
+	(:requirements :typing :hierarchy)
+	(:types
+		area milco robot - object
+		auv-explorer - robot
+	)
+
+	(:predicates 
+	)
+
+	(:task cover-area-primitive :parameters (?a - area))
+	(:task identify-primitive :parameters (?m - milco))
+
+	(:method m-cover-area-primitive
+		:parameters (?a - area ?r - auv-explorer)
+		:task (cover-area-primitive ?a)
+		 :ordered-subtasks (and
+			(fl-cover-area-primitive ?r ?a)
+			)
+	)
+	
+	(:action fl-cover-area-primitive
+		:parameters (?r - auv-explorer ?a - area)
+		:precondition ()
+		:effect ()
+	)
+
+	; Unable
+	(:method m-identify-primitive
+		:parameters (?m - milco)
+		:task (identify-primitive ?m)
+		 :ordered-subtasks (and
+			(unable-to-do)
+			)
+	)
+
+	(:action unable-to-do
+		:parameters ()
+		:precondition ()
+		:effect ()
+	)
+)
\ No newline at end of file
diff --git a/problems/hddl/tests/empty-dom.pb.hddl b/problems/hddl/tests/empty-dom.pb.hddl
new file mode 100644
index 00000000..8e196da6
--- /dev/null
+++ b/problems/hddl/tests/empty-dom.pb.hddl
@@ -0,0 +1,20 @@
+; Test file
+(define (problem pb)
+	(:domain MinehuntingLocal)
+	(:objects
+		milco-1 - milco
+		;AUVi1 - auv-identifier
+		AUVe1 - auv-explorer
+		;zone-1 - area  ;Necessary to avoid lcp error? Variable with empty symbolic domain
+	)
+	(:htn
+		:subtasks (and
+			;(cover-area-primitive zone-1)
+			(identify-primitive milco-1)
+			)
+		;:ordering ()
+		:ordering ()
+		:constraints ( ))
+	(:init
+	)
+)