abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
solution.c
Go to the documentation of this file.
1 /*
2  * Revision Control Information
3  *
4  * $Source$
5  * $Author$
6  * $Revision$
7  * $Date$
8  *
9  */
10 #include "mincov_int.h"
11 
13 
14 
15 
16 solution_t *
18 {
19  solution_t *sol;
20 
21  sol = ALLOC(solution_t, 1);
22  sol->cost = 0;
23  sol->row = sm_row_alloc();
24  return sol;
25 }
26 
27 
28 void
30 solution_t *sol;
31 {
32  sm_row_free(sol->row);
33  FREE(sol);
34 }
35 
36 
37 solution_t *
39 solution_t *sol;
40 {
41  solution_t *new_sol;
42 
43  new_sol = ALLOC(solution_t, 1);
44  new_sol->cost = sol->cost;
45  new_sol->row = sm_row_dup(sol->row);
46  return new_sol;
47 }
48 
49 
50 void
51 solution_add(sol, weight, col)
52 solution_t *sol;
53 int *weight;
54 int col;
55 {
56  (void) sm_row_insert(sol->row, col);
57  sol->cost += WEIGHT(weight, col);
58 }
59 
60 
61 void
62 solution_accept(sol, A, weight, col)
63 solution_t *sol;
64 sm_matrix *A;
65 int *weight;
66 int col;
67 {
68  register sm_element *p, *pnext;
69  sm_col *pcol;
70 
71  solution_add(sol, weight, col);
72 
73  /* delete rows covered by this column */
74  pcol = sm_get_col(A, col);
75  for(p = pcol->first_row; p != 0; p = pnext) {
76  pnext = p->next_row; /* grab it before it disappears */
77  sm_delrow(A, p->row_num);
78  }
79 }
80 
81 
82 /* ARGSUSED */
83 void
84 solution_reject(sol, A, weight, col)
85 solution_t *sol;
86 sm_matrix *A;
87 int *weight;
88 int col;
89 {
90  sm_delcol(A, col);
91 }
92 
93 
94 solution_t *
95 solution_choose_best(best1, best2)
96 solution_t *best1, *best2;
97 {
98  if (best1 != NIL(solution_t)) {
99  if (best2 != NIL(solution_t)) {
100  if (best1->cost <= best2->cost) {
101  solution_free(best2);
102  return best1;
103  } else {
104  solution_free(best1);
105  return best2;
106  }
107  } else {
108  return best1;
109  }
110  } else {
111  if (best2 != NIL(solution_t)) {
112  return best2;
113  } else {
114  return NIL(solution_t);
115  }
116  }
117 }
119 
solution_t * solution_choose_best(solution_t *best1, solution_t *best2)
Definition: solution.c:95
void solution_accept(solution_t *sol, sm_matrix *A, int *weight, int col)
Definition: solution.c:62
static Llb_Mgr_t * p
Definition: llb3Image.c:950
ABC_NAMESPACE_IMPL_START solution_t * solution_alloc()
Definition: solution.c:17
solution_t * solution_dup(solution_t *sol)
Definition: solution.c:38
sm_element * sm_row_insert(sm_row *prow, int col)
Definition: rows.c:100
#define NIL(type)
Definition: avl.h:25
void solution_reject(solution_t *sol, sm_matrix *A, int *weight, int col)
Definition: solution.c:84
sm_row * sm_row_dup(sm_row *prow)
Definition: rows.c:82
#define ALLOC(type, num)
Definition: avl.h:27
void sm_delrow(sm_matrix *A, int i)
Definition: matrix.c:273
sm_element * first_row
Definition: sparse.h:63
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
#define sm_get_col(A, colnum)
Definition: sparse.h:89
#define FREE(obj)
Definition: avl.h:31
#define WEIGHT(weight, col)
Definition: cuddSat.c:112
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
void solution_free(solution_t *sol)
Definition: solution.c:29
sm_row * row
Definition: mincov_int.h:37
typedefABC_NAMESPACE_HEADER_START struct sm_element_struct sm_element
Definition: sparse.h:21
ABC_NAMESPACE_IMPL_START sm_row * sm_row_alloc()
Definition: rows.c:21
void sm_row_free(sm_row *prow)
Definition: rows.c:53
void solution_add(solution_t *sol, int *weight, int col)
Definition: solution.c:51
void sm_delcol(sm_matrix *A, int i)
Definition: matrix.c:307