View Single Post
  #13  
Old 06-14-2008, 07:26 AM
Programmer Programmer is offline
Coder
Programmer's Avatar
Join Date: Jan 2008
Location: -78.464422, 106.837328
Posts: 449
Programmer has a spectacular aura aboutProgrammer has a spectacular aura about
Send a message via AIM to Programmer Send a message via MSN to Programmer Send a message via Yahoo to Programmer
I suppose what you would have to do is this:

Starting with 400 students, loop through and select 100 students at random.
Then go through those 100 students and group then until you have 50 groups.
If you have 2 students who are together on the incompatibility list, flip them with another set at random, as described below:

1 & 2
v
^
3 & 4

3 & 2
1 & 4

If any of those 2 are on the incompatibility list, then repeat the process. Once everything is OK, then you've got your list.

Here's the script I made to accompany this concept:

PHP Code:
function onCreated()
{
  
this.start timevar2;
  
  
this.incompatability = {
    {
102284},
    {
392126},
    {
12},
    {
34},
    {
56},
    {
78}
  };
  
  
  
this.studentsSelected.clear();
  
this.studentGroups.clear();
  
  
numStudentsSelected 0;
  
// Select students at random
  
for (0100i++)
  {
    
int(random(0400));
    
    if (
this.studentsSelected.index(f) == -1)
    {
      
this.studentsSelected.add(f);
    } else
    {
      
i--; continue;
    }
  }
  
  
// Group them
  
for (0this.studentsSelected.size(); += 2)
  {
    
this.studentGroups.add({this.studentsSelected[i], this.studentsSelected[i+1]});
  }
  
  
// Remove incompatabilities
  
for (050i++)
  {
    
sGroup this.studentGroups[i];
    
    for (
0this.incompatability.size(); a++)
    {
      if ((
sGroup[0] == this.incompatability[a][0] || sGroup[0] == this.incompatability[a][1]) && (sGroup[1] == this.incompatability[a][0] || sGroup[1] == this.incompatability[a][1]))
      {
        echo(
"INCOMPATABILITY: " sGroup);
        
        
// we've found an incompatability, so lets flip this student with the next group
        
sGroup2 this.studentGroups[i+1];
        
        
sGroup[0] = sGroup2[0];
      }
    }
  }
  
  
this.end timevar2;
  
  echo(
this.end this.start);
  
  for (
050i++)
  {
    echo(
"Group " @ (i+1) @ ": {" this.studentGroups[i][0] @ ", " this.studentGroups[i][1] @ "}");
  }

Time taken: 0.002021789

Example Output:
PHP Code:
0.002021789
Group 1
: {137114}
Group 2: {282284}
Group 3: {47288}
Group 4: {26753}
Group 5: {19329}
Group 6: {345299}
Group 7: {141228}
Group 8: {9350}
Group 9: {347390}
Group 10: {166207}
Group 11: {13941}
Group 12: {130336}
Group 13: {140376}
Group 14: {262238}
Group 15: {1960}
Group 16: {35279}
Group 17: {368151}
Group 18: {54387}
Group 19: {81108}
Group 20: {332380}
Group 21: {249160}
Group 22: {73300}
Group 23: {6466}
Group 24: {316204}
Group 25: {24824}
Group 26: {8111}
Group 27: {215396}
Group 28: {252148}
Group 29: {270240}
Group 30: {229378}
Group 31: {172209}
Group 32: {227333}
Group 33: {283127}
Group 34: {42194}
Group 35: {359302}
Group 36: {6292}
Group 37: {30293}
Group 38: {105374}
Group 39: {371324}
Group 40: {242119}
Group 41: {83348}
Group 42: {256158}
Group 43: {189128}
Group 44: {232389}
Group 45: {322191}
Group 46: {225197}
Group 47: {33334}
Group 48: {239121}
Group 49: {39213}
Group 50: {23029
Probably not very efficient, but it works. I couldn't find any incompatibilities! XD
__________________
- Iᴀɴ Zɪᴍᴍᴇʀᴍᴀɴ
Reply With Quote