Skip to content

Commit

Permalink
feat(planning): support soft (preferred) tasks & subtasks (1st attemp…
Browse files Browse the repository at this point in the history
…t, very basic)

For all tasks and/or subtasks marked as "soft", simply add a new empty ("noop") template method chronicle
  • Loading branch information
nrealus committed Jan 24, 2025
1 parent 80f2eff commit aec941a
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 1 deletion.
3 changes: 3 additions & 0 deletions planning/grpc/api/src/unified_planning.proto
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,9 @@ message Task {
// - robot (a parameter from an outer scope)
// - KITCHEN (a constant symbol in the problem)
repeated Expression parameters = 3;

// TODO
bool soft = 4;
}

// A method describes one possible way of achieving a task.
Expand Down
3 changes: 3 additions & 0 deletions planning/grpc/api/src/unified_planning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,9 @@ pub struct Task {
/// - KITCHEN (a constant symbol in the problem)
#[prost(message, repeated, tag = "3")]
pub parameters: ::prost::alloc::vec::Vec<Expression>,
/// TODO
#[prost(bool, tag = "4")]
pub soft: bool,
}
/// A method describes one possible way of achieving a task.
///
Expand Down
1 change: 1 addition & 0 deletions planning/grpc/server/src/chronicles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,7 @@ impl<'a> ChronicleFactory<'a> {
}
self.chronicle.subtasks.push(SubTask {
id: Some(subtask.id.clone()),
soft: subtask.soft,
start,
end,
task_name,
Expand Down
3 changes: 3 additions & 0 deletions planning/planning/src/chronicles/concrete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,8 @@ pub type Task = Vec<Atom>;
pub struct SubTask {
/// An optional identifier for the task that allows referring to it unambiguously.
pub id: Option<String>,
/// TODO
pub soft: bool,
/// Time reference at which the task must start
pub start: Time,
/// Time reference at which the task must end
Expand All @@ -434,6 +436,7 @@ impl Substitute for SubTask {
fn substitute(&self, s: &impl Substitution) -> Self {
SubTask {
id: self.id.clone(),
soft: self.soft,
start: s.fsub(self.start),
end: s.fsub(self.end),
task_name: self.task_name.substitute(s),
Expand Down
12 changes: 11 additions & 1 deletion planning/planning/src/parsing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ pub fn pddl_to_chronicles(dom: &pddl::Domain, prob: &pddl::Problem) -> Result<Pb
});
}

let mut templates = Vec::new();

if let Some(ref task_network) = &prob.task_network {
read_task_network(
init_container,
Expand All @@ -211,6 +213,14 @@ pub fn pddl_to_chronicles(dom: &pddl::Domain, prob: &pddl::Problem) -> Result<Pb
None,
&mut context,
)?;
for t in task_network.ordered_tasks.iter().chain(&task_network.ordered_tasks) {
if !t.soft {
continue;
}
let cont = Container::Template(templates.len());
let template = read_chronicle_template(cont, &pddl::Method::new_noop_for(t.clone()), &mut context)?;
templates.push(template);
}
}

let init_ch = ChronicleInstance {
Expand All @@ -219,7 +229,6 @@ pub fn pddl_to_chronicles(dom: &pddl::Domain, prob: &pddl::Problem) -> Result<Pb
chronicle: init_ch,
};

let mut templates = Vec::new();
for a in &dom.actions {
let cont = Container::Template(templates.len());
let template = read_chronicle_template(cont, a, &mut context)?;
Expand Down Expand Up @@ -766,6 +775,7 @@ fn read_task_network(
}
Ok(SubTask {
id,
soft: t.soft,
start,
end,
task_name,
Expand Down
16 changes: 16 additions & 0 deletions planning/planning/src/parsing/pddl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ pub struct Task {
/// Optional identifier of the task. This identifier is typically used to
/// refer to the task in ordering constraints.
pub id: Option<TaskId>,
pub soft: bool,
pub name: Sym,
pub arguments: Vec<Sym>,
source: Option<Loc>,
Expand All @@ -268,6 +269,19 @@ pub struct Method {
source: Option<Loc>,
}

impl Method {
pub fn new_noop_for(task: Task) -> Self {
Method {
name: Sym::new(format!("m-noop-{}", task.name)),
parameters: vec![],
task,
precondition: vec![],
subtask_network: TaskNetwork::default(),
source: None,
}
}
}

impl std::fmt::Display for Method {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.name)
Expand Down Expand Up @@ -635,6 +649,7 @@ fn parse_task(e: &SExpr, allow_id: bool) -> std::result::Result<Task, ErrLoc> {
}
Ok(Task {
id: None,
soft: false, // FIXME: hard by default, for now
name: head,
arguments: args,
source: Some(e.loc()),
Expand All @@ -654,6 +669,7 @@ fn parse_task(e: &SExpr, allow_id: bool) -> std::result::Result<Task, ErrLoc> {
// this is a parameter-less task
Ok(Task {
id: None,
soft: false, // FIXME: hard by default, for now
name: head,
arguments: vec![],
source: Some(e.loc()),
Expand Down

1 comment on commit aec941a

@nrealus

This comment was marked as outdated.

Please sign in to comment.