ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
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
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
28void
30solution_t *sol;
31{
32 sm_row_free(sol->row);
33 FREE(sol);
34}
35
36
39solution_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
50void
51solution_add(sol, weight, col)
52solution_t *sol;
53int *weight;
54int col;
55{
56 (void) sm_row_insert(sol->row, col);
57 sol->cost += WEIGHT(weight, col);
58}
59
60
61void
62solution_accept(sol, A, weight, col)
63solution_t *sol;
64sm_matrix *A;
65int *weight;
66int 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 */
83void
84solution_reject(sol, A, weight, col)
85solution_t *sol;
86sm_matrix *A;
87int *weight;
88int col;
89{
90 sm_delcol(A, col);
91}
92
93
96solution_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
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
#define ALLOC(type, num)
Definition avl.h:27
#define NIL(type)
Definition avl.h:25
#define FREE(obj)
Definition avl.h:31
Cube * p
Definition exorList.c:222
solution_t * solution_choose_best()
void solution_reject()
void solution_accept()
void solution_add()
struct solution_struct solution_t
Definition mincov_int.h:35
solution_t * solution_dup()
void solution_free()
ABC_NAMESPACE_IMPL_START sm_row * sm_row_alloc()
Definition rows.c:21
ABC_NAMESPACE_IMPL_START solution_t * solution_alloc()
Definition solution.c:17
typedefABC_NAMESPACE_HEADER_START struct sm_element_struct sm_element
Definition sparse.h:21
struct sm_col_struct sm_col
Definition sparse.h:23
void sm_delcol()
void sm_row_free()
sm_element * sm_row_insert()
void sm_delrow()
struct sm_matrix_struct sm_matrix
Definition sparse.h:24
sm_row * sm_row_dup()
#define sm_get_col(A, colnum)
Definition sparse.h:89
sm_element * first_row
Definition sparse.h:63