next up previous contents
Next: Basic Objects Up: User's Manual Previous: User's Manual

Introduction

Let's begin with an example. Assuming that LINK has been properly installed on your system, you can start it by typing Link at the command line prompt of your operating system (or by double-clicking the appropriate icon). You may now enter commands and start building graphs. This tutorial will give you several examples so that you can get started right away. When you need to learn the system more thoroughly, the later chapters will provide much more detail.

Our first example is shown in Figure [*].

  
Figure 7.1: Our first graph: the empty graph
\begin{figure}
\begin{flushleft}
\hrulefill

\begin{alltt}
\relax
STk\gt {\bf (d...
 ...)\(\}\)
\(\char93 \)f} }
\relax\end{alltt}
\hrulefill\end{flushleft}\end{figure}

This example may not be very exciting, but don't worry; things will get more interesting shortly! Even though our graph is not very interesting, there are many things to note about this example. First of all, note that the commands we input are enclosed in parentheses. This is a characteristic of


  
Figure 7.2: Creating an undirected hypergraph
\begin{figure}
\begin{flushleft}
\hrulefill

\begin{alltt}
\relax
STk\gt {\bf (d...
 ...)\(\}\)
\(\char93 \)f} }
\relax\end{alltt}
\hrulefill\end{flushleft}\end{figure}


  
Figure 7.3: Computing the sum of two graphs
\begin{figure}
\begin{flushleft}
\hrulefill

\begin{alltt}
\relax
STk\gt {\bf (d...
 ...)\(\}\)
\(\char93 \)f} }
\relax\end{alltt}
\hrulefill\end{flushleft}\end{figure}

Scheme, the computer language used by Link. Scheme is a functional language. Programs in this type of programming language are generally constructed by composing functions together rather than by stringing sequences of statments together. To compose two functions means to use the output of one function as input to the other. For example, in Figure [*], the function which creates the graph is graph, and its output is then passed to the function define as an argument. The result of the command is that the symbol g new refers to the newly created graph. There are many other ways to create graphs, but we will describe those later. This example shows the simplest way.


  
Figure 7.4: Adding Vertices One by One
\begin{figure}
\begin{flushleft}
\hrulefill

\begin{alltt}
\relax
STk\gt {\bf (a...
 ...)\(\}\)
\(\char93 \)f} }
\relax\end{alltt}
\hrulefill\end{flushleft}\end{figure}

A graph without any vertices isn't much fun, so let's add some vertices. Link allows you to name your vertices with integers, symbols, or character strings. The example in Figure [*] shows the addition of three vertices, one with each type of name. Of course, it might be quite inconvenient to have to add each vertex individually if we want to build a big graph. One solution to this problem is to use the add-vertices! command shown in Figure [*].

  
Figure 7.5: Adding Ranges of Vertices
\begin{figure}
\begin{flushleft}
\hrulefill

\begin{alltt}
\relax
STk\gt {\bf (d...
 ...)\(\}\)
\(\char93 \)f} }
\relax\end{alltt}
\hrulefill\end{flushleft}\end{figure}

This command allows you to specify a range of integers, then creates a vertex for each integer in the range.

Another solution to this problem, and one which will be the solution to many problems, is to use the Scheme command language. We can write a short program to add our vertices for us.

  
Figure 7.6: A Short Program to Add Vertices
\begin{figure}
\begin{flushleft}
\hrulefill

\begin{alltt}
\relax
STk\gt {\bf (d...
 ...)\(\}\)
\(\char93 \)f} }
\relax\end{alltt}
\hrulefill\end{flushleft}\end{figure}

This program uses a Scheme do loop, which will not be described in detail here. There is a tutorial on programming in Scheme in Section [*]. Also, the STk Reference Manual contains more complete information.

Now that we have given our graph some vertices, it is time to add edges. An edge is a collection of vertices. The only type of edge we will discuss here has exactly two vertices, and there is no ordering of the vertices. Such an edge is usually drawn as a line connecting the two vertices. Our next task will be to construct some edges from the vertex set.

First, we must obtain the vertex set from the graph so that we can pick out the vertices we want for our edges. The vertex set of a graph is returned by the vertices function. This is shown in Figure [*]. The figure also shows the construction of $V \choose 2$, which is a set containing every subset of the vertex set V which has size 2. This set represents all possible lines connecting vertices in our graph.


next up previous contents
Next: Basic Objects Up: User's Manual Previous: User's Manual
RHS Linux User
1/26/1998