diff --git a/algo/maxcut.cpp b/algo/maxcut.cpp index 3c0903512d47ee6d156dde2afef0a669645247b6..99f17f6b1c14333270d28be5d3b4d67e55e075aa 100644 --- a/algo/maxcut.cpp +++ b/algo/maxcut.cpp @@ -40,7 +40,7 @@ void calc_maxcut_naive(Nd * nd, int nd_size) } } -void calc_maxcut_gw(Nd * nd, int nd_size) +void calc_maxcut_gw(Nd * nd, int nd_size, bool negative_near=false) { int thread_num = 4; char cmd[1000]; @@ -52,6 +52,15 @@ void calc_maxcut_gw(Nd * nd, int nd_size) for(auto [target, weight] : nd[i].edges) matrix[i][target-nd] += weight; + if(negative_near) + { + fo(i, nd_size) fo(j, nd_size) matrix[i][j] *= 2; + fo(i, nd_size) fo(j, nd_size) matrix[i][j]++; + fo(i, nd_size-1) matrix[i][i+1]--; + fo(i, nd_size-1) matrix[i+1][i]--; + fo(i, nd_size) matrix[i][i] = 0; + } + fprintf(p_stdin, "import LinearAlgebra;\ import LinearAlgebra;\ @@ -100,6 +109,8 @@ void calc_maxcut(Nd * nd, int nd_size, const char * algorithm) if(!strcmp("naive", algorithm)) calc_maxcut_naive(nd, nd_size); else if(!strcmp("gw", algorithm)) calc_maxcut_gw(nd, nd_size); + else + if(!strcmp("gw-negative-near", algorithm)) calc_maxcut_gw(nd, nd_size, true); else assert(false); }