PixelLightAPI  .
Graph.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: Graph.h                                        *
00003  *
00004  *  Copyright (C) 2002-2011 The PixelLight Team (http://www.pixellight.org/)
00005  *
00006  *  This file is part of PixelLight.
00007  *
00008  *  PixelLight is free software: you can redistribute it and/or modify
00009  *  it under the terms of the GNU Lesser General Public License as published by
00010  *  the Free Software Foundation, either version 3 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  PixelLight is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  *  GNU Lesser General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Lesser General Public License
00019  *  along with PixelLight. If not, see <http://www.gnu.org/licenses/>.
00020 \*********************************************************/
00021 
00022 
00023 #ifndef __PLMATH_GRAPH_GRAPH_H__
00024 #define __PLMATH_GRAPH_GRAPH_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include <PLCore/Container/Bitset.h>
00032 #include <PLCore/Container/Resource.h>
00033 #include <PLCore/Container/BinaryHeap.h>
00034 #include <PLCore/Container/ElementManager.h>
00035 #include "PLMath/Graph/GraphNode.h"
00036 
00037 
00038 //[-------------------------------------------------------]
00039 //[ Namespace                                             ]
00040 //[-------------------------------------------------------]
00041 namespace PLMath {
00042 
00043 
00044 //[-------------------------------------------------------]
00045 //[ Forward declarations                                  ]
00046 //[-------------------------------------------------------]
00047 class GraphPath;
00048 
00049 
00050 //[-------------------------------------------------------]
00051 //[ Classes                                               ]
00052 //[-------------------------------------------------------]
00053 /**
00054 *  @brief
00055 *    Graph class (directed)
00056 */
00057 class Graph : public PLCore::Resource<Graph>, public PLCore::ElementManager<GraphNode> {
00058 
00059 
00060     //[-------------------------------------------------------]
00061     //[ Public functions                                      ]
00062     //[-------------------------------------------------------]
00063     public:
00064         /**
00065         *  @brief
00066         *    Constructor
00067         *
00068         *  @param[in] sName
00069         *    Resource name to set
00070         *  @param[in] pManager
00071         *    Resource manager using this resource, can be a null pointer
00072         */
00073         PLMATH_API Graph(const PLCore::String &sName = "", PLCore::ResourceManager<Graph> *pManager = nullptr);
00074 
00075         /**
00076         *  @brief
00077         *    Destructor
00078         */
00079         PLMATH_API virtual ~Graph();
00080 
00081         /**
00082         *  @brief
00083         *    Returns the shortest path from a node to another
00084         *
00085         *  @param[in] nStartNode
00086         *    Start node
00087         *  @param[in] nEndNode
00088         *    End node
00089         *
00090         *  @return
00091         *    The shortest path from the start node to the end node,
00092         *    a null pointer if no such path exist. (you have do delete this path by yourself!)
00093         *
00094         *  @note
00095         *    - Dijkstra's single source shortest path algorithm is used
00096         */
00097         PLMATH_API GraphPath *FindShortestPath(PLCore::uint32 nStartNode, PLCore::uint32 nEndNode);
00098 
00099 
00100     //[-------------------------------------------------------]
00101     //[ Private data                                          ]
00102     //[-------------------------------------------------------]
00103     private:
00104         // Temp data used during path finding (so we do not reallocate it each time...)
00105         PLCore::Array<float>                  m_lstNodeDistance;    /**< Shortest distance of each node to start node */
00106         PLCore::Array<GraphNode*>             m_lstPreviousNode;    /**< Previous node, if a null pointer, not processed yet */
00107         PLCore::Bitset                        m_lstTouched;         /**< Holds whether nodes are already touched or not */
00108         PLCore::Bitset                        m_lstProcessed;       /**< Holds whether nodes are already processed or not */
00109         PLCore::Array<GraphNode*>             m_lstNodes;           /**< Temp nodes array */
00110         PLCore::BinaryHeap<float, GraphNode*> m_mapToProcess;       /**< Current processed nodes */
00111 
00112 
00113     //[-------------------------------------------------------]
00114     //[ Private virtual PLCore::ElementManager functions      ]
00115     //[-------------------------------------------------------]
00116     private:
00117         virtual GraphNode *CreateElement(const PLCore::String &sName) override;
00118 
00119 
00120     //[-------------------------------------------------------]
00121     //[ Public virtual PLCore::Resource functions             ]
00122     //[-------------------------------------------------------]
00123     public:
00124         PLMATH_API virtual Graph &operator =(const Graph &cSource);
00125 
00126 
00127     //[-------------------------------------------------------]
00128     //[ Public virtual PLCore::Loadable functions             ]
00129     //[-------------------------------------------------------]
00130     public:
00131         PLMATH_API virtual bool Unload() override;
00132         PLMATH_API virtual PLCore::String GetLoadableTypeName() const override;
00133 
00134 
00135 };
00136 
00137 
00138 //[-------------------------------------------------------]
00139 //[ Namespace                                             ]
00140 //[-------------------------------------------------------]
00141 } // PLMath
00142 
00143 
00144 #endif // __PLMATH_GRAPH_GRAPH_H__


PixelLight PixelLight 0.9.10-R1
Copyright (C) 2002-2011 by The PixelLight Team
Last modified Fri Dec 23 2011 15:50:56
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported