I'm working on an implementation of a genetic algorithm to find good solutions for a problem. This requires me to store a vector of pairs, where each pair consists of an int value ((-1) or (1)) and a float score ([0..1]).
This is what I use to define the variables and save the data:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
//// these are defined in the class Track ////
vector<pair<int,float>> _path; // moves and chances from _initStore. (-1)=Left, (1)=Right.
float _score; // Buy % of the track '_path'
//////////
//// these commands are executed in a Track member function: void Track::calcScore(Robot* r, vector<int> path) ////
int move; // Current randomized move
pair<int,float> curMove; // Temp for current move/score
_path.reserve((leftMoves+rightMoves)); // Reserve enough space in the path vector _path
curMove=make_pair(move,_score); // move=(-1) or (1). _score=[0..1]
_path.push_back(curMove);
//////////
|
Please note that path is a vector<int> which belongs to the function calcScore, while _path is a member of instances of the class Track.
Using the debugger, after the _path.reserve command the debugger shows _path to be size=0, capacity=8.
After the curMove=... command curMove does contain the right arguments - for example (1,0.8999).
However, after the push_back command, the debugger shows _path as having size=2 and capacity=8, with the _path[0]=1 and _path[1]=0.8999. Both types are shown as int in the Type column.
Why does this happen?
Can't a vector store a pair?