Main Page   Class Hierarchy   Compound List   File List   Compound Members  

glgraph.h

00001 /*
00002 Copyright (c) 2000-2003 Lee Thomason (www.grinninglizard.com)
00003 
00004 Grinning Lizard Utilities. Note that software that uses the 
00005 utility package (including Lilith3D and Kyra) have more restrictive
00006 licences which applies to code outside of the utility package.
00007 
00008 
00009 This software is provided 'as-is', without any express or implied 
00010 warranty. In no event will the authors be held liable for any 
00011 damages arising from the use of this software.
00012 
00013 Permission is granted to anyone to use this software for any 
00014 purpose, including commercial applications, and to alter it and 
00015 redistribute it freely, subject to the following restrictions:
00016 
00017 1. The origin of this software must not be misrepresented; you must 
00018 not claim that you wrote the original software. If you use this 
00019 software in a product, an acknowledgment in the product documentation 
00020 would be appreciated but is not required.
00021 
00022 2. Altered source versions must be plainly marked as such, and 
00023 must not be misrepresented as being the original software.
00024 
00025 3. This notice may not be removed or altered from any source 
00026 distribution.
00027 */
00028 
00029 #ifndef GLGRAPH_INCLUDED
00030 #define GLGRAPH_INCLUDED
00031 
00032 #include "gllist.h"
00033 #include "gldynarray.h"
00034 #include "glinsidelist.h"
00035 #include "glcirclelist.h"
00036 
00037 
00038 /*      A class to solve a graph algorith. Vertices and edges, which have a travel cost, in
00039         a connected system.
00040 */
00041 class GlGraph
00042 {
00043   public:
00044 
00045         GlGraph( int numVertex );
00046         ~GlGraph();
00047 
00051         void AddBiEdge( int source, int dest, int length );
00052 
00056         void AddBiEdge( int source, int dest, int lengthSourceToDest, int lengthDestToSource );
00057 
00061         void AddEdge( int source, int dest, int length );
00062 
00068         void GetPath( int source, int dest, int *nextVertex, int* length, int *distance );
00069 
00070         #ifdef DEBUG
00071                 void DumpVertex();
00072         #endif
00073 
00074   private:
00075         struct DataPoint
00076         {
00077                 int             distance;       // from the DataPoint to the destination
00078                 int             vertex;         // the vertex to take
00079         };
00080 
00081         struct Edge
00082         {
00083                 int lengthTo;   // how long the edge is, from the source vertex to 'toVertex'
00084                 int lengthFrom; // how long the edge is, from the 'toVertex' back to the source
00085                 int toVertex;   // which vertex this edge goes to
00086 
00087                 bool operator==( const Edge& rhs )      { return lengthTo == rhs.lengthTo && lengthFrom == rhs.lengthFrom && toVertex == rhs.toVertex; }
00088         };
00089 
00090         struct Vertex
00091         {
00092                 Vertex() : destinationCalculated( false ) {}
00093 
00094                 bool                    destinationCalculated;
00095                 GlSList< Edge > edgeList;
00096         };
00097         
00098         void LowerAddEdge( int v0, int v1, int length0to1, int length1to0 );
00099         void ShortestPathCalc( int destVertex );
00100         DataPoint* GetDataPoint( int source, int dest ) { return ( dataPoint + dest * numVertex + source ); }
00101         int FindCheapest( GlCircleList<int>* set, int dest );
00102 
00103         enum {
00104                 GL_INFINITE = 0x1000000
00105         };
00106 
00107         int                                     numVertex;
00108         Vertex                          *vertex;
00109         DataPoint                       *dataPoint;
00110 };
00111 
00112 
00113 #endif
00114 
00115 

Generated on Mon Sep 15 12:01:10 2003 for Kyra by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001