Skip to content
Snippets Groups Projects
Commit 2151c40c authored by Jiří Kalvoda's avatar Jiří Kalvoda
Browse files

algo/maxcut: možnost záporných hran mezi sousedními vrcholy

Implementace pomocí toho, že k celé matici sousednosti přičtu konstantu
a pak odčítám.
parent 73ad049b
No related branches found
No related tags found
No related merge requests found
......@@ -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);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment