We must sort on the highest (individual availability) when the project classes are the same.

This commit is contained in:
Tom Vahlman 2012-02-27 21:33:06 +01:00
parent f10718e5b4
commit 604a38152c
3 changed files with 45 additions and 61 deletions
src
main/java/se/su/dsv/scipro/match
test/java/se/su/dsv/scipro/match

@ -280,8 +280,8 @@ public class GreedyMatchingAlgorithm implements MatchingAlgorithm {
} else if(!match.getProjectIdea().getProjectClass().equals(availability.getProjectClass()) &&
otherPair.getMatch().getProjectIdea().getProjectClass().equals(otherPair.getAvailability().getProjectClass())) {
return 1;
} else { // the supervisor can only one type of project class
return 0;
} else { // the project class is the same sort on the highest availability
return availability.compareTo(otherPair.getAvailability());
}
}
}

@ -8,7 +8,7 @@ import se.su.dsv.scipro.data.dataobjects.ProjectClass;
/**
* A class that specifies how available a supervisor is(in terms of thesis supervision)
*/
public class Availability implements Serializable {
public class Availability implements Serializable, Comparable<Availability> {
private static final long serialVersionUID = 1L;
@ -54,6 +54,17 @@ public class Availability implements Serializable {
numMatched = num;
}
@Override
public int compareTo(Availability availability) {
if(getAvailability() > availability.getAvailability()) {
return -1;
} else if(availability.getAvailability() > getAvailability()) {
return 1;
} else {
return 0;
}
}
@Override
public String toString() {
return "Availability [supervisorId=" + supervisor + ", numMatched="

@ -578,6 +578,7 @@ public class TestGreedyMatchingAlgorithm {
unmatchedProjectIdeas.add(bachelorProjectIdea);
Result result = new GreedyMatchingAlgorithm().match(supervisorAvailability, unmatchedProjectIdeas, weights);
assertTrue(result.matches.size() > 0);
assertTrue(result.matches.get(0).getProjectIdea().equals(bachelorProjectIdea));
assertTrue(result.matches.get(0).getSupervisor().equals(masterSupervisor));
assertTrue(result.unmatched.size() == 0);
@ -586,78 +587,50 @@ public class TestGreedyMatchingAlgorithm {
@Test
@Transactional
@Rollback
/* test that a master which has filled up his slot for bachelor but has slots left for master can supervise a bachelor idea */
/* test that the supervisor who has the highest total slot available will be chosen */
public void testIncreaseSlotForMasterSupervisor() {
Employee bachelorSupervisor2 = createEmployee("David", "Hallberg", languages);
supervisorAvailability.add(new Availability(masterSupervisor, 3L, 3, bachelorProjectClass));
supervisorAvailability.add(new Availability(masterSupervisor, 3L, 4, masterProjectClass));
supervisorAvailability.add(new Availability(bachelorSupervisor2, 0L, 1, bachelorProjectClass));
unmatchedProjectIdeas.add(bachelorProjectIdea);
bachelorProjectIdea.setPreferredSupervisor(masterSupervisor);
Result result = new GreedyMatchingAlgorithm().match(supervisorAvailability, unmatchedProjectIdeas, weights);
assertTrue(result.matches.size() > 0);
assertTrue(result.matches.get(0).getProjectIdea().equals(bachelorProjectIdea));
assertTrue(result.matches.get(0).getSupervisor().equals(masterSupervisor));
assertTrue(result.unmatched.size() == 0);
// increase num capable for the supervisor
Employee davidH = createEmployee("David", "Hallberg", languages);
Employee henrikH = createEmployee("Henrik", "Hansson", languages);
//ProjectIdea firstBachelorIdea = createProjectIdea(bachelorProjectClass, applicationPeriod);
supervisorAvailability.add(new Availability(henrikH, 2L, 3, bachelorProjectClass)); // total slot = 2
supervisorAvailability.add(new Availability(henrikH, 3L, 4, masterProjectClass));
supervisorAvailability.add(new Availability(davidH, 1L, 1, bachelorProjectClass)); // total slot = 1
supervisorAvailability.add(new Availability(davidH, 0L, 1, masterProjectClass));
unmatchedProjectIdeas.add(masterProjectIdea);
for (Availability availability : supervisorAvailability) {
if(availability.getProjectClass().equals(masterProjectClass)) {
availability.setNumCapable(availability.getNumCapable() + 1);
}
}
result = new GreedyMatchingAlgorithm().match(supervisorAvailability, unmatchedProjectIdeas, weights);
unmatchedProjectIdeas.add(bachelorProjectIdea);
Result result = new GreedyMatchingAlgorithm().match(supervisorAvailability, unmatchedProjectIdeas, weights);
assertTrue(result.matches.size() > 0);
assertTrue(result.matches.get(0).getProjectIdea().equals(masterProjectIdea));
assertTrue(result.matches.get(0).getSupervisor().equals(masterSupervisor));
assertTrue(result.matches.get(0).getSupervisor().equals(henrikH));
assertTrue(result.matches.get(1).getProjectIdea().equals(bachelorProjectIdea));
assertTrue(result.matches.get(1).getSupervisor().equals(henrikH));
assertTrue(result.unmatched.size() == 0);
}
@Test
@Transactional
@Rollback
/* test that a master which has filled up his slot for bachelor but has slots left for master can supervise a bachelor idea */
/* test that a master supervisor is chosen for a master project idea which has the same points as a bachelor project idea */
public void testIncreaseSlotForMasterSupervisor_v2() {
/*
supervisorAvailability.clear();
unmatchedProjectIdeas.clear();
Employee bachelorSupervisor2 = createEmployee("David", "Hallberg", languages);
supervisorAvailability.add(new Availability(masterSupervisor, 3L, 3, bachelorProjectClass));
supervisorAvailability.add(new Availability(masterSupervisor, 3L, 4, masterProjectClass));
supervisorAvailability.add(new Availability(bachelorSupervisor2, 0L, 1, bachelorProjectClass));
Employee davidH = createEmployee("David", "Hallberg", languages);
Employee henrikH = createEmployee("Henrik", "Hansson", languages);
supervisorAvailability.add(new Availability(henrikH, 3L, 3, bachelorProjectClass));
supervisorAvailability.add(new Availability(henrikH, 3L, 4, masterProjectClass));
supervisorAvailability.add(new Availability(davidH, 0L, 1, bachelorProjectClass));
unmatchedProjectIdeas.add(bachelorProjectIdea);
unmatchedProjectIdeas.add(masterProjectIdea);
bachelorProjectIdea.setPreferredSupervisor(masterSupervisor);
masterProjectIdea.setPreferredSupervisor(masterSupervisor);
List<ProjectIdea> projectIdeaList = new ArrayList<ProjectIdea>();
projectIdeaList.add(bachelorProjectIdea);
List<Employee> supervisorList = new ArrayList<Employee>();
supervisorList.add(masterSupervisor);
addKeyWords(supervisorList, projectIdeaList, createKeyword(keywordTypeWord, "UML", false));
bachelorProjectIdea.setPreferredSupervisor(henrikH);
masterProjectIdea.setPreferredSupervisor(henrikH);
Result result = new GreedyMatchingAlgorithm().match(supervisorAvailability, unmatchedProjectIdeas, weights);
assertTrue(result.matches.size() > 0);
boolean foundMasterProjIdea = false;
boolean foundMasterSuperVisor= false;
boolean foundBachelorProjIdea = false;
boolean foundBachelorSuperVisor= false;
for(Match match : result.matches) {
if(match.getProjectIdea().equals(masterProjectIdea) && match.getSupervisor().equals(masterSupervisor)) {
foundMasterProjIdea = true;
foundMasterSuperVisor = true;
}
if(match.getProjectIdea().equals(bachelorProjectIdea) && match.getSupervisor().equals(bachelorSupervisor2)) {
foundBachelorProjIdea = true;
foundBachelorSuperVisor = true;
}
}
assertTrue(foundMasterProjIdea);
assertTrue(foundBachelorProjIdea);
assertTrue(foundBachelorSuperVisor);
assertTrue(foundMasterSuperVisor);
assertTrue(result.unmatched.size() == 0); */
assertTrue(result.matches.size() > 0);
assertTrue(result.matches.get(0).getPoints() == 10);
assertTrue(result.matches.get(1).getPoints() == 0);
assertTrue(result.matches.get(0).getSupervisor().equals(henrikH));
assertTrue(result.matches.get(1).getSupervisor().equals(davidH));
assertTrue(result.matches.get(0).getProjectIdea().equals(masterProjectIdea));
assertTrue(result.matches.get(1).getProjectIdea().equals(bachelorProjectIdea));
assertTrue(result.unmatched.size() == 0);
}
@Test