<?php $isip_window_title = "ISIP Homepage"; ?>
<?php include("/data/isip/www/templates/documentation/header/header.html"); ?>


<!--#set var="isip_page_title" value="UGraph" -->
<?php include("/data/isip/www/templates/documentation/body/index_class.html"); ?>
<?php include("/data/isip/www/templates/documentation/body/bar.html"); ?>

<a name="name">
<b>name: <a href="/perl/ifc_document.pl?file=$isip/class/dstr/UGraph/UGraph.h"> UGraph &lt;TObject&gt; </a>: public <a 
href="../DoubleLinkedList">DoubleLinkedList</a>&lt; <a href="../GraphVertex/">GraphVertex&lt;TObject&gt; </a> &gt;</b>
</a></b>

<br><br>

<a name="synopsis">
<b>synopsis:</b>
<br><br>

<blockquote>
<pre>
g++ [flags ...] file ...

#include &lt;UGraph.h&gt;

UGraph(const UGraph&lt;TObject&gt;& copy_graph);
boolean insertArc(GraphArc&lt;TObject&gt;* start_vertex, GraphArc&lt;TObject&gt;* end_vertex, boolean is_epsilon = GraphArc&lt;TObject&gt;::DEF_EPSILON, float weight = GraphArc<TObject>::DEF_WEIGHT);
boolean insertArc(GraphArc&lt;TObject&gt;* start_vertex, GraphArc&lt;TObject&gt;* end_vertex, boolean is_epsilon = GraphArc&lt;TObject&gt;::DEF_EPSILON, float weight = GraphArc<TObject>::DEF_WEIGHT);
boolean removeArc(long start_index, long end_index);
boolean removeArc(GraphVertex<TObject>* start_vertex, GraphVertex<TObject>* end_vertex);
</pre>
</blockquote>

<a name="quick_start">
<b>quick start:</b>

<blockquote>
<pre>
// declare the graph object
//
UGraph&lt;Char&gt; graph;

// create some data
//
Char* char_a = new Char('a');
Char* char_b = new Char('b');

// create and add the vertices to the graph
//
GraphVertex&lt;Char&gt* vertex_a = graph.insertVertex(char_a);
GraphVertex&lt;Char&gt* vertex_b = graph.insertVertex(char_b);

// draw arcs between the vertices
//
graph.insertArc(graph.getStart(), vertex_a, false, 0.75);
graph.insertArc(vertex_a, vertex_b, false, 0.75);
graph.insertArc(vertex_b, graph.getTerm(), false, 0.75);

// write it in an Sof file
//
String tmp_filename(L"graph");
Sof tmp_file;
tmp_file.open(tmp_filename, File::WRITE_ONLY, File::TEXT);

graph.write(tmp_file, 1);
tmp_file.close();
</pre>
</blockquote>

<a name="description"> 
<b>description:</b>
<br><br>

UGraph is a generic undirected graph template class. Internally, the UGraph
is stored as a list of UGraphVertices. Each Vertex holds the information of
the connection with other vertices.

<br><br>

<a name="dependencies">
<b>dependencies:</b>
<br><br>

<ul>
  <li> <a href="../DoubleLinkedList/index.html"> DoubleLinkedList</a>
  <li> <a href="../../math/scalar/Boolean/"> Boolean</a>
</ul>

<a name="constants">
<b>public constants:</b>
<br><br>

<ul>
  <li> define the class name:
       
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/dstr/UGraph/UGraph.h&constant=CLASS_NAME">static const String CLASS_NAME = L"UGraph";</a></pre>

  <li> i/o related constants:
       
       <pre>inherited from the base DiGraph class.</pre>

  <li> default values:
       
       <pre>inherited from the base DiGraph class.</pre>
</ul>

<a name="error">
<b>error codes:</b>
<br><br>

<ul>
  <li> error code indicating UGraph class general error:
       
       <pre>inherited from the base DiGraph class.</pre>
</ul>

<a name="protected">
<b>protected data:</b>
<br><br>

<ul>
       <pre>inherited from the base DiGraph class.</pre>
</ul>

<a name="public">
<b>required public methods:</b>
<br><br>

