From 4cfe2b69ec4371769567d632a0b714afa206d482 Mon Sep 17 00:00:00 2001 From: ZigRazor Date: Thu, 15 Jul 2021 12:17:21 +0000 Subject: [PATCH] Introduced operator<< for partitioningStats Created typedef for PartitionsMap Related Issue: Implement statistic results of the partition #29 --- include/Graph.hpp | 83 +++++++++++++++++++++++++++++++---------------- 1 file changed, 55 insertions(+), 28 deletions(-) diff --git a/include/Graph.hpp b/include/Graph.hpp index 3bd263031..629c87b93 100644 --- a/include/Graph.hpp +++ b/include/Graph.hpp @@ -39,9 +39,38 @@ namespace CXXGRAPH class UndirectedWeightedEdge; template class Graph; + template + class Partition; class Weighted; + /// Struct that contains the information about Dijsktra's Algorithm results + struct DijkstraResult_struct + { + bool success; // TRUE if the function does not return error, FALSE otherwise + std::string errorMessage; //message of error + double result; //result (valid only if success is TRUE) + }; + typedef DijkstraResult_struct DijkstraResult; + + /// Struct that contains the information about the partioning statistics + struct PartioningStats_struct + { + unsigned int numberOfPartions; // The number of Partitions + unsigned int numberOfVertices; // The number of Vertices + unsigned int replicatedVerticesCount; // The number of Vertices that are replicated + unsigned int numberOfEdges; // The number of edges + unsigned int replicatedEdgesCount; // The number of edges that are replicated + unsigned int maxLoad; // Maximum load of the partitions + unsigned int minLoad; // Minimun load of the partitions + double balanceFactor; // The balance factor of the partitions (maxLoad - minLoad) / (maxLoad + minLoad), 0 is the optimal partitioning + double verticesReplicationFactor; // The replication factor of the vertices (replicatedVerticesCount / numberOfVertices), 1 is the optimal partitioning + double edgesReplicationFactor; // The replication factor of the edges (replicatedEdgesCount / numberOfEdges), 1 is the optimal partitioning + + friend std::ostream &operator<<(std::ostream &os, const PartioningStats_struct &partitionStats); + }; + typedef PartioningStats_struct PartioningStats; + template using AdjacencyMatrix = std::map *, std::vector *, const Edge *>>>; @@ -61,29 +90,10 @@ namespace CXXGRAPH std::ostream &operator<<(std::ostream &o, const Graph &graph); template std::ostream &operator<<(std::ostream &o, const AdjacencyMatrix &adj); - - /// Struct that contains the information about Dijsktra's Algorithm results - typedef struct DijkstraResult_struct - { - bool success; // TRUE if the function does not return error, FALSE otherwise - std::string errorMessage; //message of error - double result; //result (valid only if success is TRUE) - } DijkstraResult; - - /// Struct that contains the information about the partioning statistics - typedef struct PartioningStats_struct - { - unsigned int numberOfPartions; // The number of Partitions - unsigned int numberOfVertices; // The number of Vertices - unsigned int replicatedVerticesCount; // The number of Vertices that are replicated - unsigned int numberOfEdges; // The number of edges - unsigned int replicatedEdgesCount; // The number of edges that are replicated - unsigned int maxLoad; // Maximum load of the partitions - unsigned int minLoad; // Minimun load of the partitions - double balanceFactor; // The balance factor of the partitions (maxLoad - minLoad) / (maxLoad + minLoad), 0 is the optimal partitioning - double nodeReplicationFactor; // The replication factor of the nodes (replicatedVerticesCount / numberOfVertices), 1 is the optimal partitioning - double edgeReplicationFactor; // The replication factor of the nodes (replicatedEdgesCount / numberOfEdges), 1 is the optimal partitioning - } PartioningStats; + template + std::ostream &operator<<(std::ostream &o, const PartioningStats &partitionStats); + template + using PartitionMap = std::map *>; template class Node @@ -490,7 +500,7 @@ namespace CXXGRAPH int writeToStandardFile_tsv(const std::string &workingDir, const std::string &OFileName, bool compress, bool writeNodeFeat, bool writeEdgeWeight) const; int readFromStandardFile_tsv(const std::string &workingDir, const std::string &OFileName, bool compress, bool readNodeFeat, bool readEdgeWeight); void recreateGraphFromReadFiles(std::map> &edgeMap, std::map &edgeDirectedMap, std::map &nodeFeatMap, std::map &edgeWeightMap); - void greedyPartition(std::map *> &partitionMap) const; + void greedyPartition(PartitionMap &partitionMap) const; public: /// Specify the Input/Output format of the Graph for Import/Export functions @@ -619,7 +629,7 @@ namespace CXXGRAPH * @param numberOfPartition The number of partitions * @return The partiton Map of the partitioned graph */ - std::map *> partitionGraph(PartitionAlgorithm algorithm, unsigned int numberOfPartitions) const; + PartitionMap partitionGraph(PartitionAlgorithm algorithm, unsigned int numberOfPartitions) const; friend std::ostream &operator<<<>(std::ostream &os, const Graph &graph); friend std::ostream &operator<<<>(std::ostream &os, const AdjacencyMatrix &adj); @@ -1073,7 +1083,7 @@ namespace CXXGRAPH } template - void Graph::greedyPartition(std::map *> &partitionMap) const + void Graph::greedyPartition(PartitionMap &partitionMap) const { unsigned int index = 0; unsigned int numberOfPartitions = partitionMap.size(); @@ -1512,9 +1522,9 @@ namespace CXXGRAPH } template - std::map *> Graph::partitionGraph(PartitionAlgorithm algorithm, unsigned int numberOfPartitions) const + PartitionMap Graph::partitionGraph(PartitionAlgorithm algorithm, unsigned int numberOfPartitions) const { - std::map *> partitionMap; + PartitionMap partitionMap; for (unsigned int i = 0; i < numberOfPartitions; ++i) { partitionMap[i] = new Partition(i); @@ -1674,5 +1684,22 @@ namespace CXXGRAPH return os; } + template + std::ostream &operator<<(std::ostream &os, const PartioningStats &partitionStats) + { + os << "Partitioning Stats:\n"; + os << "\tNumber of Partitions:" << partitionStats.numberOfPartions << "\n"; + os << "\tNumber of Vertices: " << partitionStats.numberOfVertices << "\n"; + os << "\tNumber of Edges: " << partitionStats.numberOfEdges << "\n"; + os << "\tNumber of Vertices Replica: " << partitionStats.replicatedVerticesCount << "\n"; + os << "\tNumber of Edges Replica: " << partitionStats.replicatedEdgesCount << "\n"; + os << "\tVertices Replication Factor: " << partitionStats.verticesReplicationFactor << "\n"; + os << "\tEdges Replication Factor: " << partitionStats.edgesReplicationFactor << "\n"; + os << "\tMax Load: " << partitionStats.maxLoad << "\n"; + os << "\tMin Load: " << partitionStats.minLoad << "\n"; + os << "\tBalance Factor: " << partitionStats.balanceFactor << "\n"; + return os; + } + } // namespace CXXGRAPH #endif // __CXXGRAPH_H__ \ No newline at end of file