summaryrefslogtreecommitdiffstats
path: root/src/misc/espresso/solution.c
blob: c76407dec36d40495f8cdb905df0b74231fef76b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
pre { line-height: 125%; margin: 0; }
td.linenos pre { color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px; }
span.linenos { color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px; }
td.linenos pre.special { color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight { background: #ffffff; }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold }
/*
 * Revision Control Information
 *
 * $Source$
 * $Author$
 * $Revision$
 * $Date$
 *
 */
#include "mincov_int.h"

ABC_NAMESPACE_IMPL_START



solution_t *
solution_alloc()
{
    solution_t *sol;

    sol = ALLOC(solution_t, 1);
    sol->cost = 0;
    sol->row = sm_row_alloc();
    return sol;
}


void
solution_free(sol)
solution_t *sol;
{
    sm_row_free(sol->row);
    FREE(sol);
}


solution_t *
solution_dup(sol)
solution_t *sol;
{
    solution_t *new_sol;

    new_sol = ALLOC(solution_t, 1);
    new_sol->cost = sol->cost;
    new_sol->row = sm_row_dup(sol->row);
    return new_sol;
}


void 
solution_add(sol, weight, col)
solution_t *sol;
int *weight;
int col;
{
    (void) sm_row_insert(sol->row, col);
    sol->cost += WEIGHT(weight, col);
}


void 
solution_accept(sol, A, weight, col)
solution_t *sol;
sm_matrix *A;
int *weight;
int col;
{
    register sm_element *p, *pnext;
    sm_col *pcol;

    solution_add(sol, weight, col);

    /* delete rows covered by this column */
    pcol = sm_get_col(A, col);
    for(p = pcol->first_row; p != 0; p = pnext) {
    pnext = p->next_row;        /* grab it before it disappears */
    sm_delrow(A, p->row_num);
    }
}


/* ARGSUSED */
void 
solution_reject(sol, A, weight, col)
solution_t *sol;
sm_matrix *A;
int *weight;
int col;
{
    sm_delcol(A, col);
}


solution_t *
solution_choose_best(best1, best2)
solution_t *best1, *best2;
{
    if (best1 != NIL(solution_t)) {
    if (best2 != NIL(solution_t)) {
        if (best1->cost <= best2->cost) {
        solution_free(best2);
        return best1;
        } else {
        solution_free(best1);
        return best2;
        }
    } else {
        return best1;
    }
    } else {
    if (best2 != NIL(solution_t)) {
        return best2;
    } else {
        return NIL(solution_t);
    }
    }
}
ABC_NAMESPACE_IMPL_END