Esempio n. 1
0
void
ContestDijkstra::AddEdges(const ScanTaskPoint origin,
                          const unsigned first_point)
{
  ScanTaskPoint destination(origin.GetStageNumber() + 1,
                            std::max(origin.GetPointIndex(), first_point));

  const int min_altitude = IsFinal(destination)
    ? GetMinimumFinishAltitude(GetPoint(FindStart(origin)))
    : 0;

  if (IsFinal(destination) &&
      first_finish_candidate > destination.GetPointIndex())
    /* limit the number of finish candidates during incremental
       search */
    destination.SetPointIndex(first_finish_candidate);

  const unsigned weight = GetStageWeight(origin.GetStageNumber());

  for (const ScanTaskPoint end(destination.GetStageNumber(), n_points);
       destination != end; destination.IncrementPointIndex()) {
    if (GetPoint(destination).GetIntegerAltitude() >= min_altitude) {
      const unsigned d = weight * CalcEdgeDistance(origin, destination);
      Link(destination, origin, d);
    }
  }

}
Esempio n. 2
0
void
ContestDijkstra::AddEdges(const ScanTaskPoint origin,
                          const unsigned first_point)
{
  ScanTaskPoint destination(origin.GetStageNumber() + 1,
                            std::max(origin.GetPointIndex(), first_point));

  const int min_altitude = IsFinal(destination)
    ? GetMinimumFinishAltitude(GetPoint(FindStart(origin)))
    : 0;

  if (IsFinal(destination) &&
      first_finish_candidate > destination.GetPointIndex())
    /* limit the number of finish candidates during incremental
       search */
    destination.SetPointIndex(first_finish_candidate);

  const unsigned weight = GetStageWeight(origin.GetStageNumber());

  bool previous_above = false;
  for (const ScanTaskPoint end(destination.GetStageNumber(), n_points);
       destination != end; destination.IncrementPointIndex()) {
    bool above = GetPoint(destination).GetIntegerAltitude() >= min_altitude;

    if (above) {
      const unsigned d = weight * CalcEdgeDistance(origin, destination);
      Link(destination, origin, d);
    } else if (previous_above) {
      /* After excessive thinning, the exact TracePoint that matches
         the required altitude difference may be gone, and the
         calculated result becomes overly pessimistic.  This code path
         makes it optimistic, by checking if the previous point
         matches. */

      /* TODO: interpolate the distance */
      const unsigned d = weight * CalcEdgeDistance(origin, destination);
      Link(destination, origin, d);
    }

    previous_above = above;
  }

  if (IsFinal(destination) && predicted.IsDefined()) {
    const unsigned d = weight * GetPoint(origin).FlatDistanceTo(predicted);
    destination.SetPointIndex(predicted_index);
    Link(destination, origin, d);
  }
}
Esempio n. 3
0
void
OLCTriangle::AddFinishEdges(const ScanTaskPoint origin)
{
  assert(IsFinal(origin.GetStageNumber() + 1));

  if (predict) {
    // dummy just to close the triangle
    Link(ScanTaskPoint(origin.GetStageNumber() + 1, n_points - 1), origin, 0);
  } else {
    const ScanTaskPoint start = FindStart(origin);
    const TracePoint &start_point = GetPoint(start);
    const TracePoint &origin_point = GetPoint(origin);

    const unsigned max_range =
      trace_master.ProjectRange(origin_point.GetLocation(), max_distance);

    /* check all remaining points, see which ones match the
       conditions */
    const ScanTaskPoint begin(origin.GetStageNumber() + 1, 0);
    const ScanTaskPoint end(origin.GetStageNumber() + 1,
                            origin.GetPointIndex());
    for (ScanTaskPoint i = begin; i != end; i.IncrementPointIndex())
      if (CalcEdgeDistance(start, i) <= max_range &&
          start_point.GetLocation().Distance(GetPoint(i).GetLocation()) < max_distance)
        Link(i, origin, CalcEdgeDistance(origin, i));
  }
}
Esempio n. 4
0
void
OLCSprint::AddEdges(const ScanTaskPoint origin)
{
  const ScanTaskPoint destination(origin.GetStageNumber() + 1, n_points - 1);
  if (IsFinal(destination)) {
    /* For final, only add last valid point */
    const unsigned d = GetStageWeight(origin.GetStageNumber()) *
      CalcEdgeDistance(origin, destination);
    Link(destination, origin, d);
  } else
    ContestDijkstra::AddEdges(origin);
}
Esempio n. 5
0
/**
 * This function update count of stream
 * @brief Stream::Update
 * @return void
 */
