further method splitup for profiling

This commit is contained in:
Maximilian Keßler 2023-11-06 12:41:35 +01:00
parent f3240b7f6b
commit 47437f5a2f
Signed by: max
GPG key ID: BCC5A619923C0BA5
2 changed files with 43 additions and 16 deletions

View file

@ -4,7 +4,7 @@ SUCC=()
FAILED=() FAILED=()
while read -r instance opt; do while read -r instance opt; do
linecount=$(./build/main $GRAPHS/$instance | wc -l) linecount=$(./cmake-build-release/matching $GRAPHS/$instance | wc -l)
result=$(($linecount - 1)) result=$(($linecount - 1))
if [ "$result" -eq "$opt" ]; if [ "$result" -eq "$opt" ];
then then

View file

@ -1,6 +1,7 @@
#include "edmonds.h" #include "edmonds.h"
#include <iostream> #include <iostream>
#include <stack> #include <stack>
#include <tuple>
using namespace ED; using namespace ED;
@ -123,11 +124,9 @@ void augment(Graph & graph, std::vector<NodeId> const & x_path, std::vector<Node
collect_exposed_vertices(graph, outer_unvisited_nodes); collect_exposed_vertices(graph, outer_unvisited_nodes);
} }
void contract_blossom(Graph & graph, std::vector<NodeId> const & x_path, std::vector<NodeId> const & y_path, __attribute__((noinline))
std::stack<NodeId> & outer_unvisited_nodes) std::tuple<NodeId, size_type, size_type> find_blossom_root_id(Graph const & graph, std::vector<NodeId> const & x_path, std::vector<NodeId> const & y_path)
{ {
//std::cout << "Contract blossom" << std::endl;
// Paths are not disjoint -> shrink blossom
size_t distance_from_x = x_path.size() - 1; size_t distance_from_x = x_path.size() - 1;
size_t distance_from_y = y_path.size() - 1; size_t distance_from_y = y_path.size() - 1;
while (distance_from_x > 0 and distance_from_y > 0 and \ while (distance_from_x > 0 and distance_from_y > 0 and \
@ -143,7 +142,14 @@ void contract_blossom(Graph & graph, std::vector<NodeId> const & x_path, std::ve
++distance_from_y; ++distance_from_y;
}; };
// found first vertex fixed by rho // found first vertex fixed by rho
NodeId blossom_root_id = x_path[distance_from_x]; return { x_path[distance_from_x], distance_from_x, distance_from_y };
}
__attribute__((noinline))
void update_phi_along_blossom_paths(Graph & graph, std::vector<NodeId> const & x_path, std::vector<NodeId> const & y_path,
std::tuple<NodeId, size_type, size_type> const & blossom_root)
{
auto const [blossom_root_id, distance_from_x, distance_from_y] = blossom_root;
// Update φ along the paths to encode the ear decomposition // Update φ along the paths to encode the ear decomposition
for (size_t i = 1; i <= distance_from_x; i += 2) for (size_t i = 1; i <= distance_from_x; i += 2)
@ -153,6 +159,7 @@ void contract_blossom(Graph & graph, std::vector<NodeId> const & x_path, std::ve
graph.node(graph.phi(x_path[i])).phi = x_path[i]; graph.node(graph.phi(x_path[i])).phi = x_path[i];
} }
} }
for (size_t i = 1; i <= distance_from_y; i += 2) for (size_t i = 1; i <= distance_from_y; i += 2)
{ {
if (graph.rho(graph.phi(y_path[i])) != blossom_root_id) if (graph.rho(graph.phi(y_path[i])) != blossom_root_id)
@ -170,13 +177,20 @@ void contract_blossom(Graph & graph, std::vector<NodeId> const & x_path, std::ve
{ {
graph.node(y_path.front()).phi = x_path.front(); graph.node(y_path.front()).phi = x_path.front();
} }
}
__attribute__((noinline))
void update_rho(Graph & graph, std::vector<NodeId> const & x_path, std::vector<NodeId> const & y_path,
std::tuple<NodeId, size_type, size_type> const & blossom_root_description,
std::stack<NodeId> & outer_unvisited_nodes)
{
// Update root indices. We have to do this for all vertices v with // Update root indices. We have to do this for all vertices v with
// ρ(v) in the paths from x or y to r // ρ(v) in the paths from x or y to r
// We update ρ(v) first for the paths themselves, and then 'contract' ρ // We update ρ(v) first for the paths themselves, and then 'contract' ρ
// by updating ρ(v) to r for all vertices where ρ(ρ(v)) = r // by updating ρ(v) to r for all vertices where ρ(ρ(v)) = r
// Also, while walking along the paths, we can add all vertices (which are now outer) // Also, while walking along the paths, we can add all vertices (which are now outer)
// to the stack. // to the stack.
auto const [blossom_root_id, distance_from_x, distance_from_y] = blossom_root_description;
for (size_t i = 0; i <= distance_from_x; ++i) for (size_t i = 0; i <= distance_from_x; ++i)
{ {
graph.node(x_path[i]).rho = blossom_root_id; graph.node(x_path[i]).rho = blossom_root_id;
@ -202,7 +216,18 @@ void contract_blossom(Graph & graph, std::vector<NodeId> const & x_path, std::ve
graph.node(node_id).rho = blossom_root_id; graph.node(node_id).rho = blossom_root_id;
} }
} }
}
__attribute__((noinline))
void contract_blossom(Graph & graph, std::vector<NodeId> const & x_path, std::vector<NodeId> const & y_path,
std::stack<NodeId> & outer_unvisited_nodes)
{
//std::cout << "Contract blossom" << std::endl;
std::tuple<NodeId, size_type, size_type> const blossom_root_description = find_blossom_root_id(graph, x_path, y_path);
update_phi_along_blossom_paths(graph, x_path, y_path, blossom_root_description);
//check_integrity(graph); //check_integrity(graph);
update_rho(graph, x_path, y_path, blossom_root_description, outer_unvisited_nodes);
} }
void maximum_matching_from_initial_matching(Graph & graph) void maximum_matching_from_initial_matching(Graph & graph)
@ -240,11 +265,13 @@ void maximum_matching_from_initial_matching(Graph & graph)
if (x_path.back() != y_path.back()) if (x_path.back() != y_path.back())
{ {
// paths are disjoint -> can augment
augment(graph, x_path, y_path, outer_unvisited_nodes); augment(graph, x_path, y_path, outer_unvisited_nodes);
break; break;
} }
else else
{ {
// Paths are not disjoint -> contract the new blossom
contract_blossom(graph, x_path, y_path, outer_unvisited_nodes); contract_blossom(graph, x_path, y_path, outer_unvisited_nodes);
} }
} }