You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by si...@apache.org on 2012/02/10 14:38:32 UTC
svn commit: r1242760 - in /commons/sandbox/graph/trunk/src/site: site.xml
xdoc/model/intro.xml
Author: simonetripodi
Date: Fri Feb 10 13:38:32 2012
New Revision: 1242760
URL: http://svn.apache.org/viewvc?rev=1242760&view=rev
Log:
a little more of sparse documentation...
Modified:
commons/sandbox/graph/trunk/src/site/site.xml
commons/sandbox/graph/trunk/src/site/xdoc/model/intro.xml
Modified: commons/sandbox/graph/trunk/src/site/site.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/site/site.xml?rev=1242760&r1=1242759&r2=1242760&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/site/site.xml (original)
+++ commons/sandbox/graph/trunk/src/site/site.xml Fri Feb 10 13:38:32 2012
@@ -33,7 +33,6 @@
<menu name="Graph Model">
<item name="Introduction" href="/model/intro.html" />
<item name="Base in-memory model" href="/model/base.html" />
- <item name="Populating Graph instances" href="/model/intro.html" />
</menu>
<menu name="Graph Algorithms">
Modified: commons/sandbox/graph/trunk/src/site/xdoc/model/intro.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/site/xdoc/model/intro.xml?rev=1242760&r1=1242759&r2=1242760&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/site/xdoc/model/intro.xml (original)
+++ commons/sandbox/graph/trunk/src/site/xdoc/model/intro.xml Fri Feb 10 13:38:32 2012
@@ -34,6 +34,83 @@
<p>A <a href="../apidocs/org/apache/commons/graph/DirectedGraph.html">DirectedGraph</a> is a Graph where an
edge <code>e = (a, b)</code> is considered to be directed from <code>a</code> to <code>b</code>;
<code>a</code> is called the head and <code>b</code> is called the tail of the arc.</p>
+
+ <subsection name="Mutable Graphs">
+ <p>A <a href="../apidocs/org/apache/commons/graph/MutableGraph">MutableGraph</a> is a graph that supports the
+ addition and removal of vertices and edges.</p>
+
+ <p>The Apache Commons Graph design aims to eliminate all the boilerplate to describe vertices/edges relations
+ without sacrificing maintainability.</p>
+
+ <p>In Apache Commons Graph users implement connections, the
+ <a href="../apidocs/org/apache/commons/graph/builder/GraphConnection.html">GraphConnection</a> passes a
+ <a href="../apidocs/org/apache/commons/graph/builder/GraphConnector.html">GraphConnector</a> to your connection,
+ and your module uses the connector to add vertices and link them through edges.</p>
+
+<source>class MyConnection
+ implements GraphConnection<BaseLabeledVertex, BaseLabeledWeightedEdge<Double>>
+{
+
+ public void connect( GraphConnector<BaseLabeledVertex, BaseLabeledWeightedEdge<Double>> graphConnector )
+ {
+ BaseLabeledVertex start = graphConnector.addVertex( new BaseLabeledVertex( "start" ) );
+ BaseLabeledVertex a = graphConnector.addVertex( new BaseLabeledVertex( "a" ) );
+ BaseLabeledVertex b = graphConnector.addVertex( new BaseLabeledVertex( "b" ) );
+ BaseLabeledVertex c = graphConnector.addVertex( new BaseLabeledVertex( "c" ) );
+ BaseLabeledVertex d = graphConnector.addVertex( new BaseLabeledVertex( "d" ) );
+ BaseLabeledVertex e = graphConnector.addVertex( new BaseLabeledVertex( "e" ) );
+ BaseLabeledVertex goal = graphConnector.addVertex( new BaseLabeledVertex( "goal" ) );
+
+ graphConnector.addEdge( new BaseLabeledWeightedEdge<Double>( "start <-> a", 1.5D ) ).from( start ).to( a );
+ graphConnector.addEdge( new BaseLabeledWeightedEdge<Double>( "start <-> d", 2D ) ).from( start ).to( d );
+
+ graphConnector.addEdge( new BaseLabeledWeightedEdge<Double>( "a <-> b", 2D ) ).from( a ).to( b );
+ graphConnector.addEdge( new BaseLabeledWeightedEdge<Double>( "b <-> c", 3D ) ).from( b ).to( c );
+ graphConnector.addEdge( new BaseLabeledWeightedEdge<Double>( "c <-> goal", 3D ) ).from( c ).to( goal );
+
+ graphConnector.addEdge( new BaseLabeledWeightedEdge<Double>( "d <-> e", 3D ) ).from( d ).to( e );
+ graphConnector.addEdge( new BaseLabeledWeightedEdge<Double>( "e <-> goal", 2D ) ).from( e ).to( goal );
+ }
+
+}</source>
+
+ <p>DRY (Don't Repeat Yourself): Repeating "graphConnector" over and over for each binding can get a little tedious.
+ The Apache COmmons Graph package provides a support class named
+ <a href="../apidocs/org/apache/commons/graph/builder/AbstractGraphConnection.html">AbstractGraphConnection</a>
+ which implicitly gives you access to <code>GraphConnector</code>'s methods. For example, we could extend
+ <code>AbstractGraphConnection</code> and rewrite the above connections as:</p>
+
+<source>class MyConnection
+ extends AbstractGraphConnection<BaseLabeledVertex, BaseLabeledWeightedEdge<Double>>
+{
+
+ public void connect()
+ {
+ BaseLabeledVertex start = addVertex( new BaseLabeledVertex( "start" ) );
+ BaseLabeledVertex a = addVertex( new BaseLabeledVertex( "a" ) );
+ BaseLabeledVertex b = addVertex( new BaseLabeledVertex( "b" ) );
+ BaseLabeledVertex c = addVertex( new BaseLabeledVertex( "c" ) );
+ BaseLabeledVertex d = addVertex( new BaseLabeledVertex( "d" ) );
+ BaseLabeledVertex e = addVertex( new BaseLabeledVertex( "e" ) );
+ BaseLabeledVertex goal = addVertex( new BaseLabeledVertex( "goal" ) );
+
+ addEdge( new BaseLabeledWeightedEdge<Double>( "start <-> a", 1.5D ) ).from( start ).to( a );
+ addEdge( new BaseLabeledWeightedEdge<Double>( "start <-> d", 2D ) ).from( start ).to( d );
+
+ addEdge( new BaseLabeledWeightedEdge<Double>( "a <-> b", 2D ) ).from( a ).to( b );
+ addEdge( new BaseLabeledWeightedEdge<Double>( "b <-> c", 3D ) ).from( b ).to( c );
+ addEdge( new BaseLabeledWeightedEdge<Double>( "c <-> goal", 3D ) ).from( c ).to( goal );
+
+ addEdge( new BaseLabeledWeightedEdge<Double>( "d <-> e", 3D ) ).from( d ).to( e );
+ addEdge( new BaseLabeledWeightedEdge<Double>( "e <-> goal", 2D ) ).from( e ).to( goal );
+ }
+
+}</source>
+
+ <p>We'll use this syntax throughout the rest of the guide.</p>
+
+ <p></p>
+ </subsection>
</section>
</body>
</document>