void Stream::Update()
{
     ActualizarContadores();
   // QTimer::singleShot(30, this, SLOT(ActualizarContadores())); // el consumo de cpu es 0

    if (IsFinal(streamUltimo))
    {
        if(Timer->isActive ())
        {
            Timer->stop();
            emit  Finish();
        }
    }


}
Esempio n. 6
0
void
ContestDijkstra::AddIncrementalEdges(unsigned first_point)
{
  assert(first_point < n_points);
  assert(continuous);
  assert(incremental);
  assert(finished);

  finished = false;
  first_finish_candidate = first_point;

  /* we need a copy of the current edge map, because the following
     loop will modify it, invalidating the iterator */
#if GCC_VERSION < 40800 || GCC_VERSION > 40802
  const Dijkstra::EdgeMap edges = dijkstra.GetEdgeMap();
#else
  // workaround for http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59548
  Dijkstra::EdgeMap edges;
  edges = dijkstra.GetEdgeMap();
#endif

  /* establish links between each old node and each new node, to
     initiate the follow-up search, hoping a better solution will be
     found here */
  for (const auto &i : edges) {
    if (IsFinal(i.first))
      /* ignore final nodes */
      continue;

    /* "seek" the Dijkstra object to the current "old" node */
    dijkstra.SetCurrentValue(i.second.value);

    /* add edges from the current "old" node to all "new" nodes
       (first_point .. n_points-1) */
    AddEdges(i.first, first_point);
  }

  /* see if new start points are possible now (due to relaxed start
     height constraints); duplicates will be ignored by the Dijkstra
     class */
  AddStartEdges();
}
Esempio n. 7
0
void
ContestDijkstra::AddIncrementalEdges(unsigned first_point)
{
  assert(first_point < n_points);
  assert(continuous);
  assert(incremental);
  assert(finished);

  finished = false;
  first_finish_candidate = first_point;

  /* we need a copy of the current edge map, because the following
     loop will modify it, invalidating the iterator */
  const Dijkstra::EdgeMap edges = dijkstra.GetEdgeMap();

  /* establish links between each old node and each new node, to
     initiate the follow-up search, hoping a better solution will be
     found here */
  for (auto i = edges.begin(), end = edges.end(); i != end; ++i) {
    if (IsFinal(i->first))
      /* ignore final nodes */
      continue;

    /* "seek" the Dijkstra object to the current "old" node */
    dijkstra.SetCurrentValue(i->second.value);

    /* add edges from the current "old" node to all "new" nodes
       (first_point .. n_points-1) */
    AddEdges(i->first, first_point);
  }

  /* see if new start points are possible now (due to relaxed start
     height constraints); duplicates will be ignored by the Dijkstra
     class */
  AddStartEdges();
}
Esempio n. 8
0
void Fsm::DumpState(yostream& s, size_t state) const
{
	// Fill in a 'row': Q -> exp(V) (for current state)
	yvector< ybitset<MaxChar> > row(Size());
	for (TransitionRow::const_iterator rit = m_transitions[state].begin(), rie = m_transitions[state].end(); rit != rie; ++rit)
		for (StatesSet::const_iterator sit = rit->second.begin(), sie = rit->second.end(); sit != sie; ++sit) {
			if (*sit >= Size()) {
				std::cerr << "WTF?! Transition from " << state << " on letter " << rit->first << " leads to non-existing state " << *sit << "\n";
				YASSERT(false);
			}
			if (Letters().Contains(rit->first)) {
				const yvector<Char>& letters = Letters().Klass(Letters().Representative(rit->first));
				for (yvector<Char>::const_iterator lit = letters.begin(), lie = letters.end(); lit != lie; ++lit)
					row[*sit].set(*lit);
			} else
				row[*sit].set(rit->first);
		}

	bool statePrinted = false;
	// Display each destination state
	for (yvector< ybitset<MaxChar> >::iterator rit = row.begin(), rie = row.end(); rit != rie; ++rit) {
		unsigned begin = 0, end = 0;

		ystring delimiter;
		ystring label;
		if (rit->test(Epsilon)) {
			label += delimiter + CharDump(Epsilon);
			delimiter = " ";
		}
		if (rit->test(BeginMark)) {
			label += delimiter + CharDump(BeginMark);
			delimiter = " ";
		}
		if (rit->test(EndMark)) {
			label += delimiter + CharDump(EndMark);
			delimiter = " ";
		}
		unsigned count = 0;
		for (unsigned i = 0; i < 256; ++i)
			if (rit->test(i))
				++count;
		if (count != 0 && count != 256) {
			label += delimiter + "[";
			bool complementary = (count > 128);
			if (count > 128)
				label += "^";
			while (begin < 256) {
				for (begin = end; begin < 256 && (rit->test(begin) == complementary); ++begin)
					;
				for (end = begin; end < 256 && (rit->test(end) == !complementary); ++end)
					;
				if (begin + 1 == end) {
					label += CharDump(begin);
					delimiter = " ";
				} else if (begin != end) {
					label += CharDump(begin) + "-" + (CharDump(end-1));
					delimiter = " ";
				}
			}
			label += "]";
			delimiter = " ";
		} else if (count == 256) {
			label += delimiter + ".";
			delimiter = " ";
		}
		if (!label.empty()) {
			if (!statePrinted) {
				s << "    " << state << "[shape=\"" << (IsFinal(state) ? "double" : "") << "circle\",label=\"" << state;
				Tags::const_iterator ti = tags.find(state);
				if (ti != tags.end())
					s << " (tags: " << ti->second << ")";
				s << "\"]\n";
				if (Initial() == state)
					s << "    \"initial\" -> " << state << '\n';
				statePrinted = true;
			}
			s << "    " << state << " -> " << std::distance(row.begin(), rit) << "[label=\"" << label;

			// Display outputs
			Outputs::const_iterator oit = outputs.find(state);
			if (oit != outputs.end()) {
				Outputs::value_type::second_type::const_iterator oit2 = oit->second.find(std::distance(row.begin(), rit));
				if (oit2 == oit->second.end())
					;
				else {
					yvector<int> payload;
					for (unsigned i = 0; i < sizeof(oit2->second) * 8; ++i)
						if (oit2->second & (1ul << i))
							payload.push_back(i);
					if (!payload.empty())
						s << " (outputs: " << Join(payload.begin(), payload.end(), ", ") << ")";
				}
			}

			s << "\"]\n";
		}
	}

	if (statePrinted)
		s << '\n';
}
Esempio n. 9
0
void Fsm::DumpState(yostream& s, size_t state) const
{
	s << "    ";

	// Fill in a 'row': Q -> exp(V) (for current state)
	yvector< ybitset<MaxChar> > row(Size());
	for (TransitionRow::const_iterator rit = m_transitions[state].begin(), rie = m_transitions[state].end(); rit != rie; ++rit)
		for (StatesSet::const_iterator sit = rit->second.begin(), sie = rit->second.end(); sit != sie; ++sit) {
			if (*sit >= Size()) {
				std::cerr << "WTF?! Transition from " << state << " on letter " << rit->first << " leads to non-existing state " << *sit << "\n";
				YASSERT(false);
			}
			if (Letters().Contains(rit->first)) {
				const yvector<Char>& letters = Letters().Klass(Letters().Representative(rit->first));
				for (yvector<Char>::const_iterator lit = letters.begin(), lie = letters.end(); lit != lie; ++lit)
					row[*sit].set(*lit);
			} else
				row[*sit].set(rit->first);
		}

	// Display each destination state
	for (yvector< ybitset<MaxChar> >::iterator rit = row.begin(), rie = row.end(); rit != rie; ++rit) {
		unsigned begin = 0, end = 0;

		bool empty = true;
		if (rit->test(Epsilon)) {
			s << "<Epsilon> ";
			empty = false;
		}
		if (rit->test(BeginMark)) {
			s << "<Begin> ";
			empty = false;
		}
		if (rit->test(EndMark)) {
			s << "<End> ";
			empty = false;
		}
		while (begin < 256) {
			for (begin = end; begin < 256 && !rit->test(begin); ++begin)
				;
			for (end = begin; end < 256 && rit->test(end); ++end)
				;
			if (begin + 1 == end) {
				s << CharDump(begin);
				empty = false;
			} else if (begin != end) {
				s << CharDump(begin) << ".." << (CharDump(end-1));
				empty = false;
			}
			if (!empty)
				s << " ";
		}
		if (!empty) {
			s << " => " << std::distance(row.begin(), rit);

			// Display outputs
			Outputs::const_iterator oit = outputs.find(state);
			if (oit != outputs.end()) {
				Outputs::value_type::second_type::const_iterator oit2 = oit->second.find(std::distance(row.begin(), rit));
				if (oit2 == oit->second.end())
					;
				else {
					yvector<int> payload;
					for (unsigned i = 0; i < sizeof(oit2->second) * 8; ++i)
						if (oit2->second & (1ul << i))
							payload.push_back(i);
					if (!payload.empty())
						s << "[" << Join(payload.begin(), payload.end(), ", ") << "]";
				}
			}
			s << "\n    ";
		}
	}
	if (Initial() == state)
		s << "[initial] ";
	if (IsFinal(state))
		s << "[final] ";
	Tags::const_iterator ti = tags.find(state);
	if (ti != tags.end())
		s << "[tags: " << ti->second << "] ";
	s << "\n";
}