void CommunicationCache::insert(const UUID& uuid, const OSegEntry& sID)
  {
    BoundingBoxList bboxes = mCSeg->serverRegion(sID.server());
    BoundingBox3f bbox = bboxes[0];
    for(uint32 i = 1; i< bboxes.size(); i++)
        bbox.mergeIn(bboxes[i]);

    float xer = mCentralX - ((bbox.max().x + bbox.min().x)/2);
    float yer = mCentralY - ((bbox.max().y + bbox.min().y)/2);
    float zer = mCentralZ - ((bbox.max().z + bbox.min().z)/2);
    float distance = sqrt(xer*xer + yer*yer + zer*zer);

    float logger       = log(mDistScaledUnits*distance);
    float lookupWeight = sID.radius()/(mDistScaledUnits* distance*distance*logger*logger);

    boost::lock_guard<boost::mutex> lck(mMutex);
    mCompleteCache.insert(uuid,sID.server(),0,0,0,0,sID.radius(),lookupWeight,1);
  }
  CommunicationCache::CommunicationCache(SpaceContext* spctx, float scalingUnits, CoordinateSegmentation* cseg,uint32 cacheSize)
    : mCompleteCache(.2,"CommunicationCache",&commCacheScoreFunction,&commCacheScoreFunctionPrint,spctx,cacheSize,FLT_MAX),
      mDistScaledUnits(scalingUnits),
      mCSeg(cseg),
      ctx(spctx),
      mCacheSize(cacheSize)
  {

    BoundingBoxList bboxes = mCSeg->serverRegion(ctx->id());
    BoundingBox3f bbox = bboxes[0];
    for(uint32 i = 1; i< bboxes.size(); i++)
        bbox.mergeIn(bboxes[i]);

    mCentralX = (bbox.max().x + bbox.min().x)/2;
    mCentralY = (bbox.max().y + bbox.min().y)/2;
    mCentralZ = (bbox.max().z + bbox.min().z)/2;


  }
