I believe there is a small bug in my code because of this the segA and segB sizes when I call from main() are incremented by 1 due to which my output is going wrong. Below is my code.
#include<iostream>
#include<fstream>
#include<cstdlib>
#include<cmath>
using namespace std;
int total_cells,total_nets;
int cost,tempe;
int **conn;
int *segA,*segB;
int *cutset;
int seg();
int k=1;
int find_cutset();
int conn1();
int swap();
int flag =0;
int temperature();
int min_cutset();
int accept_move();
int conn1()
{
int x,y;
int i=0,j=0;
ifstream inFile;
char inputFileName[] = "trial.txt";
inFile.open(inputFileName);
if (!inFile)
{
cout << "Can't open input file named " << inputFileName << endl;
return 0;
}
inFile >> x >> y;
total_cells = x;
total_nets = y;
cout << "total_cells =" << total_cells << "\t"<<"total_nets ="<<total_nets<<endl;
conn = new int*[total_cells];
for (int i = 1; i <= total_cells; ++i)
conn[i] = new int[total_cells];
for(i=1;i<=total_cells;i++)
{
for(j=1;j<=total_cells;j++)
{
conn[i][j] = 0;
}
}
while (inFile >> x >> y)
{
conn[x][y] = conn[x][y] + 1;
}
for(i=1;i<=total_cells;i++)
{
for(j=1;j<=total_cells;j++)
{
//cout << "conn[" << i << "][" << j << "]: ";
//cout << conn[i][j]<< endl;
}
}
inFile.close();
return 0;
}
int seg()
{
int i;
segA = new int[total_cells/2];
segB = new int[total_cells/2];
cout<<"in segmentation"<<endl;
for(i=1;i<total_cells/2 +1;i++)
{
segA[i] = i;
segB[i] = i + total_cells/2;
cout << segA[i] << "\t" << segB[i] << "\t"<<endl;
}
return 0;
}
int find_cutset()
{
int x , y , i , j;
cutset= new int[total_nets*total_nets];
cutset[0] = 0;
cutset[1] = 0;
for(i=1;i<total_cells/2 +1;i++)
{
x = segA[i];
int min_cutset()
{
int k1=0;int i=0;
int min_value = cutset[1];
for(k1=1;k1<=k;k1++)
{
if( cutset[k1] < min_value)
{
min_value = cutset[k1];
}
}
cout<<"minimum value of cutset is "<<min_value<<endl;
for(i=1;i<=total_cells/2+1;i++)
{
cout << segA[i] << "\t" << segB[i] << "\t"<<endl;
}
return 0;
}
output file:
total_cells =6 total_nets =8
8 6(I do not know from where this is getting printed)
in segmentation
1 4
2 5
3 6
in main
1 4
2 5
3 6
27062272 0