package com.lsxy.ga.manager.impl;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import com.lsxy.ga.RandomNo;
import com.lsxy.ga.manager.AbstractManager;
import com.lsxy.ga.manager.GaManager;
import com.lsxy.ga.manager.GaModleManager;
import com.lsxy.ga.manager.KnowledgePointManager;
import com.lsxy.ga.manager.PolicyManager;
import com.lsxy.ga.manager.TestQuestionManager;
import com.lsxy.ga.manager.TypeManager;
import com.lsxy.ga.model.GaModle;
import com.lsxy.ga.model.KnowledgePoint;
import com.lsxy.ga.model.Policy;
import com.lsxy.ga.model.TestQuestion;
import com.lsxy.ga.model.Type;
public class GaManagerImpl extends AbstractManager implements GaManager {
//主要管理参数声明
private GaModleManager gaModleManager;//组卷主要参数管理
private TypeManager typeManager;//类型管理
private KnowledgePointManager knowledgePointManager;
private TestQuestionManager testQuestionManager;
private PolicyManager policyManager;
private GaModle gm = null;//得到组卷系统参数
//适应函数计算参数
private double avgExposure=0.0;//平均曝光度,遗传得到的染色体曝光度要低于平均曝光度
private int sumExposure =0; //总的曝光次数
private double avgLateTime = 0.0; //在总时间所占比率的平均
private long sumLateTimeZ = 0; //总的最近时间
private List<List<TestQuestion>> intiList = null; //初始种群
List tyList=null;//题型列表
/**
* 根据课程的知识点与题型组成一张试题列表,此列表里放入按题型分类的试题的列表
*/
public void intiLib(int[] knowledgePointIds,int[] typeIds){
intiList = null;
intiList = new ArrayList<List<TestQuestion>>();
List tqList = testQuestionManager.getQuestionsByIds(knowledgePointIds,typeIds);
tyList = typeManager.getTypeByIds(typeIds);
for(int i=0;i< tyList.size();i++){
List<TestQuestion> temp = new ArrayList<TestQuestion>();
Type type = (Type)tyList.get(i);
for(int j=0;j<tqList.size();j++){
TestQuestion tq = (TestQuestion)tqList.get(j);
if(tq.getType().getId()==type.getId()){
temp.add(tq);
}
}
intiList.add(temp);
}
sumExposure = 0;
sumLateTimeZ = 0;
for(int j=0;j<tqList.size();j++){
TestQuestion tq = (TestQuestion)tqList.get(j);
sumExposure += tq.getCount();
sumLateTimeZ += tq.getLateTime().getTime();
}
//System.out.print("总曝光度次数"+sumExposure);
double tp = sumExposure/(double)tqList.size();//平均曝光次数
//System.out.print("平均曝光次数"+tp);
if(sumExposure!=0){
avgExposure = tp/sumExposure;//平均曝光度
}else{
avgExposure=0;
}
//System.out.print("平均曝光度"+avgExposure);
long ta = sumLateTimeZ/tqList.size();//平均最近答题时间
//System.out.print("平均最近答疑时间"+ta);
avgLateTime = ta/(double)sumLateTimeZ;
//System.out.print("在总时间所占比率的平均"+avgLateTime);
}
/**
* 染色体的初始化,根据试题的总题量,得到染色体的长度,根据初始种群的大小,生成染色体;
* 染色体内题目按题型一次排列,便于进行下面的操作
* @return
*/
public List<List<TestQuestion>> ChromosomeInti(Policy p,GaModle gm){
//System.out.print("检测参数"+gm.getId());
//得到知识点的内容
String kpStr = p.getKnowledgePointIds();
int[] knowledgePointIds = null;//知识点Ids
if(kpStr!=null&&!kpStr.trim().equals("")){
String[] kpStrings = kpStr.split(",");
knowledgePointIds = new int[kpStrings.length];
for(int i=0;i<kpStrings.length;i++){
knowledgePointIds[i] = Integer.parseInt(kpStrings[i]);
}
}
//得到题型的具体内容
String typeStr = p.getTypeQuantityMark();
int[] typeIds = null;//题型Id列表
int[] sourse=null;//题型的分数
int[] counts=null;//每种题型的题量
if(typeStr!=null&&!typeStr.trim().equals("")){
String[] typeStrings = typeStr.split(",");
int typeLength = typeStrings.length;
typeIds = new int[typeLength/3];
sourse = new int[typeLength/3];
counts =new int[typeLength/3];
for(int i=0,j=0;i<typeLength;i+=3,j++){
typeIds[j] = Integer.parseInt(typeStrings[i]);
sourse[j] = Integer.parseInt(typeStrings[i+1]);
counts[j] = Integer.parseInt(typeStrings[i+2]);
}
}
/*
* 染色体的初始化
*/
intiLib(knowledgePointIds,typeIds); //初始种群
List<List<TestQuestion>> chromosomeList = new ArrayList<List<TestQuestion>>();//染色体的列表
for(int i=0;i<gm.getPopulation()*2;i++){//根据系统规定的染色体的数量的两倍进行循环
List<TestQuestion> tqList = new ArrayList<TestQuestion>();//一个染色体
//System.out.println("检测生成的随机数");
for(int j=0;j<intiList.size();j++){//根据题型去取试题
List<TestQuestion> tqTypeList =intiList.get(j);//得到第一种题型的所有试题
int[] random = RandomNo.getRandomList(tqTypeList.size(),i);//产生一个从0到tqTypeList.size()-1的
//System.out.println("检测参数======》"+counts[j]+"("+counts.length+")"); //随机数组,我们取前面几个加入到染色体内
for(int k=0;k<counts[j];k++){//根据该种题型在染色体内所占的题量加入
TestQuestion tq = tqTypeList.get(random[k]);
tqList.add(tq);
}
}
chromosomeList.add(tqList);//把一个染色体加入到染色体列表
}
return chromosomeList;
}
/**
* 求染色体的适应值
*/
public int getAdaptive(List<TestQuestion> qsList,Policy p){
double errorD = 0.0;//难度误差
double errorDt = 0.0;//区分度误差
double errorKp = 0.0;//知识点误差
double errorLateTime = 0.0;//最近出题时间误差
double errorExposure = 0.0;//曝光度误差
double errorTime = 0.0;//总的考试时间误差
double sumD = 0.0;//试题的难度和
double sumDt = 0.0;//区分度的和
double sumTime = 0.0;//考试时间和
double sumEx = 0.0;//总的曝光度
long sumLateTime = 0;//总的最近答题时间
int length = qsList.size();//染色体长度
for(int i=0;i<length;i++){
TestQuestion t = qsList.get(i);
sumD += t.getDifficulty();
sumDt += t.getDifferentiate();
sumTime += t.getAdviceTime();
sumEx += t.getCount()/(double)sumExposure;
sumLateTime += t.getLateTime().getTime();
}
errorD = Math.abs(sumD/length - p.getDifficulty());
errorDt = Math.abs(sumDt/length - p.getDifferentiate());
errorTime = Math.abs(sumTime/p.getTime()-1);
//测试参数
//System.out.println("测试参数");
//System.out.println("难度误差"+errorD);
//System.out.println("区分度误差"+errorDt);
//System.out.println("总的曝光度"+sumEx);
//System.out.println("答题时间误差"+errorTime);
double thisAvgEx =0.0;
if(sumEx!=0){
thisAvgEx = sumEx/length;
}else{
thisAvgEx = 0;
}
if(thisAvgEx>avgExposure){
errorExposure = thisAvgEx - avgExposure;//比平均曝光度大多少
}else{
errorExposure = 0.0;//如果小于平均曝光度,那么该染色体的曝光误差就为0
}
//System.out.println("曝光度误差"+errorExposure);
double avgS = sumLateTime/(double)sumLateTimeZ/(double)length;
if(avgS>avgLateTime){
errorLateTime = avgS - avgLateTime;
}else
{
errorLateTime = 0.0;
}
//System.out.println("平均最近答题时间比率误差"+errorLateTime);
//计算知识点误差
String chapterStr = p.getChapterIdInverse();
int[] chapterIds = null;//章节Ids
int[] ratio = null;
if(chapterStr!=null&&!chapterStr.trim().equals("")){
String[] kpStrings = chapterStr.split(",");
chapterIds = new int[kpStri
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
智能组卷系统(ssh)---java (557个子文件)
GaManagerImpl.class 13KB
PolicyAction.class 10KB
TestAction.class 7KB
TestQuestionManagerImpl.class 5KB
TestQuestionAction.class 4KB
TestQuestion.class 4KB
ChapterManagerImpl.class 3KB
SectionManagerImpl.class 3KB
Policy.class 3KB
TypeManagerImpl.class 3KB
TestQuestionActionForm.class 3KB
AbstractManager.class 3KB
PolicyActionForm.class 3KB
KnowledgePointManagerImpl.class 3KB
TypeAction.class 3KB
CourseAction.class 3KB
GaModleAction.class 3KB
UserAction.class 3KB
SystemExceptionHandler.class 3KB
GaModleManagerImpl.class 3KB
ChapterAction.class 3KB
CourseManagerImpl.class 3KB
KnowledgePointAction.class 3KB
SectionAction.class 2KB
QuickSort.class 2KB
UserManagerImpl.class 2KB
PagerFilter.class 2KB
Test.class 2KB
TestActionForm.class 2KB
PolicyManagerImpl.class 2KB
TestManagerImpl.class 2KB
GaModleActionForm.class 2KB
SystemException.class 2KB
GaModle.class 2KB
RandomNo.class 1KB
UserActionForm.class 1KB
SystemContext.class 1KB
User.class 1KB
Section.class 1KB
Chapter.class 1KB
Course.class 1KB
KnowledgePoint.class 1017B
KnowledgePointActionForm.class 1000B
SectionActionForm.class 979B
ChapterActionForm.class 976B
CourseActionForm.class 964B
GaManager.class 883B
TypeActionForm.class 773B
Dwrmodle.class 728B
PagerModle.class 728B
RandomTest.class 723B
Type.class 716B
TestQuestionManager.class 645B
KnowledgePointManager.class 481B
TypeManager.class 481B
ChapterManager.class 469B
CourseManager.class 445B
SectionManager.class 445B
GaModleManager.class 427B
QuestionManager.class 398B
PolicyManager.class 370B
UserManager.class 314B
TestManager.class 298B
.classpath 5KB
org.eclipse.wst.jsdt.ui.superType.container 49B
ga.css 6KB
Editor.css 3KB
Editor.css 3KB
Editor.css 3KB
Editor.css 3KB
Editor.css 3KB
Editor.css 3KB
Editor.css 3KB
Editor.css 3KB
Editor.css 3KB
MenuArea.css 545B
MenuArea.css 545B
MenuArea.css 545B
MenuArea.css 545B
MenuArea.css 545B
MenuArea.css 545B
MenuArea.css 545B
MenuArea.css 545B
MenuArea.css 545B
EditorArea.css 165B
EditorArea.css 165B
EditorArea.css 165B
EditorArea.css 165B
EditorArea.css 165B
EditorArea.css 165B
EditorArea.css 165B
EditorArea.css 165B
EditorArea.css 165B
Thumbs.db 10KB
top1.gif 33KB
flower.gif 7KB
ivy.gif 6KB
ewebeditor.gif 5KB
christmas.gif 3KB
citrus.gif 2KB
共 557 条
- 1
- 2
- 3
- 4
- 5
- 6
LinHaiBo、、
- 粉丝: 7
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页