MRXT: The Multi-Robot eXploration Tool
Multi-Robot autonomous exploration and mapping simulator.
src/architecture/planner/auxiliar/treeNode.cpp
00001         
00002         
00003 #include "treeNode.h"
00004 #include <stdlib.h>
00005 #include <stdio.h>
00006 #include <assert.h>
00007 
00008 treeNode::treeNode(int type, int nrobots):
00009         parent(0),
00010         nchildren(0),
00011         children(0),
00012 
00013         ipoints(0),
00014         nbots(0),
00015         value(0.0f),
00016         nextNodeInPlan(-1),
00017 
00018         node_type(type),
00019 
00020         numrobots(nrobots),
00021         robots(new bool[nrobots])
00022 {
00023 
00024 }
00025 
00026 treeNode::~treeNode(){
00027         for (int n=0; n<nchildren; n++){
00028                 delete children[n];
00029         }
00030         if (children)
00031                 free(children);
00032         delete[] robots;
00033 }
00034 
00035 // TODO: CHANGE THIS REALLOC TO A STD::VECTOR WITH INITIAL RESERVATION
00036 void treeNode::addChildren(treeNode& child){
00037 
00038         child.setParent(*this);
00039         nchildren++;
00040 
00041         children = (treeNode**) realloc(children, nchildren*sizeof(treeNode*));
00042 
00043         children[nchildren-1] = &child;
00044 }
00045 
00046 treeNode& treeNode::getChildren(int number) const {
00047         assert(number < nchildren);
00048         return *(children[number]);
00049 }
00050 
00051 treeNode& treeNode::getParent() const{
00052         assert(parent);
00053         return (*parent);
00054 }
00055 
00056 void treeNode::clearRobots(){
00057         for (int i = 0; i< numrobots; i++)
00058                 robots[i] = false;
00059 }
00060 
00061 bool treeNode::isRobot(int robot) const {
00062         if (robot < numrobots)
00063                 return robots[robot];
00064         else
00065                 return false;
00066 }
00067 
00068 void treeNode::setRobot(int robot){
00069         if (robot < numrobots)
00070                 robots[robot] = true;   
00071 }
00072 
00073 bool treeNode::orderByValue(const treeNode* a, const treeNode* b){
00074         //printf("ordenando por valor %f y %f\n", ((treeNode*)a)->getValue(), ((treeNode*)b)->getValue());
00075         if (a == b) return false;
00076         return (((treeNode*)a)->getValue() > ((treeNode*)b)->getValue());
00077 }
00078 
00079 bool treeNode::orderByCost(const treeNode* a, const treeNode* b){
00080         //printf("ordenando por coste %f y %f\n", ((treeNode*)a)->getCost(), ((treeNode*)b)->getCost());
00081         if (a == b) return false;
00082         else return (((treeNode*)a)->getCost() > ((treeNode*)b)->getCost());
00083 }
00084 
00085 
 All Classes Functions Variables Typedefs