Help with structure vector pairs

Hello,

I am making a pair matching project for school. Right now I'm a little stuck and was seeking help.

I've created 100 profiles, 50 males and 50 females with random attributes. I separated the profiles by gender using vectors. Now I have to create a vector of pairs and score each matching pair with a score. In the end, I should have a total of 2,500 possible pairings (males can only pair with females). Each profile is a struct with attributes and each attribute has a score.



I am not sure how to create a vector of pairs, assign every possible pairing to it, and then assign a score to each pair. Any help is appreciated.

**this is just an example**

struct profile {
//this structure has profile attributes with each
//attribute having a score to it

class Match {
private:
std::vector<profile> _males;
std::vector<profile> _females;
std::vector<std::pair<profile, profile> _pairs;
Your <profiles> need something like this. (You can probably also use std::'permutations' too)

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
#include <iostream>
#include <vector>

int main()
{
    std::vector<int> male;
    std::vector<int> female;
    
    std::vector<std::pair<int,int>> pair;
    
    for(int i = 0; i < 5; i++)
    {
        male.push_back(i);
    }
    
    for(int i = 0; i < 6; i++)
    {
        female.push_back(i);
    }
    
    for(int m = 0; m < male.size(); m++)
    {
        for(int f = 0; f < female.size(); f++)
        {
            pair.push_back( std::pair<int, int>(m,f) );
        }
    }
    
    int count{0};
    for(auto i:pair)
    {
        std::cout << count << ": " << i.first << ' ' << i.second << '\n';
        count++;
    }
    
return 0;
}
Here is some of the code:

// This struct calls other functions to generate random information about each profile.
struct Profile {
uint32_t id;
Gender gender;
std::tuple<Country, double> country;
std::tuple<Diet, double> diet;
std::tuple<bool, double> drinking;
std::tuple<Language, double> language;
std::tuple<Religion, double> religion;
std::tuple<bool, double> smoking;
};

void Match::pairs() {
Match::sortGenders();
int counter = 0;

//_maleProfile and _femaleProfiles are just the number of profiles for each gender
// _males and _females are my actual vectors for each gender

for(int i = 0; i < _maleProfiles; i++) {
for(int j = 0; j < _femaleProfiles; j++) {
counter++;
_pairs.push_back(std::make_pair(_males[i], _females[j]));
}
}
}

class Match {
private:
std::vector<Profile> _profiles;
std::vector<std::pair<Profile, Profile>> _sortedPairs;
std::vector<std::pair<Profile, Profile>> _pairs;

std::vector<Profile> _females;
std::vector<Profile> _males;
std::vector<std::pair<uint32_t, uint32_t>> _vTest;

// _maxProfiles will create the total number of profiles
int _maxProfiles = 100;
int _maleProfiles = _maxProfiles/2;
int _femaleProfiles = _maxProfiles/2;

double _score;

public:
static std::map<uint32_t, uint32_t> pairs(std::vector<Profile> &);

Match();
void sortedPairs();
void pairs();
void sortGenders();
double calcScore(const Profile &a, const Profile &b);

// Test function to print out
void dump ();
};

I am only using the counter to make sure I was getting the correct number of pairs.
FWIW I used the counter for the same reason.

I don't know whether you want any comment on yours or not. However, and it's a bit of a guess on my part, you can probably get away with just one vector of pairs and simply sort and filter that one which makes it more reliable and avoids duplication. All you would have is a set of queries of the single base dataset of pairs. (it would even be good to eliminate the need for the vector of pairs but I can't see how that could be done at a quick glance)
Topic archived. No new replies allowed.