ai-22 / src / am / aua / search / BreadthFirstFrontier.java
BreadthFirstFrontier.java
Raw
package am.aua.search;

import java.util.LinkedList;
import java.util.Queue;

public class BreadthFirstFrontier implements Frontier {
    private Queue<Node> frontier;

    // statistics
    private int stretchFactor;

    public BreadthFirstFrontier () {
        frontier = new LinkedList<>();
        stretchFactor = 0;
    }

    @Override
    public void add(Node node) {
        frontier.add(node);
        stretchFactor = Math.max(stretchFactor, frontier.size());
    }

    @Override
    public Node remove() {
        return frontier.remove();
    }

    @Override
    public void clear() {
        frontier.clear();
    }

    @Override
    public boolean isEmpty() {
        return frontier.isEmpty();
    }

    @Override
    public int stretchFactor() {
        return stretchFactor;
    }

    @Override
    public String toString() {
        return "Breadth First";
    }
}