Skip to content

Commit

Permalink
feat: goal graph heuristic
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdha committed Jun 2, 2024
1 parent 9665ef5 commit 6ffbdbe
Show file tree
Hide file tree
Showing 11 changed files with 235 additions and 397 deletions.
228 changes: 3 additions & 225 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ fxhash = "0.2.1"
memory-stats = { version = "1.1.0", features = ["always_use_statm"] }
anyhow = "1.0.86"
pddlp = "0.1.6"

[dev-dependencies]
rstest = "0.19.0"
itertools = "0.13.0"

[profile.release]
debug = 1
12 changes: 11 additions & 1 deletion src/evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@ use std::time::{Duration, Instant};
pub struct Evaluator {
heuristic: Box<dyn Heuristic>,
estimates: usize,
best_estimate: usize,
time: Duration,
}

impl Evaluator {
pub fn new(task: &Task, kind: HeuristicKind) -> Self {
println!("Generating evaluator...");
let t = Instant::now();
let heuristic = heuristic::generate(task, kind);
println!("Heuristic init time: {}s", t.elapsed().as_secs_f64());
Self {
heuristic: heuristic::generate(task, kind),
heuristic,
estimates: 0,
best_estimate: usize::MAX,
time: Duration::default(),
}
}
Expand All @@ -22,6 +28,10 @@ impl Evaluator {
let estimate = self.heuristic.estimate(task, state);
self.time += t.elapsed();
self.estimates += 1;
if estimate < self.best_estimate {
println!("New best heuristic estimate: {}", estimate);
self.best_estimate = estimate;
}
estimate
}
}
Expand Down
7 changes: 2 additions & 5 deletions src/heuristic/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ impl Add {
}

impl Heuristic for Add {
fn estimate(&self, task: &Task, state: &State) -> usize {
task.goal
.iter()
.filter(|(fact, value)| state.has_fact(task, fact) != *value)
.count()
fn estimate(&self, _: &Task, _: &State) -> usize {
todo!()
}
}
Loading

0 comments on commit 6ffbdbe

Please # to comment.