~ubuntu-branches/ubuntu/saucy/rocs/saucy-proposed

1.1.17 by Jonathan Riddell
Import upstream version 4.9.80
1
/*
2
    This file is part of Rocs.
3
    Copyright 2011       Tomaz Canabrava <tomaz.canabrava@gmail.com>
4
    Copyright 2011       Wagner Reck <wagner.reck@gmail.com>
5
    Copyright 2011-2012  Andreas Cord-Landwehr <cola@uni-paderborn.de>
6
7
    This program is free software; you can redistribute it and/or
8
    modify it under the terms of the GNU General Public License as
9
    published by the Free Software Foundation; either version 2 of
10
    the License, or (at your option) any later version.
11
12
    This program is distributed in the hope that it will be useful,
13
    but WITHOUT ANY WARRANTY; without even the implied warranty of
14
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
    GNU General Public License for more details.
16
17
    You should have received a copy of the GNU General Public License
18
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 */
20
21
#ifndef GRAPHSTRUCTURE_H
22
#define GRAPHSTRUCTURE_H
23
24
#include "rocs_graphstructure_export.h"
25
#include "DataStructure.h"
26
27
namespace Rocs
28
{
29
class ROCS_GRAPHSTRUCTURE_EXPORT GraphStructure : public DataStructure
30
{
31
    Q_OBJECT
1.1.27 by Rohan Garg
Import upstream version 4.10.80
32
    Q_PROPERTY(QString name READ name WRITE setName)
33
1.1.17 by Jonathan Riddell
Import upstream version 4.9.80
34
public:
35
    typedef enum {
36
        Graph,
37
        Multigraph
38
    } GRAPH_TYPE;
39
40
    //to avoid hide some methods
41
    using DataStructure::remove;
1.1.27 by Rohan Garg
Import upstream version 4.10.80
42
    using DataStructure::createPointer;
43
    using DataStructure::createData;
1.1.17 by Jonathan Riddell
Import upstream version 4.9.80
44
45
    static DataStructurePtr create(Document *parent);
46
    static DataStructurePtr create(DataStructurePtr other, Document *parent);
47
48
    explicit GraphStructure(Document* parent = 0);
49
    ~GraphStructure();
50
    void importStructure(DataStructurePtr other);
51
52
    /**
53
     * Internal method to create new graph edge.
54
     * Use \see Pointer::create(...) for creating new edges.
55
     * \param from is the origin of the new edge
56
     * \param to is the target of the new edge
57
     * \param pointerType is the type of this edge, defaults to 0
58
     * \return the created edge as PointerPtr
59
     */
1.1.27 by Rohan Garg
Import upstream version 4.10.80
60
    PointerPtr createPointer(DataPtr from, DataPtr to, int pointerType);
1.1.17 by Jonathan Riddell
Import upstream version 4.9.80
61
62
    /**
63
     * Internal method to create new graph node.
64
     * Use \see Data::create(...) for creating new nodes.
65
     * \param name is the name of the node
66
     * \param dataType is the type of this node, defaults to 0
67
     * \return the created node as DataPtr
68
     */
1.1.27 by Rohan Garg
Import upstream version 4.10.80
69
    DataPtr createData(const QString& name, int dataType);
1.1.17 by Jonathan Riddell
Import upstream version 4.9.80
70
71
    /**
72
     * Returns type of the graph given by enum \see GRAPH_TYPE.
73
     * \return graph type
74
     */
75
    GRAPH_TYPE graphType() const;
76
77
    bool multigraph() const;
78
79
    /**
80
     * Gives a map with plugin specific properties of the data structure.
81
     * Implementation of virtual method \see DataStructure::pluginProperties()
82
     * \return map keys are property names, values are property values.
83
     */
84
    QMap<QString, QString> pluginProperties() const;
85
86
    /**
87
     * Set plugin specific properties of data structure.
88
     * \param identifier is the unique identifier for this property
89
     * \param value is the to be set value for the property
90
     */
91
    void setPluginProperty(const QString& identifier, const QString& property);
92
93
    /**
94
     * Computes the Dijkstra's shortest path algorithm to compute
95
     * all shortest path distances from \p from. Note: this shortest path
96
     * algorithm works only for graphs with all edges values non-negative.
97
     * For undirected graphs reverse edges are add automatically.
98
     * The algorithm has time complexity O(V log V + E).
99
     *
100
     * \param from the node from which the computation starts
101
     * \return list is map with keys = target elements, values = path to target
102
     */
103
    QMap<DataPtr,PointerList> dijkstraShortestPaths(DataPtr from);
104
1.1.27 by Rohan Garg
Import upstream version 4.10.80
105
    /**
106
     * Returns a list of all nodes of the graph.
107
     * \return array containing the nodes
108
     */
109
    Q_INVOKABLE QScriptValue nodes();
110
111
    /**
112
     * Returns a list of all nodes of given \p type in the graph.
113
     * \param type is the overlay for the to created pointer
114
     * \return array containing the nodes
115
     */
116
    Q_INVOKABLE QScriptValue nodes(int type);
117
118
    /**
119
     * Returns a list of all edges of the graph.
120
     * \return array containing the edges
121
     */
122
    Q_INVOKABLE QScriptValue edges();
123
124
    /**
125
     * Returns a list of all edges of given \p type in the graph.
126
     * \param type is the overlay for the to created pointer
127
     * \return array containing the edges
128
     */
129
    Q_INVOKABLE QScriptValue edges(int type);
130
131
    /**
132
     * Creates a new data element and return it. If the specified data type is not registered,
133
     * no data element is created.
134
     * \param type is the data type of the created node
135
     * \return script value for the new node
136
     */
137
    Q_INVOKABLE QScriptValue createNode(int type);
138
139
    /**
140
     * Creates a new data element and return it.
141
     * \return script value for the new node
142
     */
143
    Q_INVOKABLE QScriptValue createNode();
144
145
    /**
146
     * Creates a new edge edge from \param fromRaw to \param toRaw
147
     * of pointer type \param type. If the specified pointer type does not exist, no pointer
148
     * is created.
149
     * \param fromRaw is origin of pointer
150
     * \param toRaw is target of pointer
151
     * \param overlay is the overlay for the to created pointer
152
     * \return script value for the new pointer
153
     */
154
    Q_INVOKABLE QScriptValue createEdge(Data* fromRaw, Data* toRaw, int type);
155
156
    /**
157
     * Creates a new edge from \param fromRaw to \param toRaw.
158
     * \param fromRaw is origin of pointer
159
     * \param toRaw is target of pointer
160
     * \return script value for the new pointer
161
     */
162
    Q_INVOKABLE QScriptValue createEdge(Data* fromRaw, Data* toRaw);
163
164
1.1.17 by Jonathan Riddell
Import upstream version 4.9.80
165
public slots:
166
    /**
167
     * Setter for graph type. No conversations are performed.
168
     * \param type as specified  by enum GRAPH_TYPE
169
     * \return void
170
     */
171
    void setGraphType(int type);
172
173
    /**
174
     * Returns a list of all nodes of the graph.
175
     * \return array containing the nodes
1.1.27 by Rohan Garg
Import upstream version 4.10.80
176
     * \deprecated
1.1.17 by Jonathan Riddell
Import upstream version 4.9.80
177
     */
178
    QScriptValue list_nodes();
179
180
    /**
181
     * Returns a list of all nodes of given \p type in the graph.
182
     * \param type is the overlay for the to created pointer
183
     * \return array containing the nodes
1.1.27 by Rohan Garg
Import upstream version 4.10.80
184
     * \deprecated
1.1.17 by Jonathan Riddell
Import upstream version 4.9.80
185
     */
186
    QScriptValue list_nodes(int type);
187
188
    /**
189
     * Returns a list of all edges of the graph.
190
     * \return array containing the edges
1.1.27 by Rohan Garg
Import upstream version 4.10.80
191
     * \deprecated
1.1.17 by Jonathan Riddell
Import upstream version 4.9.80
192
     */
193
    QScriptValue list_edges();
194
195
    /**
196
     * Returns a list of all edges of given \p type in the graph.
197
     * \param type is the overlay for the to created pointer
198
     * \return array containing the edges
1.1.27 by Rohan Garg
Import upstream version 4.10.80
199
     * \deprecated
1.1.17 by Jonathan Riddell
Import upstream version 4.9.80
200
     */
201
    QScriptValue list_edges(int type);
202
203
    /**
204
     * Gives array of edges of specified overlay. If overlay
205
     * does not exist an empty array is returned.
206
     * \param overlay integer that identifies the overlay
207
     * \return QScriptValue array
1.1.27 by Rohan Garg
Import upstream version 4.10.80
208
     * \deprecated
1.1.17 by Jonathan Riddell
Import upstream version 4.9.80
209
     */
210
    QScriptValue overlay_edges(int overlay);
211
212
    /**
213
     * Creates a new node with specified \param name.
214
     * \param name of the new node
215
     * \return script value for the new node
1.1.27 by Rohan Garg
Import upstream version 4.10.80
216
     * \deprecated
1.1.17 by Jonathan Riddell
Import upstream version 4.9.80
217
     */
218
    QScriptValue add_node(const QString& name);
219
220
    /**
221
     * Creates a new overlay edge from \param fromRaw to \param toRaw
222
     * at overlay \param overlay. If the overlay does not exist no pointer
223
     * is created.
224
     * \param fromRaw is origin of pointer
225
     * \param toRaw is target of pointer
226
     * \param overlay is the overlay for the to created pointer
227
     * \return script value for the new pointer
1.1.27 by Rohan Garg
Import upstream version 4.10.80
228
     * \deprecated
1.1.17 by Jonathan Riddell
Import upstream version 4.9.80
229
     */
230
    QScriptValue add_overlay_edge(Data* fromRaw, Data* toRaw, int overlay);
231
232
    /**
233
     * Creates a new edge from \param fromRaw to \param toRaw.
234
     * \param fromRaw is origin of pointer
235
     * \param toRaw is target of pointer
236
     * \return script value for the new pointer
1.1.27 by Rohan Garg
Import upstream version 4.10.80
237
     * \deprecated
1.1.17 by Jonathan Riddell
Import upstream version 4.9.80
238
     */
239
    QScriptValue add_edge(Data* fromRaw, Data* toRaw);
240
241
    /**
242
     * Computes the Dijkstra's shortest path algorithm to compute
243
     * the shortes path from \param from to \param to. Note: this shortest path
244
     * algorithm works only for graphs with all edges values non-negative.
245
     * For undirected graphs reverse edges are add automatically.
246
     * The algorithm has time complexity O(V log V + E).
247
     *
248
     * \param from the node from which the computation starts
249
     * \param to the node to which the shortest path shall be computed
250
     * \return the edge set of the shortest path
251
     */
252
    QScriptValue dijkstra_shortest_path(Data* fromRaw, Data* toRaw);
253
254
    /**
255
     * Computes the Dijkstra's shortest path algorithm to compute
256
     * all shortest path distances from \p from. If edge has value 0, the edge value
1.1.27 by Rohan Garg
Import upstream version 4.10.80
257
     * is set to 1. Infinity is returned when there is no path
258
     * between \p from and another node in the graph. Note: this shortest path
259
     * algorithm works only for graphs with all edges values non-negative. For
260
     * undirected graphs reverse edges are added automatically.
1.1.17 by Jonathan Riddell
Import upstream version 4.9.80
261
     * The algorithm has time complexity O(V log V + E).
262
     *
263
     * \param from the node from which the computation starts
264
     * \return the edge set of the shortest path
265
     */
266
    QScriptValue distances(Data* fromRaw);
267
268
private:
269
    GraphStructure::GRAPH_TYPE _type;
270
};
271
}
272
#endif // GRAPHSTRUCTURE_H