• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
liyuken
博客园    首页    新随笔    联系   管理    订阅  订阅

第六次作业--结对编程第二次作业

结队成员:

自己:

学号 姓名 性别
616 语恳 男

队友:

学号 姓名 性别 队友博客
618 炜坤 男 队友博客

github链接

项目要求

  • 1、输入的数据,另外写生成程序随机实现。
  • 2、为输入输出设计接口,为该匹配程序模块后期可能的整合入系统提供便利。
  • 3、输入输出采用 json 文本文件方式,可自由讨论确定细节内容,但需要明确并体现在博客中。
  • 4、需要为匹配算法确立几条分配或排序原则,比如 绩点优先、或兴趣优先、或活动时间优先、或其他等等,请你们结对讨论确定。
  • 5、对不同策略做出评价,并在博客中展示测试结果。提醒:对于同一组输入,输出的未被导师选中的学生数越少越好。
  • 6、博客中列出代码你们的代码规范要求。
  • 7、实现的程序语言以C/C++优先,部分同学如果对Java/C#掌握更加熟练也可接受。
  • 8、代码提交在GitHub上,并在博客中提供项目链接(注意不是Github个人主页)。
  • 9、两人博客中涉及到设计及代码展示可以相同,但是要求使用自己语言加以描述。

设计说明

  • 接口设计(API)

  • void Generate_JSON(int N,int M); //随机产生需要输入的数据(需要部门数和学生数)

  • void ReadJson(Department* &department, Student* &student,int N,int M); //读入json文件

  • void match(Department* &department,Student* &student,int N,int M); //部门匹配学生

  • void output(Department* department, Student* student, int N, int M) //输出匹配结果

  • 内部实现设计(类图)

  • 匹配算法设计(思想/流程等)

  • 根据项目要求,设计两个类学生类和部门类,其中学生类包含学生的学号,姓名,志愿,绩点,兴趣以及空闲时间。部门类包含部门号,兴趣要求,绩点要求,活动时间,部门人数等。在主函数随机生成的若干学生和诺干部门中进行匹配。由于在部门占有较高主动权,所以以部门为单位,依次遍历学生,根据学生的绩点,兴趣以及空闲时间,判断是否能招。由于判断条件主次不一,我们分别设定兴趣吻合度,时间吻合度,以及绩点吻合度。
    匹配兴趣时,遍历学生的兴趣,发现1个跟部门要求相同的兴趣,对该学生评分加4分,两个加8分一次类推。同理,时间吻合度也是一个匹配的时间加4分。绩点要求,只要该生绩点大于要求绩点,该生评分加10分。最后算出每个学生的总评分,然后根据评分的大小进行排序,根据部门招募人数决定评分最高的几名学生入选。

  • 测试数据如何生成?

  • 创建一个数据生成器的头文件DataGenerator.h及类DataGenerator(包括各项属性的生成方式),分别定义定部门数据生成、学生数据生成(引用部门类和学生类)。
    学生:学号(S0315xxxx),姓名(AZxxx),性别(female/male),绩点(15分),兴趣标签(25个),空闲时间(210个),部门志愿(2~5个)。
    部门:编号(AZx),部门名称(同学生),人数限制(015人),活动时间(15个),标签(35个),绩点限制(1~3分)。
    有关字符串方面的数据均通过定义固定的string数组,随机生成数组下标来达成随机字符串的目的。
    基于最大数据(100,5000),学号和部门号均不重复,现阶段的随机形式也够用了,但这些数据离现实还是有很多差距,有待改进。

  • 如何评价自己的匹配算法?
    我们的匹配算法其实仅仅是根据老师要求上的几个判定条件写的,没有多加别的判断条件,所以匹配算法比较简单,但是还是能做到对学生基本的区分。还有就是,多次遍历导致计算量较大,还需要多加改进才行。

关键代码解释

志愿匹配函数:

  • 用于将学生与部门进行匹配的函数,函数中包含对学生评分的筛选。
  • 该函数针对单个单个部门和单个学生,具体要求多个部门对多个学生可在外部加入双重循环。部门根据当前学生的志愿进行查找,寻找是否有本部门的部门号,如果有则匹配,没有则跳出。匹配到学生时,首先判断本部门是否已达到人满,如果人未满,则直接将其放入预选名单中,并记录其评分,如果人满,则需要将该学生的评分算出,与预选名单中的学生评分进行比较,若发现该学生评分大于预选表中某学生的评分则将其放入预选表中,并将评分较低的学生淘汰。
