array re-arrange

s exam
t ______
u |1000
d |0101
e |0011
n
t

period
1 2 3
_____
e 1|100
x2|010
a3|001
m4|100





hi. i try to make a code that can create a timetable (array exam-per) according to array enrollement (student-exam).the timetable array must arrange the elements in such a way that no student of array enrollemet has to sit in two exams in the same period. in first place i create a random timetable(i did it) an then if i multiply timetable*enrollements when an ellement >1 occurs tha means that there is a collision of two exams. (i did it too). now i dont know how to do the rearrange of the elements in array timetable so as to produce a feasible timetable.
I'm not entirely sure what you're doing, but if you multiply two booleans and only one can be 1, then ">0" points out overlaps.

Anyway, you need some kind of improvement heuristic. Easiest would be just swapping assignments until you have a feasible schedule.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

for(int chr=0; chr<numChr; chr++)
{        

    for( int p=0; p <timeslot; ++p)
    {
         for(int r=0; r< R; ++r)
            {      

        for(int  i=0; i < numS; i++)
        {
              for(int e=0; e < numE; e++)
                {
        C[chr][p][r][i] += timetable[chr][e][p][r]*enrollement[i][e] ;
           
          }  
        }}
}    }



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
for(int chr=0; chr<numChr; chr++)
{    for(int e=0; e < numE; e++)
                {
                      
        for(int  p=0; p < timeslot; p++)
        {
                for(int r=0; r< R; ++r)
            {           
            
          
                 
            for(int i=0; i< numS; i++)
                 { 
                  
                         if (C[chr][p][i]>1 && timetable[chr][e][p][r]==1)
                        
                         {
                      
                      do
                      {
                       timetable[chr][e][p][r]=0;
                       p=rand()%timeslot;
                       
                       timetable[chr][e][p][r]=1;
                       }while (C[chr][p][i]>1);
             
                        }
                        }  }
        }    cout<<"  "<<endl;  
        }cout<<endl;
        cout<<endl;      
}




this is the code i try to make work
Topic archived. No new replies allowed.