Domanda

I am currently working on a solution for exam timetable scheduling for a university. I was thinking of using Genetic Algorithms.

Right now I started with a simple example so that I catch on what is happening since I am new to all this. In this example I have 10 exams, 6 students and 6 available time-slots. I am representing a chromosome such that I have 10 positions in a bit-string with values varying from 1-6 representing time-slots so for example: [3 1 4 1 3 5 5 6 4 2] implies that exam 1 takes place in the 3rd time-slot, exam 2 in the 1st time-slot, etc...

Now if I have the following array representing which exams are each of the students taking:

int[][] students_exams = 
{
    {3, 1, 2, 5, 8},   // student 1
    {10, 4, 5, 7},     // student 2
    {1, 2, 3, 6},      // student 3
    {2, 7, 4, 5},      // student 4
    {1, 6, 2, 10},     // student 5
    {8, 9, 1, 3}       // student 6
};

how can I efficiently represent this information as a [n x n] matrix where n is the number of exams (in this case 10) where M[i][j] is equal to the number of students taking exam i and exam j?

Is there a data structure I can use or do I have to compare each exam with each other exam and have an incrementing counter? Because thinking about it, I think this will not be efficient for the amount of students and exams I will have in reality.

If you can refer me to any papers or references you'll be of much help to me.

Thanks

È stato utile?

Soluzione

Here is the brute force approach you are probably trying to avoid:

class testMatrixSO{
    public static void main(String[] args){

        int[][] students_exams = 
        {
        {3, 1, 2, 5, 8},   // student 1
        {10, 4, 5, 7},     // student 2
        {1, 2, 3, 6},      // student 3
        {2, 7, 4, 5},      // student 4
        {1, 6, 2, 10},     // student 5
        {8, 9, 1, 3}       // student 6
        };

        int[][] finalMatrix = new int[10][10];
        //here is the part that creates your matrix
        for(int i=0; i<students_exams.length; i++)
            for(int j=0; j<students_exams[i].length; j++)
                for(int k=0; k<students_exams[i].length; k++)
                    if(j != k) finalMatrix[students_exams[i][j]-1][students_exams[i][k]-1]++;



        //print results
        for(int i=0; i < finalMatrix.length; i++){
            for(int j=0; j < finalMatrix[i].length; j++)
                System.out.print(finalMatrix[i][j] + " ");
            System.out.println();
        }

    }
}

on a positive note, if you assume each student will have 6 or less exams, then we can confidently say that the loop that updates the matrix will execute less than (number of students)*(6*6) times. i.e. the algorith is of linear order, O(n).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top