jubatus_core  0.1.2
Jubatus: Online machine learning framework for distributed environment
graph.cpp
Go to the documentation of this file.
1 // Jubatus: Online machine learning framework for distributed environment
2 // Copyright (C) 2011,2012 Preferred Networks and Nippon Telegraph and Telephone Corporation.
3 //
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License version 2.1 as published by the Free Software Foundation.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 
17 #include "graph.hpp"
18 
19 #include <string>
20 #include <utility>
21 #include <vector>
22 
23 #include "jubatus/util/lang/shared_ptr.h"
24 
25 #include "../graph/graph_factory.hpp"
26 #include "../common/vector_util.hpp"
27 #include "../storage/storage_factory.hpp"
28 
29 using std::string;
30 using std::vector;
31 using std::pair;
36 using jubatus::util::lang::shared_ptr;
37 
38 namespace jubatus {
39 namespace core {
40 namespace driver {
41 
42 graph::graph(shared_ptr<jubatus::core::graph::graph_wo_index> graph_method)
43  : graph_(graph_method),
44  mixable_(graph_method) {
46 }
47 
49 }
50 
51 void graph::create_node(node_id_t id) { /* no lock here */
52  this->create_node_here(id);
53 }
54 
56  graph_->update_node(id, p);
57 }
58 
60  graph_->remove_node(id);
61  graph_->remove_global_node(id);
62 }
63 
65  edge_id_t eid,
66  node_id_t src,
67  node_id_t target,
68  const property & p) {
69  // TODO(kuenishi): assert id==ei.src
70  this->create_edge_here(eid, src, target, p);
71 }
72 
73 void graph::update_edge(edge_id_t eid, const property& p) {
74  graph_->update_edge(eid, p);
75 }
76 
78  graph_->remove_edge(eid);
79 }
80 
82  node_id_t nid,
84  const preset_query& q) const {
85  return graph_->centrality(nid, ct, q);
86 }
87 
88 std::vector<node_id_t> graph::get_shortest_path(
89  node_id_t src,
90  node_id_t target,
91  uint64_t max_hop,
92  const preset_query &q) const {
93  std::vector<jubatus::core::graph::node_id_t> ret;
94  graph_->shortest_path(src, target, max_hop, ret, q);
95  return ret;
96 }
97 
99  graph_->add_centrality_query(q);
100 }
101 
103  graph_->add_shortest_path_query(q);
104 }
105 
107  graph_->remove_centrality_query(q);
108 }
109 
111  graph_->remove_shortest_path_query(q);
112 }
113 
116  graph_->get_node(nid, info);
117  return info;
118 }
119 
122  graph_->get_edge(eid, info);
123  return info;
124 }
125 
127  graph_->update_index();
128 }
129 
130 void graph::clear() {
131  graph_->clear();
132 }
133 
135  try {
136  graph_->create_node(nid);
137  graph_->create_global_node(nid);
138  } catch (const jubatus::core::graph::local_node_exists& e) { // pass through
139  } catch (const jubatus::core::graph::global_node_exists& e) { // pass through
140  } catch (const std::runtime_error& e) {
141  throw;
142  }
143 }
144 
146  try {
147  graph_->remove_global_node(nid);
148  } catch (const jubatus::core::graph::local_node_exists& e) {
149  } catch (const jubatus::core::graph::global_node_exists& e) {
150  } catch (const std::runtime_error& e) {
151  throw;
152  }
153 } // update internal
154 
156  edge_id_t eid,
157  node_id_t src,
158  node_id_t target,
159  const property& p) {
160  try {
161  graph_->create_edge(eid, src, target);
162  graph_->update_edge(eid, p);
163  } catch (const jubatus::core::graph::graph_exception& e) {
164  throw;
165  }
166 }
167 
169  graph_->pack(pk);
170 }
171 
172 void graph::unpack(msgpack::object o) {
173  graph_->unpack(o);
174 }
175 
176 } // namespace driver
177 } // namespace core
178 } // namespace jubatus
graph(jubatus::util::lang::shared_ptr< core::graph::graph_wo_index > graph_method)
Definition: graph.cpp:42
void remove_global_node(jubatus::core::graph::node_id_t nid)
Definition: graph.cpp:145
jubatus::util::lang::shared_ptr< core::graph::graph_wo_index > graph_
Definition: graph.hpp:90
void update_edge(jubatus::core::graph::edge_id_t eid, const jubatus::core::graph::property &p)
Definition: graph.cpp:73
jubatus::core::graph::edge_info get_edge(jubatus::core::graph::edge_id_t eid) const
Definition: graph.cpp:120
void create_edge(jubatus::core::graph::edge_id_t eid, jubatus::core::graph::node_id_t src, jubatus::core::graph::node_id_t target, const jubatus::core::graph::property &p)
Definition: graph.cpp:64
void remove_node(jubatus::core::graph::node_id_t id)
Definition: graph.cpp:59
void remove_edge(jubatus::core::graph::edge_id_t eid)
Definition: graph.cpp:77
void update_node(jubatus::core::graph::node_id_t id, const jubatus::core::graph::property &p)
Definition: graph.cpp:55
void create_node(jubatus::core::graph::node_id_t id)
Definition: graph.cpp:51
std::map< std::string, std::string > property
Definition: graph_type.hpp:39
void create_node_here(jubatus::core::graph::node_id_t id)
Definition: graph.cpp:134
jubatus::core::graph::node_info get_node(jubatus::core::graph::node_id_t nid) const
Definition: graph.cpp:114
void pack(framework::packer &pk) const
Definition: graph.cpp:168
std::vector< jubatus::core::graph::node_id_t > get_shortest_path(jubatus::core::graph::node_id_t src, jubatus::core::graph::node_id_t target, uint64_t max_hop, const jubatus::core::graph::preset_query &q) const
Definition: graph.cpp:88
jubatus::core::graph::mixable_graph_wo_index mixable_
Definition: graph.hpp:91
void unpack(msgpack::object o)
Definition: graph.cpp:172
void add_shortest_path_query(const jubatus::core::graph::preset_query &q)
Definition: graph.cpp:102
void create_edge_here(jubatus::core::graph::edge_id_t eid, jubatus::core::graph::node_id_t src, jubatus::core::graph::node_id_t target, const jubatus::core::graph::property &p)
Definition: graph.cpp:155
void add_centrality_query(const jubatus::core::graph::preset_query &q)
Definition: graph.cpp:98
double get_centrality(jubatus::core::graph::node_id_t nid, jubatus::core::graph::centrality_type ct, const jubatus::core::graph::preset_query &q) const
Definition: graph.cpp:81
void remove_centrality_query(const jubatus::core::graph::preset_query &q)
Definition: graph.cpp:106
void register_mixable(framework::mixable *mixable)
Definition: driver.cpp:242
void remove_shortest_path_query(const jubatus::core::graph::preset_query &q)
Definition: graph.cpp:110