All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.thesett.aima.search.Traversable Maven / Gradle / Ivy

Go to download

Search code developed from 'Artificial Intelligence a Modern Approach', Prentice Hall.

There is a newer version: 0.9.117
Show newest version
/*
 * Copyright The Sett Ltd, 2005 to 2014.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.thesett.aima.search;

import java.util.Iterator;

import com.thesett.aima.state.State;
import com.thesett.common.util.logic.UnaryPredicate;

/**
 * The Traversable interface defines methods for a state space that can be traversed by applying operators. Applying a
 * valid operation to a state results in a new state. An operation may have an associated cost.
 *
 * 

*
CRC Card
Responsibilities *
Translate operations into new states *
Report the cost of an operation *
Enumerate the valid operations on a state *
Provide links to successor states *
* * @param The type of the operator that this traversable uses to traverse states. * * @author Rupert Smith * @todo State models the state and this class models the operators on a state that lead to new states. Consider * making this not extend state but rather operate on states so that multiple traversers can be applied to the * same state space under different sets of operators. */ public interface Traversable extends State { /** * Returns the state obtained by applying the specified operation. If the operation is not valid then this may * return null. The effect of the operator on the child state does not have to be evaluated immediately. It * can be done when this method is called, or when the goal predicate is evaluated. * * @param op The operator to apply to the traversable state. * * @return The new traversable state generated by applying the specified operator. */ public Traversable getChildStateForOperator(Operator op); /** * Calculates the cost of applying the specified operations. * * @param op The operator to apply. * * @return The cost of applying the specified operation. */ public float costOf(Operator op); /** * Gets all operators valid from this state. * * @param reverse When set, indicates that the successors should be presented in reverse order. This is only * necessary if the traversal cares about the ordering of the successor states, and is used to * generate intuitive, left-to-right goal checking in depth first search based searches. * * @return An iterator over all the operators that may be applied to this state. */ public Iterator> validOperators(boolean reverse); /** * Gets an enumeration of successors of the state. * * @param reverse When set, indicates that the successors should be presented in reverse order. This is only * necessary if the traversal cares about the ordering of the successor states, and is used to * generate intuitive, left-to-right goal checking in depth first search based searches. * * @return An iterator over all the {@link Successor}s that can be reached by applying valid operators to this * state. */ public Iterator> successors(boolean reverse); /** * Implementations may override this to provide different default goal predicates over the search space. If no * default is to be provided, null may be returned. * * @return The default goal predicate, or null if no default is provided. This implementation returns * null. */ public UnaryPredicate getDefaultGoalPredicate(); }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy