Builds the Virtual Connections (VCs) between groups of stones a single color. More...
#include <VCBuilder.hpp>
Classes | |
class | OrRule |
class | WorkQueue |
Queue of endpoint pairs that need processing. More... | |
Public Member Functions | |
VCBuilder (VCBuilderParam ¶m) | |
Constructor. | |
~VCBuilder () | |
Destrutor. | |
VCBuilderParam & | Parameters () |
Returns parameters used in search. | |
const VCBuilderParam & | Parameters () const |
Returns parameters used in search. | |
VCBuilderStatistics | Statistics (HexColor color) const |
Returns statistics for the last run. | |
void | ClearStatistics () |
Clears the statistics for both colors. | |
void | Build (VCSet &con, const Groups &groups, const PatternState &patterns) |
Computes connections from scratch. | |
void | Build (VCSet &cons, const Groups &oldGroups, const Groups &newGroups, const PatternState &patterns, bitset_t added[BLACK_AND_WHITE], ChangeLog< VC > *log) |
Updates connections from oldGroups to newGroups Assumes existing vc data is valid for oldGroups. | |
Private Types | |
enum | AndRule { CREATE_FULL, CREATE_SEMI } |
The types of VC to create when using the AND rule. More... | |
Private Member Functions | |
void | doAnd (HexPoint from, HexPoint over, HexPoint to, AndRule rule, const VC &vc, const bitset_t &capturedSet, const VCList *old) |
Compares vc to each connection in the softlimit of the given list. | |
void | andClosure (const VC &vc) |
Computes the and closure for the vc. | |
void | DoSearch () |
void | ProcessSemis (HexPoint xc, HexPoint yc) |
void | ProcessFulls (HexPoint p1, HexPoint p2) |
bool | AddNewFull (const VC &vc) |
Tries to add a new full-connection to list between (vc.x(), vc.y()). | |
bool | AddNewSemi (const VC &vc) |
Tries to add a new semi-connection to list between (vc.x(), vc.y()). | |
void | LoadCapturedSetPatterns () |
void | ComputeCapturedSets (const PatternState &patterns) |
void | AddBaseVCs () |
Computes the 0-connections defined by adjacency. | |
void | AddPatternVCs () |
Adds vcs obtained by pre-computed patterns. | |
void | AbsorbMergeShrinkUpgrade (const bitset_t &added_black, const bitset_t &added_white) |
void | Merge (const Groups &oldGroups, bitset_t added[BLACK_AND_WHITE]) |
void | MergeAndShrink (const bitset_t &affected, const bitset_t &added) |
void | MergeAndShrink (const bitset_t &added, HexPoint xin, HexPoint yin, HexPoint xout, HexPoint yout) |
void | RemoveAllContaining (const Groups &groups, const bitset_t &bs) |
Removes all connections whose intersection with given set is non-empty. | |
Private Attributes | |
OrRule | m_orRule |
VCBuilderParam & | m_param |
WorkQueue | m_queue |
VCBuilderStatistics | m_statsForColor [BLACK_AND_WHITE] |
VCBuilderStatistics * | m_statistics |
const Groups * | m_groups |
const StoneBoard * | m_brd |
VCSet * | m_con |
HexColor | m_color |
ChangeLog< VC > * | m_log |
bitset_t | m_capturedSet [BITSETSIZE] |
PatternSet | m_capturedSetPatterns [BLACK_AND_WHITE] |
HashedPatternSet | m_hash_capturedSetPatterns [BLACK_AND_WHITE] |
Builds the Virtual Connections (VCs) between groups of stones a single color.
VCs can be built from scratch or incrementally from a previous state. We use Anchelevich's rules for VC computation. This means that between each pair of cells on the board, we store a VCList of FULL connections and another VCList of SEMI connections.
IMPORTANT: Take a list of semis between x and y. If any subset of of these semis has an empty intersection, we require that the list of full connections between x and y has at least one connection.
See also:
Definition at line 129 of file VCBuilder.hpp.
enum VCBuilder::AndRule [private] |
The types of VC to create when using the AND rule.
Definition at line 199 of file VCBuilder.hpp.
VCBuilder::VCBuilder | ( | VCBuilderParam & | param | ) |
VCBuilder::~VCBuilder | ( | ) |
Destrutor.
Definition at line 41 of file VCBuilder.cpp.
void VCBuilder::AbsorbMergeShrinkUpgrade | ( | const bitset_t & | added_black, | |
const bitset_t & | added_white | |||
) | [private] |
void VCBuilder::AddBaseVCs | ( | ) | [private] |
Computes the 0-connections defined by adjacency.
Definition at line 96 of file VCBuilder.cpp.
References VCSet::Add(), VCBuilderStatistics::base_attempts, VCBuilderStatistics::base_successes, HexColorSetUtil::ColorOrEmpty(), StoneBoard::GetEmpty(), m_brd, m_color, m_con, m_groups, m_log, m_queue, m_statistics, and VCBuilder::WorkQueue::push().
Referenced by Build().
bool VCBuilder::AddNewFull | ( | const VC & | vc | ) | [private] |
Tries to add a new full-connection to list between (vc.x(), vc.y()).
If vc is successfully added, then:
1) Removes any semi-connections between (vc.x(), vc.y()) that are supersets of vc.
2) Adds (vc.x(), vc.y()) to the queue if vc was added inside the softlimit.
Definition at line 764 of file VCBuilder.cpp.
References VCSet::Add(), VCList::ADD_FAILED, VCList::ADDED_INSIDE_SOFT_LIMIT, VC::carrier(), VC::FULL, VCSet::GetList(), HexAssert, m_con, m_log, m_queue, VCBuilder::WorkQueue::push(), VC::SEMI, VC::type(), VC::x(), and VC::y().
Referenced by doAnd().
bool VCBuilder::AddNewSemi | ( | const VC & | vc | ) | [private] |
Tries to add a new semi-connection to list between (vc.x(), vc.y()).
Does not add if vc is a superset of some full-connection between (vc.x(), and vc.y()).
If vc is successfully added and intersection on semi-list is empty, then:
1) if vc added inside soft limit, adds (vc.x(), vc.y()) to queue.
2) otherwise, if no full exists between (vc.x(), vc.y()), adds the or over the entire semi list.
Definition at line 797 of file VCBuilder.cpp.
References VCList::add(), VCList::ADD_FAILED, VCList::ADDED_INSIDE_SOFT_LIMIT, VC::carrier(), VCList::empty(), VC::FULL, VCList::getGreedyUnion(), VCSet::GetList(), VCList::getUnion(), VCList::getX(), VCList::getY(), VCList::hardIntersection(), VCList::isSupersetOfAny(), m_con, m_log, m_param, m_queue, benzene_bitset< _Nb >::none(), VCBuilder::WorkQueue::push(), VC::SEMI, VCBuilderParam::use_greedy_union, VC_RULE_ALL, VC::x(), and VC::y().
Referenced by doAnd().
void VCBuilder::AddPatternVCs | ( | ) | [private] |
Adds vcs obtained by pre-computed patterns.
Definition at line 115 of file VCBuilder.cpp.
References VCSet::Add(), VCPattern::Endpoint(), StoneBoard::GetColor(), VCPattern::GetPatterns(), StoneBoard::Height(), HexPointUtil::isEdge(), m_brd, m_color, m_con, m_log, m_param, m_queue, m_statistics, VCPattern::Matches(), VCPattern::NotOpponent(), VCBuilderStatistics::pattern_attempts, VCBuilderStatistics::pattern_successes, VCBuilder::WorkQueue::push(), benzene_bitset< _Nb >::reset(), VCBuilderParam::use_non_edge_patterns, VC_RULE_BASE, and StoneBoard::Width().
Referenced by Build().
void VCBuilder::andClosure | ( | const VC & | vc | ) | [private] |
Computes the and closure for the vc.
Let x and y be vc's endpoints. A single pass over the board is performed. For each z, we try to and the list of fulls between z and x and z and y with vc. This function is a major bottleneck. Every operation in it needs to be as efficient as possible.
Definition at line 505 of file VCBuilder.cpp.
References VCBuilderParam::and_over_edge, Groups::CaptainOf(), VC::carrier(), CREATE_FULL, CREATE_SEMI, doAnd(), EMPTY, benzene_bitset< _Nb >::flip(), VC::FULL, StoneBoard::GetColor(), VCSet::GetList(), HexAssert, HexPointUtil::isEdge(), LogInfo(), m_brd, m_capturedSet, m_color, m_con, m_groups, m_param, HexColorSetUtil::NotColor(), VCList::softIntersection(), benzene_bitset< _Nb >::test(), VC::x(), and VC::y().
Referenced by ProcessFulls().
void VCBuilder::Build | ( | VCSet & | cons, | |
const Groups & | oldGroups, | |||
const Groups & | newGroups, | |||
const PatternState & | patterns, | |||
bitset_t | added[BLACK_AND_WHITE], | |||
ChangeLog< VC > * | log | |||
) |
Updates connections from oldGroups to newGroups Assumes existing vc data is valid for oldGroups.
Logging is used if passed log is not 0. Breaks all connections whose carrier contains a new stone unless a 1-connection of player color and p is the key; these are upgraded to 0-connections for player p.
Definition at line 170 of file VCBuilder.cpp.
References AddPatternVCs(), BLACK, Groups::Board(), VCBuilder::WorkQueue::clear(), VCSet::Color(), ComputeCapturedSets(), DoSearch(), Get(), HexAssert, LogFine(), m_brd, m_color, m_con, m_groups, m_log, m_param, m_queue, m_statistics, m_statsForColor, Merge(), VCBuilderParam::use_patterns, and WHITE.
void VCBuilder::Build | ( | VCSet & | con, | |
const Groups & | groups, | |||
const PatternState & | patterns | |||
) |
Computes connections from scratch.
Old connections are removed prior to starting.
Definition at line 71 of file VCBuilder.cpp.
References AddBaseVCs(), AddPatternVCs(), Groups::Board(), VCBuilder::WorkQueue::clear(), VCSet::Clear(), VCSet::Color(), ComputeCapturedSets(), DoSearch(), Get(), LogFine(), m_brd, m_color, m_con, m_groups, m_log, m_param, m_queue, m_statistics, m_statsForColor, and VCBuilderParam::use_patterns.
Referenced by HexBoard::BuildVCs().
void VCBuilder::ClearStatistics | ( | ) | [inline] |
Clears the statistics for both colors.
Definition at line 302 of file VCBuilder.hpp.
References BLACK, m_statsForColor, and WHITE.
Referenced by HexBoard::ComputeAll(), HexBoard::PlayMove(), and HexBoard::PlayStones().
void VCBuilder::ComputeCapturedSets | ( | const PatternState & | patterns | ) | [private] |
Definition at line 143 of file VCBuilder.cpp.
References StoneBoard::Const(), ConstBoard::EdgesAndInterior(), EMPTY, EMPTY_BITSET, StoneBoard::GetColor(), m_brd, m_capturedSet, m_color, m_hash_capturedSetPatterns, PatternState::MatchOnCell(), and PatternState::STOP_AT_FIRST_HIT.
Referenced by Build().
void VCBuilder::doAnd | ( | HexPoint | from, | |
HexPoint | over, | |||
HexPoint | to, | |||
AndRule | rule, | |||
const VC & | vc, | |||
const bitset_t & | capturedSet, | |||
const VCList * | old | |||
) | [private] |
Compares vc to each connection in the softlimit of the given list.
Creates a new connection if intersection is empty, or if the intersection is a subset of the captured set. Created connections are added with AddNewFull() or AddNewSemi().
Definition at line 557 of file VCBuilder.cpp.
References AddNewFull(), AddNewSemi(), VCBuilderStatistics::and_full_attempts, VCBuilderStatistics::and_full_successes, VCBuilderStatistics::and_semi_attempts, VCBuilderStatistics::and_semi_successes, VC::AndVCs(), VCList::begin(), VC::carrier(), CREATE_FULL, CREATE_SEMI, VCList::empty(), VCList::end(), BitsetUtil::IsSubsetOf(), m_statistics, benzene_bitset< _Nb >::none(), and VCList::softlimit().
Referenced by andClosure().
void VCBuilder::DoSearch | ( | ) | [private] |
Definition at line 465 of file VCBuilder.cpp.
References VCBuilderParam::abort_on_winning_connection, Groups::CaptainOf(), HexPointUtil::colorEdge1(), HexPointUtil::colorEdge2(), VCBuilder::WorkQueue::empty(), VCSet::Exists(), VCBuilder::WorkQueue::front(), VC::FULL, HexAssert, LogFine(), m_color, m_con, m_groups, m_param, m_queue, VCBuilder::WorkQueue::pop(), ProcessFulls(), and ProcessSemis().
Referenced by Build().
void VCBuilder::LoadCapturedSetPatterns | ( | ) | [private] |
Definition at line 45 of file VCBuilder.cpp.
References BLACK, Pattern::LoadPatternsFromFile(), LogFine(), m_capturedSetPatterns, m_hash_capturedSetPatterns, and WHITE.
Referenced by VCBuilder().
Definition at line 221 of file VCBuilder.cpp.
References Group::Captain(), Group::Color(), StoneBoard::Const(), Groups::GetGroup(), m_brd, m_color, MergeAndShrink(), ConstBoard::Nbs(), RemoveAllContaining(), and benzene_bitset< _Nb >::set().
Referenced by Build().
void VCBuilder::MergeAndShrink | ( | const bitset_t & | added, | |
HexPoint | xin, | |||
HexPoint | yin, | |||
HexPoint | xout, | |||
HexPoint | yout | |||
) | [private] |
Definition at line 274 of file VCBuilder.cpp.
References VCList::add(), VC::carrier(), VC::FULL, VCSet::GetList(), HexAssert, m_con, m_log, m_statistics, VCList::removeAllContaining(), VCList::removeSuperSetsOf(), VC::SEMI, VC::ShrinkFull(), VC::ShrinkSemi(), VCBuilderStatistics::shrunk0, VCBuilderStatistics::shrunk1, benzene_bitset< _Nb >::test(), VCBuilderStatistics::upgraded, and VC::UpgradeSemi().
Definition at line 245 of file VCBuilder.cpp.
References Groups::CaptainOf(), Groups::IsCaptain(), m_brd, m_color, m_groups, m_queue, HexColorSetUtil::NotColor(), VCBuilder::WorkQueue::push(), StoneBoard::Stones(), and benzene_bitset< _Nb >::test().
Referenced by Merge().
const VCBuilderParam & VCBuilder::Parameters | ( | ) | const [inline] |
Returns parameters used in search.
Definition at line 292 of file VCBuilder.hpp.
References m_param.
VCBuilderParam & VCBuilder::Parameters | ( | ) | [inline] |
Returns parameters used in search.
Definition at line 287 of file VCBuilder.hpp.
References m_param.
Referenced by ProofUtil::InitialProofForOpponent(), HexEnvironmentCommands::ParamVC(), ResistanceUtil::SimulateAndOverEdge(), and HexUctState::StartSearch().
Definition at line 447 of file VCBuilder.cpp.
References andClosure(), VCList::begin(), VCList::end(), VC::FULL, VCSet::GetList(), m_con, m_log, ChangeLog< T >::push(), and VCList::softlimit().
Referenced by DoSearch().
Definition at line 398 of file VCBuilder.cpp.
References VCList::add(), VCList::begin(), VCBuilderStatistics::doOrs, VCList::empty(), VCList::end(), benzene_bitset< _Nb >::flip(), VC::FULL, VCList::getGreedyUnion(), VCSet::GetList(), VCList::getUnion(), VCBuilderStatistics::goodOrs, VCList::hardIntersection(), m_capturedSet, m_con, m_log, m_orRule, m_param, m_statistics, VCBuilderParam::max_ors, ChangeLog< T >::push(), VC::SEMI, VCList::softlimit(), VCBuilderParam::use_greedy_union, and VC_RULE_ALL.
Referenced by DoSearch().
Removes all connections whose intersection with given set is non-empty.
Any list that is modified is added to the queue, since some unprocessed connections could have been brought under the softlimit.
Definition at line 366 of file VCBuilder.cpp.
References Group::Color(), VC::FULL, Groups::GetGroup(), VCSet::GetList(), VCBuilderStatistics::killed0, VCBuilderStatistics::killed1, m_color, m_con, m_groups, m_log, m_queue, m_statistics, HexColorSetUtil::NotColor(), VCBuilder::WorkQueue::push(), VCList::removeAllContaining(), and VC::SEMI.
Referenced by Merge().
VCBuilderStatistics VCBuilder::Statistics | ( | HexColor | color | ) | const [inline] |
Returns statistics for the last run.
Definition at line 297 of file VCBuilder.hpp.
References m_statsForColor.
Referenced by VCCommands::CmdBuilderStats().
const StoneBoard* VCBuilder::m_brd [private] |
Definition at line 272 of file VCBuilder.hpp.
Referenced by AddBaseVCs(), AddPatternVCs(), andClosure(), Build(), ComputeCapturedSets(), Merge(), and MergeAndShrink().
bitset_t VCBuilder::m_capturedSet[BITSETSIZE] [private] |
Definition at line 280 of file VCBuilder.hpp.
Referenced by andClosure(), ComputeCapturedSets(), VCBuilder::OrRule::operator()(), and ProcessSemis().
Definition at line 282 of file VCBuilder.hpp.
Referenced by LoadCapturedSetPatterns().
HexColor VCBuilder::m_color [private] |
Definition at line 276 of file VCBuilder.hpp.
Referenced by AddBaseVCs(), AddPatternVCs(), andClosure(), Build(), ComputeCapturedSets(), DoSearch(), Merge(), MergeAndShrink(), and RemoveAllContaining().
VCSet* VCBuilder::m_con [private] |
Definition at line 274 of file VCBuilder.hpp.
Referenced by AddBaseVCs(), AddNewFull(), AddNewSemi(), AddPatternVCs(), andClosure(), Build(), DoSearch(), MergeAndShrink(), ProcessFulls(), ProcessSemis(), and RemoveAllContaining().
const Groups* VCBuilder::m_groups [private] |
Definition at line 270 of file VCBuilder.hpp.
Referenced by AddBaseVCs(), andClosure(), Build(), DoSearch(), MergeAndShrink(), and RemoveAllContaining().
Definition at line 284 of file VCBuilder.hpp.
Referenced by ComputeCapturedSets(), and LoadCapturedSetPatterns().
ChangeLog<VC>* VCBuilder::m_log [private] |
Definition at line 278 of file VCBuilder.hpp.
Referenced by AddBaseVCs(), AddNewFull(), AddNewSemi(), AddPatternVCs(), Build(), MergeAndShrink(), ProcessFulls(), ProcessSemis(), and RemoveAllContaining().
OrRule VCBuilder::m_orRule [private] |
Definition at line 224 of file VCBuilder.hpp.
Referenced by ProcessSemis().
VCBuilderParam& VCBuilder::m_param [private] |
Definition at line 262 of file VCBuilder.hpp.
Referenced by AddNewSemi(), AddPatternVCs(), andClosure(), Build(), DoSearch(), Parameters(), and ProcessSemis().
WorkQueue VCBuilder::m_queue [private] |
Definition at line 264 of file VCBuilder.hpp.
Referenced by AddBaseVCs(), AddNewFull(), AddNewSemi(), AddPatternVCs(), Build(), DoSearch(), MergeAndShrink(), and RemoveAllContaining().
VCBuilderStatistics* VCBuilder::m_statistics [private] |
Definition at line 268 of file VCBuilder.hpp.
Referenced by AddBaseVCs(), AddPatternVCs(), Build(), doAnd(), MergeAndShrink(), ProcessSemis(), and RemoveAllContaining().
Definition at line 266 of file VCBuilder.hpp.
Referenced by Build(), ClearStatistics(), and Statistics().