combinatorics - Weekly group assignment algorithm with odd number of participants -
there round-robin solution question i asked before. works great number of people none of suggestions seem work once implement algorithm , try them out. i've tried many variations , (grouping last 1 whole bunch of other people, second group last group, different combinations, 2 , 4 last of bottom row, thought give me optimal solution still many duplicates). can suggest way go, or proof there cannot solution without 2 people working more once can stop trying make work. if want algorithm in java can post can play it.
thanks.
14 weeks 23 students in groups of 2 , 1 3 sufficiently undemanding local search able find solution.
18 1 11| 3 4| 5 7| 9 6| 0 17| 2 12| 10 19| 15 16| 21 8| 14 20| 13 22| 6 13 18| 17 4| 5 0| 20 1| 12 11| 10 9| 2 14| 15 7| 3 8| 19 16| 21 22| 21 17 7| 19 22| 3 1| 2 8| 0 10| 14 12| 13 11| 6 16| 5 15| 18 20| 9 4| 8 1 13| 18 2| 6 11| 20 0| 12 10| 14 15| 5 17| 9 21| 4 19| 3 22| 16 7| 0 4 16| 17 20| 21 3| 7 18| 13 19| 1 5| 9 11| 15 2| 14 8| 10 6| 12 22| 12 1 17| 15 4| 8 6| 16 18| 9 0| 11 22| 5 14| 3 2| 7 13| 19 20| 21 10| 4 1 22| 12 8| 15 6| 7 0| 9 17| 11 3| 13 2| 5 18| 10 14| 19 21| 20 16| 0 1 6| 13 21| 15 12| 17 8| 20 10| 11 4| 3 14| 5 16| 7 2| 19 9| 18 22| 13 16 3| 2 9| 11 20| 6 17| 22 10| 5 12| 0 14| 15 1| 8 18| 19 7| 21 4| 14 1 7| 2 4| 5 9| 3 6| 8 10| 13 12| 21 0| 17 16| 22 20| 19 18| 11 15| 14 18 21| 12 4| 5 6| 2 19| 8 20| 1 9| 13 0| 11 16| 17 15| 3 10| 7 22| 21 6 2| 3 20| 5 13| 16 8| 18 17| 0 12| 22 14| 10 1| 9 15| 7 4| 11 19| 0 11 2| 6 4| 16 14| 7 8| 17 10| 1 19| 13 9| 3 18| 21 12| 20 5| 15 22| 1 16 2| 14 13| 3 7| 8 4| 11 10| 9 12| 0 18| 15 19| 17 22| 6 20| 21 5|
here's java code made it.
public class schedule { private final int weekcount; private final int groupcount; private final int personcount; private final int groupfirstslot[]; private final int weekslotperson[][]; public schedule(int weekcount, int groupcount, int personcount) { this.weekcount = weekcount; this.groupcount = groupcount; this.personcount = personcount; int remainingpersoncount = personcount; this.groupfirstslot = new int[groupcount + 1]; (int remaininggroupcount = groupcount; remaininggroupcount > 0; remaininggroupcount--) { groupfirstslot[remaininggroupcount] = remainingpersoncount; remainingpersoncount -= remainingpersoncount / remaininggroupcount; } this.weekslotperson = new int[weekcount][personcount]; (int week = 0; week < weekcount; week++) { (int person = 0; person < personcount; person++) { weekslotperson[week][person] = person; } } } public int getweekcount() { return weekcount; } public int getgroupcount() { return groupcount; } public int getpersoncount() { return personcount; } public int getgroupfirstslot(int group) { return groupfirstslot[group]; } public int getweekslotperson(int week, int slot) { return weekslotperson[week][slot]; } public void swapweekslotperson(int week, int slotone, int slottwo) { int temp = weekslotperson[week][slotone]; weekslotperson[week][slotone] = weekslotperson[week][slottwo]; weekslotperson[week][slottwo] = temp; } public int getconflictcount() { int paircount[][] = new int[personcount][personcount]; (int week = 0; week < weekcount; week++) { (int group = 0; group < groupcount; group++) { (int slotone = groupfirstslot[group]; slotone < groupfirstslot[group + 1]; slotone++) { int personone = weekslotperson[week][slotone]; (int slottwo = groupfirstslot[group]; slottwo < groupfirstslot[group + 1]; slottwo++) { int persontwo = weekslotperson[week][slottwo]; paircount[personone][persontwo]++; } } } } int conflictcount = 0; (int personone = 0; personone < personcount; personone++) { (int persontwo = personone + 1; persontwo < personcount; persontwo++) { int pc = paircount[personone][persontwo]; conflictcount += pc * (pc - 1) / 2; } } return conflictcount; } public static void main(string[] args) { schedule sched = new schedule(14, 11, 23); java.util.random rand = new java.util.random(); int oldcc = sched.getconflictcount(); while (oldcc > 0) { int week = rand.nextint(sched.getweekcount()); int slotone = rand.nextint(sched.getpersoncount()); int slottwo = rand.nextint(sched.getpersoncount()); sched.swapweekslotperson(week, slotone, slottwo); int newcc = sched.getconflictcount(); if (newcc < oldcc) { oldcc = newcc; } else { sched.swapweekslotperson(week, slotone, slottwo); } } (int week = 0; week < sched.getweekcount(); week++) { (int group = 0; group < sched.getgroupcount(); group++) { (int slot = sched.getgroupfirstslot(group); slot < sched.getgroupfirstslot(group + 1); slot++) { system.out.printf("%3d", sched.getweekslotperson(week, slot)); } system.out.print('|'); } system.out.println(); } } }
Comments
Post a Comment