14
14
#include < string>
15
15
#include < functional>
16
16
#include < fstream>
17
+ #include < limits.h>
17
18
18
19
namespace CXXGRAPH
19
20
{
@@ -53,23 +54,43 @@ namespace CXXGRAPH
53
54
};
54
55
typedef DijkstraResult_struct DijkstraResult;
55
56
56
- // / Struct that contains the information about the partioning statistics
57
- struct PartioningStats_struct
58
- {
59
- unsigned int numberOfPartions; // The number of Partitions
60
- unsigned int numberOfVertices; // The number of Vertices
61
- unsigned int replicatedVerticesCount; // The number of Vertices that are replicated
62
- unsigned int numberOfEdges; // The number of edges
63
- unsigned int replicatedEdgesCount; // The number of edges that are replicated
64
- unsigned int maxLoad; // Maximum load of the partitions
65
- unsigned int minLoad; // Minimun load of the partitions
66
- double balanceFactor; // The balance factor of the partitions (maxLoad - minLoad) / (maxLoad + minLoad), 0 is the optimal partitioning
67
- double verticesReplicationFactor; // The replication factor of the vertices (replicatedVerticesCount / numberOfVertices), 1 is the optimal partitioning
68
- double edgesReplicationFactor; // The replication factor of the edges (replicatedEdgesCount / numberOfEdges), 1 is the optimal partitioning
69
-
70
- friend std::ostream &operator <<(std::ostream &os, const PartioningStats_struct &partitionStats);
57
+ // / Struct that contains the information about the partitioning statistics
58
+ struct PartitioningStats_struct
59
+ {
60
+ unsigned int numberOfPartitions; // The number of Partitions
61
+ unsigned int numberOfNodes; // The number of Nodes
62
+ unsigned int replicatedNodesCount; // The number of Nodes that are replicated
63
+ unsigned int numberOfEdges; // The number of edges
64
+ unsigned int replicatedEdgesCount; // The number of edges that are replicated
65
+ unsigned int maxEdgesLoad; // Maximum edges load of the partitions
66
+ unsigned int minEdgesLoad; // Minimun edges load of the partitions
67
+ unsigned int maxNodesLoad; // Maximum nodes load of the partitions
68
+ unsigned int minNodesLoad; // Minimun nodes load of the partitions
69
+ double balanceEdgesFactor; // The balance edges factor of the partitions (maxEdgesLoad - minEdgesLoad) / (maxEdgesLoad), 0 is the optimal partitioning
70
+ double balanceNodesFactor; // The balance edges factor of the partitions (maxNodesLoad - minNodesLoad) / (maxNodesLoad), 0 is the optimal partitioning
71
+ double nodesReplicationFactor; // The replication factor of the Nodes (replicatedNodesCount / numberOfNodes), 1 is the optimal partitioning
72
+ double edgesReplicationFactor; // The replication factor of the edges (replicatedEdgesCount / numberOfEdges), 1 is the optimal partitioning
73
+
74
+ friend std::ostream &operator <<(std::ostream &os, const PartitioningStats_struct &partitionStats)
75
+ {
76
+ os << " Partitioning Stats:\n " ;
77
+ os << " \t Number of Partitions: " << partitionStats.numberOfPartitions << " \n " ;
78
+ os << " \t Number of Nodes: " << partitionStats.numberOfNodes << " \n " ;
79
+ os << " \t Number of Edges: " << partitionStats.numberOfEdges << " \n " ;
80
+ os << " \t Number of Nodes Replica: " << partitionStats.replicatedNodesCount << " \n " ;
81
+ os << " \t Number of Edges Replica: " << partitionStats.replicatedEdgesCount << " \n " ;
82
+ os << " \t Nodes Replication Factor: " << partitionStats.nodesReplicationFactor << " \n " ;
83
+ os << " \t Edges Replication Factor: " << partitionStats.edgesReplicationFactor << " \n " ;
84
+ os << " \t Max Edges Load: " << partitionStats.maxEdgesLoad << " \n " ;
85
+ os << " \t Min Edges Load: " << partitionStats.minEdgesLoad << " \n " ;
86
+ os << " \t Balance Edges Factor: " << partitionStats.balanceEdgesFactor << " \n " ;
87
+ os << " \t Max Nodes Load: " << partitionStats.maxNodesLoad << " \n " ;
88
+ os << " \t Min Nodes Load: " << partitionStats.minNodesLoad << " \n " ;
89
+ os << " \t Balance Nodes Factor: " << partitionStats.balanceNodesFactor << " \n " ;
90
+ return os;
91
+ }
71
92
};
72
- typedef PartioningStats_struct PartioningStats ;
93
+ typedef PartitioningStats_struct PartitioningStats ;
73
94
74
95
template <typename T>
75
96
using AdjacencyMatrix = std::map<const Node<T> *, std::vector<std::pair<const Node<T> *, const Edge<T> *>>>;
@@ -91,8 +112,6 @@ namespace CXXGRAPH
91
112
template <typename T>
92
113
std::ostream &operator <<(std::ostream &o, const AdjacencyMatrix<T> &adj);
93
114
template <typename T>
94
- std::ostream &operator <<(std::ostream &o, const PartioningStats &partitionStats);
95
- template <typename T>
96
115
using PartitionMap = std::map<unsigned int , Partition<T> *>;
97
116
98
117
template <typename T>
@@ -1089,7 +1108,7 @@ namespace CXXGRAPH
1089
1108
unsigned int numberOfPartitions = partitionMap.size ();
1090
1109
if (index == numberOfPartitions)
1091
1110
{
1092
- // ERROR partion map of zero element
1111
+ // ERROR partition map of zero element
1093
1112
return ;
1094
1113
}
1095
1114
auto edgeSet = getEdgeSet ();
@@ -1557,6 +1576,24 @@ namespace CXXGRAPH
1557
1576
private:
1558
1577
unsigned int partitionId;
1559
1578
};
1579
+ template <typename T>
1580
+ static PartitioningStats getPartitionStats (const PartitionMap<T> &partitionMap);
1581
+ template <typename T>
1582
+ static unsigned int getMaxEdgesLoad (const PartitionMap<T> &partitionMap);
1583
+ template <typename T>
1584
+ static unsigned int getMinEdgesLoad (const PartitionMap<T> &partitionMap);
1585
+ template <typename T>
1586
+ static unsigned int getMaxNodesLoad (const PartitionMap<T> &partitionMap);
1587
+ template <typename T>
1588
+ static unsigned int getMinNodesLoad (const PartitionMap<T> &partitionMap);
1589
+ template <typename T>
1590
+ static unsigned int getNumberOfEdges (const PartitionMap<T> &partitionMap);
1591
+ template <typename T>
1592
+ static unsigned int getNumberOfNodes (const PartitionMap<T> &partitionMap);
1593
+ template <typename T>
1594
+ static unsigned int getNumberOfReplicatedEdges (const PartitionMap<T> &partitionMap);
1595
+ template <typename T>
1596
+ static unsigned int getNumberOfReplicatedNodes (const PartitionMap<T> &partitionMap);
1560
1597
1561
1598
template <typename T>
1562
1599
Partition<T>::Partition() : Graph<T>()
@@ -1594,6 +1631,150 @@ namespace CXXGRAPH
1594
1631
this ->partitionId = partitionId;
1595
1632
}
1596
1633
1634
+ template <typename T>
1635
+ PartitioningStats getPartitionStats (const PartitionMap<T> &partitionMap)
1636
+ {
1637
+ PartitioningStats result;
1638
+ result.numberOfPartitions = partitionMap.size ();
1639
+ result.numberOfNodes = getNumberOfNodes (partitionMap);
1640
+ result.numberOfEdges = getNumberOfEdges (partitionMap);
1641
+ result.replicatedNodesCount = getNumberOfReplicatedNodes (partitionMap);
1642
+ result.replicatedEdgesCount = getNumberOfReplicatedEdges (partitionMap);
1643
+ result.maxEdgesLoad = getMaxEdgesLoad (partitionMap);
1644
+ result.minEdgesLoad = getMinEdgesLoad (partitionMap);
1645
+ result.maxNodesLoad = getMaxNodesLoad (partitionMap);
1646
+ result.minNodesLoad = getMinNodesLoad (partitionMap);
1647
+ result.edgesReplicationFactor = (double )result.replicatedEdgesCount / result.numberOfEdges ;
1648
+ result.nodesReplicationFactor = (double )result.replicatedNodesCount / result.numberOfNodes ;
1649
+ result.balanceEdgesFactor = (double )(result.maxEdgesLoad - result.minEdgesLoad ) / (result.maxEdgesLoad );
1650
+ result.balanceNodesFactor = (double )(result.maxNodesLoad - result.minNodesLoad ) / (result.maxNodesLoad );
1651
+ return result;
1652
+ }
1653
+
1654
+ template <typename T>
1655
+ unsigned int getMaxEdgesLoad (const PartitionMap<T> &partitionMap)
1656
+ {
1657
+ unsigned int maxLoad = 0 ;
1658
+ for (auto it = partitionMap.begin (); it != partitionMap.end (); ++it)
1659
+ {
1660
+ if (it->second ->getEdgeSet ().size () > maxLoad)
1661
+ {
1662
+ maxLoad = it->second ->getEdgeSet ().size ();
1663
+ }
1664
+ }
1665
+ return maxLoad;
1666
+ }
1667
+
1668
+ template <typename T>
1669
+ unsigned int getMinEdgesLoad (const PartitionMap<T> &partitionMap)
1670
+ {
1671
+ unsigned int minLoad = std::numeric_limits<unsigned int >::max ();
1672
+ for (auto it = partitionMap.begin (); it != partitionMap.end (); ++it)
1673
+ {
1674
+ if (it->second ->getEdgeSet ().size () < minLoad)
1675
+ {
1676
+ minLoad = it->second ->getEdgeSet ().size ();
1677
+ }
1678
+ }
1679
+ return minLoad;
1680
+ }
1681
+
1682
+ template <typename T>
1683
+ unsigned int getMaxNodesLoad (const PartitionMap<T> &partitionMap)
1684
+ {
1685
+ unsigned int maxLoad = 0 ;
1686
+ for (auto it = partitionMap.begin (); it != partitionMap.end (); ++it)
1687
+ {
1688
+ if (it->second ->getNodeSet ().size () > maxLoad)
1689
+ {
1690
+ maxLoad = it->second ->getNodeSet ().size ();
1691
+ }
1692
+ }
1693
+ return maxLoad;
1694
+ }
1695
+
1696
+ template <typename T>
1697
+ unsigned int getMinNodesLoad (const PartitionMap<T> &partitionMap)
1698
+ {
1699
+ unsigned int minLoad = std::numeric_limits<unsigned int >::max ();
1700
+ for (auto it = partitionMap.begin (); it != partitionMap.end (); ++it)
1701
+ {
1702
+ if (it->second ->getNodeSet ().size () < minLoad)
1703
+ {
1704
+ minLoad = it->second ->getNodeSet ().size ();
1705
+ }
1706
+ }
1707
+ return minLoad;
1708
+ }
1709
+
1710
+ template <typename T>
1711
+ unsigned int getNumberOfEdges (const PartitionMap<T> &partitionMap)
1712
+ {
1713
+ unsigned int numberOfEdges = 0 ;
1714
+ std::list<const Edge<T> *> edgeSet;
1715
+
1716
+ for (auto it = partitionMap.begin (); it != partitionMap.end (); ++it)
1717
+ {
1718
+ const std::list<const Edge<T> *> partitionEdgeSet = it->second ->getEdgeSet ();
1719
+ for (auto it2 = partitionEdgeSet.begin (); it2 != partitionEdgeSet.end (); ++it2)
1720
+ {
1721
+ if (std::find_if (edgeSet.begin (), edgeSet.end (), [it2](const Edge<T> *edge)
1722
+ { return (*(*it2) == *edge); }) == edgeSet.end ())
1723
+ {
1724
+ edgeSet.push_back (*it2);
1725
+ }
1726
+ }
1727
+ }
1728
+
1729
+ return edgeSet.size ();
1730
+ }
1731
+
1732
+ template <typename T>
1733
+ unsigned int getNumberOfNodes (const PartitionMap<T> &partitionMap)
1734
+ {
1735
+
1736
+ unsigned int numberOfNodes = 0 ;
1737
+ std::list<const Node<T> *> nodeSet;
1738
+
1739
+ for (auto it = partitionMap.begin (); it != partitionMap.end (); ++it)
1740
+ {
1741
+ const std::list<const Node<T> *> partitionNodeSet = it->second ->getNodeSet ();
1742
+ for (auto it2 = partitionNodeSet.begin (); it2 != partitionNodeSet.end (); ++it2)
1743
+ {
1744
+ if (std::find_if (nodeSet.begin (), nodeSet.end (), [it2](const Node<T> *node)
1745
+ { return (*(*it2) == *node); }) == nodeSet.end ())
1746
+ {
1747
+ nodeSet.push_back (*it2);
1748
+ }
1749
+ }
1750
+ }
1751
+
1752
+ return nodeSet.size ();
1753
+ }
1754
+
1755
+ template <typename T>
1756
+ unsigned int getNumberOfReplicatedEdges (const PartitionMap<T> &partitionMap)
1757
+ {
1758
+
1759
+ unsigned int numberOfEdges = 0 ;
1760
+ for (auto it = partitionMap.begin (); it != partitionMap.end (); ++it)
1761
+ {
1762
+ numberOfEdges += it->second ->getEdgeSet ().size ();
1763
+ }
1764
+ return numberOfEdges;
1765
+ }
1766
+
1767
+ template <typename T>
1768
+ unsigned int getNumberOfReplicatedNodes (const PartitionMap<T> &partitionMap)
1769
+ {
1770
+ unsigned int numberOfNodes = 0 ;
1771
+ for (auto it = partitionMap.begin (); it != partitionMap.end (); ++it)
1772
+ {
1773
+ numberOfNodes += it->second ->getNodeSet ().size ();
1774
+ }
1775
+ return numberOfNodes;
1776
+ }
1777
+
1597
1778
// ostream overload
1598
1779
template <typename T>
1599
1780
std::ostream &operator <<(std::ostream &os, const Node<T> &node)
@@ -1683,23 +1864,23 @@ namespace CXXGRAPH
1683
1864
}
1684
1865
return os;
1685
1866
}
1686
-
1867
+ /*
1687
1868
template <typename T>
1688
- std::ostream &operator <<(std::ostream &os, const PartioningStats &partitionStats)
1869
+ std::ostream &operator<<(std::ostream &os, const PartitioningStats_struct &partitionStats)
1689
1870
{
1690
1871
os << "Partitioning Stats:\n";
1691
- os << " \t Number of Partitions:" << partitionStats.numberOfPartions << " \n " ;
1692
- os << " \t Number of Vertices : " << partitionStats.numberOfVertices << " \n " ;
1872
+ os << "\tNumber of Partitions:" << partitionStats.numberOfPartitions << "\n";
1873
+ os << "\tNumber of Nodes : " << partitionStats.numberOfNodes << "\n";
1693
1874
os << "\tNumber of Edges: " << partitionStats.numberOfEdges << "\n";
1694
- os << " \t Number of Vertices Replica: " << partitionStats.replicatedVerticesCount << " \n " ;
1875
+ os << "\tNumber of Nodes Replica: " << partitionStats.replicatedNodesCount << "\n";
1695
1876
os << "\tNumber of Edges Replica: " << partitionStats.replicatedEdgesCount << "\n";
1696
- os << " \t Vertices Replication Factor: " << partitionStats.verticesReplicationFactor << " \n " ;
1877
+ os << "\tNodes Replication Factor: " << partitionStats.nodesReplicationFactor << "\n";
1697
1878
os << "\tEdges Replication Factor: " << partitionStats.edgesReplicationFactor << "\n";
1698
1879
os << "\tMax Load: " << partitionStats.maxLoad << "\n";
1699
1880
os << "\tMin Load: " << partitionStats.minLoad << "\n";
1700
1881
os << "\tBalance Factor: " << partitionStats.balanceFactor << "\n";
1701
1882
return os;
1702
1883
}
1703
-
1884
+ */
1704
1885
} // namespace CXXGRAPH
1705
1886
#endif // __CXXGRAPH_H__
0 commit comments