Rename "complete subgraph" to "clique" and use std::set instead of sorted std::vector in LanParty
This commit is contained in:
parent
f687f416ac
commit
03788ddf55
@ -34,10 +34,10 @@ class LanParty
|
||||
Graph<std::string, void> lan_{};
|
||||
std::map<std::string, int> labelMap_{};
|
||||
int findOrAddVertex(const std::string& vertexId);
|
||||
void computeInterconnectedThreeSetCount(const int vertexTx);
|
||||
void computeThreeCliqueCount(const int vertexTx);
|
||||
bool canProcessVertex(const int vertexToCheck, const int vertexTx) const;
|
||||
bool findCompleteSubgraph(const int vertex, const size_t targetSize);
|
||||
bool isSubgraphComplete(const std::vector<int>& neighbors, const std::vector<bool>& combination) const;
|
||||
bool findClique(const int vertex, const size_t targetSize);
|
||||
bool isClique(const std::vector<int>& neighbors, const std::vector<bool>& combination) const;
|
||||
std::string calcPassword(const std::vector<int>& neighbors, const std::vector<bool>& combination,
|
||||
const int vertex) const;
|
||||
};
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <numeric>
|
||||
#include <set>
|
||||
|
||||
const std::string LanParty::getPuzzleName() const
|
||||
{
|
||||
@ -40,7 +41,7 @@ void LanParty::finish()
|
||||
const auto itTxEnd = labelMap_.upper_bound(getLastTxComputerName());
|
||||
while (itTx != itTxEnd)
|
||||
{
|
||||
computeInterconnectedThreeSetCount(itTx->second);
|
||||
computeThreeCliqueCount(itTx->second);
|
||||
targetCliqueNumber = std::max(targetCliqueNumber, lan_.getDegree(itTx->second));
|
||||
++itTx;
|
||||
}
|
||||
@ -54,7 +55,7 @@ void LanParty::finish()
|
||||
auto itTx = labelMap_.lower_bound(getFirstTxComputerName());
|
||||
while (!isFound && itTx != itTxEnd)
|
||||
{
|
||||
isFound = findCompleteSubgraph(itTx->second, targetCliqueNumber);
|
||||
isFound = findClique(itTx->second, targetCliqueNumber);
|
||||
++itTx;
|
||||
}
|
||||
--targetCliqueNumber;
|
||||
@ -86,7 +87,7 @@ int LanParty::findOrAddVertex(const std::string& vertexId)
|
||||
}
|
||||
}
|
||||
|
||||
void LanParty::computeInterconnectedThreeSetCount(const int vertexTx)
|
||||
void LanParty::computeThreeCliqueCount(const int vertexTx)
|
||||
{
|
||||
auto itFirstNeighbor = lan_.begin(vertexTx);
|
||||
while (itFirstNeighbor != lan_.end())
|
||||
@ -117,7 +118,7 @@ bool LanParty::canProcessVertex(const int vertexToCheck, const int vertexTx) con
|
||||
return (label[0] != 't' || label > lan_.getVertexData(vertexTx));
|
||||
}
|
||||
|
||||
bool LanParty::findCompleteSubgraph(const int vertex, const size_t targetSize)
|
||||
bool LanParty::findClique(const int vertex, const size_t targetSize)
|
||||
{
|
||||
// Validates that the degree of the start vertex is actually high enough for the target clique size.
|
||||
if (targetSize > lan_.getDegree(vertex) + 1)
|
||||
@ -141,7 +142,7 @@ bool LanParty::findCompleteSubgraph(const int vertex, const size_t targetSize)
|
||||
|
||||
do
|
||||
{
|
||||
if (isSubgraphComplete(neighbors, combination))
|
||||
if (isClique(neighbors, combination))
|
||||
{
|
||||
part2 = calcPassword(neighbors, combination, vertex);
|
||||
return true;
|
||||
@ -151,7 +152,7 @@ bool LanParty::findCompleteSubgraph(const int vertex, const size_t targetSize)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool LanParty::isSubgraphComplete(const std::vector<int>& neighbors, const std::vector<bool>& combination) const
|
||||
bool LanParty::isClique(const std::vector<int>& neighbors, const std::vector<bool>& combination) const
|
||||
{
|
||||
for (size_t i = 0; i < combination.size(); ++i)
|
||||
{
|
||||
@ -172,16 +173,15 @@ bool LanParty::isSubgraphComplete(const std::vector<int>& neighbors, const std::
|
||||
std::string LanParty::calcPassword(const std::vector<int>& neighbors, const std::vector<bool>& combination,
|
||||
const int vertex) const
|
||||
{
|
||||
std::vector<std::string> completeSubgraph{ lan_.getVertexData(vertex) };
|
||||
std::set<std::string> clique{ lan_.getVertexData(vertex) };
|
||||
|
||||
for (size_t i = 0; i < combination.size(); ++i)
|
||||
{
|
||||
if (combination[i])
|
||||
{
|
||||
completeSubgraph.push_back(lan_.getVertexData(neighbors[i]));
|
||||
clique.insert(lan_.getVertexData(neighbors[i]));
|
||||
}
|
||||
}
|
||||
std::sort(completeSubgraph.begin(), completeSubgraph.end());
|
||||
return std::accumulate(++completeSubgraph.begin(), completeSubgraph.end(), *completeSubgraph.begin(),
|
||||
return std::accumulate(++clique.begin(), clique.end(), *clique.begin(),
|
||||
[](const std::string& acc, const std::string& x) { return acc + "," + x; });
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user