Example #1
0
TFiniteAutomaton& TFiniteAutomaton::Enumerate() {
    vector<size_t> newIndexes(Size());
    size_t newIndex = 0;

    vector<bool> visited(Size());  // TODO: maybe vector<char> ? Compare performance
    visited[StartState] = true;
    std::deque<size_t> que;
    que.push_front(StartState);
    while (!que.empty()) {
        size_t state = que.front();
        que.pop_front();
        newIndexes[state] = newIndex++;
        const TTransitions& tran = States[state].Transitions;
        TTransitions::const_iterator it = tran.find(EPSILON);
        for (TTransitions::const_iterator it = tran.begin(), end = tran.end(); it != end; ++it)
            for (TStateIdSet::const_iterator stIt = it->second.begin(), stEnd = it->second.end(); stIt != stEnd; ++stIt)
                if (!visited[*stIt]) {
                    visited[*stIt] = true;
                    que.push_back(*stIt);
                }
    }

    // and now enumerate not visited states
    for (size_t i = 0, size = newIndexes.size(); i < size; ++i) {
        if (!visited[i])
            newIndexes[i] == newIndex++;
    }

    vector<TState> newStates(Size());
    for (size_t i = 0, size = Size(); i < size; ++i) {
        TState& newState = newStates[newIndexes[i]];
        newState.Swap(States[i]);
        TTransitions& tran = newState.Transitions;
        for (TTransitions::iterator trIt = tran.begin(), trEnd = tran.end(); trIt != trEnd; ++trIt) {
            // TODO: make incrementing iterator
            TStateIdSet newSet;
            for (TStateIdSet::const_iterator stIt = trIt->second.begin(), stEnd = trIt->second.end(); stIt != stEnd; ++stIt)
                newSet.insert(newIndexes[*stIt]);
            trIt->second.swap(newSet);
        }
    }

    States.swap(newStates);

    StartState = newIndexes[StartState];
    TStateIdSet newFinals;
    for (TStateIdSet::const_iterator it = FinalStates.begin(), end = FinalStates.end(); it != end; ++it)
        newFinals.insert(newIndexes[*it]);
    FinalStates.swap(newFinals);

    return *this;
}
Example #2
0
NS_IMETHODIMP
nsXTFElementWrapper::SetIntrinsicState(nsEventStates::InternalType aNewState)
{
  nsIDocument *doc = GetCurrentDoc();
  nsEventStates newStates(aNewState);
  nsEventStates bits = mIntrinsicState ^ newStates;

  if (!doc || bits.IsEmpty())
    return NS_OK;

  NS_WARN_IF_FALSE(!newStates.HasAllStates(NS_EVENT_STATE_MOZ_READONLY |
                                           NS_EVENT_STATE_MOZ_READWRITE),
                   "Both READONLY and READWRITE are being set.  Yikes!!!");

  mIntrinsicState = newStates;
  mozAutoDocUpdate upd(doc, UPDATE_CONTENT_STATE, PR_TRUE);
  doc->ContentStateChanged(this, bits);

  return NS_OK;
}
Example #3
0
bool ompl::geometric::PathSimplifier::reduceVertices(PathGeometric &path, unsigned int maxSteps, unsigned int maxEmptySteps, double rangeRatio)
{
    if (path.getStateCount() < 3)
        return false;

    if (maxSteps == 0)
        maxSteps = path.getStateCount();

    if (maxEmptySteps == 0)
        maxEmptySteps = path.getStateCount();

    bool result = false;
    unsigned int nochange = 0;
    const base::SpaceInformationPtr &si = path.getSpaceInformation();
    std::vector<base::State*> &states = path.getStates();

    if (si->checkMotion(states.front(), states.back()))
    {
        if (freeStates_)
            for (std::size_t i = 2 ; i < states.size() ; ++i)
                si->freeState(states[i-1]);
        std::vector<base::State*> newStates(2);
        newStates[0] = states.front();
        newStates[1] = states.back();
        states.swap(newStates);
        result = true;
    }
    else
        for (unsigned int i = 0 ; i < maxSteps && nochange < maxEmptySteps ; ++i, ++nochange)
        {
            int count = states.size();
            int maxN  = count - 1;
            int range = 1 + (int)(floor(0.5 + (double)count * rangeRatio));

            int p1 = rng_.uniformInt(0, maxN);
            int p2 = rng_.uniformInt(std::max(p1 - range, 0), std::min(maxN, p1 + range));
            if (abs(p1 - p2) < 2)
            {
                if (p1 < maxN - 1)
                    p2 = p1 + 2;
                else
                    if (p1 > 1)
                        p2 = p1 - 2;
                    else
                        continue;
            }

            if (p1 > p2)
                std::swap(p1, p2);

            if (si->checkMotion(states[p1], states[p2]))
            {
                if (freeStates_)
                    for (int j = p1 + 1 ; j < p2 ; ++j)
                        si->freeState(states[j]);
                states.erase(states.begin() + p1 + 1, states.begin() + p2);
                nochange = 0;
                result = true;
            }
        }
    return result;
}