AuD
Lecture 'Algorithmen und Datenstrukturen' (code examples)
aud.example.graph.MaxFlowExample Class Reference

Example for computing the maximum flow using a Ford-Fulkerson type algorithm. More...

+ Inheritance diagram for aud.example.graph.MaxFlowExample:
+ Collaboration diagram for aud.example.graph.MaxFlowExample:

Public Member Functions

 MaxFlowExample ()
 create application More...
 
void computeMaxFlow (MyGraph g)
 main algorithm (calls findAugmentingPath and addPath More...
 
- Public Member Functions inherited from aud.util.SingleStepper
 SingleStepper (JFrame parent)
 create new instance More...
 
 SingleStepper (String caption)
 create new instance More...
 
JFrame parent ()
 get parent widget More...
 
void halt (String text, int timeout)
 display text and wait for user or timeout
More...
 
void setTimeout (int timeout)
 Set global timeout. More...
 
SingleStepper whereAmI ()
 print location of calling code More...
 
SingleStepper showSource ()
 jmp to caller's location in editor (emacs only) More...
 
void halt (String text)
 display text and wait for user (or global timeout) More...
 
void halt ()
 wait for user More...
 

Static Public Member Functions

static void main (String[] args)
 example (see also usage) More...
 
static void main (String[] args)
 

Protected Member Functions

void onHalt ()
 
- Protected Member Functions inherited from aud.util.SingleStepper
JComponent createComponents ()
 
void onNext ()
 call on button pressed More...
 
void println (String text)
 print to both, text area and stdout More...
 
void onHalt ()
 

Static Protected Member Functions

static void usage ()
 
static MyGraph createGraph ()
 create a small example graph More...
 

Protected Attributes

DotViewer viewer_
 
- Protected Attributes inherited from aud.util.SingleStepper
JFrame frame
 
JTextArea history
 
JButton next
 
Object monitor = new Object()
 
int timeout = 0
 

Detailed Description

Example for computing the maximum flow using a Ford-Fulkerson type algorithm.

Actually, the class implements the Edmonds-Karp algorithm, which uses a breadth-first search to find augmenting paths.

The main part of the algorithm is found in computeMaxFlow calling #findAugmentingPath and #addPath

The implementation manipulates the graph and temporarily adds backward edges to model the return flow.

Definition at line 21 of file MaxFlowExample.java.

Constructor & Destructor Documentation

◆ MaxFlowExample()

create application

Definition at line 34 of file MaxFlowExample.java.

34 {
35 super("aud.example.graph.MaxFlowExample");
36 }

Member Function Documentation

◆ computeMaxFlow()

void aud.example.graph.MaxFlowExample.computeMaxFlow ( MyGraph  g)

main algorithm (calls findAugmentingPath and addPath

Definition at line 60 of file MaxFlowExample.java.

60 {
61 initialize(g);
62
63 double cp;
64
65 while (!Double.isInfinite(cp=findAugmentingPath())) {
66 addPath(cp);
67 }
68
69 cleanup();
70 }

◆ createGraph()

static MyGraph aud.example.graph.MaxFlowExample.createGraph ( )
staticprotected

create a small example graph

Definition at line 239 of file MaxFlowExample.java.

239 {
240 MyGraph g=new MyGraph(true);
241 MyNode s=g.addNode(), t=g.addNode(), a=g.addNode(), b=g.addNode();
242 s.setLabel("s");
243 t.setLabel("t");
244 s.setPosition(0.0,0.0);
245 t.setPosition(4.0,0.0);
246 a.setPosition(2.0,2.0);
247 b.setPosition(2.0,-2.0);
248 g.addEdge(s,a).setWeight(4.0);
249 g.addEdge(s,b).setWeight(2.0);
250 g.addEdge(a,b).setWeight(3.0);
251 g.addEdge(a,t).setWeight(1.0);
252 g.addEdge(b,t).setWeight(6.0);
253 return g;
254 }

References aud.graph.GraphAM< Node extends AbstractNode, Edge extends AbstractEdge >.addEdge(), aud.graph.GraphAM< Node extends AbstractNode, Edge extends AbstractEdge >.addNode(), aud.graph.SimpleNode.setLabel(), and aud.graph.SimpleNode.setPosition().

+ Here is the call graph for this function:

◆ main()

static void aud.example.graph.MaxFlowExample.main ( String[]  args)
static

example (see also usage)

Reimplemented from aud.util.SingleStepper.

Definition at line 257 of file MaxFlowExample.java.

257 {
258 MyGraph g=new MyGraph(true);
259
260 File graph=null;
261 double widthfactor=2.0; // emphasize pen width for visualization
262
263 for (int i=0;i<args.length;++i) {
264 if (args[i].compareTo("-g")==0)
265 graph=new File(args[++i]);
266 if (args[i].compareTo("-w")==0)
267 widthfactor=Double.parseDouble(args[++i]);
268 }
269
271 app.widthfactor=widthfactor;
272
273 if (graph==null)
274 g=createGraph();
275 else {
276 new GraphParser(g.getAbstractGraph()).parse(graph);
277 }
278
279 // compute max-flow
280 app.computeMaxFlow(g);
281 app.halt("DONE");
282
283 System.exit(0);
284 }
static MyGraph createGraph()
create a small example graph
MaxFlowExample()
create application

◆ onHalt()

void aud.example.graph.MaxFlowExample.onHalt ( )
protected

Reimplemented from aud.util.SingleStepper.

Definition at line 29 of file MaxFlowExample.java.

29 {
30 viewer_.display(g_);
31 }
void display(String code)
display dot code
Definition: DotViewer.java:107

References aud.util.DotViewer.display(), and aud.example.graph.MaxFlowExample.viewer_.

+ Here is the call graph for this function:

◆ usage()

static void aud.example.graph.MaxFlowExample.usage ( )
staticprotected

Definition at line 231 of file MaxFlowExample.java.

231 {
232 System.err.println(
233 "java aud.example.graph.MaxFlowExample "+
234 "[-g graphfile] [-w factor]");
235 System.exit(-1);
236 }

Member Data Documentation

◆ viewer_

DotViewer aud.example.graph.MaxFlowExample.viewer_
protected
Initial value:
= DotViewer.displayWindow
((String) null,"aud.example.graph.MaxFlowExample")

Definition at line 26 of file MaxFlowExample.java.

Referenced by aud.example.graph.MaxFlowExample.onHalt().


The documentation for this class was generated from the following file: