数字化婚姻配对尝试

一、标题:

数字化婚姻配对尝试

二、题目:

建立一个模型,来模拟推导社会男女择偶过程。

为了模型简化,一个人的特性指标有三个,这里假设为财富、样貌、品格,每个指标均可取值1-100之间任意数字。同样也对这3项指标有自己的需求。这3个需求值取值范围都在1-98间,当然三者的和必须为100.所以任意一个人可以用以下数组来表述:

G(A、B、C、A1、B1、C1)G代表男,M代表女。

举例G11(80、50、40、10、30、60),表示男11号,拥有财富80、样貌50、品格40,对异性品格的偏好为:财富在乎程度百分之10、样貌在乎程度百分之30、品格在乎程度百分之60。

同样为了模型简化,假设信息是完全对称的,即是说,每个人都能一眼就能看清楚任意一个人的财富、样貌、品格。

还是为了模型简化,我建模所用样本为男女各100个,即男女人数相同。

每个人对异性的满意度将如下定义:每个偏好指标与异性的对应的禀赋指标相乘,三个指标的乘积再相加,即他(她)对某个异性的满意度。

举例G11(80、50、40、10、30、60)对M(50、60、80、40、10、50)的满意度为:

(1050+3060+60*80)= 7100分

相对的 MM 对 GG的满意度则为:

(4080+1050+50*40) = 5700分

好了,配对活动开始,设计的配对法则如下:

1、100个男方,顺序,轮流从0号到99号女方中挑选自己最满意的一位,然后向她发出配对邀请。

2、接受邀请最多的女方开始行动,对这些邀请的男性中,选择最满意的一位。

3、那么这两位配对成功,剔除出样本,剩下的99对继续这样配对。

4、循环该配对法则,直到最后一对男女配对成功。

三、代码实现

#include <iostream>
#include <unordered_map>
#include <map>
#include <vector>
#include <set>
#include <algorithm>
#include <assert.h>
#include <time.h>
#include <thread>
#include <string.h>
#include <string>
#include <pthread.h>
#include <omp.h>

using namespace std;

#define THREADS 4
struct Node
{
   
	Node(int id = 0,int su = 0,int sa = 0):ID(id),sum(su)
								,satisfaction(sa)
	{
   }
	int ID;
	int sum;
	int satisfaction;
};

struct Node2
{
   
	Node2(int id = 0,int su = 0,int c = 0):ID(id),sum(su)
		,count(c)
	{
   }
	int ID;
	int sum;
	int count;
};

class comp
{
   
public:
	bool operator()(const Node &left, const Node &right)
	{
   
		if(left.satisfaction > right.satisfaction)
		{
   
			return true;
		}
		else if(left.satisfaction == right.satisfaction)
		{
   
			if(left.sum > right.sum)
			{
   
				return true;
			}
			else if(left.sum == right.sum && left.ID < right.ID)
			{
   
				return true;
			}
		}
		return false;
	}
};

struct people
{
   
	people(int id = 0,int w = 0, int a = 0, int c = 0, 
			int s_w = 0, int s_a = 0, int s_c = 0)
			:ID(id),wealth(w),appearance(a),chararter(c),
			s_wealth(s_w),s_appearance(s_a),s_chararter(s_c)
	{
   }
	
	int ID; //对象的编号
	int wealth; //财富
	int appearance; //样貌
	int chararter;  //品格
	int s_wealth;   //期望配偶财富
	int s_appearance; //期望配偶样貌
	int s_chararter;  //期望配偶品格
	
	
	//对于男性,记录对所有女性的满意度
	//对于女性,记录选择她的男性的满意度
	set<Node,comp> recode;
};


class comp2
{
   
public:
	bool operator()(const Node2 &left, const Node2 &right)
	{
   
		if(left.count > right.count)
		{
   
			return true;
		}
		else if(left.count == right.count)
		{
   
			if(left.sum > right.sum)
			{
   
				return true;
			}
			else if(left.sum == right.sum && left.ID < right.ID)
			{
   
				return true;
			}		
		}
		return false;
	}
};



class man
{
   
public:
	//计算所有女性在男性心里的满意度,并添加
	void countMaleSatisfaction(unordered_map<int,people>::iterator &it_male
								,unordered_map<int,people> &female )
	{
   
		auto it_female = female.begin();
		for(; it_female != female.end(); ++it_female)
		{
   
			int sum = it_female->second.wealth + it_fem
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值