毕设:智能组卷平台(遗传算法)
项目描述
智能组卷平台(遗传算法)
分为3个端:管理员端,老师端,学生端
主要功能包括 登录,学生管理,老师管理,题目管理,试卷管理,
知识管理。任务管理,教育管理,试卷管理,批卷管理,
运行环境
jdk8+redis+mysql+IntelliJ IDEA+maven
项目技术
springboot+layui+vue
项目截图
老师端
学生端
部分代码
遗传算法的使用
/*** 遗传算法*/
public class GAUtil {//编译概率private static final double mutationRate = 0.085;//精英主义private static final boolean elitism = true;//淘汰数组大小private static final int tournamentSize = 5;/*** 种群进化* @param pop 种群对象* @param rule 进化规则* @return*/public static Population evolvePopulation(Population pop, Rule rule,QuestionService questionService){Population newPop = new Population(pop.getLength());int elitismOffset;//精英主义if(elitism){elitismOffset = 1;//保留上一代最优秀的个体ExamPaperAlgotithmBean fitness = pop.getFitness();fitness.setId(0);newPop.setPaper(0,fitness);}//种群交叉操作,从当前的种群pop来创建下一代种群newPopfor (int i = elitismOffset; i < newPop.getLength(); i++){//得到两个较优选择ExamPaperAlgotithmBean parent1 = select(pop);ExamPaperAlgotithmBean parent2 = select(pop);//保持连个选择不同while (parent1.getId() == parent2.getId()){parent2 = select(pop);}//交叉ExamPaperAlgotithmBean child = crossover(parent1, parent2, rule,questionService);child.setId(i);newPop.setPaper(i,child);}//种群变异操作ExamPaperAlgotithmBean tmpPeper;for (int i = elitismOffset; i < newPop.getLength(); i++){tmpPeper = newPop.getPaper(i);mutate(tmpPeper,questionService);//计算知识点覆盖率和适应度tmpPeper.setChapterCoverage(rule);tmpPeper.setAdaptationDegree(rule, ExamPaperWeightEnum.CHAPTER_WEIGHT,ExamPaperWeightEnum.DIFFICULTY_WEIGHT);}return newPop;}/*** 选择算子:得到最优个体* @param population* @return*/public static ExamPaperAlgotithmBean select(Population population){Population pop = new Population(tournamentSize);for (int i = 0; i < tournamentSize; i++){pop.setPaper(i,population.getPaper((int)(Math.random()*population.getLength())));}return pop.getFitness();}/*** 交叉算子:* @param parent1* @param parent2* @param rule* @return*/public static ExamPaperAlgotithmBean crossover(ExamPaperAlgotithmBean parent1,ExamPaperAlgotithmBean parent2,Rule rule,QuestionService questionService){ExamPaperAlgotithmBean child = new ExamPaperAlgotithmBean(parent1.getQuestionSize());int s1 = (int) Math.random() * parent1.getQuestionSize();int s2 = (int) Math.random() * parent1.getQuestionSize();// parent1的startPos、endPos之间的序列,会被遗传到下一代int startPos = s1 < s2 ? s1 : s2;int endPos = s1 > s2 ? s1 : s2;for (int i = startPos; i < endPos; i++){child.saveQuestion(i,parent1.getQuestions().get(i));//parent1遗传给下一代的序列}List<Integer> chapterList = rule.getChapters();for (int i = 0; i < startPos; i++){if (!child.containsQuestion(parent2.getQuestions().get(i))){child.saveQuestion(i,parent2.getQuestions().get(i));}else {//如果出现相同题目,重新查找一题题目类型、知识点相同的题目Integer type = parent2.getQuestions().get(i).getQuestionType();List<Question> questions = questionService.selectByLevelTypeChapters(type, chapterList);child.saveQuestion(i,questions.get((int) Math.random()*questions.size()));}}for (int i = endPos; i < parent2.getQuestionSize(); i++){if (!child.containsQuestion(parent2.getQuestions().get(i))){child.saveQuestion(i,parent2.getQuestions().get(i));}else {//如果出现相同题目,重新查找一题题目类型、知识点相同的题目Integer type = parent2.getQuestions().get(i).getQuestionType();List<Question> questions = questionService.selectByLevelTypeChapters(type, chapterList);child.saveQuestion(i,questions.get((int) Math.random()*questions.size()));}}return child;}/*** 突变算子 每个个体的每个基因都有可能突变 每个基因变异的概率大概为0.085,小于等于时可以变异* @param paper*/public static void mutate(ExamPaperAlgotithmBean paper,QuestionService questionService){Question tmpQuestion;List<Question> list;int index;for (int i = 0;i < paper.getQuestionSize(); i++){if (Math.random() <= mutationRate){//进行突变tmpQuestion = paper.getQuestions().get(i);//从题库中获取和变异的题目类型一样分数相同的的题目(不包含编译题目)Integer type = paper.getQuestions().get(i).getQuestionType();Integer chapterId = paper.getQuestions().get(i).getChapterId();List<Integer> chapterIds = new ArrayList<>();chapterIds.add(chapterId);list = questionService.selectByLevelTypeChapters(type, chapterIds);if (list.size() > 0){index = (int) Math.random()*list.size();paper.saveQuestion(i,list.get(index));}}}}}
智能组卷
/*** 随机生成试卷题目id列表* @param model* @param user* @return*/private List<Integer> getRandomQuetionIds(ExamPaperAttrVM model, User user){ ;List<Integer> errorIds = examPaperQuestionCustomerAnswerService.selectErrorIdList(user.getId());ExamPaperQuestionsAttrVM questionsAttrVM = new ExamPaperQuestionsAttrVM(model.getSubjectId(), model.getDifficult(), errorIds);List<Integer> newIds = questionMapper.selectNotErrorQuestionIds(questionsAttrVM);Integer errorNum = model.getErrorQuestionNum();Integer newNum = model.getNewQuestionNum();List<Integer> ids = ExamUtil.randomNewErrorQuestionIds(errorNum, newNum, errorIds, newIds);return ids;}/*** 生成试卷请求编辑vo -- 用于生成试卷对象 -- 智能训练* @param model* @return*/@Overridepublic ExamPaperEditRequestVM getExamPaperEditRequestVM(ExamPaperAttrVM model){User user = webContext.getCurrentUser();List<Integer> Ids = getRandomQuetionIds(model,user);List<Question> questions = questionService.selectQuestionsByIds(Ids);String totalScore = ExamUtil.scoreToVM(questions.stream().mapToInt(q -> q.getScore()).sum());//试卷总分List<Integer> qTypes = questions.stream().map(q ->q.getQuestionType()).distinct().collect(Collectors.toList());//试卷所有类型题名(单选、多选..)List<ExamPaperTitleItemVM> titleItems = qTypes.stream().map(qt -> {List<Question> titleQuestions =questions.stream().filter(q -> q.getQuestionType() == qt).collect(Collectors.toList());//试卷每个小标题下的题目列表List<QuestionEditRequestVM> titleQuestionEditRequestVMs = titleQuestions.stream().map(q -> {QuestionEditRequestVM titleQuestionEditRequestVM = questionService.getQuestionEditRequestVM(q);return titleQuestionEditRequestVM;}).collect(Collectors.toList());//将Quetion转换为vo对象ExamPaperTitleItemVM examPaperTitleItemVM = new ExamPaperTitleItemVM();//生产试卷examPaperTitleItemVM.setName(QuestionTypeEnum.fromCode(qt).getName());examPaperTitleItemVM.setQuestionItems(titleQuestionEditRequestVMs);return examPaperTitleItemVM;}).collect(Collectors.toList());ExamPaperEditRequestVM vm = new ExamPaperEditRequestVM();vm.setName(ExamPaperTypeEnum.TelligentTrain.getName() + count.incrementAndGet());vm.setLevel(user.getUserLevel());vm.setSubjectId(model.getSubjectId());vm.setScore(totalScore);vm.setPaperType(ExamPaperTypeEnum.TelligentTrain.getCode());vm.setSuggestTime(ExamUtil.getExamPaperSuggestTime(questions));vm.setTitleItems(titleItems);return vm;}/*** 智能组卷* @param model* @return*/@Overridepublic ExamPaperEditRequestVM getExamPaperEditRequestVM(ExamPaperRuleVM model) {User user = webContext.getCurrentUser();ExamPaperEditRequestVM vm = getIntelligenceExamPaper(model, user, ExamPaperWeightEnum.runCount, ExamPaperWeightEnum.population_size, ExamPaperWeightEnum.expectAdapter);return vm;}/*** 智能组卷* @param model* @param user* @param runCount* @param populationSize* @param expectAdapter* @return*/private ExamPaperEditRequestVM getIntelligenceExamPaper(ExamPaperRuleVM model, User user, int runCount, int populationSize,double expectAdapter ){Rule rule = getRuleFromVM(model);if (rule == null){throw new RuntimeException();}List<List<Question>> lists = getQuestionsByLevelAndChapters(rule.getChapters());ExamPaperAlgotithmBean fitness = getFitnessFromPopulation(rule, lists, true, runCount, populationSize, expectAdapter);List<Question> questions = fitness.getQuestions();String totalScore = ExamUtil.scoreToVM(questions.stream().mapToInt(q -> q.getScore()).sum());List<Integer> qTypes = questions.stream().map(q ->q.getQuestionType()).distinct().collect(Collectors.toList());List<ExamPaperTitleItemVM> titleItems = qTypes.stream().map(qt -> {List<Question> titleQuestions =questions.stream().filter(q -> q.getQuestionType() == qt).collect(Collectors.toList());List<QuestionEditRequestVM> titleQuestionEditRequestVMs = titleQuestions.stream().map(q -> {Chapter chapter = chapterMapper.selectByPrimaryKey(q.getChapterId());TextContent textContent = textContentService.selectById(q.getInfoTextContentId());QuestionObject questionObject = JsonUtil.toJsonObject(textContent.getContent(), QuestionObject.class);QuestionEditRequestVM titleQuestionEditRequestVM = questionService.getQuestionEditRequestVM(q);titleQuestionEditRequestVM.setTitle(questionObject.getTitleContent() + "(" + chapter.getName() + ")");return titleQuestionEditRequestVM;}).collect(Collectors.toList());//将Quetion转换为vo对象ExamPaperTitleItemVM examPaperTitleItemVM = new ExamPaperTitleItemVM();//生产试卷examPaperTitleItemVM.setName(QuestionTypeEnum.fromCode(qt).getName());examPaperTitleItemVM.setQuestionItems(titleQuestionEditRequestVMs);return examPaperTitleItemVM;}).collect(Collectors.toList());ExamPaperEditRequestVM vm = new ExamPaperEditRequestVM();vm.setName(ExamPaperTypeEnum.TelligentExam.getName() + count.incrementAndGet());vm.setLevel(user.getUserLevel());vm.setSubjectId(model.getSubjectId());vm.setScore(totalScore);vm.setPaperType(ExamPaperTypeEnum.TelligentExam.getCode());vm.setSuggestTime(ExamUtil.getExamPaperSuggestTime(questions));vm.setTitleItems(titleItems);return vm;}/*** 得到不同类型题chapters知识点内的题目,然后添加到列表中* @param chapters* @return*/private List<List<Question>> getQuestionsByLevelAndChapters(List<Integer> chapters){List<List<Question>> questions = new ArrayList<>(5);for (int i = QuestionTypeEnum.SingleChoice.getCode();i <= QuestionTypeEnum.ShortAnswer.getCode(); i++){questions.add(questionService.selectByLevelTypeChapters(i,chapters));}return questions;}private Rule getRuleFromVM(ExamPaperRuleVM model){Rule rule = modelMapper.map(model, Rule.class);double difficulty = rule.getDifficulty();rule.setDifficulty(difficulty * 1.5 / 5);//不限、简单、中等、困难 * 1.5Integer total = ExamUtil.getExpectTotalScore(rule);rule.setTotalScore(total);return rule;}/*** 种群进化选出最优个体* @param rule* @param lists* @param initFlag* @param runCount* @param populationSize* @param expectAdapter* @return*/private ExamPaperAlgotithmBean getFitnessFromPopulation(Rule rule,List<List<Question>> lists,boolean initFlag,int runCount,int populationSize,double expectAdapter){int initCount = 0;Population population = new Population(populationSize,true,rule,lists);System.out.println("---------------------------------------");int index = 0;for (ExamPaperAlgotithmBean e: population.getPapers()){System.out.println("个体:" + ++index + "适应度为:" + e.getAdaptationDegree() + "难度为:" + e.getDifficulty() + "知识点覆盖率为:" + e.getChapterCoverage());}System.out.println("初始适应度:" + population.getFitness().getAdaptationDegree());while (initCount < runCount && population.getFitness().getAdaptationDegree() < expectAdapter){initCount++;GAUtil.evolvePopulation(population,rule,questionService);System.out.println("第 " + initCount + " 次进化,适应度为:" + population.getFitness().getAdaptationDegree());}System.out.println("进化次数:" + initCount);System.out.println(population.getFitness().getAdaptationDegree());ExamPaperAlgotithmBean fitness = population.getFitness();return fitness;}
毕设:智能组卷平台(遗传算法)相关推荐
- python自动组卷系统_基于遗传算法(C#编写)的智能组卷系统优化
原创 guodongwe1991 机器学习算法与Python学习 2016-08-25 最近由于项目的需要,基于.Net 4.0框架和WPF开发window的客户端(开发环境为win7 旗舰版:Vis ...
- Java使用遗传算法实现智能组卷
遗传算法实现智能组卷 0.需求:用户选择知识点.年级.难度系数.题型.题目总数量,一键智能生成试卷,如下 1.遗传算法: 1.0 参考博文: 理论概念详解:https://www.jianshu.co ...
- 组卷系统php遗传算法,基于遗传算法的智能组卷系统实现
考试作为教育测量学和教育统计学和的基本原理,不仅是对学生学习能力和知识水平的检验方式,也是对教师教育教学水平评价和体现的重要手段之一.如何更加客观公正地反映学生的学习状况,全面地掌握和评价教师的教学工 ...
- 渐进式遗传组卷算法(大规模题库,实际可用的算法) 智能组卷系统
基本遗传算法的缺陷分析:设一套题共需5种题型,共20道题目.设每道题在题库中有100道侯选题目.那么总共的组卷空间大小大约是10020 ,假设遗传算法的种群大小为1000,叠代1000次,那么最多搜索 ...
- 七彩智能组卷软件系统 V4.9.0.0官方版
名称:七彩智能组卷软件系统 V4.9.0.0官方版 版本:4.9.0.0 软件大小:2 MB 软件语言:简体中文 软件授权:免费版 应用平台:Win8/Win7/WinXP 七彩智能组卷终身免费版(精 ...
- java毕业设计《组成原理》课程智能组卷mybatis+源码+调试部署+系统+数据库+lw
java毕业设计<组成原理>课程智能组卷mybatis+源码+调试部署+系统+数据库+lw java毕业设计<组成原理>课程智能组卷mybatis+源码+调试部署+系统+数据库 ...
- 在线答题刷题,创建题库智能组卷,更高效!
互联网时代的到来改变了许多生活习惯,包括考试在内,已经逐渐专为线上考试,线上考试有着快速刷题.智能组卷.自动分析等多种优势功能.搭建这样的在线考试系统也十分容易,今天就一起看一下在线刷题的一些功能. ...
- 智能组卷、专项针对性练习,提高刷题效果!
目前在线考试已经成为非常常见的考试形式,便捷到考生只需要一部手机就可以参加考试.同时,在线考试系统也成为了许多想要刷题的人的首选,一部手机,空余时间就可以高效利用,何乐为不为呢? 想要提高刷题速度,一 ...
- 七彩智能组卷软件系统、
http://soft.7caiedu.cn/Index.html http://addon.discuz.com/resource/preview/19477/1.jpg?rRvis http:// ...
最新文章
- Vivado Fir Ip核动态更改滤波器系数的两种方法
- 【企业管理】如何降低内部成本
- 二叉树、二叉排序树及其遍历
- android 将SQLite数据库的表格导出为csv格式,并解析csv文件
- 文件上传漏洞——upload-labs(1-10)
- Python到底有多实用?这些功能你需要了解
- /MD, /MDD, /ML, /MT,/MTD(使用运行时库)
- java定位线程阻塞_Arthas - 定位 Java 性能问题原来这么简单
- Redis-主从复制
- CompletableFuture详解~thenCombine
- 怎么把ps转化成html,【论文】浅谈Photoshop转化成Html的方法.pdf
- java多线程构造函数_java线程基础巩固---多线程与JVM内存结构的关系及Thread构造函数StackSize的理解...
- Table表格边框线、样式
- 头豹研究院发布《2022年中国数据库产品策略解析报告》
- awk(4)-awk介绍
- java仿qq好友列表_QQ好友列表树形列表java代码实现代码
- SpringCloud Alibaba实战第八课 缓存设计、网关认证、重构策略
- OSS——阿里OSS
- Intel历史上最强的竞争对手:但并不是AMD
- 工作,是人生的另一道窄门