next up previous contents
Next: Algorithms Class Up: NetWorKs & Graph Algorithms Previous: Data Structures

Graph Algorithms Interface

In addition to providing a graph algorithm access to vertices and edges, NetWorKs must ``instruct'' the graph algorithm when to step forward or to restart the algorithm. The NetWorKs program must also be able to ``query'' the algorithm for information such as a title, the required graph type, and which Vertex and Edge attributes should be displayed. To define a graph algorithm interface for the NetWorKs program, all graph algorithms must be extensions of the GraphAlgorithm abstract class. The term abstract class means that the class declares abstract methods which extensions must implement. Note that the GraphAlgorithm init(), step(), GraphType() and title() methods are abstract. The NetWorKs program uses the step() and restart() methods to ``run'' algorithms. Each of these has a GraphPanel argument and returns a String. GraphAlgorithms use the GraphPanel argument to access the appropriate Graph, and the returned String is displayed on the NetWorKs algorithm control panel.

package GraphStuff;

public abstract class GraphAlgorithm extends Object {

        public abstract String init (GraphPanel gP);

        public abstract String step(GraphPanel gP);

        public abstract int GraphType();
         // General.Simple 
         // or General.SimpleUndirected

        public abstract String title();

        public boolean showWeights() {return false; }

        public boolean showFlows() {return false; }

        public boolean showCapacities() {return false; }

        public boolean showMinimums() {return false; }

        public boolean showLabels() {return false; }

        public boolean showDemands() {return false; }

}

The GraphType() method returns an int indicating the type of Graph the algorithm requires, and the title() method returns a String to be displayed on the NetWorKs algorithm selection list. The remaining methods indicate the attributes of Edge and Vertex objects that should be displayed. For example, the following methods in an extension would indicate that Edge weights and Vertex labels should be displayed:

        public boolean showWeights() {return true; }
        public boolean showLabels() {return true; }



Kelly Waters
Mon Oct 27 18:18:15 EST 1997