00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00027 #include <hess_color.h>
00028 #include <print_seq.h>
00029
00030 namespace coco
00031 {
00032
00033 #define HESS_COLOR_DEBUG 0
00034
00035 void hess_star_color1(const unsigned int n,
00036 const linalg::matrix<int>& H,
00037 std::vector<std::vector<unsigned int> >& parts,
00038 std::vector<linalg::sparse_vector<unsigned int> >& provides)
00039 {
00040
00041 std::vector<unsigned int> color(n,n);
00042
00043
00044
00045 std::vector<unsigned int> forb_colors(n,n);
00046
00047
00048 unsigned int v, w, x, y, c;
00049 linalg::matrix<int>::OneD::const_iterator itv, itw, itx;
00050 int maxcolor(-1);
00051
00052
00053 for (v=0; v<n; ++v)
00054 {
00055 #if HESS_COLOR_DEBUG > 1
00056 std::cout << "hess_star_color1: processing vertex " << v << std::endl;
00057 #endif
00058 for (itv=H[v].begin(); itv<H[v].end(); ++itv)
00059 {
00060 w = itv.column();
00061 if (color[w] != n)
00062 forb_colors[color[w]] = v;
00063 for (itw=H[w].begin(); itw<H[w].end(); ++itw)
00064 {
00065 x = itw.column();
00066 if (color[x] == n) continue;
00067 if (color[w] == n)
00068 forb_colors[color[x]] = v;
00069 else
00070 {
00071 for (itx=H[x].begin(); itx<H[x].end(); ++itx)
00072 {
00073 y = itx.column();
00074 if (y == w || color[y] == n) continue;
00075 if (color[y] == color[w])
00076 {
00077 forb_colors[color[x]] = v;
00078 break;
00079 }
00080 }
00081 }
00082 }
00083 }
00084
00085
00086 for (c=0; c<n; ++c)
00087 {
00088 if (forb_colors[c] != v)
00089 {
00090 color[v] = c;
00091 #if HESS_COLOR_DEBUG > 1
00092 std::cout << "hess_star_color1: setting color[" << v << "] = "
00093 << c << std::endl;
00094 #endif
00095 if ((int)c > maxcolor)
00096 maxcolor = c;
00097 break;
00098 }
00099 }
00100 if (c==n)
00101 throw api_exception(apiee_internal, "internal error in hess_star_color1");
00102 }
00103
00104
00105
00106 parts.clear();
00107 for (int ii=0; ii<=maxcolor; ++ii)
00108 {
00109 std::vector<unsigned int> vec;
00110 parts.push_back(vec);
00111 }
00112 for (v=0; v<n; ++v)
00113 parts[color[v]].push_back(v);
00114
00115 unsigned int i,j,k;
00116 unsigned int cnt, ind;
00117
00118 #if HESS_COLOR_DEBUG
00119 std::cout << "hess_star_color1: maxcolor = " << maxcolor << std::endl;
00120 std::cout << "hess_star_color1: parts:" << std::endl;
00121 for (i=0; i<=(unsigned int)maxcolor; ++i)
00122 std::cout << parts[i] << std::endl;
00123 #endif
00124
00125 for (i=0; i<parts.size(); ++i)
00126 {
00127 provides.push_back(linalg::sparse_vector<unsigned int>());
00128 for (j=0; j<n; ++j)
00129 {
00130 cnt = 0; ind = 0;
00131 for (k=0; k<parts[i].size(); k++)
00132 {
00133 if (H(j,parts[i][k]) != 0)
00134 {
00135 cnt++;
00136 ind = parts[i][k];
00137 if (cnt > 1)
00138 break;
00139 }
00140 }
00141 if (cnt == 1)
00142 provides[i][j] = ind+1;
00143 }
00144 }
00145 #if HESS_COLOR_DEBUG
00146 std::cout << "hess_color_eval_provides: provides = " << std::endl;
00147 std::cout << provides << std::endl;
00148
00149 #endif
00150 }
00151
00152 }