pub fn solve<PS: Problem>(ps: &mut PS, steps: i32) -> (bool, i32)
Expand description

Solve a problem using iterative repair algorithm. Conflicts can be ranked.

Example

use std::vec;

use rusty_planner::iterative_repair;

struct Problem {}

impl iterative_repair::Problem for Problem {
    type Conflict = (i32, i32);
    type Iter = vec::IntoIter<(Self::Conflict, f64)>;
    fn find_conflicts(&self) -> Self::Iter {
        // TODO: Add code that finds conflicts...
        vec![].into_iter()
    }
    fn fix_conflict(&mut self, conflict: &Self::Conflict) {
        // TODO: Add code that solves a conflict...
    }
}

let mut ps = Problem {};
iterative_repair::solve(&mut ps, 10);
Examples found in repository?
examples/example_0.rs (line 68)
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
fn main() -> Result<(), num::ParseIntError> {
    let mut board: collections::HashMap<i32, Queen> = collections::HashMap::new();
    board.insert(0, Queen { x: 0, y: 0 });
    board.insert(1, Queen { x: 1, y: 2 });
    board.insert(2, Queen { x: 2, y: 2 });
    board.insert(3, Queen { x: 3, y: 0 });
    let mut ps = Chess { board: &mut board };

    let res = iterative_repair::solve(&mut ps, 10);
    println!("Solution found: {}.\nIterations: {}.", res.0, res.1);

    for (i, queen) in board {
        println!("Queen {} is now @ ({}, {}).", i, queen.x, queen.y)
    }
    Ok(())
}