void GoRegionBoard::OnExecutedUncodedMove(int move, SgBlackWhite moveColor)
{
    if (DEBUG_REGION_BOARD)
        SgDebug() << "OnExecutedUncodedMove " << SgWritePoint(move) << '\n';
    {
        m_stack.StartMoveInfo();
        if (move != SG_PASS)
        {
            SG_ASSERT(! Board().LastMoveInfo(GO_MOVEFLAG_SUICIDE));
            // can't handle yet,
            // should be forbidden anyway. @todo allowed in Chinese rules.
            bool fWasCapture = Board().LastMoveInfo(GO_MOVEFLAG_CAPTURING);

            UpdateBlock(move, moveColor);

            {
                GoRegion* r = PreviousRegionAt(move, moveColor);
                bool split = GoEyeUtil::IsSplitPt(move, r->Points());

                r->OnAddStone(move);
                PushStone(r, move);
                SgPointSet points = r->Points();
                // needed even after RemoveRegion(r).
                if (split || points.IsEmpty())
                // must remove old region before generating new ones,
                // because removing clears m_anchor[]
                    RemoveRegion(r);

                if (split) // find new regions
                {
                    for (SgConnCompIterator it(points, Board().Size());
                         it; ++it)
                        GenRegion(*it, moveColor);
                }
            }

            if (fWasCapture)
            {
            //  FindNewNeighborRegions(move, moveColor);
                MergeAdjacentAndAddBlock(move, SgOppBW(moveColor));
            }

            m_code = Board().GetHashCode();
            if (HEAVYCHECK)
                CheckConsistency();
        }
    }

    {
        for (SgBWIterator it; it; ++it)
        {
            SgBlackWhite color(*it);
            for (SgVectorIteratorOf<GoRegion> it(AllRegions(color)); it; ++it)
            {   GoRegion* r1 = *it;
                if (! r1->IsValid())
                    r1->ComputeBasicFlags();
            }
        }
    }
}
//______________________________________________________________________________
void TFractionFitter::ReleaseRangeZ() {
   // Release restrictions on the Z range of the histogram to be used in the fit.

   fLowLimitZ = 1;
   fHighLimitZ = fData->GetNbinsZ();
   CheckConsistency();
}
//______________________________________________________________________________
void TFractionFitter::SetData(TH1* data) {
   // Change the histogram to be fitted to. Notes:
   // - Parameter constraints and settings are retained from a possible previous fit.
   // - Modifying the dimension or number of bins results in an error (in this case
   //   rather instantiate a new TFractionFitter object)

   fData = data;
   fFitDone = kFALSE;
   CheckConsistency();
}
 //! MapExtractor basic constructor
 MapExtractor(const RCP<const Map>& fullmap, const std::vector<RCP<const Map> >& maps) {
   fullmap_ = fullmap;
   maps_ = maps;
   importers_.resize(maps_.size());
   for (unsigned i = 0; i < maps_.size(); ++i)
     if (maps[i] != null)
       importers_[i] = ImportFactory::Build(fullmap_, maps[i]);
   TEUCHOS_TEST_FOR_EXCEPTION(CheckConsistency() == false, std::logic_error,
                              "logic error. full map and sub maps are inconsistently distributed over the processors.");
 }
