https://gitlab.com/Aldorn/pds-code
Revision 121131be58bc1b6f91a4863bd01fe7cbd0439ab9 authored by Max Göttlicher on 16 August 2023, 15:14:58 UTC, committed by Max Göttlicher on 16 August 2023, 15:16:03 UTC
1 parent 0fb04b6
Tip revision: 121131be58bc1b6f91a4863bd01fe7cbd0439ab9 authored by Max Göttlicher on 16 August 2023, 15:14:58 UTC
readme
readme
Tip revision: 121131b
check_graph.cpp
//
// Created by max on 19.08.22.
//
#include <mpgraphs/graph.hpp>
#include <range/v3/all.hpp>
#include <boost/program_options.hpp>
#include "pds.hpp"
#include "graphio.hpp"
namespace pds {
using Vertex = PowerGrid::VertexDescriptor;
bool visitComponent(const PowerGrid& graph, Vertex start, set<Vertex>& seen) {
if (seen.contains(start)) return false;
seen.insert(start);
for (auto w: graph.neighbors(start)) {
visitComponent(graph, w, seen);
}
return true;
}
size_t numComponents(const PowerGrid &graph) {
set<Vertex> seen;
size_t nComponents = 0;
for (auto v: graph.vertices()) {
if (visitComponent(graph, v, seen)) ++nComponents;
}
return nComponents;
}
bool isConnected(const PowerGrid& graph) {
set<Vertex> seen;
size_t nComponents = 0;
for (auto v: graph.vertices()) {
if (visitComponent(graph, v, seen)) ++nComponents;
if (nComponents > 1) return false;
}
return true;
}
bool isTree(const PowerGrid& graph) {
return graph.numEdges() + 1 == graph.numVertices() && isConnected(graph);
}
bool isForest(const PowerGrid& graph) {
return graph.numEdges() + numComponents(graph) == graph.numVertices();
}
}
int main(int argc, const char** argv) {
using namespace pds;
auto graph = pds::readGraphML(argv[1]);
fmt::print("n={}, m={}\n", graph.numVertices(), graph.numEdges());
fmt::print("is connected: {}\n", isConnected(graph));
fmt::print("is forest: {}\n", isForest(graph));
fmt::print("is tree: {}\n", isTree(graph));
}

Computing file changes ...