void Department::willmatching(Student &s)
{
	if (D_Limit != 0)
	{
		for (int i = 0; i < 5; i++)
		{
			if (s.S_Choice[i] == D_No)
			{			
				if (numofstu < D_Limit)
				{
					student[numofstu] = s.S_No;
					m[numofstu] = cmp(s.GPA, s.S_Schedules, s.S_Tags, GPA_Limit, D_Schedules, D_Tags);
					numofstu++;
				}
				else if (numofstu > D_Limit)
				{
					m[numofstu] = cmp(s.GPA, s.S_Schedules, s.S_Tags, GPA_Limit, D_Schedules, D_Tags);
					for (int u = 0; u < D_Limit; u++)
					{
						if (m[numofstu] > m[u])
						{							
							m[u] = m[numofstu];
							student[u] = student[numofstu];
							break;
						}
					}
				}
			}
		}
	}
}

评分计算函数

  • 用于计算各学生的评分,根据不同的条件要求,对学生进行评分,算出部们对学生的总评分。
  • 对于学生的兴趣条目与部门的兴趣要求进行匹配,发现一个相同的对该学生评分加4分,两个加8分,一次类推。同理对时间表也是发现一个相同的加4分,对于绩点要求,学生绩点高于部门要求绩点,评分加十分。
int  cminterests(string* s_interest, string* d_interest)
{
	int i, j, n = 0, n1 = 0, mark = 0;
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < n1; j++)
		{
			if (s_interest[i] == d_interest[j])
			{
				mark = mark + 1;
			}
		}
	}
	mark = mark * 4;
	return mark;
}
int  cmschedual(string* s_che, string* d_che)
{
	int i, j, n = 0, n1 = 0, mark = 0;
	for (i = 0; i < 10; i++)
	{
		if (s_che[i] == "")break;
		for (j = 0; j < 5; j++)
		{
			if (d_che[j] == "")break;
			if (s_che[i] == d_che[j])
			{
				mark = mark + 1;
			}
		}
	}
	mark = mark * 4;
	return mark;
}
int	 cmpoint(float p1, float p2)
{
	int mark = 0;
	if (p1 >= p2)
	{
		mark = mark + 10;
	}
	return mark;
}
int  cmp(float point, string* schedual, string* interests, float point1, string* schedual1, string* interests1)
{
	int mark;
	mark = cminterests(interests, interests1) + cmschedual(schedual, schedual1) + cmpoint(point, point1);
	return mark;
}

