分组策略的算法
1:按确定的组数来分(要尽量使小组的人数平衡,此处用的是解二元一次方程组的办法)
iStudentTotal;//一个班的总的学生数
iGroupNumber;//要分的组数
int iup = iStudentTotal / iGroupNumber+1;//取每组人数的上限值
int iDown = iStudentTotal / iGroupNumber;//取每组人数的下限值
int iupx = iStudentTotal - iDown * iGroupNumber;//x为小组人数为iup的小组的数目
int iCountSutdent = 0;//标记每个小组的人数
int iCountGroup = 1;//标记小组数目(到现在分了多少个组了)
int i = 1;//分配小组ID的号码
group = new SGrid.APP.Group();
group.IGroupID = checkClass.IClassID * iBase + i++;
group.SGroupName = group.IGroupID.ToString() + "组";
group.Save();
checkClass.Link(group);
foreach (Student studentItem in lsStudent)
{
if (iCountSutdent == iup&&iCountGroup <= iupx )
{
iCountSutdent = 0;
iCountGroup++;
group = new SGrid.APP.Group();
group.IGroupID = checkClass.IClassID * iBase + i++;
group.SGroupName = group.IGroupID.ToString() + "组";
group.Save();
checkClass.Link(group);
}
else if (iCountSutdent == iDown&&iCountGroup >iupx)
{
iCountSutdent = 0;
iCountGroup++;
group = new SGrid.APP.Group();
group.IGroupID = checkClass.IClassID * iBase + i++;
group.SGroupName = group.IGroupID.ToString() + "组";
group.Save();
checkClass.Link(group);
}
group.Link(studentItem);
iCountSutdent ++;
}
}
2:按每组多少人来分(最后一组剩余多少人就算多少)
int i = 1;
int iCountStudent = 0;
group = new SGrid.APP.Group();
group.IGroupID = checkClass.IClassID * iBase + i++;
group.SGroupName = group.IGroupID.ToString() + "组";
group.Save();
checkClass.Link(group);
foreach (Student studentItem in lsStudent)
{
if (iCountStudent == iGroupNumber)
{
iCountStudent = 0;
group = new SGrid.APP.Group();
group.IGroupID = checkClass.IClassID * iBase + i++;
group.SGroupName = group.IGroupID.ToString() + "组";
group.Save();
checkClass.Link(group);
}
group.Link(studentItem);
iCountStudent ++;
}
}