473,394 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Help with compiling needed

Hi everyone, I'm implementing Dijkstra's algorithm for a class
project, and I'm having trouble compiling the class that runs the
algorithm. All of the other files compile fine except for this one.
I am using the compiler like this:

javac -classpath .. <filename.java>

The source code of the classes follow. Dijkstra.java is the class
that won't compile, because the compiler doesn't recgonise the Vertex
and GraphMap classes, even though the other files compile. What could
the problem be? Thanks!
----------------------------------------------------
package graphADT;

import java.io.*;
import java.util.*;

public abstract class Vertex
{
// ID number
protected int m_iID;

// Returns number
public int getID()
{
return this.m_iID;
}

// Comparison functions
// Two vertices are equal if they are the same object or the ID is
the same
public boolean equals(Object o)
{
return this == o || equals((Vertex)o);
}

public boolean equals(Vertex v)
{
return this.m_iID == v.m_iID;
}

public int compareTo(Object o)
{
return compareTo((Vertex)o);
}

public int compareTo(Vertex v)
{
return this.m_iID = v.m_iID;
}
}
--------------------------------------------------------
package graphADT;

import java.io.*;
import java.util.*;

public abstract class Edge
{
// ArrayList of vertices on this edge
private ArrayList m_alVertex = new ArrayList();
// Distance
private int m_iDistance = 0;

// Add a new vertex to this edge
public void addEdge(Edge e,int distance)
{
if (!m_alVertex.isEmpty())
{
this.m_iDistance += distance;
}
m_alVertex.add(e);
}

// Return the total distance of this edge
public int getDistance()
{
return m_iDistance;
}

// Return the total number of vertices on this edge. Starting one is
not counted
public int getVertices()
{
return (m_alVertex.isEmpty()) ? 0 : m_alVertex.size() - 1;
}

// Gets the last stop on this edge
public Vertex getLastVertex()
{
if (m_alVertex.isEmpty())
{
return null;
}
else
{
return (Vertex)m_alVertex.get(m_alVertex.size() - 1);
}
}

// Returns whether or not the given Vertex is in this edge
public boolean hasVertex(Vertex v)
{
return m_alVertex.contains(v);
}
}
---------------------------------------------------------------
package graphADT;

import java.util.*;

public abstract class GraphMap
{
// The two dimensional array that represents the graph
private final int[][] edges;

GraphMap(int Num)
{
edges = new int[Num][Num];
}

// Link two vertices with a direct edge with given distance
public void addDirectEdge(Vertex start,Vertex end,int distance)
{
edges[start.getID()][end.getID()] = distance;
}

// return the distance between two vertices, or 0 if no path
public int getDistance(Vertex start,Vertex end)
{
return edges[start.getID()][end.getID()];
}

// Return all destinations from a given vertex
public abstract List getDestinations(Vertex v);

// Return all vertices leading to a given vertex
public abstract List getPredecessors(Vertex v);

// Return the transposed graph of this graph
// We're returning a two dimensional array because this is an
abstract class
public int[][] getInverse()
{
int[][] inverse = new int[edges.length][edges.length];

for (int i = 0;i < edges.length;i++)
{
for (int j = 0;j < edges.length;j++)
{
inverse[i][j] = edges[j][i];
}
}
return inverse;
}
}
-----------------------------------------------------------------------
package groupADT;

import java.util.*;

public abstract class Dijkstra
{
public static final int MAX_DISTANCE = Integer.MAX_VALUE;

private final Comparator shortestDistanceComparator = new
Comparator()
{
public int compare(Object left,Object right) throws
IllegalArgumentException
{
if (!(left instanceof Vertex) || !(right instanceof Vertex))
{
throw IllegalArgumentException;
}
return compare((Vertex)left,(Vertex)right);
}

private int compare(Vertex left,Vertex right)
{
// This trick doesn't work for huge distances, approaching
Integer.MAX_VALUE
int result = getShortestDistance(left) -
getShortestDistance(right);
return (result == 0) ? left.compareTo(right) : result;
}
};

// The graph
private final GraphMap graph;

// The working set of vertices
private final SortedSet unsettledNodes = new
TreeSet(shortestDistanceComparator);

// Set of vertices for which the shortest distance from the starting
point has been found
private final Set settledNodes = new HashSet();

// The currently known shortest distance to all vertices
private final Map shortestDistances = new HashMap();

// Maps a vertex to it's predecessor in a spanning tree of shortest
paths
private final Map predecessors = new HashMap();

// Constructor
public Dijkstra(GraphMap graph)
{
this.graph = graph;
}

// Get the vertex with the shortest distance, and remove it from the
priority queue
private Vertex extractMin()
{
if (unsettledNodes.isEmpty())
{
return null;
}

Vertex min = (Vertex)unsettledNodes.first();
unsettledNodes.remove(min);

return min;
}

// Compute shortest distance for neighbouring nodes and update if
better distance
private void relaxNeighbours(Vertex u)
{
for (Iterator i = graph.getDestinations(u).iterator();i.hasNext();)
{
Vertex v = (Vertex)i.next();

// skip node already settled
if (isSettled(v))
{
continue;
}
if (getShortestDistance(v) > getShortestDistance(u) +
graph.getDistance(u,v))
{
// assign new shortest distance and mark unsettled
setShortestDistance(v,getShortestDistance(u) +
graph.getDistance(u,v));
// assign predecessor in shortest path
setPredecessor(v,u);
}
}
}

// Mark a vertex as settled
private void markSettled(Vertex v)
{
settledNodes.add(v);
}

// Return whether a vertex has a shortest distance
private boolean isSettled(Vertex v)
{
return settledNodes.contains(v);
}

// Return the shortest distance from a source to the given vertex or
max int
public int getShortestDistance(Vertex v)
{
Integer d = (Integer)shortestDistances.get(v);
return (d == null) ? MAX_DISTANCE : d.intValue();
}

// Set the new shortest distance, and rebalance
private void setShortestDistances(Vertex v,int distance)
{
// ensure no duplicates
unsettledNodes.remove(v);

shortestDistances.put(v,new Integer(distance));
// Rebalance the set with the shortest distances found
unsettledNodes.add(v);
}

// Return the city leading to the city on the shortest path
public Vertex getPredecessor(Vertex v)
{
return (Vertex)predecessors.get(v);
}

private void setPredecessor(Vertex a,Vertex b)
{
predecessors.put(a,b);
}

// Initalise all data structures
private void init(Vertex start)
{
settledNodes.clear();
unsettledNodes.clear();
shortestDistances.clear();
predecessors.clear();

// add starting vertex
setShortestDistance(start,0);
unsettlednodes.add(start);
}

// Run Dijkstra's algorithm
public void execute(Vertex start,Vertex end)
{
init(start);

Vertex current;

while ((current = extractMin()) != null)
{
if (!isSettled(current))
{
break;
}

// destination reached, stop
if (current == end)
{
break;
}
markSettled(current);
relaxNeighbours(current);
}
}
}
Jul 17 '05 #1
5 2506
"Herman" ...
....
...All of the other files compile fine except for this one.
I am using the compiler like this:

