-/**
- * Generate the initial problem matrices and vectors.
- */
-static problem_instance_t *new_pi(const copy_opt_t *co) {
- DBG((dbg, LEVEL_1, "Generating new instance...\n"));
- problem_instance_t *pi = calloc(1, sizeof(*pi));
- pi->irg = co->irg;
- pi->name = get_entity_name(get_irg_entity(co->irg));
- pi->num2pos = new_set(set_cmp_num2pos, SLOTS_NUM2POS);
- pi->bigM = 1;
-
- /* Vector x
- * one entry per node and possible color */
- obstack_init(&pi->ob);
- dom_tree_walk_irg(co->irg, pi_collect_x_names, NULL, pi);
- pi->x = obstack_finish(&pi->ob);
-
- /* Matrix Q
- * weights for the 'same-color-optimization' target */
- {
- unit_t *curr;
- pi->Q = new_matrix(pi->x_dim, pi->x_dim);
-
- list_for_each_entry(unit_t, curr, &co->units, units) {
- const ir_node *root, *arg;
- int rootnr, argnr;
- unsigned rootpos, argpos;
- int i;
-
- root = curr->nodes[0];
- rootnr = get_irn_graph_nr(root);
- rootpos = pi_get_first_pos(pi, rootnr);
- for (i = 1; i < curr->node_count; ++i) {
- int weight = -get_weight(root, arg);
- arg = curr->nodes[i];
- argnr = get_irn_graph_nr(arg);
- argpos = pi_get_first_pos(pi, argnr);
-
- DBG((dbg, LEVEL_2, "Q[%n, %n] := %d\n", root, arg, weight));
- /* for all colors root and arg have in common, set the weight for
- * this pair in the objective function matrix Q */
- while (rootpos < pi->x_dim && argpos < pi->x_dim &&
- pi->x[rootpos].n == rootnr && pi->x[argpos].n == argnr) {
- if (pi->x[rootpos].c < pi->x[argpos].c)
- ++rootpos;
- else if (pi->x[rootpos].c > pi->x[argpos].c)
- ++argpos;
- else {
- matrix_set(pi->Q, rootpos++, argpos++, weight);
-
- if (weight < pi->minQij) {
- DBG((dbg, LEVEL_2, "minQij = %d\n", weight));
- pi->minQij = weight;
- }
- if (weight > pi->maxQij) {
- DBG((dbg, LEVEL_2, "maxQij = %d\n", weight));
- pi->maxQij = weight;
- }
- }
- }
- }
- }
- }
-
- /* Matrix A
- * knapsack constraint for each node */
- {
- int row = 0, col = 0;
- pi->A = new_matrix(pi->A_dim, pi->x_dim);
- while (col < pi->x_dim) {
- int curr_n = pi->x[col].n;
- while (col < pi->x_dim && pi->x[col].n == curr_n) {
- DBG((dbg, LEVEL_2, "A[%d, %d] := %d\n", row, col, 1));
- matrix_set(pi->A, row, col++, 1);
- }
- ++row;
- }
- assert(row == pi->A_dim);
- }