Main Page | Modules | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

Graph.h

Go to the documentation of this file.
00001 #ifndef __GRAPH_H
00002 #define __GRAPH_H
00003 
00004 #include <string>
00005 #include <vector>
00006 #include <set>
00007 #include <map>
00008 #include <ishtar/settings.h>
00009 
00014 namespace Teem
00015 {
00022     class TagSet : public std::set<std::string>
00023     {
00024     public:
00026         virtual ~TagSet() {}
00028         TagSet() {}
00030         TagSet(const std::string &tag) { insert(tag); }
00032         TagSet& operator+(const std::string &tag) { insert(tag); return *this; }
00034         TagSet& operator+(const char *tag) { insert(tag); return *this; }
00035     };
00036     
00043     class IshtarSettingsMap : public std::map<std::string, double>
00044     {
00045     public:
00047         IshtarSettingsMap(const std::string &root);
00049         virtual ~IshtarSettingsMap() { }
00050     
00051     protected:
00052         /*//! Comparaison functor
00053         class Comparator
00054         {
00055         protected:
00056             const std::string &key;
00057             
00058         public:
00059             Comparator(const std::string &theKey) : key(theKey) { }
00060             int operator()(const std::pair<std::string, Ishtar::ParsedValues> &first, const std::pair<std::string, Ishtar::ParsedValues> &second)
00061             {
00062                 if (first.first.compare("") == 0)
00063                     return second.first.find(key) == 0;
00064                 else
00065                     return first.first.find(key) == 0;
00066             }
00067         };*/
00068     };
00069     
00080     class Graph
00081     {
00082         friend class GraphNeuralNetwork;
00083         
00084     public:
00086         typedef size_t Node;
00088         typedef size_t Link;
00089         
00093         class Filter
00094         {
00095         public:
00097             virtual ~Filter() { }
00098             
00100             virtual void filter(Graph *graph) = 0;
00101         };
00102         
00103     public:
00105         Graph() { }
00107         virtual ~Graph() { }
00108         
00110         void addDefaultNodeParam(const std::string &id, double value) { defaultNodeParams[id] = value; }
00111         
00113         void addDefaultNodeParam(const std::map<std::string, double> &params) { defaultNodeParams.insert(params.begin(), params.end()); }
00114 
00116         void addDefaultLinkParam(const std::string &id, double value) { defaultLinkParams[id] = value; }
00117         
00119         void addDefaultLinkParam(const std::map<std::string, double> &params) { defaultLinkParams.insert(params.begin(), params.end()); }
00120         
00126         Node createNode(const std::string &type, const std::set<std::string> &tags = TagSet());
00127         
00135         Link createLink(Node from, Node to, const std::string &type, const std::set<std::string> &tags = TagSet());
00136         
00138         void addNodeParam(Node node, const std::string &id, double value) {nodes[node].params[id] = value;}
00139         
00141         void addNodeParam(Node node, const std::map<std::string, double> &params) {nodes[node].params.insert(params.begin(), params.end());}
00142         
00144         void addLinkParam(Link link, const std::string &id, double value) {links[link].params[id] = value;}
00145         
00147         void addLinkParam(Link link, const std::map<std::string, double> &params) {links[link].params.insert(params.begin(), params.end());}
00148         
00150         Node getNode(const std::string &tag, size_t index) { return nodeLists[tag][index]; }
00151         
00153         size_t getNodeCount(const std::string &tag) { return nodeLists[tag].size(); }
00154         
00156         Link getLink(const std::string &tag, size_t index) { return linkLists[tag][index]; }
00157         
00159         size_t getLinkCount(const std::string &tag) { return linkLists[tag].size(); }
00160         
00162         void exportToDot(const std::string &filename) const;
00163         
00166         void exportToMatlab(const std::string &filename) const;
00167         
00168     protected:
00169         
00171         struct NodeData
00172         {
00173             std::string type; 
00174             std::set<std::string> tags; 
00175             std::map<std::string, double> params; 
00176         };
00177         
00179         struct LinkData
00180         {
00181             std::string type; 
00182             std::set<std::string> tags; 
00183             Node from; 
00184             Node to; 
00185             std::map<std::string, double> params; 
00186         };
00187         
00188         std::vector<NodeData> nodes; 
00189         std::vector<LinkData> links; 
00190         
00191         std::map<std::string, double> defaultNodeParams; 
00192         std::map<std::string, double> defaultLinkParams; 
00193         
00194         std::map<std::string, std::vector<Node> > nodeLists; 
00195         std::map<std::string, std::vector<Link> > linkLists; 
00196 
00197     };
00198 }
00199 
00200 #endif

Generated on Mon Oct 24 17:38:25 2005 for Teem by  doxygen 1.4.2