javac -classpath .. <filename.java>


Try "javac -classpath .. *.java"

HTH

--
Andrew Thompson
* http://www.PhySci.org/ Open-source software suite
* http://www.PhySci.org/codes/ Web & IT Help
* http://www.1point1C.org/ Science & Technology
Jul 17 '05 #2
"Andrew Thompson" <Se********@www.invalid> wrote in message news:<XL******************@news-server.bigpond.net.au>...
"Herman" ...
...
...All of the other files compile fine except for this one.
I am using the compiler like this:

javac -classpath .. <filename.java>


Try "javac -classpath .. *.java"

HTH

Ok, I'll give that a shot. Do the files have to be compiled in a
certain order or something?
Jul 17 '05 #3
"Andrew Thompson" <Se********@www.invalid> wrote in message news:<XL******************@news-server.bigpond.net.au>...
"Herman" ...
...
...All of the other files compile fine except for this one.
I am using the compiler like this:

javac -classpath .. <filename.java>


Try "javac -classpath .. *.java"

HTH


Nope, this didn't work. Any other ideas?
Jul 17 '05 #4
"Herman" <he*******@hotmail.com> wrote in message
news:d6*************************@posting.google.co m...
"Andrew Thompson" <Se********@www.invalid> wrote in message

news:<XL******************@news-server.bigpond.net.au>...
"Herman" ...
...
...All of the other files compile fine except for this one.
I am using the compiler like this:

javac -classpath .. <filename.java>


Try "javac -classpath .. *.java"

HTH


Nope, this didn't work. Any other ideas?


Do you know what the ".." means? Did you try just one "."? What directory
are you in? Which are your files in?
Jul 17 '05 #5
he*******@hotmail.com (Herman) wrote in message news:<d6**************************@posting.google. com>...
"Andrew Thompson" <Se********@www.invalid> wrote in message news:<XL******************@news-server.bigpond.net.au>...
"Herman" ...
...
...All of the other files compile fine except for this one.
I am using the compiler like this:

javac -classpath .. <filename.java>


Try "javac -classpath .. *.java"

HTH

Ok, I'll give that a shot. Do the files have to be compiled in a
certain order or something?


No, the files do no have to be compiled in any specific order.

---
Jared Dykstra
http://www.bork.org/~jared
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Johnathan Doe | last post by:
I've been thinking about what the issues would be in compiling Python into native machine code, and since type information is important in Python, it seems possible that Python code can be...
10
by: svenn.are | last post by:
Hi, I wanted to run a program that is written in PyQt on my mac, and went over to Riverbank to get PyQ 3.13 and SIP 4.1.1 sources. I followed the installation guide except for the compiling...
0
by: Martin Bless | last post by:
I need to access a MSSQL database (MS-Sql, not MySQL!)and would very much like to use mssql-0.09.tar.gz which is available from http://www.object-craft.com.au/projects/mssql/download.html ...
6
by: Jax | last post by:
I have Visual Studio 2002 Standard Edition. It has been working fine up to a point and now i'm at that point. Due to the limitations of the edition i am not using any of my own .dll's and instead...
3
by: Dan Trowbridge | last post by:
Hi everyone, In my attempt to port code from VS 6.0 to VS.NET I had some code break along the way, mostly due to not adhereing closely to the C++ standard. This may be another instance but I...
7
by: Tina | last post by:
I have an asp project that has 144 aspx/ascx pages, most with large code-behind files. Recently my dev box has been straining and taking long times to reneder the pages in the dev environment. ...
5
by: skumar434 | last post by:
Hi everybody, I am faceing problem with strings. The code is given bellow .In this program i am tring to copy data from a file into structure . I am able to copy the data ,but the dat is...
8
by: WebSnozz | last post by:
I have an application written in C that does a lot of low level stuff. It does a lot of things like casting from void*'s. I want to create a new GUI for it in either C# or MC++, but reuse the...
2
by: Luis Speciale | last post by:
Hi I'm trying to build mod_pyton on Leopard 10.5.4 on a Mac G5 with this cvs version http://svn.apache.org/repos/asf/quetzalcoatl/mod_python/trunk with this Python python Python 2.5.2...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.