Beispiel #3
0
void ObjectFactory::generateRandomObjects(const BoundingBox3f& region, const Duration& duration, double forceRadius, int forceNumRandomObjects) {
    Time start(Time::null());
    Time end = start + duration;
    Vector3f region_extents = region.extents();

    uint32 nobjects              = GetOptionValue<uint32>(OBJECT_NUM_RANDOM);
    if (forceNumRandomObjects)
        nobjects=forceNumRandomObjects;
    if (nobjects == 0) return;
    bool simple                  =   GetOptionValue<bool>(OBJECT_SIMPLE);
    bool only_2d                 =       GetOptionValue<bool>(OBJECT_2D);
    std::string motion_path_type = GetOptionValue<String>(OBJECT_STATIC);
    float driftX                 = GetOptionValue<float>(OBJECT_DRIFT_X);
    float driftY                 = GetOptionValue<float>(OBJECT_DRIFT_Y);
    float driftZ                 = GetOptionValue<float>(OBJECT_DRIFT_Z);

    float percent_queriers       = GetOptionValue<float>(OBJECT_QUERY_FRAC);

    Vector3f driftVecDir(driftX,driftY,driftZ);


    for(uint32 i = 0; i < nobjects; i++) {
        UUID id = randomUUID();

        ObjectInputs* inputs = new ObjectInputs;

        Vector3f startpos = region.min() + Vector3f(randFloat()*region_extents.x, randFloat()*region_extents.y, (only_2d ? 0.5 : randFloat())*region_extents.z);

        double radval = forceRadius;
        if (!radval)
            radval=10;
        float bounds_radius = (simple ? radval : (randFloat()*2*radval));
        //SILOG(oh,error,"Creating "<<id.toString()<<" radius "<<bounds_radius);
        inputs->localID = mLocalIDSource++;

        if (motion_path_type == "static")//static
            inputs->motion = new StaticMotionPath(start, startpos);
        else if (motion_path_type == "drift") //drift
        {
          //   inputs->motion = new OSegTestMotionPath(start, end, startpos, 3, Duration::milliseconds((int64)1000), region, zfactor); // FIXME
          inputs->motion = new OSegTestMotionPath(start, end, startpos, 3, Duration::milliseconds((int64)1000), region, 0.5, driftVecDir); // FIXME
        }
        else //random
            inputs->motion = new RandomMotionPath(start, end, startpos, 3, Duration::milliseconds((int64)1000), region, (only_2d ? 0.0 : 1.0)); // FIXME
        inputs->bounds = BoundingSphere3f( Vector3f(0, 0, 0), bounds_radius );
        inputs->registerQuery = (randFloat() <= percent_queriers);
        inputs->queryAngle = SolidAngle(SolidAngle::Max / 900.f); // FIXME how to set this? variability by objects?
        inputs->connectAt = Duration::seconds(0.f);

        inputs->startTimer = Network::IOTimer::create(mContext->ioService);

        mObjectIDs.insert(id);
        mInputs[id] = inputs;
    }
}
Beispiel #4
0
bool LoadMonitor::isAdjacent(BoundingBox3f& box1, BoundingBox3f& box2) {

    if (box1.min().x == box2.max().x || box1.max().x == box2.min().x) {
        //if box1.miny or box1.maxy lies between box2.maxy and box2.miny, return true;
        //if box2.miny or box2.maxy lies between box1.maxy and box1.miny, return true;

        if (box2.min().y <= box1.min().y && box1.min().y <= box2.max().y) return true;
        if (box2.min().y <= box1.max().y && box1.max().y <= box2.max().y) return true;

        if (box1.min().y <= box2.min().y && box2.min().y <= box1.max().y) return true;
        if (box1.min().y <= box2.max().y && box2.max().y <= box1.max().y) return true;

    }

    if (box1.min().y == box2.max().y || box1.max().y == box2.min().y) {
        //if box1.minx or box1.maxx lies between box2.maxx and box2.minx, return true;
        //if box2.minx or box2.maxx lies between box1.maxx and box1.minx, return true;
        if (box2.min().x <= box1.min().x && box1.min().x <= box2.max().x) return true;
        if (box2.min().x <= box1.max().x && box1.max().x <= box2.max().x) return true;

        if (box1.min().x <= box2.min().x && box2.min().x <= box1.max().x) return true;
        if (box1.min().x <= box2.max().x && box2.max().x <= box1.max().x) return true;

    }

    return false;
}
Beispiel #5
0
void LoadBalancer::service() {
  boost::mutex::scoped_lock overloadedRegionsListLock(mOverloadedRegionsListMutex);
  boost::mutex::scoped_lock underloadedRegionsListLock(mUnderloadedRegionsListMutex);

  //splitting overloaded regions
  for (std::vector<SegmentedRegion*>::iterator it = mOverloadedRegionsList.begin();
       it != mOverloadedRegionsList.end(); 
       it++)
  {
    uint32 availableSvrIndex = getAvailableServerIndex();
    if (availableSvrIndex != INT_MAX) {

      ServerID availableServer = mAvailableServers[availableSvrIndex].mServer;

      mAvailableServers[availableSvrIndex].mAvailable = false;

      SegmentedRegion* overloadedRegion = *it;
      overloadedRegion->mLeftChild = new SegmentedRegion(overloadedRegion);
      overloadedRegion->mRightChild = new SegmentedRegion(overloadedRegion);

      BoundingBox3f region = overloadedRegion->mBoundingBox;
      float minX = region.min().x; float minY = region.min().y;
      float maxX = region.max().x; float maxY = region.max().y;
      float minZ = region.min().z; float maxZ = region.max().z;

      assert(overloadedRegion->mParent == NULL || overloadedRegion->mSplitAxis != SegmentedRegion::UNDEFINED);

      if (overloadedRegion->mSplitAxis == SegmentedRegion::Y) {
        overloadedRegion->mLeftChild->mBoundingBox = BoundingBox3f( region.min(),
							    Vector3f( (minX+maxX)/2.0, maxY, maxZ) );
        overloadedRegion->mRightChild->mBoundingBox = BoundingBox3f( Vector3f( (minX+maxX)/2.0,minY,minZ),
                                                             region.max() );

        overloadedRegion->mLeftChild->mSplitAxis = overloadedRegion->mRightChild->mSplitAxis = SegmentedRegion::X;
      }
      else {
        overloadedRegion->mLeftChild->mBoundingBox = BoundingBox3f( region.min(),
                                                                    Vector3f( maxX, (minY+maxY)/2.0, maxZ) );
        overloadedRegion->mRightChild->mBoundingBox = BoundingBox3f( Vector3f( minX,(minY+maxY)/2.0,minZ),
                                                             region.max() );

        overloadedRegion->mLeftChild->mSplitAxis = overloadedRegion->mRightChild->mSplitAxis = SegmentedRegion::Y;
      }
      overloadedRegion->mLeftChild->mServer = overloadedRegion->mServer;
      overloadedRegion->mRightChild->mServer = availableServer;

      std::cout << "Split\n";
      std::cout << overloadedRegion->mServer << " : " << overloadedRegion->mLeftChild->mBoundingBox << "\n";
      std::cout << availableServer << " : " << overloadedRegion->mRightChild->mBoundingBox << "\n";
      
      mCSeg->mWholeTreeServerRegionMap.erase(overloadedRegion->mServer);      
      mCSeg->mWholeTreeServerRegionMap.erase(availableServer);
      mCSeg->mLowerTreeServerRegionMap.erase(overloadedRegion->mServer);
      mCSeg->mLowerTreeServerRegionMap.erase(availableServer);


      std::vector<SegmentationInfo> segInfoVector;
      SegmentationInfo segInfo, segInfo2;
      segInfo.server = overloadedRegion->mServer;
      segInfo.region = mCSeg->serverRegion(overloadedRegion->mServer);
      segInfoVector.push_back( segInfo );

      segInfo2.server = availableServer;
      segInfo2.region = mCSeg->serverRegion(availableServer);
      segInfoVector.push_back(segInfo2);

      Thread thrd(boost::bind(&DistributedCoordinateSegmentation::notifySpaceServersOfChange,mCSeg,segInfoVector));
      
      mOverloadedRegionsList.erase(it);
      
      return; //enough work for this iteration. No further splitting or merging.
    }
    else {
      //No idle servers are available at this time...
      break;
    }
  }

  //merging underloaded regions
  for (std::vector<SegmentedRegion*>::iterator it = mUnderloadedRegionsList.begin();
       it != mUnderloadedRegionsList.end();
       it++)
  {
    SegmentedRegion* underloadedRegion = *it;
    if (underloadedRegion->mParent == NULL) {
      mUnderloadedRegionsList.erase(it);
      break;
    }

    bool isRightChild = (underloadedRegion->mParent->mRightChild == underloadedRegion);
    SegmentedRegion* sibling = NULL;
    if (isRightChild) {
      sibling = underloadedRegion->mParent->mLeftChild;
    }
    else {
      sibling = underloadedRegion->mParent->mRightChild;
    }

    std::vector<SegmentedRegion*>::iterator sibling_it = 
               std::find(mUnderloadedRegionsList.begin(), mUnderloadedRegionsList.end(), sibling);
    if (sibling_it == mUnderloadedRegionsList.end()) 
    {
      mUnderloadedRegionsList.erase(it);
      break;
    }

    SegmentedRegion* parent = underloadedRegion->mParent;
    parent->mServer = parent->mLeftChild->mServer;
    for (uint32 i=0; i<mAvailableServers.size(); i++) {
      if (mAvailableServers[i].mServer == parent->mRightChild->mServer) {
        mAvailableServers[i].mAvailable = true;
        break;
      }
    }

    mCSeg->mWholeTreeServerRegionMap.erase(parent->mRightChild->mServer);
    mCSeg->mLowerTreeServerRegionMap.erase(parent->mRightChild->mServer);
    mCSeg->mWholeTreeServerRegionMap.erase(parent->mLeftChild->mServer);
    mCSeg->mLowerTreeServerRegionMap.erase(parent->mLeftChild->mServer);

    std::vector<SegmentationInfo> segInfoVector;
    SegmentationInfo segInfo, segInfo2;
    segInfo.server = parent->mRightChild->mServer;
    segInfo.region = mCSeg->serverRegion(parent->mRightChild->mServer);
    segInfoVector.push_back( segInfo );

    segInfo2.server = parent->mLeftChild->mServer;
    segInfo2.region = mCSeg->serverRegion(parent->mLeftChild->mServer);
    segInfoVector.push_back(segInfo2);

    Thread thrd(boost::bind(&DistributedCoordinateSegmentation::notifySpaceServersOfChange,mCSeg,segInfoVector));

    mUnderloadedRegionsList.erase(it);
    sibling_it = std::find(mUnderloadedRegionsList.begin(), mUnderloadedRegionsList.end(), sibling);   
    mUnderloadedRegionsList.erase(sibling_it);

    std::cout << "Merged " << parent->mLeftChild->mServer << " : " << parent->mRightChild->mServer << "!\n";

    delete parent->mLeftChild;
    delete parent->mRightChild;
    parent->mLeftChild = NULL;
    parent->mRightChild = NULL;


    break;
  }
}