Professional Documents
Culture Documents
java
/**
*/
package roadgraph;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Set;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import geography.GeographicPoint;
import util.GraphLoader;
/**
*/
/**
*/
public MapGraph() {
/**
*/
return pointNodeMap.values().size();
/**
return edges.size();
MapNode n = pointNodeMap.get(pt);
System.out.println(n);
System.out.println("******PRINTING EDGES******");
System.out.println(e);
/**
* @param latitude
* The latitude of the location
* @param longitude
*/
this.addVertex(pt);
/**
* @param location
*/
MapNode n = pointNodeMap.get(location);
if (n == null) {
n = new MapNode(location);
pointNodeMap.put(location, n);
} else {
/**
* @param roadName
* @param roadType
*/
public void addEdge(double lat1, double lon1, double lat2, double lon2, String roadName,
String roadType) {
MapNode n1 = pointNodeMap.get(pt1);
MapNode n2 = pointNodeMap.get(pt2);
if (n1 == null)
if (n2 == null)
MapNode n1 = pointNodeMap.get(pt1);
MapNode n2 = pointNodeMap.get(pt2);
if (n1 == null)
if (n2 == null)
MapNode n1 = pointNodeMap.get(pt1);
MapNode n2 = pointNodeMap.get(pt2);
if (n1 == null)
if (n2 == null)
return pointNodeMap.containsKey(point);
}
// agrega una arista cuando ya conozcas los nos involucrados con la arista
private void addEdge(MapNode n1, MapNode n2, String roadName, String roadType,
double length) {
edges.add(edge);
n1.addEdge(edge);
return pointNodeMap.keySet();
return node.getNeighbors();
};
/**
* Find the path from start to goal using Breadth First Search
*
* @param start
* @param goal
* @return The list of intersections that form the shortest path from start
*/
Consumer<GeographicPoint> nodeSearched) {
if (!arePreconditionsFulfilled(start, goal)) {
return null;
toExplore.add(startNode);
while (!toExplore.isEmpty()) {
next = toExplore.remove();
if (next.equals(endNode))
break;
if (!visited.contains(neighbor)) {
visited.add(neighbor);
parentMap.put(neighbor, next);
toExplore.add(neighbor);
if (pointNodeMap.get(start) == null) {
return false;
if (pointNodeMap.get(goal) == null) {
return true;
boolean pathFound) {
if (!pathFound) {
return null;
while (!current.equals(start)) {
path.addFirst(current.getLocation());
current = parentMap.get(current);
// agrega inicio.
path.addFirst(start.getLocation());
return path;
/** Find the path from start to goal using Dijkstra's algorithm
*/
/** Find the path from start to goal using Dijkstra's algorithm
* @param nodeSearched A hook for visualization. See assignment instructions for how to
use it.
* @return The list of intersections that form the shortest path from
*/
GeographicPoint
goal, Consumer<GeographicPoint> nodeSearched)
//nodeSearched.accept(next.getLocation());
return null;
}
/**
* @param start
* @param goal
* @return The list of intersections that form the shortest path from start
*/
};
/**
* @param start
* @param goal
* @param nodeSearched
* to use it.
* @return The list of intersections that form the shortest path from start
Consumer<GeographicPoint> nodeSearched) {
return null;
/*
* GraphLoader.loadRoadMap("data/testdata/simpletest.map", theMap);
* System.out.println("DONE.");
*/
GraphLoader.loadRoadMap("data/testdata/simpletest.map", theMap);
System.out.println("DONE.");
GraphLoader.loadRoadMap("data/maps/utc.map", theMap);
System.out.println("DONE.");
}
MAPEDGE.java
package roadgraph;
import geography.GeographicPoint;
/**
* @author UCSD Intermediate Programming MOOC team
*
* A directed edge in a map graph from Node start to Node end
*/
class MapEdge
{
/** The name of the road */
private String roadName;
// retorna la longitud
double getLength()
{
return length;
}
return toReturn;
}
}
/**
* Clase que representa un nodo en el Mapa
*/
package roadgraph;
import java.util.HashSet;
import java.util.Set;
import geography.GeographicPoint;
/**
* @author UCSD MOOC development team
*
* Class representing a vertex (or node) in our MapGraph
*
*/
// WEEK 3 SOLUTIONS implementando comparable
class MapNode implements Comparable
{
/** la lista de aristas fuera de este nodo */
private HashSet<MapEdge> edges;
// WEEK 3 SOLUTIONS
MapNode(GeographicPoint loc)
{
location = loc;
edges = new HashSet<MapEdge>();
distance = 0.0;
actualDistance = 0.0;
}
// WEEK 3 SOLUTIONS