00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "mincov_int.h"
00011
00012
00013 solution_t *
00014 solution_alloc()
00015 {
00016 solution_t *sol;
00017
00018 sol = ALLOC(solution_t, 1);
00019 sol->cost = 0;
00020 sol->row = sm_row_alloc();
00021 return sol;
00022 }
00023
00024
00025 void
00026 solution_free(sol)
00027 solution_t *sol;
00028 {
00029 sm_row_free(sol->row);
00030 FREE(sol);
00031 }
00032
00033
00034 solution_t *
00035 solution_dup(sol)
00036 solution_t *sol;
00037 {
00038 solution_t *new_sol;
00039
00040 new_sol = ALLOC(solution_t, 1);
00041 new_sol->cost = sol->cost;
00042 new_sol->row = sm_row_dup(sol->row);
00043 return new_sol;
00044 }
00045
00046
00047 void
00048 solution_add(sol, weight, col)
00049 solution_t *sol;
00050 int *weight;
00051 int col;
00052 {
00053 (void) sm_row_insert(sol->row, col);
00054 sol->cost += WEIGHT(weight, col);
00055 }
00056
00057
00058 void
00059 solution_accept(sol, A, weight, col)
00060 solution_t *sol;
00061 sm_matrix *A;
00062 int *weight;
00063 int col;
00064 {
00065 register sm_element *p, *pnext;
00066 sm_col *pcol;
00067
00068 solution_add(sol, weight, col);
00069
00070
00071 pcol = sm_get_col(A, col);
00072 for(p = pcol->first_row; p != 0; p = pnext) {
00073 pnext = p->next_row;
00074 sm_delrow(A, p->row_num);
00075 }
00076 }
00077
00078
00079
00080 void
00081 solution_reject(sol, A, weight, col)
00082 solution_t *sol;
00083 sm_matrix *A;
00084 int *weight;
00085 int col;
00086 {
00087 sm_delcol(A, col);
00088 }
00089
00090
00091 solution_t *
00092 solution_choose_best(best1, best2)
00093 solution_t *best1, *best2;
00094 {
00095 if (best1 != NIL(solution_t)) {
00096 if (best2 != NIL(solution_t)) {
00097 if (best1->cost <= best2->cost) {
00098 solution_free(best2);
00099 return best1;
00100 } else {
00101 solution_free(best1);
00102 return best2;
00103 }
00104 } else {
00105 return best1;
00106 }
00107 } else {
00108 if (best2 != NIL(solution_t)) {
00109 return best2;
00110 } else {
00111 return NIL(solution_t);
00112 }
00113 }
00114 }