-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
1,955 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
max_width = 120 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use super::SearchAlgorithm; | ||
use crate::{search::Error, trace, FxIndexMap}; | ||
use indexmap::map::Entry::Vacant; | ||
use pddllib::{state::State, successor_generation::successors}; | ||
|
||
pub struct BFS { | ||
index: usize, | ||
parents: FxIndexMap<State, usize>, | ||
} | ||
|
||
impl BFS { | ||
pub fn new(initial_state: &State) -> Self { | ||
let mut parents = FxIndexMap::default(); | ||
parents.insert(initial_state.clone(), 0); | ||
Self { index: 0, parents } | ||
} | ||
} | ||
|
||
impl<'a> SearchAlgorithm<'a> for BFS { | ||
fn step(&mut self, task: &'a pddllib::task::Task) -> super::Result<'a> { | ||
let (node, _) = self.parents.get_index(self.index).ok_or(Error::Unsolvable)?; | ||
for successor in successors(task, node) { | ||
if successor.covers(task, &task.goal) { | ||
let mut path = trace(&self.parents, self.index); | ||
path.push(successor); | ||
return Ok(path); | ||
} | ||
if let Vacant(e) = self.parents.entry(successor) { | ||
e.insert(self.index); | ||
} | ||
} | ||
self.index += 1; | ||
Err(Error::Unfinished) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use std::fmt::Display; | ||
|
||
#[derive(Debug)] | ||
pub enum Error { | ||
Unfinished, | ||
Unsolvable, | ||
OutOfTime, | ||
OutOfMemory, | ||
} | ||
|
||
impl std::error::Error for Error {} | ||
|
||
impl Display for Error { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
Error::Unfinished => write!(f, "Unfinished"), | ||
Error::Unsolvable => write!(f, "Unsolvable"), | ||
Error::OutOfTime => write!(f, "Out of time"), | ||
Error::OutOfMemory => write!(f, "Out of memory"), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters