2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * @brief Heuristic PBQP solver.
24 * @author Sebastian Buchwald
29 #include "adt/array.h"
34 #include "heuristical.h"
37 #include "html_dumper.h"
41 #include "pbqp_edge.h"
42 #include "pbqp_edge_t.h"
43 #include "pbqp_node.h"
44 #include "pbqp_node_t.h"
49 static void apply_RN(pbqp *pbqp)
51 pbqp_node *node = NULL;
52 unsigned min_index = 0;
56 /* We want to reduce a node with maximum degree. */
57 node = get_node_with_max_degree();
59 assert(pbqp_node_get_degree(node) > 2);
62 if (pbqp->dump_file) {
64 sprintf(txt, "RN-Reduction of Node n%d", node->index);
65 dump_section(pbqp->dump_file, 2, txt);
66 pbqp_dump_graph(pbqp);
70 min_index = get_local_minimal_alternative(pbqp, node);
73 if (pbqp->dump_file) {
74 fprintf(pbqp->dump_file, "node n%d is set to %d<br><br>\n",
75 node->index, min_index);
80 FILE *fh = fopen("solutions.pb", "a");
81 fprintf(fh, "[%u]", min_index);
86 /* Now that we found the local minimum set all other costs to infinity. */
87 select_alternative(node, min_index);
90 static void apply_heuristic_reductions(pbqp *pbqp)
93 if (edge_bucket_get_length(edge_bucket) > 0) {
95 } else if (node_bucket_get_length(node_buckets[1]) > 0) {
97 } else if (node_bucket_get_length(node_buckets[2]) > 0) {
99 } else if (node_bucket_get_length(node_buckets[3]) > 0) {
107 void solve_pbqp_heuristical(pbqp *pbqp)
109 /* Reduce nodes degree ... */
110 initial_simplify_edges(pbqp);
112 /* ... and put node into bucket representing their degree. */
113 fill_node_buckets(pbqp);
116 FILE *fh = fopen("solutions.pb", "a");
117 fprintf(fh, "Solution");
121 apply_heuristic_reductions(pbqp);
123 pbqp->solution = determine_solution(pbqp);
126 fh = fopen("solutions.pb", "a");
127 fprintf(fh, ": %lld RE:%u R0:%u R1:%u R2:%u RM:%u RN/BF:%u\n", pbqp->solution,
128 pbqp->num_edges, pbqp->num_r0, pbqp->num_r1, pbqp->num_r2,
129 pbqp->num_rm, pbqp->num_rn);
133 /* Solve reduced nodes. */
134 back_propagate(pbqp);