473,407 Members | 2,315 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

change multidim array to vector

I have a "population" of objects that is suppose to do a lot of stuff during its lifecycle... I had everything working fine (not fancy code, though) with an array, but now I've received instructions to let the population change size over generations. This means my array no longer works...I want to change it to a vector (or map), keeping the basic structure of the code. But it beats my skills...I read a thread (http://www.thescripts.com/forum/thread452569.html) about something similar (2d vectors), but I didn't quite get it.

Here's part of the code:
Expand|Select|Wrap|Line Numbers
  1. #include <vector>
  2.  
  3. #define Ngener 3000
  4. #define Nfitgene 2
  5. #define popSize 1000
  6.  
  7. using namespace std;
  8.  
  9. class individual {
  10.         public: 
  11.             int habgene[2], fitgene[2][Nfitgene];
  12.             int chromosum() {return habgene[0] + habgene[1];}
  13.             int chromofitsum (int index) {return fitgene[0][index] + fitgene[1][index];};
  14.             int chosenHab;
  15.             int alive;
  16.         } bicho [popSize];
  17.  
  18. int i, j, k, generation = 0;
  19.  
  20. //---------------------------------------------------------------
  21. int main ()
  22. {
  23.  
  24. for(i=0; i<popSize; i++)
  25. {
  26. bicho[i].habgene[0]=binaryPick(freq0_A); /*binaryPick is a function that doesn't matter right now*/ 
  27. bicho[i].habgene[1]=binaryPick(freq0_A);
  28.     for (j=0; j<Nfitgene; j++)
  29.     {
  30.     bicho[i].fitgene[0][j]=binaryPick(fitfreq0_A[j]);
  31.     bicho[i].fitgene[1][j]=binaryPick(fitfreq0_A[j]);
  32.     }
  33. }
  34. /* individuals will survive, reproduce, die and descendants will form a new population*/
  35.  
  36. }
please give me some pointers, considering that my C++ knowledge is quite limited.
Oct 13 '06 #1
0 1380

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Sona | last post by:
Please could someone tell me how to use a single-dimensional array as a two-dimensional array? Is the following correct: int ROW_SIZE = 5; int COL_SIZE = 3; int *arr = (int*)...
10
by: BCC | last post by:
Ive been googling and reading through my books but I haven't figured out a solution (much less an elegant one) to create a multidimensional array with a runtime determined number of dimensions. I...
8
by: Levent | last post by:
Hi, Is it possible to have static multi-dim array as a function return parameter? in particular, class Foo { int arr; public: ? getArr() {return (?) arr;}
2
by: Salman Khilji | last post by:
After reading all the FAQs, I cannot solve the following problem: I have a pointer of type double. I am supposed to 1) Allocate memory for it assuming that the pointer will be pointing to a...
1
by: Abhi | last post by:
Hi! I am wondering if someone can point me to the needed sort function. There are so many of them that I simply got lost by reading their descriptions. I try to explain what I need. I have a...
49
by: vfunc | last post by:
If I have a large array 10,000+ elements then how do I reserve memory for this ? Currently I get a segmentation fault. Dynamic reservation is good, but allowing a chunk for the program is an...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
9
by: JoeC | last post by:
I am crating a new version of my map game and my map will be a 2d array. I had problems trying to create a 2d array dynamically, in fact C++ won't let me do it. My question is how to create the...
6
by: remlostime | last post by:
now, i write some code code1: int a; int main(){} code2: vector<inta(10000000); int main(){} after using g++ compile, and run it, code1 is broken, but code2 runs
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.