setting the next result to 0

hello everyone
i have been doing a problem on quadratic assignment problem
i got a problem on the answer of the coding..
i have a set of answer, the first answer it appear correct however the 2nd until 10 answer its calculate double..
i already set the result to 0 in the array however it still calculate wrong..
please help me

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191

   #include "stdafx.h"
   #include <iostream>
   #include <fstream>
   #include <vector>
   #include <cstdio>
   #include <string>
   #include <iomanip>
   #include <cstdlib>
   #include <ctime>

   using namespace std;

   //declare function 
   void input(); //assign all inout data into array
   void initial_solution();

   //declare variables & files
   //const int m = 12; //no of flow n distant
   const int pop_size = 12;
   const int no_of_facloc = 12;

   vector< vector <long double>> flow (no_of_facloc, vector <long double> 
   (no_of_facloc,0));
   vector< vector <long double>> dist (no_of_facloc, vector <long double> 
   (no_of_facloc,0));
   vector< vector <long double>> Result (pop_size, vector <long double> 
   (no_of_facloc,0));
   vector< vector <long double>> x (no_of_facloc, vector <long double> 
   (no_of_facloc,0));

   vector <long double> facility (no_of_facloc);
   //vector <long double> objFunction (no_of_facloc);

   //vector <long double> loc (no_of_facloc);

   int i, k, j, q, p, z;
   int temp_loc,  same_temp_loc, loc; 
   long double	objFunction;

   ofstream outResult ("Result12rou.txt"); //write result


    void input()
   {
	//open input file
	ifstream inpFlow ("flow12rou.txt"); //read flow data
	ifstream inpDist ("dist12rou.txt"); //read dist data
	
	

	//assign flow into array
	for ( i = 0; i < no_of_facloc; i++ )
	{
		for ( k = 0; k < no_of_facloc; k++ )
		{
			inpFlow >> flow[i][k];
			//cout << "flow ["<<i<<"]["<<k<<"]="<<flow [i][k] 
    <<endl;
		}
	}

		//assign distant into array
	for ( j = 0; j < no_of_facloc; j++ )
	{
		for ( q = 0; q < no_of_facloc; q++ )
		{
			inpDist >> dist[j][q];
			//cout << "dist ["<<j<<"]["<<q<<"]="<<dist [j][q] 
  <<endl;
		}
	}


	

   }
   //find possible x
   void pointer_x()
   {
	for (i = 0; i<no_of_facloc; i++)
		{
			loc = facility[i];
			x[i][loc]= 1;  // assign the facility i and loc i to 
                        x
	    }
   }


   //generate objective function
   void obj_function()
   {
	objFunction=0;
	int sum=0;
	
	for (i = 0; i<no_of_facloc; i++)
		{
			for ( k = 0; k < no_of_facloc; k++ )
			{
				for ( j = 0; j < no_of_facloc; j++ )
					{
						for (q = 0; q < no_of_facloc; 
                                                q++)
							{
								sum = flow[i][k] * dist[j][q] * x[i][j] * x[k][q];
								objFunction = objFunction + sum;
								//objFunction = sum;
								//if (sum > 0)
									 // objFunction = objFunction;
							}
						
					 } 
			}
	     }
					
		cout << objFunction<< ' ';
		cout << endl;
			//objFunction=0;
   }



   // generate inital solution 
   void initial_solution()
   {
 	for ( p = 0; p < pop_size; p++ ) //for each population size 1 until n
	{
		for ( i = 0; i<no_of_facloc; i++) //for each facility [i] 
                until size
		{
			//obj_function;
			{			
			  check:
			  temp_loc = rand() % no_of_facloc; //assignt 
                           facility to temporary random location
			  same_temp_loc = 0;
			  //chek for each facility whitch has been assign to
			  
			  for (j = 0; j<i; j++)
			  {
				   if(facility[j] == temp_loc)
				   { 
					   same_temp_loc = 1; 
					   goto check;
			       }
			       	
			  }
			  //check if same, repeat; if not, assign
			  if (same_temp_loc == 0)
			  {
				  facility[i] = temp_loc; //assign facility 
                                  to temp_lock
				 
			  }	
			  
			  cout << setw(3) << facility[i] << ' ';
			 //outResult << setw(3) << facility[i] << ' ';
			   
			}
			
		}
		pointer_x();
		obj_function();
		//outResult << endl;
		cout<< endl;	    
	} 	
	//obj_function;
	//cout << setw(3) << obj_function()<< ' ';
	//cout<< endl;
   }






   int main()
	
   {
	input();
	srand(time(NULL));
	initial_solution();
	//pointer_x();
	//obj_function();
	//Read_Result();

	system("pause");
	
	return 0;

   }


the objective function is where it calculate the result

this is the example of the result i get..
only the 1st one is correct


10 3 4 9 2 11 7 8 0 1 5 6 =52410

5 11 10 7 1 0 2 6 4 8 9 3 =145936

10 3 6 7 2 11 5 0 4 9 8 1 =228342

9 10 11 8 6 1 0 2 7 3 5 4 =466138

9 1 7 3 11 6 2 4 10 5 0 8 =747670

9 10 6 8 2 11 1 0 4 5 7 3 =768470

11 7 2 8 4 10 9 6 1 5 3 0 =1.03283e+006

5 6 7 2 0 3 8 11 4 10 9 1 =1.31354e+006

0 4 5 3 2 7 10 6 1 8 11 9 =1.63161e+006

4 6 10 9 3 7 5 8 11 1 0 2 =1.80093e+006

2 10 4 3 6 1 8 9 7 11 5 0 =2.08034e+006

9 1 3 0 2 4 10 11 5 8 6 7 =2.24092e+006


Last edited on
this is the data

dist12rou.txt

0 36 54 26 59 72 9 34 79 17 46 95
36 0 73 35 90 58 30 78 35 44 79 36
54 73 0 21 10 97 58 66 69 61 54 63
26 35 21 0 93 12 46 40 37 48 68 85
59 90 10 93 0 64 5 29 76 16 5 76
72 58 97 12 64 0 96 55 38 54 0 34
9 30 58 46 5 96 0 83 35 11 56 37
34 78 66 40 29 55 83 0 44 12 15 80
79 35 69 37 76 38 35 44 0 64 39 33
17 44 61 48 16 54 11 12 64 0 70 86
46 79 54 68 5 0 56 15 39 70 0 18
95 36 63 85 76 34 37 80 33 86 18 0

flow12rou.txt

0 90 10 23 43 0 0 0 0 0 0 0
90 0 0 0 0 88 0 0 0 0 0 0
10 0 0 0 0 0 26 16 0 0 0 0
23 0 0 0 0 0 0 0 0 0 0 0
43 0 0 0 0 0 0 0 0 0 0 0
0 88 0 0 0 0 0 0 1 0 0 0
0 0 26 0 0 0 0 0 0 0 0 0
0 0 16 0 0 0 0 0 0 96 0 0
0 0 0 0 0 1 0 0 0 0 29 0
0 0 0 0 0 0 0 96 0 0 0 37
0 0 0 0 0 0 0 0 29 0 0 0
0 0 0 0 0 0 0 0 0 37 0 0
Topic archived. No new replies allowed.