<ul>
  <li> static methods: diagnose method is moved outside the class
       header file and defined in the UGraphDiagnose.h in order to avoid
       issues related to preprocessing of the diagnose code
       
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/dstr/UGraph/UGraph.h&method=name">static const String& name();</a></pre>
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/dstr/UGraph/UGraphDiagnose.h&method=diagnose">static boolean diagnose(Integral::DEBUG debug_level);</a></pre>

  <li> destructor/constructor(s):
       
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/dstr/UGraph/UGraph.h&method=destructor">~UGraph();</a></pre>
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/dstr/UGraph/UGraph.h&method=default+constructor">UGraph(ALLOCATION alloc = DEF_ALLOCATION);</a></pre>
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/dstr/UGraph/UGraph.h&method=copy+constructor">UGraph(const UGraph&lt;TObject&gt;& copy_graph);</a></pre>
       
  <li> assign methods:
       
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/dstr/UGraph/UGraph.h&method=assign&instance=0">boolean assign(const UGraph&lt;TObject&gt;& copy_graph);</a></pre>

  <li> operator= methods:
       
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/dstr/UGraph/UGraph.h&method=operator%3D">UGraph&lt;TObject&gt;& operator=(const UGraph&lt;TObject&gt;& arg);</a></pre>

  <li> equality methods:

       <pre><a href="/perl/ifc_document.pl?file=$isip/class/dstr/UGraph/UGraph.h&method=eq">boolean eq(const UGraph&lt;TObject&gt;& compare_vertex) const;</a></pre>
</ul>

<a name="specific">
<b>class-specific public methods:</b>
<br><br>

<ul>
  <li> methods that insert and remove graph arcs:
       
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/dstr/UGraph/UGraph.h&method=insertArc&instance=0">boolean insertArc(long start_index, long end_index, boolean is_epsilon = GraphArc&lt;TObject&gt;::DEF_EPSILON, float weight = GraphArc<TObject>::DEF_WEIGHT);</a></pre>
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/dstr/UGraph/UGraph.h&method=insertArc&instance=1">boolean insertArc(GraphArc&lt;TObject&gt;* start_vertex, GraphArc&lt;TObject&gt;* end_vertex, boolean is_epsilon = GraphArc&lt;TObject&gt;::DEF_EPSILON, float weight = GraphArc<TObject>::DEF_WEIGHT);</a></pre>
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/dstr/UGraph/UGraph.h&method=removeArc&instance=0">boolean removeArc(long start_index, long end_index);</a></pre>
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/dstr/UGraph/UGraph.h&method=removeArc&instance=1">boolean removeArc(GraphVertex<TObject>* start_vertex, GraphVertex<TObject>* end_vertex);</a></pre>
</ul>

<a name="private">
<b>private methods:</b>
<br><br>

<ul>
  <li> none.
</ul>

<a name="examples">
<b>examples:</b>
<br><br>

<ul>
  <li> This example shows how to create a graph:
       
       <pre>
// declare the graph object
//
UGraph&lt;Char&gt; graph(DstrBase::USER);

// perform the required assignments
//
Char* chr_a = new Char(L'a');
GraphVertex&lt;Char&gt;* vertex_a = graph.insertVertex(chr_a);
graph.insertArc(graph.getStart(), vertex_a, true);

Char* chr_b = new Char(L'b');
GraphVertex&lt;Char&gt;* vertex_b = graph.insertVertex(chr_b);
graph.insertArc(graph.getStart(), vertex_b, true);

Char* chr_c = new Char(L'c');
GraphVertex&lt;Char&gt;* vertex_c = graph.insertVertex(chr_c);
graph.insertArc(graph.getStart(), vertex_c, true);

Char* chr_d = new Char(L'd');
GraphVertex&lt;Char&gt;* vertex_d = graph.insertVertex(chr_d);
graph.insertArc(graph.getStart(), vertex_d, true);                     
      
// connect two vertices using the insertArc method
//
graph.insertArc(vertex_a,vertex_d, false, (float)0.7);
graph.insertArc(vertex_b, vertex_d, false, (float)0.9);
graph.insertArc(vertex_c, vertex_d, false, (float)3.7);
graph.insertArc(vertex_d, graph.getTerm(), true);

// clean up allocated memory
//
graph.clear(Integral::FREE);</pre>

  <li> The graph when drawn appears like this:
       
       <img src="graph.jpg">
</ul>

<a name = "notes">
<b>notes:</b>
<br><br>

<ul>
  <li> Unlike other classes, we have two read and write methods in dstr
       classes. The interface is still the same as that in other
       classes. The reason behind this is that we can not use
       "CLASS_NAME" as default argument in the read and write methods
       here because the data structures build the class name on the fly.
</ul>

<!--#include virtual="/hse/ies/templates/documentation/footer/footer.html" -->
