44 boost::shared_lock<boost::shared_mutex> lock(
id_mutex_);
50 boost::unique_lock<boost::shared_mutex> lock(
id_mutex_);
56 boost::shared_lock<boost::shared_mutex> lock(
type_mutex_);
62 boost::unique_lock<boost::shared_mutex> lock(
type_mutex_);
80 boost::shared_lock<boost::shared_mutex> lock(
base_mutex_);
86 boost::unique_lock<boost::shared_mutex> lock(
base_mutex_);
88 if(robot_base.
valid == -1) {
95 boost::shared_lock<boost::shared_mutex> lock(
base_mutex_);
110 std::map<int, NeighborBase>::iterator n_it =
neighbors_.find(robot_id);
124 boost::upgrade_to_unique_lock<boost::shared_mutex> uniqueLock(lock);
144 std::map<int, NeighborBase>::iterator n_it =
neighbors_.find(robot_id);
147 NeighborBase new_neighbor_base(distance, azimuth, elevation, x, y, z,vx, vy, vz);
148 boost::upgrade_to_unique_lock<boost::shared_mutex> uniqueLock(lock);
149 n_it->second = new_neighbor_base;
152 NeighborBase new_neighbor_base(distance, azimuth, elevation, x, y, z, vx, vy, vz);
153 boost::upgrade_to_unique_lock<boost::shared_mutex> uniqueLock(lock);
154 neighbors_.insert(std::pair<int, NeighborBase>(robot_id ,new_neighbor_base));
167 std::map<int, NeighborBase>::iterator n_it =
neighbors_.find(robot_id);
178 std::map<int, NeighborBase>::iterator n_it;
181 std::cout<<n_it->first<<
": ";
182 std::cout<<n_it->second.distance<<
","<<n_it->second.azimuth<<
","<<n_it->second.elevation<<
","<<\
183 n_it->second.x<<
","<<n_it->second.y<<
","<<n_it->second.z<<
", "<<
184 n_it->second.vx<<
","<<n_it->second.vy<<
","<<n_it->second.vz;
185 std::cout<<std::endl;
191 boost::upgrade_lock<boost::shared_mutex> lock(
swarm_mutex_);
192 std::map<int, bool>::iterator s_it =
swarms_.find(swarm_id);
195 boost::upgrade_to_unique_lock<boost::shared_mutex> uniqueLock(lock);
196 s_it->second = value;
199 boost::upgrade_to_unique_lock<boost::shared_mutex> uniqueLock(lock);
200 swarms_.insert(std::pair<int, bool>(swarm_id, value));
206 boost::shared_lock<boost::shared_mutex> lock(
swarm_mutex_);
207 std::map<int, bool>::iterator s_it =
swarms_.find(swarm_id);
219 std::map<int, bool>::iterator s_it;
220 boost::shared_lock<boost::shared_mutex> lock(
swarm_mutex_);
223 swarm_list.push_back(s_it->first);
230 boost::unique_lock<boost::shared_mutex> lock(
swarm_mutex_);
236 std::map<int, bool>::iterator s_it;
237 boost::shared_lock<boost::shared_mutex> lock(
swarm_mutex_);
239 std::cout<<s_it->first<<
": ";
240 std::cout<<s_it->second;
241 std::cout<<std::endl;
247 std::map<int, NeighborSwarmTuple>::iterator os_it;
251 if(os_it->second.swarmIDExist(swarm_id)) {
265 std::map<int, NeighborSwarmTuple>::iterator os_it;
270 if(os_it->second.swarmIDExist(swarm_id)) {
271 boost::upgrade_to_unique_lock<boost::shared_mutex> uniqueLock(lock);
272 os_it->second.age = 0;
275 boost::upgrade_to_unique_lock<boost::shared_mutex> uniqueLock(lock);
276 os_it->second.addSwarmID(swarm_id);
277 os_it->second.age = 0;
281 std::vector<int> swarm_list;
282 swarm_list.push_back(swarm_id);
285 boost::upgrade_to_unique_lock<boost::shared_mutex> uniqueLock(lock);
286 neighbor_swarms_.insert(std::pair<int, NeighborSwarmTuple>(robot_id, new_neighbor_swarm));
292 std::map<int, NeighborSwarmTuple>::iterator os_it;
297 if(os_it->second.swarmIDExist(swarm_id)) {
298 boost::upgrade_to_unique_lock<boost::shared_mutex> uniqueLock(lock);
299 os_it->second.removeSwarmID(swarm_id);
300 os_it->second.age = 0;
303 std::cout<<
"robot"<<robot_id<<
" is not in swarm"<<swarm_id<<
"."<<std::endl;
307 std::cout<<
"robot_id "<<robot_id<<
" neighbor_swarm tuple is not exist."<<std::endl;
314 std::map<int, NeighborSwarmTuple>::iterator os_it;
320 boost::upgrade_to_unique_lock<boost::shared_mutex> uniqueLock(lock);
321 os_it->second = new_neighbor_swarm;
325 boost::upgrade_to_unique_lock<boost::shared_mutex> uniqueLock(lock);
326 neighbor_swarms_.insert(std::pair<int, NeighborSwarmTuple>(robot_id ,new_neighbor_swarm));
332 std::map<int, NeighborSwarmTuple>::iterator os_it;
333 swarm_members.clear();
339 if(os_it->second.swarmIDExist(swarm_id)) {
340 swarm_members.insert(os_it->first);
353 std::map<int, NeighborSwarmTuple>::iterator os_it;
356 std::cout<<
"neighbor swarm "<<os_it->first<<
": ";
357 std::vector<int> temp = os_it->second.swarm_id_vector;
358 for(
int i=0; i< temp.size(); i++) {
359 std::cout<<temp[i]<<
",";
361 std::cout<<
"age: "<<os_it->second.age;
362 std::cout<<std::endl;
368 std::map<int, std::map<std::string, VirtualStigmergyTuple> >::iterator vst_it;
369 boost::upgrade_lock<boost::shared_mutex> lock(
vstig_mutex_);
375 std::map<std::string, VirtualStigmergyTuple> vst;
376 boost::upgrade_to_unique_lock<boost::shared_mutex> uniqueLock(lock);
377 virtual_stigmergy_.insert(std::pair<
int, std::map<std::string, VirtualStigmergyTuple> >(
id, vst));
382 unsigned int lclock, time_t wtime,
unsigned int rcount,
int robot_id)
384 std::map<int, std::map<std::string, VirtualStigmergyTuple> >::iterator vst_it;
385 boost::upgrade_lock<boost::shared_mutex> lock(
vstig_mutex_);
389 std::map<std::string, VirtualStigmergyTuple>::iterator svstt_it = vst_it->second.find(key);
390 if(svstt_it != vst_it->second.end()) {
392 boost::upgrade_to_unique_lock<boost::shared_mutex> uniqueLock(lock);
393 svstt_it->second = new_tuple;
397 boost::upgrade_to_unique_lock<boost::shared_mutex> uniqueLock(lock);
398 vst_it->second.insert(std::pair<std::string, VirtualStigmergyTuple>(key ,new_tuple));
402 std::cout<<
"ID "<<
id<<
" VirtualStigmergy is not exist."<<std::endl;
409 std::map<int, std::map<std::string, VirtualStigmergyTuple> >::iterator vst_it;
410 boost::shared_lock<boost::shared_mutex> lock(
vstig_mutex_);
413 std::map<std::string, VirtualStigmergyTuple>::iterator svstt_it = vst_it->second.find(key);
414 if(svstt_it != vst_it->second.end()) {
423 std::map<int, std::map<std::string, VirtualStigmergyTuple> >::iterator vst_it;
424 boost::shared_lock<boost::shared_mutex> lock(
vstig_mutex_);
427 std::map<std::string, VirtualStigmergyTuple>::iterator svstt_it = vst_it->second.find(key);
428 if(svstt_it != vst_it->second.end()) {
429 vstig_tuple = svstt_it->second;
438 std::map<int, std::map<std::string, VirtualStigmergyTuple> >::iterator vst_it;
439 boost::upgrade_lock<boost::shared_mutex> lock(
vstig_mutex_);
443 std::map<std::string, VirtualStigmergyTuple>::iterator svstt_it = vst_it->second.find(key);
444 if(svstt_it != vst_it->second.end()) {
445 boost::upgrade_to_unique_lock<boost::shared_mutex> uniqueLock(lock);
446 svstt_it->second.read_count = count;
449 std::cout<<
"ID: "<<
id<<
" VirtualStigmergy, key: "<<key<<
" is not exist."<<std::endl;
453 std::cout<<
"ID "<<
id<<
" VirtualStigmergy is not exist."<<std::endl;
460 std::map<int, std::map<std::string, VirtualStigmergyTuple> >::iterator vst_it;
461 boost::shared_lock<boost::shared_mutex> lock(
vstig_mutex_);
464 return vst_it->second.size();
472 boost::unique_lock<boost::shared_mutex> lock(
vstig_mutex_);
478 std::map<int, std::map<std::string, VirtualStigmergyTuple> >::iterator vst_it;
479 boost::upgrade_lock<boost::shared_mutex> lock(
vstig_mutex_);
482 std::map<std::string, VirtualStigmergyTuple>::iterator svstt_it = vst_it->second.find(key);
483 if(svstt_it != vst_it->second.end()) {
484 boost::upgrade_to_unique_lock<boost::shared_mutex> uniqueLock(lock);
485 vst_it->second.erase(key);
498 std::map<int, std::map<std::string, VirtualStigmergyTuple> >::iterator vst_it;
499 std::map<std::string, VirtualStigmergyTuple>::iterator svstt_it;
500 boost::shared_lock<boost::shared_mutex> lock(
vstig_mutex_);
502 std::cout<<
"["<<vst_it->first<<
":"<<std::endl;
503 std::map<std::string, VirtualStigmergyTuple>* svstt_pointer = &(vst_it->second);
504 for (svstt_it = svstt_pointer->begin(); svstt_it != svstt_pointer->end(); svstt_it++) {
505 std::cout<<svstt_it->first<<
" ";
511 std::cout<<
"]"<<std::endl;
512 std::cout<<std::endl;
524 Base msg_src_neighbor(nb.
x, nb.
y, nb.
z, nb.
vx, nb.
vy, nb.
vz, 1);
525 std::map<int, NeighborBase>::iterator it =
neighbors_.begin();
527 if(it->first == robot_id) {
530 Base neighbor(it->second.x, it->second.y, it->second.z, it->second.vx, it->second.vy, it->second.vz, 1);
531 if(!
cni_->isNeighbor(msg_src_neighbor, neighbor)) {
542 std::map<int, std::map<std::string, BlackBoardTuple> >::iterator bb_it;
543 boost::upgrade_lock<boost::shared_mutex> lock(
bb_mutex_);
550 std::map<std::string, BlackBoardTuple> bb;
551 boost::upgrade_to_unique_lock<boost::shared_mutex> uniqueLock(lock);
552 blackboard_.insert(std::pair<
int, std::map<std::string, BlackBoardTuple> >(
id, bb));
558 std::map<int, std::map<std::string, BlackBoardTuple> >::iterator bb_it;
559 boost::upgrade_lock<boost::shared_mutex> lock(
bb_mutex_);
563 std::map<std::string, BlackBoardTuple>::iterator sbbt_it = bb_it->second.find(key);
564 if(sbbt_it != bb_it->second.end()) {
566 boost::upgrade_to_unique_lock<boost::shared_mutex> uniqueLock(lock);
567 sbbt_it->second = new_tuple;
571 boost::upgrade_to_unique_lock<boost::shared_mutex> uniqueLock(lock);
572 bb_it->second.insert(std::pair<std::string, BlackBoardTuple>(key ,new_tuple));
576 std::cout<<
"ID "<<
id<<
" BlackBoard is not exist."<<std::endl;
583 std::map<int, std::map<std::string, BlackBoardTuple> >::iterator bb_it;
584 boost::shared_lock<boost::shared_mutex> lock(
bb_mutex_);
587 std::map<std::string, BlackBoardTuple>::iterator sbbt_it = bb_it->second.find(key);
588 if(sbbt_it != bb_it->second.end()) {
597 std::map<int, std::map<std::string, BlackBoardTuple> >::iterator bb_it;
598 boost::shared_lock<boost::shared_mutex> lock(
bb_mutex_);
601 std::map<std::string, BlackBoardTuple>::iterator sbbt_it = bb_it->second.find(key);
602 if(sbbt_it != bb_it->second.end()) {
603 bb_tuple = sbbt_it->second;
610 std::map<int, std::map<std::string, BlackBoardTuple> >::iterator bb_it;
611 boost::shared_lock<boost::shared_mutex> lock(
bb_mutex_);
615 return bb_it->second.size();
623 boost::unique_lock<boost::shared_mutex> lock(
bb_mutex_);
629 std::map<int, std::map<std::string, BlackBoardTuple> >::iterator bb_it;
630 boost::upgrade_lock<boost::shared_mutex> lock(
bb_mutex_);
634 std::map<std::string, BlackBoardTuple>::iterator sbbt_it=bb_it->second.find(key);
635 if(sbbt_it != bb_it->second.end()) {
636 boost::upgrade_to_unique_lock<boost::shared_mutex> uniqueLock(lock);
637 bb_it->second.erase(key);
650 std::map<int, std::map<std::string, BlackBoardTuple> >::iterator bb_it;
651 std::map<std::string, BlackBoardTuple>::iterator sbbt_it;
653 boost::shared_lock<boost::shared_mutex> lock(
bb_mutex_);
655 std::cout<<
"["<<bb_it->first<<
":"<<std::endl;
656 std::map<std::string, BlackBoardTuple>* sbbt_pointer = &(bb_it->second);
657 for (sbbt_it = sbbt_pointer->begin(); sbbt_it != sbbt_pointer->end(); sbbt_it++) {
662 std::cout<<
"]"<<std::endl;
663 std::cout<<std::endl;
684 std::map<std::string, boost::shared_ptr<ListenerHelper> >::iterator lh_it;
689 boost::upgrade_to_unique_lock<boost::shared_mutex> uniqueLock(lock);
690 lh_it->second = helper;
693 boost::upgrade_to_unique_lock<boost::shared_mutex> uniqueLock(lock);
700 std::map<std::string, boost::shared_ptr<ListenerHelper> >::iterator lh_it;
705 return lh_it->second;
708 std::cout<<
"could not get the callback function which has the key "<<key<<
"!"<<std::endl;
733 std::map<std::string, SCDSPSODataTuple>::iterator iter =
scds_pso_tuple_.find(aKey);
744 std::map<std::string, SCDSPSODataTuple>::iterator iter =
scds_pso_tuple_.find(aKey);
752 boost::upgrade_to_unique_lock<boost::shared_mutex> uniqueLock(lock);
756 boost::upgrade_to_unique_lock<boost::shared_mutex> uniqueLock(lock);
boost::shared_mutex status_mutex_
boost::shared_mutex type_mutex_
std::map< int, std::map< std::string, BlackBoardTuple > > blackboard_
bool isBlackBoardTupleExist(int id, const std::string &key)
void setRobotType(int robot_type)
boost::shared_mutex bb_mutex_
void joinNeighborSwarm(int robot_id, int swarm_id)
void createVirtualStigmergy(int id)
void getSwarmList(std::vector< int > &swarm_list)
boost::shared_mutex neighbor_distance_mutex_
void deleteBlackBoard(int id)
int getBlackBoardSize(int id)
std::map< std::string, SCDSPSODataTuple > scds_pso_tuple_
const Base & getRobotBase()
int getVirtualStigmergySize(int id)
bool checkNeighborsOverlap(int robot_id)
bool getVirtualStigmergyTuple(int id, const std::string &key, VirtualStigmergyTuple &vstig_tuple)
void setRobotID(int robot_id)
void printNeighborSwarm()
void deleteBlackBoardValue(int id, const std::string &key)
bool getNeighborBase(int robot_id, NeighborBase &nb)
void deleteNeighborSwarm(int robot_id)
boost::shared_mutex neighbor_mutex_
void setRobotBase(const Base &robot_base)
void setNeighborDistance(float neighbor_distance)
void insertOrUpdateNeighbor(int robot_id, float distance, float azimuth, float elevation, float x, float y, float z, float vx, float vy, float vz)
void insertOrUpdateSwarm(int swarm_id, bool value)
void deleteSwarm(int swarm_id)
void insertOrUpdateVirtualStigmergy(int id, const std::string &key, const std::vector< uint8_t > &value, unsigned int lclock, time_t wtime, unsigned int rcount, int robot_id)
boost::shared_mutex scds_pso_tuple_mutex_
boost::shared_mutex barrier_mutex_
void insertOrUpdateListenerHelper(const std::string &key, const boost::shared_ptr< ListenerHelper > helper)
bool inNeighbors(int robot_id)
bool inNeighborSwarm(int robot_id, int swarm_id)
boost::shared_mutex vstig_mutex_
void deleteNeighbor(int robot_id)
void printVirtualStigmergy()
const float & getNeighborDistance()
void insertOrUpdateBlackBoard(int id, const std::string &key, const std::vector< uint8_t > &value, const ros::Time ×tamp, int robot_id)
const boost::shared_ptr< ListenerHelper > getListenerHelper(const std::string &key)
bool getSwarmFlag(int swarm_id)
boost::shared_mutex listener_helpers_mutex_
void setRobotStatus(int robot_status)
std::map< int, NeighborSwarmTuple > neighbor_swarms_
void deleteListenerHelper(const std::string &key)
boost::shared_ptr< CheckNeighborInterface > cni_
std::map< int, bool > swarms_
void insertOrRefreshNeighborSwarm(int robot_id, const std::vector< int > &swarm_list)
std::map< int, NeighborBase > neighbors_
void getSwarmMembers(int swarm_id, std::set< int > &swarm_members)
boost::shared_mutex swarm_mutex_
boost::shared_mutex id_mutex_
std::map< int, std::map< std::string, VirtualStigmergyTuple > > virtual_stigmergy_
void leaveNeighborSwarm(int robot_id, int swarm_id)
std::map< int, NeighborBase > getNeighbors()
void createBlackBoard(int id)
boost::shared_mutex base_mutex_
void deleteVirtualStigmergy(int id)
boost::shared_mutex neighbor_swarm_mutex_
void updateVirtualStigmergyTupleReadCount(int id, const std::string &key, int count)
void deleteVirtualStigmergyValue(int id, const std::string &key)
bool isVirtualStigmergyTupleExist(int id, const std::string &key)
void getBlackBoardTuple(int id, const std::string &key, BlackBoardTuple &bb_tuple)
void insertOrUpdateSCDSPSOValue(const std::string &aKey, const SCDSPSODataTuple &aT)
void insertBarrier(int robot_id)
std::map< std::string, boost::shared_ptr< ListenerHelper > > listener_helpers_
bool getSCDSPSOValue(const std::string &aKey, SCDSPSODataTuple &aT)