Exemplo n.º 1
0
SolverResult
OLCTriangle::Solve(bool exhaustive)
{
  if (trace_master.size() < 3) {
    ClearTrace();
    is_complete = false;
    return SolverResult::FAILED;
  }

  if (!running) {
    // branch and bound is currently in finished state, update trace
    UpdateTrace(exhaustive);
  }

  if (!is_complete || running) {
    if (n_points < 3) {
      ResetBranchAndBound();
      return SolverResult::FAILED;
    }

    if (is_closed)
      SolveTriangle(exhaustive);

    if (!SaveSolution())
      return SolverResult::FAILED;

    return SolverResult::VALID;
  } else {
    return SolverResult::FAILED;
  }
}
Exemplo n.º 2
0
AbstractContest::SolverResult
OLCPlus::Solve(bool exhaustive)
{
  return SaveSolution()
    ? SolverResult::VALID
    : SolverResult::FAILED;
}
Exemplo n.º 3
0
SolverResult
ContestDijkstra::Solve(bool exhaustive)
{
  assert(num_stages <= MAX_STAGES);

  if (trace_master.size() < num_stages) {
    /* not enough data in master trace */
    ClearTrace();
    finished = false;
    return SolverResult::FAILED;
  }

  if (finished || dijkstra.IsEmpty()) {
    UpdateTrace(exhaustive);

    if (n_points < num_stages)
      return SolverResult::FAILED;

    // don't re-start search unless we have had new data appear
    if (!trace_dirty && !finished)
      return SolverResult::FAILED;
  } else if (exhaustive || n_points < num_stages ||
             CheckMasterSerial()) {
    UpdateTrace(exhaustive);
    if (n_points < num_stages)
      return SolverResult::FAILED;
  }

  assert(n_points >= num_stages);

  if (trace_dirty) {
    trace_dirty = false;
    finished = false;

    dijkstra.Clear();
    dijkstra.Reserve(CONTEST_QUEUE_SIZE);

    StartSearch();
    AddStartEdges();
    if (dijkstra.IsEmpty())
      return SolverResult::FAILED;
  }

  SolverResult result = DistanceGeneral(exhaustive ? 0 - 1 : 25);
  if (result != SolverResult::INCOMPLETE) {
    if (incremental && continuous)
      /* enable the incremental solver, which considers the existing
         Dijkstra edge map */
      finished = true;
    else
      /* start the next iteration from scratch */
      dijkstra.Clear();

    if (result == SolverResult::VALID && !SaveSolution())
      result = SolverResult::FAILED;
  }

  return result;
}
Exemplo n.º 4
0
bool
ContestDijkstra::Solve(bool exhaustive)
{
  if (dijkstra.empty()) {
    set_weightings();
    dijkstra.reserve(CONTEST_QUEUE_SIZE);
  }

  assert(num_stages <= MAX_STAGES);

  if (dijkstra.empty()) {

    update_trace();
    if (n_points < num_stages)
      return true;

    // don't re-start search unless we have had new data appear
    if (!trace_dirty) {
      return true;
    }
  } else if (exhaustive) {
    update_trace();
    if (n_points < num_stages)
      return true;
  } else if (n_points < num_stages) {
    update_trace();
    return true;
  }

  if (trace_dirty) {
    trace_dirty = false;

    dijkstra.restart(ScanTaskPoint(0, 0));
    start_search();
    add_start_edges();
    if (dijkstra.empty()) {
      return true;
    }
  }

#ifdef INSTRUMENT_TASK
  count_olc_solve++;
  count_olc_size = max(count_olc_size, dijkstra.queue_size());
#endif

  if (distance_general(exhaustive ? 0 - 1 : 25)) {
    SaveSolution();
    update_trace();
    return true;
  }

  return !dijkstra.empty();
}
Exemplo n.º 5
0
SolverResult
OLCLeague::Solve(bool exhaustive)
{
  if (trace.size() < 2)
    return SolverResult::FAILED;

  const TracePoint &first = trace.front();
  const TracePoint &last = trace.back();

  if (!IsFinishAltitudeValid(first, last))
    return SolverResult::FAILED;

  // solution found, so set start/finish points
  solution[0] = first;
  solution[4] = last;

  // scan through classic solution to find points there to add

  unsigned index_fill = 1;

  for (unsigned index_classic = 1; index_classic + 1 < solution_classic.size();
       ++index_classic) {
    if (solution_classic[index_classic].IsNewerThan(solution[index_fill - 1]) &&
        solution_classic[index_classic].IsOlderThan(last)) {

      solution[index_fill] = solution_classic[index_classic];
      index_fill++;
      if (index_fill == 4)
        break;
    }
  }

  // if insufficient points found, add repeats of previous points

  for (; index_fill < 4; ++index_fill)
    solution[index_fill] = solution[index_fill - 1];

  SaveSolution();
  return SolverResult::VALID;
}
Exemplo n.º 6
0
bool
OLCPlus::Solve(bool exhaustive)
{
  return SaveSolution();
}