-2

I am creating a genetic algorithm that classifies set of data for which I need to generate random sequences of 1s,0s and 2s for defining a rule 2 represents it being in 2 states a 1 and 0. I am trying to use Map STL for mapping the random set of rules generated and the output for each rule. I need the Map key to be dynamic/ changing every iteration/generation to be filled by new population of rules.

I realise I have option of using pointers which complicates my code and will have readability issue.

The other option I know about is copying the key elements and value and deleting it so it can be replace by the new rule.

So, My question is:

1). Is it better to use vector and my own mapping algorithm? The only problem being is I want to be efficient and fast as I will be dealing with 2000 or more data.

2). Are there any other STL which I can use no libraries that I need to download pls.?

3). Shall I just use Map and keep reseting the elements in the map each time so I can initialise them again?

which method would be effective?

Open to any other suggestion or advice.

Sad.coder
  • 21
  • 10
  • Ok I need to read what is the bench mark for asking questions here. I understand this might be a broad question. Please do guide me rather than down voting this. – Sad.coder Oct 29 '16 at 17:53
  • Does it even matter? Experienced developers write simple, clear code first, and then see if performance is an issue. And yes, you can do that even if you magically know the performance is going to be an issue - you want a known-good version so you can then compare it to your fast-but-complex version. – MSalters Oct 29 '16 at 19:58
  • It doesn't matter but I wanted to know that I have looked through as many option as possible. I am solely basing that performance of my program is going to be an issue in that I know that a lot of people have worked on map stl and made it as efficient as possible as well as less bugs to deal with. – Sad.coder Oct 29 '16 at 21:47
  • Thank you for your advice as well. – Sad.coder Oct 29 '16 at 21:48

1 Answers1

0

If you don't want data to be in sorted order you could consider std::unordered_map<>. Have a look at this for some benchmarks.

Community
  • 1
  • 1
Sulabh Kumar
  • 101
  • 7
  • Umm... my map isn't static. Reading the comments on the link provided it seems it will probably not be beneficial to use unordered map. I want my program to be as fast and simple as possible but if I do need to trade one it will probably be fast. – Sad.coder Oct 29 '16 at 18:01