运行及测试结果展示

  • 运行结果为有匹配部门的学生及其选中的部门,有匹配学生的部门及其选入的学生名单
    为匹配到学生的部门,未匹配到部门的学生。
  • 完整数据链接
  • 测试200位同学,20个部门的情况
  • 测试结果概况描述
  • 测试输入数据片段展示及完整数据链接
{
    "department": [
        {
            "Department_No": "D087",
            "Department_Name": "H867",
            "Limit": 3,
            "GPA_Limit": 1.1069999933242798,
            "Tags": [
                "programing",
                "basketball",
                "film",
                "dancing",
                "running"
            ],
            "Schedules": [
                "Sat.9: 00~10: 00",
                "Fri.13: 00~14: 00",
                "Wed.13: 00~14: 00",
                "Tue.19: 00~20: 00",
                "Wed.9: 00~10: 00"
            ]
        },
        {
            "Department_No": "D062",
            "Department_Name": "H174",
            "Limit": 1,
            "GPA_Limit": 2.4739999771118166,
            "Tags": [
                "travelling",
                "hiking",
                "basketball",
                "swimming",
                "English"
            ],
            "Schedules": [
                "Thu.19: 00~20: 00"
            ]
        },
				.....
				```

- 测试输出数据片段展示及[完整数据链接](https://github.com/liyuken/diliucizuoye/tree/master/test/)

{
"matched_department_view": [
{
"department_no": "D087",
"chosen_students": [
"S031500435",
"S031501608",
"S031508124"
]
},
{
"department_no": "D062",
"chosen_students": [
"S031504347"
]
},
{
"department_no": "D084",
"chosen_students": [
"S031502714",
"S031506434",
"S031503323",
"S031504005",
"S031508933",
"S031504339",
"S031504409",
"S031508606",
"S031504627",
"S031507531",
"S031507641"
]
},
"standalone_departments": [
"D092",
"D091"
],
"standalone_students": [
"S031502852",
"S031501222",
"S031508038",
"S031506137",
"S031501149",
"S031500014",
"S031507024",
"S031505205",
"S031505725",
```

  • 测试500位同学,30个部门的情况
  • 测试结果概况描述
  • 测试输入数据片段展示及完整数据链接
{
    "department": [
        {
            "Department_No": "D042",
            "Department_Name": "S141",
            "Limit": 1,
            "GPA_Limit": 1.8980000019073487,
            "Tags": [
                "film",
                "math",
                "sports",
                "swimming",
                "travelling"
            ],
            "Schedules": [
                "Sun.21: 00~22: 00",
                "Sun.20: 00~21: 00"
            ]
        },
        {
            "Department_No": "D077",
            "Department_Name": "B520",
            "Limit": 8,
            "GPA_Limit": 1.5379999876022339,
            "Tags": [
                "dancing",
                "swimming",
                "game"
            ],
            "Schedules": [
                "Wed.9: 00~10: 00",
                "Fri.21: 00~22: 00",
                "Mon.9: 00~10: 00"
            ]
        },
				```
- 测试输出数据片段展示及[完整数据链接](https://github.com/liyuken/diliucizuoye/tree/master/test/)
```{
    "matched_department_view": [
        {
            "department_no": "D042",
            "chosen_students": [
                "S031505929"
            ]
        },
        {
            "department_no": "D077",
            "chosen_students": [
                "S031504701",
                "S031508922",
                "S031508632",
                "S031503702",
                "S031508414",
                "S031500038",
                "S031508523",
                "S031505004"
            ]
        },
        {
            "department_no": "D063",
            "chosen_students": [
                "S031501654",
                "S031503205",
                "S031506213",
                "S031507959",
                "S031505035",
                "S031500735",
                "S031506715",
                "S031503157",
                "S031505921",
                "S031503035",
                "S031502451",
                "S031502355",
                "S031504214",
                "S031508232"
            ]
        },
				```

- **测试1000位同学,50个部门的情况**
- 测试结果概况描述
![](http://images2017.cnblogs.com/blog/1221263/201710/1221263-20171015194104746-1173972340.png)
- 测试输入数据片段展示及[完整数据链接](https://github.com/liyuken/diliucizuoye/tree/master/test/)

{
"department": [
{
"Department_No": "D027",
"Department_Name": "G845",
"Limit": 10,
"GPA_Limit": 2.9040000438690187,
"Tags": [
"running",
"hiking",
"reading"
],
"Schedules": [
"Mon.21: 00~22: 00"
]
},
{
"Department_No": "D091",
"Department_Name": "I720",
"Limit": 5,
"GPA_Limit": 2.5739998817443849,
"Tags": [
"sports",
"music",
"travelling",
"math",
"English"
],
"Schedules": [
"Wed.13: 00~14: 00",
"reading"
]
},
```

  • 测试输出数据片段展示及完整数据链接
{
    "matched_department_view": [
        {
            "department_no": "D027",
            "chosen_students": [
                "S031507325",
                "S031503359",
                "S031507141",
                "S031508603",
                "S031505059",
                "S031503650",
                "S031504418",
                "S031500937",
                "S031500310",
                "S031507038"
            ]
        },
        {
            "department_no": "D091",
            "chosen_students": [
                "S031505307",
                "S031508045",
                "S031504656",
                "S031508513",
                "S031506740"
            ]
        },
        {
            "department_no": "D079",
            "chosen_students": [
                "S031505352",
                "S031506410",
                "S031500919",
                "S031507053",
                "S031503759",
                "S031508419",
                "S031503512",
                "S031500806",
                "S031503621",
                "S031507116",
                "S031507408",
                "S031507702",
                "S031508058",
                "S031503014"
            ]
        },
				```

- **测试5000位同学,100个部门的情况**
- 测试结果概况描述
![](http://images2017.cnblogs.com/blog/1221263/201710/1221263-20171015194112090-1163575569.png)
- 测试输入数据片段展示及[完整数据链接](https://github.com/liyuken/diliucizuoye/tree/master/test/)

{
"department": [
{
"Department_No": "D062",
"Department_Name": "R449",
"Limit": 3,
"GPA_Limit": 1.7549999952316285,
"Tags": [
"dancing",
"game",
"painting",
"sports",
"swimming"
],
"Schedules": [
"Sun.9: 00~10: 00"
]
},
{
"Department_No": "D008",
"Department_Name": "B439",
"Limit": 2,
"GPA_Limit": 1.8799999952316285,
"Tags": [
"programing",
"dancing",
"painting",
"hiking",
"reading"
],
"Schedules": [
"Mon.16: 00~17: 00",
"Thu.9: 00~10: 00",
"Sun.13: 00~14: 00"
]
},
```

  • 测试输出数据片段展示及完整数据链接
{
    "matched_department_view": [
        {
            "department_no": "D062",
            "chosen_students": [
                "S031504203",
                "S031502320",
                "S031502028"
            ]
        },
        {
            "department_no": "D008",
            "chosen_students": [
                "S031501242",
                "S031503131"
            ]
        },
        {
            "department_no": "D078",
            "chosen_students": [
                "S031504022",
                "S031502028"
            ]
        },
        {
            "department_no": "D094",
            "chosen_students": [
                "S031507955",
                "S031502314",
                "S031503612",
                "S031502258",
                "S031508532",
                "S031500105"
            ]
        },
        {
            "department_no": "D072",
            "chosen_students": [
                "S031508705",
                "S031500603",
                "S031503635",
                "S031506657",
                "S031507502",
                "S031504046",
                "S031503022",
                "S031505705",
                "S031504402",
                "S031502806",
                "S031506526"
            ]
        },
				```
### **改进后的程序**
-测试输出数据片段 5000个学生及200个部门
![](http://images2017.cnblogs.com/blog/1221263/201710/1221263-20171018013403099-296754753.png)


### **遇到的困难及解决方法**

- **困难描述**
- 第一次接触jason,并不是很了解。由于代码量比较大,所以测试起来有点麻烦。

- **做过哪些尝试**
- 网上搜集资料,利用开元的代码。

- **是否解决**
- 解决。

- **有何收获**
- 了解了jason的用法,以及加强了对代码的理解及应用。

### **对队友的评价**
- **有哪些好的地方值得学习**
- 有钻研精神,踏实恳干,态度好。
- **有哪些不好或者需要改进的地方**
- 打代码打的较慢。

| PSP2.1                                  | Personal Software Process Stages        | 预估耗时(分钟) | 实际耗时(分钟) |
|-----------------------------------------|-----------------------------------------|------------------|------------------|
| Planning                                | 计划                                    |       50          |          40        |
| · Estimate                              | · 估计这个任务需要多少时间              |       50         |        50          |
| Development                             | 开发                                    |        200          |          450        |
| · Analysis                              | · 需求分析 (包括学习新技术)             |       50          |         60        |
| · Design Spec                           | · 生成设计文档                          |       0           |       0          |
| · Design Review                         | · 设计复审 (和同事审核设计文档)         |        0          |         0         |
| · Coding Standard                       | · 代码规范 (为目前的开发制定合适的规范) |       0           |         0         |
| · Design                                | · 具体设计                              |       150           |         200         |
| · Coding                                | · 具体编码                              |        0          |        0          |
| · Code Review                           | · 代码复审                              |        0          |        0          |
| · Test                                  | · 测试(自我测试,修改代码,提交修改)  |        30          |         50         |
| Reporting                               | 报告                                    |       50           |        100          |
| · Test Report                           | · 测试报告                              |       5           |         5         |
| · Size Measurement                      | · 计算工作量                            |         30         |         20         |
| · Postmortem & Process Improvement Plan | · 事后总结, 并提出过程改进计划          |        30          |        30          |
| 合计              |               |     610      |   1005  |  

## **学习进度条**
|    第N周     |     新增代码(行)     | 累计代码(行)  |本周学习耗时(小时)|累计学习耗时(小时)|重要成长
| ------------- |:-------------:| -----:|-----:|-----:|-----:|
|  1    | 300 | 300 | 6  | 6  | 重拾C++,初学PHP  |
|  2    |   0   |  0  |  0 | 0  |  学习了原型设计软件的操作及NABCD概念|		
|  3    | 1200 | 900 | 10  | 10  | 接触了jason,巩固了c++  |
posted @ 2017-10-15 19:42  liyuken  阅读(248)  评论(2)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3