Esempio n. 1
0
void TNearestNeighbor::PartialFit(const TIntFltKdV& Vec, const int& RecId) {
    if (InitVecs < WindowSize) {
        // not yet full, extend matrix and distance vectors
        Mat.Add(Vec);
		IDVec.Add(RecId);
        // make sure we are very far from everything for update distance to kick in
        DistV.Add(TFlt::Mx); DistColV.Add(InitVecs);
        // update distance for new vector
        UpdateDistance(InitVecs);
        // move onwards
        InitVecs++;
        // check if we are initialized
        if (InitVecs == WindowSize) { UpdateThreshold(); }
    } else {
        // we are full, make space first
        Forget(NextCol);
        // overwrite
        Mat[NextCol] = Vec;
		IDVec[NextCol] = RecId;
        DistV[NextCol] = TFlt::Mx;
        DistColV[NextCol] = NextCol;
        // update distance for overwriten vector
        UpdateDistance(NextCol);
        // establish new threshold
        UpdateThreshold();
        // move onwards
        NextCol++;
        if (NextCol >= WindowSize) { NextCol = 0; }
    }
}
void MovingMonsters::FillDistances()
{
	_currentDistance = 0;
	_somethingChanged = true;
	while (_somethingChanged) //нашлись ли еще ходы
	{
		_somethingChanged = false; //сбрасываем флажок
		//перебираем клетки
		for (int row = _fieldBottom; row <= _fieldTop; row++)
		{
			for (int col = _fieldLeft; col <= _fieldRight; col++)
			{
				Game::FieldAddress fa(col, row);
				if (_movesToRecievers[fa] == _currentDistance) //из этой надо двигаться дальше
				{
					//специально проверяем приемник с заказом
					if (_currentDistance == 0) //расстояние 0 значит приемник прямо тут
					{
						EnergyReceiver *reciever = Gadgets::receivers.GetReceiverOnSquare(fa);
						if (reciever && reciever->IsOrdered())
						{   //если есть заказ то придти к приемнику один фиг нельзя
							continue;
						}
					}

					UpdateDistance(fa, fa.UP);
					UpdateDistance(fa, fa.LEFT);
					UpdateDistance(fa, fa.RIGHT);
					UpdateDistance(fa, fa.DOWN);
				}
			}
		}
		++_currentDistance;
	}
}
Esempio n. 3
0
	DamerauLevenshteinDistance::DamerauLevenshteinDistance(const String &reference, const String &target)
		: reference_(reference), current_index_(0), num_rows_(1), min_distance_(0)
	{
		distance_matrix_ = new int*[3];
		for (int i = 0; i < 3; ++i)
			distance_matrix_[i] = new int[reference.length() + 1];
		// Computes the distance between the null string and reference
		distance_matrix_[0][0] = 0;
		for (int i = 1; i < reference.length() + 1; ++i)
			distance_matrix_[0][i] = i;
		UpdateDistance(target);
	}
Esempio n. 4
0
void TNearestNeighbor::Forget(const int& ColId) {
    // identify which vectors we should update
    TIntV CheckV;
    for (int ColN = 0; ColN < Mat.Len(); ColN++) {
        // skip self
        if (ColN == ColId) { continue; }
        // we are the nearest neighbor, need to find a new one
        if (DistColV[ColN] == ColId) { CheckV.Add(ColN); }
    }
    // reasses
    for (const int ColN : CheckV) {
        // update distance for ColN ignoring vector ColId
        UpdateDistance(ColN, ColId);
    }
}