Logo Search packages:      
Sourcecode: vdr-plugin-sudoku version File versions  Download package

bool Algorithm::find_solution (  )  [private]

Find the next valid solution to the problem, return true if a solution was found.

Definition at line 112 of file backtrack.cpp.

References create_left_leaf(), find_valid_sibling(), BackTrack::Solution::is_last_level(), BackTrack::Solution::is_valid_at(), and visit_new_node().

Referenced by find_next_solution().

{
  // If first time, need to create a root.
  if (first)
  {
    first = false;
    level = -1;
    if (solution.is_last_level(level))
      return solution.is_valid_at(level);
    create_left_leaf();
  }
  // Otherwise visit new node since solution contains the last solution.
  else if (!visit_new_node())
    return false;

  for (;;)
  {
    if (find_valid_sibling())
    {
      if (solution.is_last_level(level))
        return true;
      create_left_leaf();
    }
    else if (max_iter != 0 && iter > max_iter)
      return false;
    else if (!visit_new_node())
      return false; // The tree has been exhausted, so no solution exists.
  }
}


Generated by  Doxygen 1.6.0   Back to index