emacs.d/clones/lisp/www.cs.cmu.edu/Groups/AI/html/cltl/clm/node275.html

80 lines
6.3 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN">
<!Converted with LaTeX2HTML 0.6.5 (Tue Nov 15 1994) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds >
<HEAD>
<TITLE>28.1.5.1. Topological Sorting</TITLE>
</HEAD>
<BODY>
<meta name="description" value=" Topological Sorting">
<meta name="keywords" value="clm">
<meta name="resource-type" value="document">
<meta name="distribution" value="global">
<P>
<b>Common Lisp the Language, 2nd Edition</b>
<BR> <HR><A NAME=tex2html5096 HREF="node276.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html5094 HREF="node274.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html5088 HREF="node274.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html5098 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html5099 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
<B> Next:</B> <A NAME=tex2html5097 HREF="node276.html"> Examples</A>
<B>Up:</B> <A NAME=tex2html5095 HREF="node274.html"> Determining the Class </A>
<B> Previous:</B> <A NAME=tex2html5089 HREF="node274.html"> Determining the Class </A>
<HR> <P>
<H3><A NAME=SECTION003215100000000000000>28.1.5.1. Topological Sorting</A></H3>
<P>
<img align=bottom alt="change_begin" src="gif/change_begin.gif"><br>
Topological sorting proceeds by finding a class <i>C</i> in <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43435.gif"> such
that no other class precedes that element according to the elements
in <i>R</i>. The class <i>C</i> is placed first in the result.
Remove <i>C</i> from <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43435.gif">, and remove all pairs of the form
<b>(C, D)</b>,
<IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43419.gif">, from <i>R</i>. Repeat the process, adding
classes with no predecessors to the end of the result. Stop when no
element can be found that has no predecessor.
<P>
If <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43435.gif"> is not empty and the process has stopped, the set <i>R</i> is
inconsistent. If every class in the finite set of classes is preceded
by another, then <i>R</i> contains a loop. That is, there is a chain of
classes <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43423.gif">
such that <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43425.gif"> precedes
<IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43347.gif">, 1 &lt;= <i>i</i> &lt; <i>n</i>,
and <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43341.gif"> precedes <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43387.gif">.
<P>
Sometimes there are several classes from <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43435.gif"> with no
predecessors. In this case select the one that has a direct
subclass rightmost in the class precedence list computed so far.
<P>
If there is no
such candidate class, <i>R</i> does not generate a partial ordering - the
<IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43499.gif">, <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43407.gif">, are inconsistent.
<P>
In more precise terms, let <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43441.gif">,
<i>m</i> &gt;= 2, be
the classes from <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43435.gif"> with no predecessors. Let <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43447.gif">, <i>n</i> &gt;= 1, be the class precedence list
constructed so far. <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43387.gif"> is the most specific class, and <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43453.gif"> is the least specific. Let 1 &lt;= <i>j</i> &lt;= <i>n</i> be the largest number
such that there exists an <i>i</i> where 1 &lt;= <i>i</i> &lt;= <i>m</i> and
<IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43463.gif">
is a direct superclass of <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43461.gif">;
<IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43463.gif"> is placed next.
<P>
The effect of this rule for selecting from a set of classes with no
predecessors is that classes in a simple superclass chain are
adjacent in the class precedence list and that classes in each
relatively separated subgraph are adjacent in the class
precedence list. For example, let <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43475.gif"> and <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43487.gif"> be subgraphs
whose only element in common is the class <i>J</i>. Suppose
that no superclass of <i>J</i> appears in either <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43475.gif"> or <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43487.gif">.
Let <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43387.gif"> be the bottom of <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43475.gif">; and let <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43591.gif"> be the
bottom of <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43487.gif">. Suppose <i>C</i> is a class whose direct superclasses
are <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43387.gif"> and <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43591.gif"> in that order; then the class precedence
list for <i>C</i> will start with <i>C</i> and will be followed by all classes
in <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43475.gif"> except <i>J</i>. All the classes of <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43487.gif"> will be next.
The class <i>J</i> and its superclasses will appear last.
<br><img align=bottom alt="change_end" src="gif/change_end.gif">
<P>
<BR> <HR><A NAME=tex2html5096 HREF="node276.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html5094 HREF="node274.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html5088 HREF="node274.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html5098 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html5099 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
<B> Next:</B> <A NAME=tex2html5097 HREF="node276.html"> Examples</A>
<B>Up:</B> <A NAME=tex2html5095 HREF="node274.html"> Determining the Class </A>
<B> Previous:</B> <A NAME=tex2html5089 HREF="node274.html"> Determining the Class </A>
<HR> <P>
<HR>
<P><ADDRESS>
AI.Repository@cs.cmu.edu
</ADDRESS>
</BODY>