From 2c6199a3df7095ad63da82a2e1c7419ba2b81373 Mon Sep 17 00:00:00 2001 From: Sebastian Buchwald Date: Tue, 2 Dec 2008 22:58:45 +0000 Subject: [PATCH] Some refactoring. [r24239] --- heuristical.c | 49 ++++++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/heuristical.c b/heuristical.c index b667196fc..a2ec4c6a1 100644 --- a/heuristical.c +++ b/heuristical.c @@ -428,6 +428,35 @@ static void initial_simplify_edges(pbqp *pbqp) } } +num determine_solution(pbqp *pbqp) +{ + unsigned node_index; + unsigned node_len; + num solution; + + if (pbqp->dump_file) { + dump_section(pbqp->dump_file, 1, "4. Determine Solution/Minimum"); + dump_section(pbqp->dump_file, 2, "4.1. Trivial Solution"); + } + + /* Solve trivial nodes and calculate solution. */ + node_len = node_bucket_get_length(node_buckets[0]); + for (node_index = 0; node_index < node_len; ++node_index) { + pbqp_node *node = node_buckets[0][node_index]; + assert(node); + + node->solution = vector_get_min_index(node->costs); + solution = pbqp_add(solution, + node->costs->entries[node->solution].data); + if (pbqp->dump_file) { + fprintf(pbqp->dump_file, "node n%d is set to %d
\n", node->index, node->solution); + dump_node(pbqp, node); + } + } + + return solution; +} + void solve_pbqp_heuristical(pbqp *pbqp) { unsigned node_index; @@ -453,25 +482,7 @@ void solve_pbqp_heuristical(pbqp *pbqp) } } - if (pbqp->dump_file) { - dump_section(pbqp->dump_file, 1, "4. Determine Solution/Minimum"); - dump_section(pbqp->dump_file, 2, "4.1. Trivial Solution"); - } - - /* Solve trivial nodes and calculate solution. */ - node_len = node_bucket_get_length(node_buckets[0]); - for (node_index = 0; node_index < node_len; ++node_index) { - pbqp_node *node = node_buckets[0][node_index]; - assert(node); - - node->solution = vector_get_min_index(node->costs); - pbqp->solution = pbqp_add(pbqp->solution, - node->costs->entries[node->solution].data); - if (pbqp->dump_file) { - fprintf(pbqp->dump_file, "node n%d is set to %d
\n", node->index, node->solution); - dump_node(pbqp, node); - } - } + pbqp->solution = determine_solution(pbqp); if (pbqp->dump_file) { dump_section(pbqp->dump_file, 2, "Minimum"); -- 2.20.1