Ejemplo n.º 1
0
void nofGeologist::HandleDerivedEvent(const unsigned int id)
{
    switch(state)
    {
        default:
            break;
        case STATE_GEOLOGIST_DIG:
        {
            // Ressourcen an diesem Punkt untersuchen
            unsigned char resources = gwg->GetNode(pos).resources;


            if((resources >= 0x41 && resources <= 0x47) || (resources >= 0x49 && resources <= 0x4F) ||
                    (resources >= 0x51 && resources <= 0x57) || (resources >= 0x59 && resources <= 0x5F) ||
                    (resources >= 0x21 && resources <= 0x2F))
            {
                // Es wurde was gefunden, erstmal Jubeln
                state = STATE_GEOLOGIST_CHEER;
                current_ev = em->AddEvent(this, 15, 1);
            }
            else
            {
                // leeres Schild hinstecken und ohne Jubel weiterziehen
                SetSign(resources);
                GoToNextNode();
                /// Punkt wieder freigeben
                gwg->GetNode(pos).reserved = false;;
            }

        } break;
        case STATE_GEOLOGIST_CHEER:
        {
            // Schild reinstecken
            SetSign(gwg->GetNode(pos).resources);
            // Und weiterlaufen
            GoToNextNode();
            /// Punkt wieder freigeben
            gwg->GetNode(pos).reserved = false;;
            /// Sounds evtl löschen
            SOUNDMANAGER.WorkingFinished(this);
        } break;
    }
}
Ejemplo n.º 2
0
void nofGeologist::HandleDerivedEvent(const unsigned /*id*/)
{
    switch(state)
    {
        default: break;
        case STATE_GEOLOGIST_DIG:
        {
            // Check what is here
            Resource foundRes = gwg->GetNode(pos).resources;
            // We don't care for fish (and most likely never find it)
            if(foundRes.getType() == Resource::Fish)
                foundRes.setType(Resource::Nothing);

            if(foundRes.getAmount() > 0u)
            {
                // Es wurde was gefunden, erstmal Jubeln
                state = STATE_GEOLOGIST_CHEER;
                current_ev = GetEvMgr().AddEvent(this, 15, 1);
            } else
            {
                // leeres Schild hinstecken und ohne Jubel weiterziehen
                SetSign(foundRes);
                /// Punkt wieder freigeben
                gwg->SetReserved(pos, false);
                GoToNextNode();
            }
        }
        break;
        case STATE_GEOLOGIST_CHEER:
        {
            // Schild reinstecken
            SetSign(gwg->GetNode(pos).resources);
            /// Punkt wieder freigeben
            gwg->SetReserved(pos, false);
            /// Sounds evtl löschen
            SOUNDMANAGER.WorkingFinished(this);
            // Und weiterlaufen
            GoToNextNode();
        }
        break;
    }
}
Ejemplo n.º 3
0
void
_DtTermPrimParserSaveSign
(
    Widget w
)
{
    ParserContext   context = GetParserContext(w);

    SetSign(context, (*GetInputChar(context) == '-') ? TermPARSER_SIGNnegative :
	    TermPARSER_SIGNpositive);
}
Ejemplo n.º 4
0
int MatrixDense<T>::Equil(T *d, T *e) {
  DEBUG_ASSERT(this->_done_init);
  if (!this->_done_init)
    return 1;

  // Number of elements in matrix.
  size_t num_el = this->_m * this->_n;

  // Create bit-vector with signs of entries in A and then let A = f(A),
  // where f = |A| or f = |A|.^2.
  unsigned char *sign = 0;
  size_t num_sign_bytes = (num_el + 7) / 8;
  sign = new unsigned char[num_sign_bytes];
  ASSERT(sign != 0);

  // Fill sign bits, assigning each thread a multiple of 8 elements.
  size_t num_chars = num_el / 8;
  if (kNormEquilibrate == kNorm2 || kNormEquilibrate == kNormFro) {
    SetSign(_data, sign, num_chars, SquareF<T>());
  } else {
    SetSign(_data, sign, num_chars, AbsF<T>());
  }

  // If numel(A) is not a multiple of 8, then we need to set the last couple
  // of sign bits too. 
  if (num_el > num_chars * 8) {
    if (kNormEquilibrate == kNorm2 || kNormEquilibrate == kNormFro) {
      SetSignSingle(_data + num_chars * 8, sign + num_chars,
          num_el - num_chars * 8, SquareF<T>());
    } else {
      SetSignSingle(_data + num_chars * 8, sign + num_chars, 
          num_el - num_chars * 8, AbsF<T>());
    }
  }

  // Perform Sinkhorn-Knopp equilibration.
  SinkhornKnopp(this, d, e);

  // Transform A = sign(A) .* sqrt(A) if 2-norm equilibration was performed,
  // or A = sign(A) .* A if the 1-norm was equilibrated.
  if (kNormEquilibrate == kNorm2 || kNormEquilibrate == kNormFro) {
    UnSetSign(_data, sign, num_chars, SqrtF<T>());
  } else {
    UnSetSign(_data, sign, num_chars, IdentityF<T>());
  }

  // Deal with last few entries if num_el is not a multiple of 8.
  if (num_el > num_chars * 8) {
    if (kNormEquilibrate == kNorm2 || kNormEquilibrate == kNormFro) {
     UnSetSignSingle(_data + num_chars * 8, sign + num_chars, 
          num_el - num_chars * 8, SqrtF<T>());
    } else {
      UnSetSignSingle(_data + num_chars * 8, sign + num_chars, 
          num_el - num_chars * 8, IdentityF<T>());
    }
  }

  // Compute D := sqrt(D), E := sqrt(E), if 2-norm was equilibrated.
  if (kNormEquilibrate == kNorm2 || kNormEquilibrate == kNormFro) {
    std::transform(d, d + this->_m, d, SqrtF<T>());
    std::transform(e, e + this->_n, e, SqrtF<T>());
  }

  // Compute A := D * A * E.
  MultDiag(d, e, this->_m, this->_n, _ord, _data);

  // Scale A to have norm of 1 (in the kNormNormalize norm).
  T normA = NormEst(kNormNormalize, *this);
  gsl::vector<T> a_vec = gsl::vector_view_array(_data, num_el);
  gsl::vector_scale(&a_vec, 1 / normA);

  // Scale d and e to account for normalization of A.
  gsl::vector<T> d_vec = gsl::vector_view_array<T>(d, this->_m);
  gsl::vector<T> e_vec = gsl::vector_view_array<T>(e, this->_n);
  gsl::vector_scale(&d_vec, 1 / std::sqrt(normA));
  gsl::vector_scale(&e_vec, 1 / std::sqrt(normA));

  DEBUG_PRINTF("norm A = %e, normd = %e, norme = %e\n", normA,
      gsl::blas_nrm2(&d_vec), gsl::blas_nrm2(&e_vec));

  delete [] sign;

  return 0;
}