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

aima.core.environment.map.StraightLineDistanceHeuristicFunction Maven / Gradle / Ivy

Go to download

AIMA-Java Core Algorithms from the book Artificial Intelligence a Modern Approach 3rd Ed.

There is a newer version: 3.0.0
Show newest version
package aima.core.environment.map;

import aima.core.util.datastructure.Point2D;

/**
 * @author Ruediger Lunde
 */
public class StraightLineDistanceHeuristicFunction extends
		AdaptableHeuristicFunction {

	public StraightLineDistanceHeuristicFunction(Object goal, Map map) {
		this.goal = goal;
		this.map = map;
	}

	public double h(Object state) {
		double result = 0.0;
		Point2D pt1 = map.getPosition((String) state);
		Point2D pt2 = map.getPosition((String) goal);
		if (pt1 != null && pt2 != null) {
			result = pt1.distance(pt2);
		}
		return result;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy