Hi guys,
i am working on a Project about mobile Navigation on a lego Mindstorms Robot but i am stuck right now.
I get this error:"The method MinDistanceNode() is undefined for the type ArrayList<Node>"
I have four different Classes. The problem is probablyin "DijkstraAlgorithm" or in the Method "minDistanceNode" which is in the Class Node.
First class DijkstraAlgorithm
package navigation;
import java.util.ArrayList;
import maps.topological.Node;
import maps.topological.TopoMap;
class DijkstraAlgorithm {
public static void compute(int startNode, TopoMap graph) {
int numberOfNodes = Node.numberOfNodes;
int[] distance = new int[numberOfNodes];
int[] parent = new int[numberOfNodes];
int[][] weight = new int[numberOfNodes][numberOfNodes];
// Initialisierung von Distanzen und Vorgaengerknoten
for (int iNode = 0; iNode < numberOfNodes; ++iNode) {
distance[iNode] = -1;
parent[iNode] = -1;
}
// Distanz des Startknotens zu sich selbst
distance[startNode] = 0;
parent[startNode] = -1;
// Write all Nodes in a Nodeslist
ArrayList<Node> nodesUnvisited = graph.getNodes();
// Dijkstra-Algorithmus: do it until all Nodes are visited
// and the distances are measured
while (nodesUnvisited.size() > 0) {
// get the Node with the smallest distance to your start Node
int actual = nodesUnvisited.MinDistanceNode(); //Here is the error
// ... and delete it from the list
nodesUnvisited.remove(actual);
}
}
}
second Class Node
package maps.topological;
import java.util.ArrayList;
import java.util.Iterator;
import lejos.geom.Point;
public class Node {
public static short numberOfNodes = 0;
private short number;
public static int nodeNumber;
private Point position;
// ggf. einfache Liste
private ArrayList<Edge> edges;
Node(float x, float y) {
numberOfNodes += 1;
number = numberOfNodes;
position = new Point(x, y);
edges = new ArrayList<Edge>();
}
public short getNumber() {
return number;
}
public Point getPosition() {
return position;
}
/**
* Findet den Nachbarknoten mit der minimalen Distanz
*
* @return Knotenindex dieses Knotens, -1 wenn kein Nachbar existiert
*/
public int MinDistanceNode() {
Iterator<Edge> iter = edges.iterator();
int nodeNumber = -1;
float lastWeight;
if (iter.hasNext()) {
Edge e = iter.next();
lastWeight = e.weight;
nodeNumber = e.targetNodeNumber;
while (iter.hasNext()) {
e = iter.next();
if (e.weight < lastWeight) {
nodeNumber = e.targetNodeNumber;
lastWeight = e.weight;
}
}
}
return nodeNumber;
}
}
Third Class TopoMap
package maps.topological;
import java.util.ArrayList;
import java.util.Iterator;
import lejos.geom.Point;
/**
* Topologische Karte - implementiert durch die Adjazenzlistenrepräsentation
* eines Graphen
*
*/
public class TopoMap {
public ArrayList<Node> nodes;
// zulässiger Positionsfehler für das Aufinden von Knoten
private float error = 0.25f;
public TopoMap() {
nodes = new ArrayList<Node>();
}
/**
* @param error
*/
public TopoMap(float error) {
nodes = new ArrayList<Node>();
this.error = error;
}
/**
* Fügt einen Knoten mit den Koordinaten (x,y) ein
*
* @param x
* @param y
*/
public void addNode(float x, float y) {
if (this.getNodeByPos(x, y) == null) {
nodes.add(new Node(x, y));
}
}
/**
*
* @return sort the List
*/
public ArrayList<Node> getNodes() {
ArrayList<Node> ret = new ArrayList<Node>();
for (short i = 0; i <= nodes.size(); i++) {
ret.add(i, this.getNodeByNumber(i));
}
return ret;
}
}
fourth Class Edge
package maps.topological;
/**
* Kante einer topologischen Karte
*/
public class Edge implements Comparable<Edge> {
short targetNodeNumber;
float weight;
Edge(short j, float weight) {
targetNodeNumber = j;
this.weight = weight;
}
Edge(short toNode) {
targetNodeNumber = toNode;
this.weight = 1;
}
public void updateWeight(float newWeight) {
this.weight = newWeight;
}
@Override
public int compareTo(Edge o) {
// Kanten zu gleichem Knoten sollten nicht doppelt vorkommen
if (this.targetNodeNumber < o.targetNodeNumber)
return -1;
else
return 1;
}
}
What am i doing wrong? Please help me!