//______________________________________________________________________________
void TFractionFitter::SetMC(Int_t parm, TH1* MC) {
   // Change the histogram for template number <parm>. Notes:
   // - Parameter constraints and settings are retained from a possible previous fit.
   // - Modifying the dimension or number of bins results in an error (in this case
   //   rather instantiate a new TFractionFitter object)

   CheckParNo(parm);
   fMCs.RemoveAt(parm);
   fMCs.AddAt(MC,parm);
   fFitDone = kFALSE;
   CheckConsistency();
}
//______________________________________________________________________________
void TFractionFitter::SetRangeX(Int_t low, Int_t high) {
   // Set the X range of the histogram to be used in the fit.
   // Use ReleaseRangeX() to go back to fitting the full histogram.
   // The consistency check ensures that no empty fit range occurs (and also
   // recomputes the bin content integrals).
   // Arguments:
   //     low:  lower X bin number
   //     high: upper X bin number

   fLowLimitX = (low > 0 ) ? low : 1;
   fHighLimitX = ( high > 0 && high <= fData->GetNbinsX()) ? high : fData->GetNbinsX();
   CheckConsistency();
}
//______________________________________________________________________________
void TFractionFitter::ExcludeBin(Int_t bin) {
   // Exclude the given bin from the fit. The bin numbering to be used is that
   // of TH1::GetBin().

   int excluded = fExcludedBins.size();
   for (int b = 0; b < excluded; ++b) {
      if (fExcludedBins[b] == bin) {
         Error("ExcludeBin", "bin %d already excluded", bin);
         return;
      }
   }
   fExcludedBins.push_back(bin);
   // This call serves to properly (re)determine the number of degrees of freeom
   CheckConsistency();
}
//______________________________________________________________________________
void TFractionFitter::IncludeBin(Int_t bin) {
   // Include the given bin in the fit, if it was excluded before using ExcludeBin().
   // The bin numbering to be used is that of TH1::GetBin().

   for (std::vector<Int_t>::iterator it = fExcludedBins.begin();
        it != fExcludedBins.end(); ++it) {
      if (*it == bin) {
         fExcludedBins.erase(it);
         // This call serves to properly (re)determine the number of degrees of freeom
         CheckConsistency();
         return;
      }
   }
   Error("IncludeBin", "bin %d was not excluded", bin);
}
//______________________________________________________________________________
void TFractionFitter::SetRangeY(Int_t low, Int_t high) {
   // Set the Y range of the histogram to be used in the fit (2D or 3D histograms only).
   // Use ReleaseRangeY() to go back to fitting the full histogram.
   // The consistency check ensures that no empty fit range occurs (and also
   // recomputes the bin content integrals).
   // Arguments:
   //     low:  lower Y bin number
   //     high: upper Y bin number

   if (fData->GetDimension() < 2) {
      Error("SetRangeY","Y range cannot be set for 1D histogram");
      return;
   }

   fLowLimitY = (low > 0) ? low : 1;
   fHighLimitY = (high > 0 && high <= fData->GetNbinsY()) ? high : fData->GetNbinsY();
   CheckConsistency();
}
void GoRegionBoard::GenBlocksRegions()
{
    if (UpToDate())
        return;

    Clear();
    GenBlocks();

    for (SgBWIterator it; it; ++it)
    {
        SgBlackWhite color(*it);
        for (SgConnCompIterator it(AllPoints() - All(color), Board().Size());
             it; ++it)
            GenRegion(*it, color);
    }

    FindBlocksWithEye();

    m_code = Board().GetHashCode();
    m_invalid = false;
    if (HEAVYCHECK)
        CheckConsistency();
}
Exemple #11
0
void C4SolidMask::Put(bool fCauseInstability, C4TargetRect *pClipRect,
                      bool fRestoreAttachment) {
  // If not put, put mask to background,
  // storing background pixels in cSolidMask.

  // No mask
  if (!pSolidMask || !pSolidMaskMatBuff) {
    iAttachingObjectsCount = 0;
    return;
  }
  // Contained
  if (pForObject->Contained) {
    iAttachingObjectsCount = 0;
    return;
  }
  // Mask is put
  if (fCauseInstability) CheckConsistency();

  bool RegularPut;
  if (!pClipRect) {
    // Regular Put: Update MaskPutRect and MaskPutRotation
    MaskPutRotation = pForObject->r;
    pClipRect = &MaskPutRect;
    RegularPut = true;
  } else {
    // Reput by C4SolidMask::Remove
    // Don't change MaskPutRotation or MaskPutRect
    // Intersect ClipRect with the MaskPutRect
    if (!pClipRect->ClipBy(MaskPutRect)) return;
    RegularPut = false;
  }
  // Lock mask surface
  int iPitch = pForObject->SolidMask.Wdt;
  int xcnt, ycnt, iTx, iTy;
  // Put mask pixels
  BYTE byPixel;
  // not rotated?
  if (!MaskPutRotation) {
    // calc put rect
    if (RegularPut) {
      int ox, oy;
      ox = pForObject->x + pForObject->Def->Shape.x + pForObject->SolidMask.tx;
      oy = pForObject->y + pForObject->Def->Shape.y + pForObject->SolidMask.ty;
      MaskPutRect.x = ox;
      if (MaskPutRect.x < 0) {
        MaskPutRect.tx = -MaskPutRect.x;
        MaskPutRect.x = 0;
      } else
        MaskPutRect.tx = 0;
      MaskPutRect.y = oy;
      if (MaskPutRect.y < 0) {
        MaskPutRect.ty = -MaskPutRect.y;
        MaskPutRect.y = 0;
      } else
        MaskPutRect.ty = 0;
      MaskPutRect.Wdt = Min<int32_t>(ox + pForObject->SolidMask.Wdt, GBackWdt) -
                        MaskPutRect.x;
      MaskPutRect.Hgt = Min<int32_t>(oy + pForObject->SolidMask.Hgt, GBackHgt) -
                        MaskPutRect.y;
    }
    // fill rect with mask
    for (ycnt = 0; ycnt < pClipRect->Hgt; ++ycnt) {
      BYTE *pPix = pSolidMask +
                   (ycnt + pClipRect->ty) * pForObject->SolidMask.Wdt +
                   pClipRect->tx;
      for (xcnt = 0; xcnt < pClipRect->Wdt; ++xcnt, ++pPix) {
        if (*pPix) {
          // solid mask present here
          // calc position in landscape
          iTx = pClipRect->x + xcnt;
          iTy = pClipRect->y + ycnt;
          // is background mat to be stored? always do this in the given rect
          if (!MaskPut) {
            // get background pixel
            byPixel = GBackPix(iTx, iTy);
            // store it. If MCVehic, also store in initial put, but won't be
            // used in restore
            // do not overwrite current value in re-put issued by
            // SolidMask-remover
            if (byPixel != MCVehic || RegularPut)
              pSolidMaskMatBuff[(ycnt + pClipRect->ty) * MatBuffPitch + xcnt +
                                pClipRect->tx] = byPixel;
          }
          // and set mask
          _SBackPix(iTx, iTy, MCVehic);
        } else
            // no SolidMask: mark buffer as unused here
            if (!MaskPut)
          pSolidMaskMatBuff[(ycnt + pClipRect->ty) * MatBuffPitch + xcnt +
                            pClipRect->tx] = MCVehic;
      }
    }
  } else {
    // calc matrix for given rotation
    FIXED Ma1 = Cos(itofix(-MaskPutRotation)),
          Ma2 = -Sin(itofix(-MaskPutRotation)),
          Mb1 = Sin(itofix(-MaskPutRotation)),
          Mb2 = Cos(itofix(-MaskPutRotation));
    // get upper-left corner of landscape copy rect
    int centerx = pForObject->Def->Shape.x + pForObject->SolidMask.tx +
                  pForObject->SolidMask.Wdt / 2;
    int centery = pForObject->Def->Shape.y + pForObject->SolidMask.ty +
                  pForObject->SolidMask.Hgt / 2;
    int xstart = pForObject->x +
                 fixtoi(Ma1 * itofix(centerx) - Ma2 * itofix(centery)) -
                 MatBuffPitch / 2;
    int ystart = pForObject->y +
                 fixtoi(-Mb1 * itofix(centerx) + Mb2 * itofix(centery)) -
                 MatBuffPitch / 2;
    // store put rect
    if (RegularPut) {
      MaskPutRect.x = xstart;
      if (MaskPutRect.x < 0) {
        MaskPutRect.tx = -MaskPutRect.x;
        MaskPutRect.Wdt = MaskPutRect.x;
        MaskPutRect.x = 0;
      } else {
        MaskPutRect.tx = 0;
        MaskPutRect.Wdt = 0;
      }
      MaskPutRect.y = ystart;
      if (MaskPutRect.y < 0) {
        MaskPutRect.ty = -MaskPutRect.y;
        MaskPutRect.Hgt = MaskPutRect.y;
        MaskPutRect.y = 0;
      } else {
        MaskPutRect.ty = 0;
        MaskPutRect.Hgt = 0;
      }
      MaskPutRect.Wdt =
          Min<int32_t>(xstart + MatBuffPitch, GBackWdt) - MaskPutRect.x;
      MaskPutRect.Hgt =
          Min<int32_t>(ystart + MatBuffPitch, GBackHgt) - MaskPutRect.y;
    }
    // go through clipping rect
    const FIXED y0 = itofix(pClipRect->ty - MatBuffPitch / 2);
    const FIXED x0 = itofix(pClipRect->tx - MatBuffPitch / 2);
    iTy = pClipRect->y;
    int w = pForObject->SolidMask.Wdt;
    int h = pForObject->SolidMask.Hgt;
    FIXED ya = y0 * Ma2;
    FIXED yb = y0 * Mb2;
    for (ycnt = 0; ycnt < pClipRect->Hgt; ycnt++) {
      iTx = pClipRect->x;
      int i = (ycnt + pClipRect->ty) * MatBuffPitch + pClipRect->tx;
      FIXED xa = x0 * Ma1;
      FIXED xb = x0 * Mb1;
      for (xcnt = 0; xcnt < pClipRect->Wdt; xcnt++) {
        // calc position in solidmask buffer
        int iMx = fixtoi(xa + ya) + w / 2;
        int iMy = fixtoi(xb + yb) + h / 2;
        // in bounds? and solidmask?
        if (iMx >= 0 && iMy >= 0 && iMx < w && iMy < h &&
            pSolidMask[iMy * iPitch + iMx]) {
          // is background mat to be stored?
          if (!MaskPut) {
            // get background pixel
            byPixel = _GBackPix(iTx, iTy);
            // store it. If MCVehic, also store in initial put, but won't be
            // used in restore
            // do not overwrite current value in re-put issued by
            // SolidMask-remover
            if (byPixel != MCVehic || RegularPut)
              pSolidMaskMatBuff[i + xcnt] = byPixel;
          }
          // set mask pix
          _SBackPix(iTx, iTy, MCVehic);
        } else if (!MaskPut)
          // mark pix as unused in buf
          pSolidMaskMatBuff[i + xcnt] = MCVehic;
        xa += Ma1;
        xb += Mb1;
        ++iTx;
      }
      ya += Ma2;
      yb += Mb2;
      ++iTy;
    }
  }
  // Store mask put status
  MaskPut = TRUE;
  // restore attached object positions if moved
  if (fRestoreAttachment && iAttachingObjectsCount) {
    int32_t dx = pForObject->x - MaskRemovalX;
    int32_t dy = pForObject->y - MaskRemovalY;
    if (dx | dy)
      for (int i = 0; i < iAttachingObjectsCount; ++i) {
        C4Object *pObj = ppAttachingObjects[i];
        if (pObj->IsMoveableBySolidMask())
          if (!pObj->Shape.ContactCheck(pObj->x + dx, pObj->y + dy))
            if (pObj->iLastAttachMovementFrame != Game.FrameCounter) {
              pObj->iLastAttachMovementFrame = Game.FrameCounter;
              pObj->MovePosition(dx, dy);
            }
      }
    iAttachingObjectsCount = 0;
  }

  if (fCauseInstability) CheckConsistency();
}
Exemple #12
0
      fullmap_ = tfullmap;

      unsigned int numMaps = maps.size();
      maps_.empty();
      importer_.resize(numMaps);
      for (unsigned i=0; i<numMaps; ++i)
      {
        if (maps[i]!=Teuchos::null)
        {
          XPETRA_RCP_DYNAMIC_CAST(const TpetraMapClass, maps[i], tmapi, "Xpetra::TpetraMapextractor constructors only accept Xpetra::TpetraMap as input arguments.");
          maps_.push_back(tmapi);
          importer_[i] = Teuchos::rcp(new Xpetra::TpetraImport<LocalOrdinal,GlobalOrdinal,Node>(tfullmap,tmapi));
        }
      }
      TEUCHOS_TEST_FOR_EXCEPTION(CheckConsistency()==false,std::logic_error,"logic error. full map and sub maps are inconsistently distributed over the processors.");
    }

    //! TpetraMapExtractor constructor
    TpetraMapExtractor(const Teuchos::RCP<const TpetraMapClass>& fullmap, const std::vector<Teuchos::RCP<const TpetraMapClass> >& maps)
    {
      XPETRA_RCP_DYNAMIC_CAST(const TpetraMapClass, fullmap, tfullmap, "Xpetra::TpetraMapextractor constructors only accept Xpetra::TpetraMap as input arguments.");

      fullmap_ = tfullmap;
      maps_    = maps;

      importer_.resize(maps_.size());
      for (unsigned i=0; i< importer_.size(); ++i)
      {
        if (maps_[i]!=Teuchos::null)
        {
Exemple #13
0
BOOL NNOBOTExtSnd::sender_routine(uint32_t id, uint64_t myNumOTs) {
	uint64_t myStartPos = id * myNumOTs;
	uint64_t wd_size_bits = m_nBlockSizeBits;
	uint64_t processedOTBlocks = min((uint64_t) NUMOTBLOCKS, ceil_divide(myNumOTs, wd_size_bits));
	uint64_t OTsPerIteration = processedOTBlocks * wd_size_bits;
	uint64_t tmpctr, tmpotlen;
	uint32_t nchans = 2;
	bool use_mat_chan = (m_eSndOTFlav == Snd_GC_OT || m_bUseMinEntCorRob);
	if(use_mat_chan) {
		nchans = 3;
	}

	channel* ot_chan = new channel(nchans*id, m_cRcvThread, m_cSndThread);
	channel* check_chan = new channel(nchans*id + 1, m_cRcvThread, m_cSndThread);
	channel* mat_chan;
	if(use_mat_chan) {
		mat_chan = new channel(nchans*id+2, m_cRcvThread, m_cSndThread);
	}

	myNumOTs = min(myNumOTs + myStartPos, m_nOTs) - myStartPos;
	uint64_t lim = myStartPos + myNumOTs;
	uint64_t** rndmat;

	// The vector with the received bits
	CBitVector vRcv(m_nBaseOTs * OTsPerIteration);
	vRcv.Reset();

	// Holds the reply that is sent back to the receiver
	uint32_t numsndvals = 2;
	CBitVector* vSnd;

	CBitVector* seedbuf = new CBitVector[m_nSndVals];
	for (uint32_t u = 0; u < m_nSndVals; u++)
		seedbuf[u].Create(OTsPerIteration * m_cCrypt->get_aes_key_bytes() * 8);
#ifdef ZDEBUG
	cout << "seedbuf size = " <<OTsPerIteration * AES_KEY_BITS << endl;
#endif
	vSnd = new CBitVector[numsndvals];
	for (uint32_t i = 0; i < numsndvals; i++) {
		vSnd[i].Create(OTsPerIteration * m_nBitLength);
	}

	// Contains the parts of the V matrix
	CBitVector Q(wd_size_bits * OTsPerIteration);
	mask_buf_t tmpmaskbuf;

	uint64_t OT_ptr = myStartPos;

	uint8_t *rcvbuftmpptr, *rcvbufptr;

	queue<nnob_snd_check_t> check_queue;
	queue<mask_buf_t> mask_queue;

	uint32_t startpos = 0;
	if(m_eRecOTFlav==Rec_R_OT) {
		startpos = 1;
	}

	if(m_eSndOTFlav == Snd_GC_OT) {
		initRndMatrix(&rndmat, m_nBitLength, m_nBaseOTs);
	}

#ifdef OTTiming
	double totalMtxTime = 0, totalTnsTime = 0, totalHshTime = 0, totalRcvTime = 0, totalSndTime = 0, totalUnMaskTime = 0,
			totalHashCheckTime = 0;
	timeval tempStart, tempEnd;
#endif

	while (OT_ptr < lim) //do while there are still transfers missing
	{
		processedOTBlocks = min((uint64_t) NUMOTBLOCKS, ceil_divide(lim - OT_ptr, wd_size_bits));
		OTsPerIteration = processedOTBlocks * wd_size_bits;

#ifdef ZDEBUG
		cout << "Processing block " << nProgress << " with length: " << OTsPerIteration << ", and limit: " << lim << endl;
#endif

#ifdef OTTiming
		gettimeofday(&tempStart, NULL);
#endif
		rcvbufptr = ot_chan->blocking_receive_id_len(&rcvbuftmpptr, &tmpctr, &tmpotlen);
		//vRcv.AttachBuf(rcvbuftmpptr, bits_in_bytes(m_nBaseOTs * OTsPerIteration));
		vRcv.SetBytes(rcvbuftmpptr, bits_in_bytes(OTsPerIteration*startpos), bits_in_bytes((m_nBaseOTs-startpos)*OTsPerIteration));
		free(rcvbufptr);
		//vRcv.PrintHex();
#ifdef OTTiming
		gettimeofday(&tempEnd, NULL);
		totalRcvTime += getMillies(tempStart, tempEnd);
		gettimeofday(&tempStart, NULL);
#endif
		BuildQMatrix(Q, OT_ptr, processedOTBlocks);
#ifdef OTTiming
		gettimeofday(&tempEnd, NULL);
		totalMtxTime += getMillies(tempStart, tempEnd);
		gettimeofday(&tempStart, NULL);
#endif
		check_queue.push(UpdateCheckBuf(Q.GetArr(), vRcv.GetArr(), OT_ptr, processedOTBlocks, check_chan));
		FillAndSendRandomMatrix(rndmat, mat_chan);
#ifdef OTTiming
		gettimeofday(&tempEnd, NULL);
		totalHashCheckTime += getMillies(tempStart, tempEnd);
		gettimeofday(&tempStart, NULL);
#endif
		UnMaskBaseOTs(Q, vRcv, processedOTBlocks);

		GenerateSendAndXORCorRobVector(Q, OTsPerIteration, mat_chan);

#ifdef OTTiming
		gettimeofday(&tempEnd, NULL);
		totalUnMaskTime += getMillies(tempStart, tempEnd);
		gettimeofday(&tempStart, NULL);
#endif
		Q.Transpose(wd_size_bits, OTsPerIteration);
#ifdef OTTiming
		gettimeofday(&tempEnd, NULL);
		totalTnsTime += getMillies(tempStart, tempEnd);
		gettimeofday(&tempStart, NULL);
#endif
		HashValues(Q, seedbuf, vSnd, OT_ptr, min(lim - OT_ptr, OTsPerIteration), rndmat);
#ifdef OTTiming
		gettimeofday(&tempEnd, NULL);
		totalHshTime += getMillies(tempStart, tempEnd);
		gettimeofday(&tempStart, NULL);
#endif

		//TODO: outsource into method
		tmpmaskbuf.otid = OT_ptr;
		tmpmaskbuf.otlen = min(lim - OT_ptr, OTsPerIteration);
		tmpmaskbuf.maskbuf = new CBitVector[numsndvals];
		for(uint32_t i = 0; i < numsndvals; i++)
			tmpmaskbuf.maskbuf[i].Copy(vSnd[i]);
		mask_queue.push(tmpmaskbuf);

		if(check_chan->data_available()) {
			assert(CheckConsistency(&check_queue, check_chan));//TODO assert
			tmpmaskbuf = mask_queue.front();
			mask_queue.pop();
			MaskAndSend(tmpmaskbuf.maskbuf, tmpmaskbuf.otid, tmpmaskbuf.otlen, ot_chan);
		}
#ifdef OTTiming
		gettimeofday(&tempEnd, NULL);
		totalSndTime += getMillies(tempStart, tempEnd);
#endif
		OT_ptr += min(lim - OT_ptr, OTsPerIteration);
		Q.Reset();

		//free(rcvbufptr);
	}

	while(!check_queue.empty()) {
		if(check_chan->data_available()) {
			assert(CheckConsistency(&check_queue, check_chan));//TODO assert
			tmpmaskbuf = mask_queue.front();
			mask_queue.pop();
			MaskAndSend(tmpmaskbuf.maskbuf, tmpmaskbuf.otid, tmpmaskbuf.otlen, ot_chan);
		}
	}

	//vRcv.delCBitVector();
	ot_chan->synchronize_end();
	check_chan->synchronize_end();

	Q.delCBitVector();
	for (uint32_t u = 0; u < m_nSndVals; u++)
		seedbuf[u].delCBitVector();

	for (uint32_t i = 0; i < numsndvals; i++)
		vSnd[i].delCBitVector();
	if (numsndvals > 0)
		free(vSnd);

	if(use_mat_chan) {
		mat_chan->synchronize_end();
	}

	if(m_eSndOTFlav == Snd_GC_OT) {
		freeRndMatrix(rndmat, m_nBaseOTs);
	}
#ifdef OTTiming
	cout << "Sender time benchmark for performing " << myNumOTs << " OTs on " << m_nBitLength << " bit strings" << endl;
	cout << "Time needed for: " << endl;
	cout << "\t Matrix Generation:\t" << totalMtxTime << " ms" << endl;
	cout << "\t BaseOT Unmasking:\t" << totalUnMaskTime << " ms" << endl;
	cout << "\t Check Hashing:\t" << totalHashCheckTime << " ms" << endl;
	cout << "\t Sending Matrix:\t" << totalSndTime << " ms" << endl;
	cout << "\t Transposing Matrix:\t" << totalTnsTime << " ms" << endl;
	cout << "\t Hashing Matrix:\t" << totalHshTime << " ms" << endl;
	cout << "\t Receiving Values:\t" << totalRcvTime << " ms" << endl;
#endif


	delete ot_chan;
	delete check_chan;
	return TRUE;
}
void GoRegionBoard::OnUndoneMove()
// Called after a move has been undone. The board is guaranteed to be in
// a legal state.
{
    //SG_ASSERT(false); // incremental code is incomplete, do not call
    if (DEBUG_REGION_BOARD)
        SgDebug() << "OnUndoneMove " << '\n';

    const bool IS_UNDO = false;
    SgVectorOf<GoRegion> changed;

    for (int val = m_stack.PopEvent(); val != SG_NEXTMOVE;
         val = m_stack.PopEvent())
    {

        switch (val)
        {
            case REGION_REMOVE:
            {   GoRegion* r = static_cast<GoRegion*>(m_stack.PopPtr());
                AddRegion(r, IS_UNDO);
                changed.Insert(r);
            }
            break;
            case REGION_ADD:
            {   GoRegion* r = static_cast<GoRegion*>(m_stack.PopPtr());
                RemoveRegion(r, IS_UNDO);
            }
            break;
            case REGION_REMOVE_BLOCK:
            {   GoBlock* b = static_cast<GoBlock*>(m_stack.PopPtr());
                AddBlock(b, IS_UNDO);
                for (int nu = m_stack.PopInt(); nu > 0; --nu)
                {
                    GoRegion* r = static_cast<GoRegion*>(m_stack.PopPtr());
                    if (CHECK)
                        SG_ASSERT(! r->Blocks().Contains(b));
                    r->BlocksNonConst().PushBack(b);
                    changed.Insert(r);
                }
            }
            break;
            case REGION_ADD_BLOCK:
            {   GoBlock* b = static_cast<GoBlock*>(m_stack.PopPtr());
                RemoveBlock(b, IS_UNDO, true);
            }
            break;
            case REGION_ADD_STONE:
            {   GoRegion* r = static_cast<GoRegion*>(m_stack.PopPtr());
                SgPoint p = m_stack.PopInt();
                r->OnRemoveStone(p);
                m_region[r->Color()][p] = r;
                changed.Insert(r);
            }
            break;
            case REGION_ADD_STONE_TO_BLOCK:
            {   GoBlock* b = static_cast<GoBlock*>(m_stack.PopPtr());
                SgPoint p = m_stack.PopInt();
                b->RemoveStone(p);
                m_block[p] = 0;
            }
            break;
            default:
                SG_ASSERT(false);
        }
    }

    for (SgVectorIteratorOf<GoRegion> it(changed); it; ++it)
    {
        (*it)->ResetNonBlockFlags();
        (*it)->ComputeBasicFlags();
    }

    if (HEAVYCHECK)
    {
        for (SgBWIterator it; it; ++it)
        {
            SgBlackWhite color(*it);
            for (SgVectorIteratorOf<GoRegion> it(AllRegions(color)); it; ++it)
            {
                const GoRegion* r = *it;
                SG_UNUSED(r);
                SG_ASSERT(r->IsValid());
            }
        }
    }

    m_code = Board().GetHashCode();
    if (HEAVYCHECK)
        CheckConsistency();
}
//______________________________________________________________________________
TFractionFitter::TFractionFitter(TH1* data, TObjArray  *MCs, Option_t *option) :
fFitDone(kFALSE), fChisquare(0), fPlot(0)  {
   // TFractionFitter constructor. Does a complete initialisation (including
   // consistency checks, default fit range as the whole histogram but without
   // under- and overflows, and declaration of the fit parameters). Note that
   // the histograms are not copied, only references are used.
   // Arguments:
   //     data: histogram to be fitted
   //     MCs:  array of TH1* corresponding template distributions
   //    Option:  can be used to control the print level of the minimization algorithm
   //             option = "Q"  : quite - no message is printed
   //             option = "V"  : verbose - max print out
   //             option = ""   : default: print initial fraction values and result

   fData = data;
   // Default: include all of the histogram (but without under- and overflows)
   fLowLimitX = 1;
   fHighLimitX = fData->GetNbinsX();
   if (fData->GetDimension() > 1) {
      fLowLimitY = 1;
      fHighLimitY = fData->GetNbinsY();
      if (fData->GetDimension() > 2) {
         fLowLimitZ = 1;
         fHighLimitZ = fData->GetNbinsZ();
      }
   }
   fNpar = MCs->GetEntries();
   Int_t par;
   for (par = 0; par < fNpar; ++par) {
      fMCs.Add(MCs->At(par));
      // Histogram containing template prediction
      TString s = Form("Prediction for MC sample %i",par);
      TH1* pred = (TH1*) ((TH1*)MCs->At(par))->Clone(s);
      pred->SetTitle(s);
      fAji.Add(pred);
   }
   fIntegralMCs = new Double_t[fNpar];
   fFractions = new Double_t[fNpar];

   CheckConsistency();
   fWeights.Expand(fNpar);

   fractionFitter = TVirtualFitter::Fitter(this, fNpar);
   fractionFitter->Clear();
   fractionFitter->SetObjectFit(this);
   fractionFitter->SetFCN(TFractionFitFCN);

   // set print level
   TString opt(option);
   opt.ToUpper();
   double plist[1];
   if (opt.Contains("Q") ) {
      plist[0] = -1;
      fractionFitter->ExecuteCommand("SET PRINT",plist,1);
      fractionFitter->ExecuteCommand("SET NOW",plist,0);
   }
   else if (opt.Contains("V") ) {
      plist[0] =  1;
      fractionFitter->ExecuteCommand("SET PRINT",plist,1);
   }

   Double_t defaultFraction = 1.0/((Double_t)fNpar);
   Double_t defaultStep = 0.01;
   for (par = 0; par < fNpar; ++par) {
      TString name("frac"); name += par;
      fractionFitter->SetParameter(par, name.Data(), defaultFraction, defaultStep, 0, 0);
   }
}
Exemple #16
0
 //! EpetraMap constructor to wrap a Epetra_Map object
 StridedEpetraMap(const Teuchos::RCP<const Epetra_BlockMap> &map, std::vector<size_t>& stridingInfo, LocalOrdinal stridedBlockId=-1, GlobalOrdinal offset = 0) 
   : EpetraMap(map), StridedMap<int, int>(stridingInfo, stridedBlockId, offset) { 
   int nDofsPerNode = Teuchos::as<int>(getFixedBlockSize());
   TEUCHOS_TEST_FOR_EXCEPTION(map_->NumMyPoints() % nDofsPerNode != 0, Exceptions::RuntimeError, "StridedEpetraMap::StridedEpetraMap: wrong distribution of dofs among processors.");
   TEUCHOS_TEST_FOR_EXCEPTION(CheckConsistency() == false, Exceptions::RuntimeError, "StridedEpetraMap::StridedEpetraMap: CheckConsistency() == false");
 }
Exemple #17
0
void C4SolidMask::Remove(bool fCauseInstability, bool fBackupAttachment) {
  // If put, restore background pixels from buffer

  // Not put
  if (!MaskPut || !pSolidMask || !pSolidMaskMatBuff) return;

  CheckConsistency();

  // reput background pixels
  for (int ycnt = 0; ycnt < MaskPutRect.Hgt; ++ycnt) {
    BYTE *pPix = pSolidMaskMatBuff + (ycnt + MaskPutRect.ty) * MatBuffPitch +
                 MaskPutRect.tx;
    for (int xcnt = 0; xcnt < MaskPutRect.Wdt; ++xcnt, ++pPix)
      // only if mask was used here
      if (*pPix != MCVehic) {
        // calc position in landscape
        int iTx = MaskPutRect.x + xcnt;
        int iTy = MaskPutRect.y + ycnt;
        // restore pixel here
        // The pPix-check ensures that only pixels that hads been overwritten by
        // this SolidMask are restored
        // Non-SolidMask-pixels should not happen here, because all relevant
        // landscape change routines should
        // temp remove SolidMasks before
        assert(_GBackPix(iTx, iTy) == MCVehic);
        _SBackPixIfMask(iTx, iTy, *pPix, MCVehic);
        // Instability
        if (fCauseInstability) Game.Landscape.CheckInstabilityRange(iTx, iTy);
      }
  }
  // Mask not put flag
  MaskPut = false;
  // update surrounding masks in that range
  C4TargetRect ClipRect;
  for (C4SolidMask *pSolid = C4SolidMask::Last; pSolid; pSolid = pSolid->Prev)
    if (pSolid->MaskPut)
      if (pSolid->MaskPutRect.Overlap(MaskPutRect)) {
        // set clipping rect for all calls, since they may modify it
        ClipRect.Set(MaskPutRect.x, MaskPutRect.y, MaskPutRect.Wdt,
                     MaskPutRect.Hgt, 0, 0);
        // doubled solidmask-pixels have just been removed in the clipped area!
        pSolid->MaskPut = false;
        // re-put the solidmask
        pSolid->Put(false, &ClipRect, false);
      }

  // backup attachment if desired: Backup old pos and all objects that attach to
  // or lie on the SolidMask
  if (fBackupAttachment) {
    MaskRemovalX = pForObject->x;
    MaskRemovalY = pForObject->y;
    iAttachingObjectsCount = 0;
    C4LArea SolidArea(&Game.Objects.Sectors, MaskPutRect.x - 1,
                      MaskPutRect.y - 1, MaskPutRect.Wdt + 2,
                      MaskPutRect.Hgt + 2);
    C4LSector *pSct;
    C4Object *pObj;
    for (C4ObjectList *pLst = SolidArea.FirstObjectShapes(&pSct); pLst;
         pLst = SolidArea.NextObjectShapes(pLst, &pSct))
      for (C4ObjectLink *clnk = pLst->First; clnk; clnk = clnk->Next)
        if ((pObj = clnk->Obj) && pObj != pForObject &&
            pObj->IsMoveableBySolidMask() &&
            !pObj->Shape.CheckContact(pObj->x, pObj->y)) {
          // check for any contact to own SolidMask - attach-directions, bottom
          // - "stuck" (CNAT_Center) is ignored, because that causes problems
          // with things being stuck in basements :(
          int iVtx = 0;
          for (; iVtx < pObj->Shape.VtxNum; ++iVtx)
            if (pObj->Shape.GetVertexContact(
                    iVtx, pObj->Action.t_attach | CNAT_Bottom, pObj->x, pObj->y,
                    DensityProvider(pForObject, *this)))
              if (pObj->Shape.GetVertexContact(
                      iVtx, pObj->Action.t_attach | CNAT_Bottom, pObj->x,
                      pObj->y, DensityProvider(pForObject, *this)))
                break;
          if (iVtx == pObj->Shape.VtxNum) continue;  // no contact
          // contact: Add object to list
          if (iAttachingObjectsCapacity == iAttachingObjectsCount) {
            iAttachingObjectsCapacity += 4;
            C4Object **ppNewAttachingObjects =
                new C4Object *[iAttachingObjectsCapacity];
            if (iAttachingObjectsCount)
              memcpy(ppNewAttachingObjects, ppAttachingObjects,
                     sizeof(C4Object *) * iAttachingObjectsCount);
            delete[] ppAttachingObjects;
            ppAttachingObjects = ppNewAttachingObjects;
          }
          ppAttachingObjects[iAttachingObjectsCount++] = pObj;
        }
  }

  CheckConsistency();
}