C++:时间表程序

j2cgzkjk  于 2022-11-19  发布在  其他
关注(0)|答案(1)|浏览(166)

我必须为一所大学的6门课制定一个时间表。下面是我想出的课程。

class ClassRoom  
{  
    private:  
    char id[5];
    char type;
    int cap;
public:
    void setRoom();
    void disp();
}c[15];
class StudentGroup
{
    int sem;
    char group[3];
    int strength;
  public:
    void setGroup();
}stud[8];
class Course
{
    char courseID[7];
    int semNo;
    char courseCode[5];
    char courseName[50];
    char type;
    int lec;
    int tut;
    int prac;
public:
    void setCourse();
}cour[75];
class CourseDetails
{
    public:
  char courseID[7];
  char preference[3];
  char resourceType;
  char classPref[3];
};
class Faculty
{
  char facID[6];
  char name[50];
  int noCourses;
  public:

  CourseDetails cD[6];
      void setFaculty();
      void disp();
}fac[50];
class ElecPair
{
    int noPaired;
    char courseId[10][7];
public:
    void setElecPair();
}ePair[10];
class Period
{
    int semNo;
    char className[3];
    char courseID;
    char facID;
    bool availability;
};
class TimeTable
{
    Period prd[5][7];
}tt[6];

我必须创建具有通常约束条件的时间表:
任何教师不得同时在两个班级上课。
学生不能同时上两节课,以此类推。
我不想要的代码,但我想得到的建议,最好的可能的方式,我可以生成这个时间表,而不使用遗传算法。
PS:有没有一种方法我可以使用堆栈或递归来生成这个时间表?

mutmk8jj

mutmk8jj1#

我用C#编写了一个简单的算法,可以解决在相同的给定时间内,教师、教室和讲课之间没有冲突的时间表问题。它的思想很简单:1-为每位教师生成可能的讲座(教师+时间段)。2 -为每个教室生成可能的讲座(房间+时间段)。3-从给定的教师时间段列表中随机选择一个时间段,然后检查两件事。a -该随机时间段是否存在于房间时间段中?B -该随机时间段是否不是由同一个班级的学生占用?如果这两个条件成立,那么你必须做三件事:1-选择具有相同时间段的教室并将其添加到解决方案(在解决方案列表中)。2-从教师时间段和教室时间段列表中删除此时间段。否则,重复此过程。公共课计划{

static List<Room> rooms ;

    private static List<Room> GetListeOfRoomsFomSource()
    {
        throw new NotImplementedException();
    }

    public static  void Main(string[] args)
    {
        var listTeachers = GetListeOfTeachersFomSource();
        rooms= GetListeOfRoomsFomSource();
        foreach (var techer in listTeachers)
        {

            var temp = techer.periods.ToList();
            var rnd = new Random();
            var rnd2 = new Random();
            var period = 0;

            var exist = false;
            do
            {
                if (temp.Count == 0) break;
                int index = rnd.Next(0, temp.Count - 1);
                period = temp[index];
                exist = CheckIfLectureExist(period, section,techer);
                temp.Remove(temp[index]);

            } while (!exist);
            if (exist)
            {
                AddSolution( techer,period);
            }
            else
            {
                AddNoSolution();
                // list.Remove(tc1);
            }

        }



    }

    private static void AddSolution( Teacher item, int period)
    {
        // get a random room with the this given period;

        var lisOfrooms = new List<Room>();
        foreach (var room in rooms)
        {
            if (room.periods.Any(x=>x.Equals(period))) lisOfrooms.Add(room);
        }
        var rnd2 =  new Random();
        var r2 = rnd2.Next(0, lisOfrooms.Count());
        var availableRoom = lisOfrooms[r2];
        // create solution which is a combination of the techer + availableRoom + period  + class.
        //remove the period from the periods of the given techer;

        //remove the period from the periods of the given room;
        //r;
    }

    private static void AddNoSolution()
    {
        throw new NotImplementedException();
    }

   private static bool CheckIfLectureExist(int period, object classRoom ,Teacher teacher)
    {
       // chech if this period has an available (free) room in the list of rooms.
       // chech if this period + classroom + techer does not exist in the solutions to avoid the conflict between classes.
       throw new NotImplementedException();
    }

    private static  List<Teacher> GetListeOfTeachersFomSource()
    {
        throw new NotImplementedException();
    }
}
public class Teacher{
    public Teacher (int periodsWeek)
    {
      _periodWeek = periodsWeek;
      GeneratePerids();
    }
    int _periodWeek;
    public int[] periods {get;set;}
    public void GeneratePerids(){
        for (int i = 0; i < _periodWeek; i++)
        {
            //populate periods;
        }
    }

}
 public class Room
 {
    public Room (int periodsWeek)
    {
      _periodWeek = periodsWeek;
      GeneratePerids();
    }
    int _periodWeek;
      public int[] periods {get;set;}

      public void GeneratePerids(){
        for (int i = 0; i < _periodWeek; i++)
        {
            //populate periods;
        }
      }

 }

相关问题