23 #ifndef VIRTUAL_STIGMERGY_H_ 24 #define VIRTUAL_STIGMERGY_H_ 37 #include "gsdf_msgs/CommPacket.h" 38 #include "gsdf_msgs/VirtualStigmergyQuery.h" 39 #include "gsdf_msgs/VirtualStigmergyPut.h" 40 #include "gsdf_msgs/VirtualStigmergyPuts.h" 84 void put(
const std::string& key,
const Type& data)
90 bool success =
rth_->getVirtualStigmergyTuple(
vstig_id_, key, vst);
100 bool success =
rth_->getVirtualStigmergyTuple(
vstig_id_, key, local);
102 gsdf_msgs::VirtualStigmergyPut vsp;
110 gsdf_msgs::CommPacket p;
111 p.header.source =
rth_->getRobotID();
113 p.header.data_len = vsp_vec.size();
114 p.header.version = 1;
115 p.header.checksum = 0;
116 p.content.buf = vsp_vec;
118 mqm_->getOutMsgQueue(
"vstig")->push(msg_data);
122 Type
get(
const std::string& key)
125 bool success =
rth_->getVirtualStigmergyTuple(
vstig_id_, key, vst);
128 std::cout<<
"ID "<<
vstig_id_<<
" virtual stigmergy, "<<key<<
" is not exist."<<std::endl;
133 Type data = deserialize_ros<Type>(data_vec);
137 bool get_new_local =
rth_->getVirtualStigmergyTuple(
vstig_id_, key, new_local);
141 double rt = (double)rand()/RAND_MAX;
143 if(rt <= temperature) {
144 gsdf_msgs::VirtualStigmergyQuery vsq;
152 gsdf_msgs::CommPacket p;
155 p.header.data_len = vsq_vec.size();
156 p.header.version = 1;
157 p.header.checksum = 0;
158 p.content.buf = vsq_vec;
160 mqm_->getOutMsgQueue(
"vstig")->push(msg_data);
167 void puts(
const std::string& key,
const Type& data)
173 bool success =
rth_->getVirtualStigmergyTuple(
vstig_id_, key, vst);
183 bool success =
rth_->getVirtualStigmergyTuple(
vstig_id_, key, local);
185 gsdf_msgs::VirtualStigmergyPuts vsps;
191 int neighbor_size =
rth_->getNeighborSize();
192 if(neighbor_size < 3) {
196 vsps.prob = 2.0/neighbor_size;
201 gsdf_msgs::CommPacket p;
202 p.header.source =
rth_->getRobotID();
204 p.header.data_len = vsps_vec.size();
205 p.header.version = 1;
206 p.header.checksum = 0;
207 p.content.buf = vsps_vec;
209 mqm_->getOutMsgQueue(
"vstig")->push(msg_data);
213 Type
gets(
const std::string& key)
216 bool success =
rth_->getVirtualStigmergyTuple(
vstig_id_, key, vst);
219 std::cout<<
"ID "<<
vstig_id_<<
" virtual stigmergy, "<<key<<
" is not exist."<<std::endl;
224 Type data = deserialize_ros<Type>(data_vec);
229 void remove(
const std::string& key)
241 rth_->printVirtualStigmergy();
VirtualStigmergy(const VirtualStigmergy &vs)
Type gets(const std::string &key)
std::vector< uint8_t > vstig_value
boost::shared_ptr< RuntimeHandle > rth_
std::vector< uint8_t > serialize_ros(T t)
static boost::shared_ptr< T > getSingleton()
void put(const std::string &key, const Type &data)
VirtualStigmergy(int vstig_id)
void puts(const std::string &key, const Type &data)
VirtualStigmergy & operator=(const VirtualStigmergy &vs)
boost::shared_ptr< micros_swarm::MsgQueueManager > mqm_