how do i code this?

hello, i a beginner in using c++. im doing a quadratic assignment problem
i have this problem.. i really blackout in coding this. i already start with reading the data and than the next step is create the initial solution

dist12rou=

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=

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

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
  #include "stdafx.h"
  #include <iostream>
  #include <fstream>
  #include <vector>

  using namespace std;

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

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


  vector< vector <long double>> flow (m, vector <long double> (m,0));
  vector< vector <long double>> dist (m, vector <long double> (m,0));

  vector <long double> startfacility (pop_size);

  int i, k, j, q;


  void main()
	
  {
	input();

  }

  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 < m; i++ )
	{
		for ( k = 0; k < m; k++ )
		{
			inpFlow >> flow[i][k];
			//cout << "flow ["<<i<<"]["<<k<<"]="<<flow [i][k] 
  <<endl;
		}
	}

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

  }


  // generate initial solution (this part i didnt know how to code)
  // generate inital solution 
  int main()
  {
	for ( i = 0; i < pop_size; i++ ) //for each population size 1 until n

	{
		for (facility[i]= 0; i<pop_size; i++); //for each facility [i] until size

			 facility[i]= rand location[j][0];  //facility[i]=0 assign to random location 
                                                                         // [j],
			  {
				 if location[j]==0; // location [j] is not visited  which is = 0                                                                  
				 facility [i]=location[j]; //assign				
				 else location [j]==1; //the location has been visit which is =1
				 facility [i]!=location[j]; //do not assign 
                           }
	}
  }
  //end 


what i want to do is like this

for each population = 0 until 2
for each facility [i] until size
facility[i]=0 assign to random location [j], location [j]=random value
if location [j] is not visited which is = 0
assign to
else the location has been visit which is =1
do not assign
else go back to choose random location
end for i
end for population

please help me
Last edited on
> for each population = 0 until 2
> for each facility [i] until size
But you only have 'flow' and 'dist'?



the flow consist facility i and k and the dist consist location j and q
Last edited on
Topic archived. No new replies allowed.