You are passing a particular 2d array stored in the 3d vector to fitnessChart() by supplying the 1st index only. Was this your 1st question? |
exactly! :D
I'm guessing that this was caused by lines 27 and/or 52. The upper limit in those for loops should be "size of population" |
no, the function has to iterate as many times as there are rows/columns in the 2d matrix, not the total number of 2d matrices. These could be different.
EDIT: oh wait, no, you're right ... i was looking at fitness function, that's where my comment applies >.<
also, what is the 'array' part in
1 2 3 4
|
for(int i = 0; i < vertices; i++)
{
fitnessChart(array[2], vertices);
}
|
says no suitable conversion from stdblahblah <int> to stdblahblah <int&>
thanks for bearing with me :3 this is really fun actually = ^.^ = for me at least X3 i like learning new stuffs :D
EDIT: still getting "vector subscript out of range"
blarg ... gonna go stare at it some more
here's what it looks like now btw, pretty much same
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
|
#include "stdafx.h"
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include<vector>
using namespace std;
void fitnessChart(std::vector<std::vector<int> > array);
int main(int argc, char* argv[])
{
int vertices;
const int initial_value = 0;
int i;
std::cout << "Enter the number of vertices:" << std::endl;
std::cin >> vertices;
std::cout << "Enter the size of the population:" << std::endl;
std::cin >> i;
std::vector<int> sub_sub_array(vertices, initial_value);
std::vector<std::vector<int> > sub_array(vertices, sub_sub_array);
std::vector<std::vector<std::vector<int> > > array(i, sub_array);
int e;
for(int i = 0; i < array.size(); ++i)
{
for(int j = 0; j < array[i].size(); ++j)
{
for(int k = 0; k < array[i][j].size(); ++k)
{
e = rand() %2;
if (j == k)
{
array[i][j][k] = 9;
break;
}
else
{
array[i][j][k] = e;
array[i][k][j] = e;
}
}
}
}
// Print out the full array contents
for(int i = 0; i < array.size(); ++i)
{
for(int j = 0; j < array[i].size(); ++j)
{
for(int k = 0; k < array[i][j].size(); ++k)
{
if(j!=k)
{
std::cout << " " << array[i][j][k] << " ";
}
else
std::cout << " - ";
}
std::cout << "\n";
}
std::cout << "\n";
}
for(int i = 0; i < vertices; i++)
{
fitnessChart(array[2]);
}
system ("pause");
}
void fitnessChart(std::vector<std::vector<int> >array)
{
int count=0, match, j=0;
for(unsigned int k = 0; k < array[k].size(); ++k)
{
match = array[j][k];
j=k;
for(unsigned int k = 0; k < array[k].size(); ++k)
if (array[j][k+1] == match)
{
if (array[j][k+1] == match)
{
count++;
}
}
}
}
cout << count << endl;
}
|
here's what needs to happen:
test drive with 4 vertices and just one 2d matrix
after the first function randomly filled the array with 1's and 0's the fitness function checks to see if there is a subgraph of 3 vertices as such:
if array[a][b]=1 it means vertices a and b are connected:
a--1--b
| \ _ / |
0 1x0 1
| /__\ |
c--1--d |
(pardon the shitty illustration +.+ ... no trailing spaces >.<)
here vertices a, b, d are connected and create a subgraph ('x' is the intersection of two inner diagonals, not a vertex).
yet another EDIT: asked around, people keep saying it works on their compiler, but freaks out in my Visual Studio ... this is unsettling :\ ...