We must sort on the highest (individual availability) when the project classes are the same.
This commit is contained in:
parent
f10718e5b4
commit
604a38152c
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()) &&
|
} else if(!match.getProjectIdea().getProjectClass().equals(availability.getProjectClass()) &&
|
||||||
otherPair.getMatch().getProjectIdea().getProjectClass().equals(otherPair.getAvailability().getProjectClass())) {
|
otherPair.getMatch().getProjectIdea().getProjectClass().equals(otherPair.getAvailability().getProjectClass())) {
|
||||||
return 1;
|
return 1;
|
||||||
} else { // the supervisor can only one type of project class
|
} else { // the project class is the same sort on the highest availability
|
||||||
return 0;
|
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)
|
* 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;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@ -54,6 +54,17 @@ public class Availability implements Serializable {
|
|||||||
numMatched = num;
|
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
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Availability [supervisorId=" + supervisor + ", numMatched="
|
return "Availability [supervisorId=" + supervisor + ", numMatched="
|
||||||
|
@ -578,6 +578,7 @@ public class TestGreedyMatchingAlgorithm {
|
|||||||
unmatchedProjectIdeas.add(bachelorProjectIdea);
|
unmatchedProjectIdeas.add(bachelorProjectIdea);
|
||||||
Result result = new GreedyMatchingAlgorithm().match(supervisorAvailability, unmatchedProjectIdeas, weights);
|
Result result = new GreedyMatchingAlgorithm().match(supervisorAvailability, unmatchedProjectIdeas, weights);
|
||||||
assertTrue(result.matches.size() > 0);
|
assertTrue(result.matches.size() > 0);
|
||||||
|
|
||||||
assertTrue(result.matches.get(0).getProjectIdea().equals(bachelorProjectIdea));
|
assertTrue(result.matches.get(0).getProjectIdea().equals(bachelorProjectIdea));
|
||||||
assertTrue(result.matches.get(0).getSupervisor().equals(masterSupervisor));
|
assertTrue(result.matches.get(0).getSupervisor().equals(masterSupervisor));
|
||||||
assertTrue(result.unmatched.size() == 0);
|
assertTrue(result.unmatched.size() == 0);
|
||||||
@ -586,78 +587,50 @@ public class TestGreedyMatchingAlgorithm {
|
|||||||
@Test
|
@Test
|
||||||
@Transactional
|
@Transactional
|
||||||
@Rollback
|
@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() {
|
public void testIncreaseSlotForMasterSupervisor() {
|
||||||
Employee bachelorSupervisor2 = createEmployee("David", "Hallberg", languages);
|
Employee davidH = createEmployee("David", "Hallberg", languages);
|
||||||
supervisorAvailability.add(new Availability(masterSupervisor, 3L, 3, bachelorProjectClass));
|
Employee henrikH = createEmployee("Henrik", "Hansson", languages);
|
||||||
supervisorAvailability.add(new Availability(masterSupervisor, 3L, 4, masterProjectClass));
|
//ProjectIdea firstBachelorIdea = createProjectIdea(bachelorProjectClass, applicationPeriod);
|
||||||
supervisorAvailability.add(new Availability(bachelorSupervisor2, 0L, 1, bachelorProjectClass));
|
supervisorAvailability.add(new Availability(henrikH, 2L, 3, bachelorProjectClass)); // total slot = 2
|
||||||
unmatchedProjectIdeas.add(bachelorProjectIdea);
|
supervisorAvailability.add(new Availability(henrikH, 3L, 4, masterProjectClass));
|
||||||
bachelorProjectIdea.setPreferredSupervisor(masterSupervisor);
|
supervisorAvailability.add(new Availability(davidH, 1L, 1, bachelorProjectClass)); // total slot = 1
|
||||||
Result result = new GreedyMatchingAlgorithm().match(supervisorAvailability, unmatchedProjectIdeas, weights);
|
supervisorAvailability.add(new Availability(davidH, 0L, 1, masterProjectClass));
|
||||||
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
|
|
||||||
unmatchedProjectIdeas.add(masterProjectIdea);
|
unmatchedProjectIdeas.add(masterProjectIdea);
|
||||||
for (Availability availability : supervisorAvailability) {
|
unmatchedProjectIdeas.add(bachelorProjectIdea);
|
||||||
if(availability.getProjectClass().equals(masterProjectClass)) {
|
|
||||||
availability.setNumCapable(availability.getNumCapable() + 1);
|
Result result = new GreedyMatchingAlgorithm().match(supervisorAvailability, unmatchedProjectIdeas, weights);
|
||||||
}
|
|
||||||
}
|
|
||||||
result = new GreedyMatchingAlgorithm().match(supervisorAvailability, unmatchedProjectIdeas, weights);
|
|
||||||
assertTrue(result.matches.size() > 0);
|
assertTrue(result.matches.size() > 0);
|
||||||
assertTrue(result.matches.get(0).getProjectIdea().equals(masterProjectIdea));
|
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);
|
assertTrue(result.unmatched.size() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Transactional
|
@Transactional
|
||||||
@Rollback
|
@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() {
|
public void testIncreaseSlotForMasterSupervisor_v2() {
|
||||||
/*
|
Employee davidH = createEmployee("David", "Hallberg", languages);
|
||||||
supervisorAvailability.clear();
|
Employee henrikH = createEmployee("Henrik", "Hansson", languages);
|
||||||
unmatchedProjectIdeas.clear();
|
supervisorAvailability.add(new Availability(henrikH, 3L, 3, bachelorProjectClass));
|
||||||
Employee bachelorSupervisor2 = createEmployee("David", "Hallberg", languages);
|
supervisorAvailability.add(new Availability(henrikH, 3L, 4, masterProjectClass));
|
||||||
supervisorAvailability.add(new Availability(masterSupervisor, 3L, 3, bachelorProjectClass));
|
supervisorAvailability.add(new Availability(davidH, 0L, 1, bachelorProjectClass));
|
||||||
supervisorAvailability.add(new Availability(masterSupervisor, 3L, 4, masterProjectClass));
|
|
||||||
supervisorAvailability.add(new Availability(bachelorSupervisor2, 0L, 1, bachelorProjectClass));
|
|
||||||
unmatchedProjectIdeas.add(bachelorProjectIdea);
|
unmatchedProjectIdeas.add(bachelorProjectIdea);
|
||||||
unmatchedProjectIdeas.add(masterProjectIdea);
|
unmatchedProjectIdeas.add(masterProjectIdea);
|
||||||
bachelorProjectIdea.setPreferredSupervisor(masterSupervisor);
|
bachelorProjectIdea.setPreferredSupervisor(henrikH);
|
||||||
masterProjectIdea.setPreferredSupervisor(masterSupervisor);
|
masterProjectIdea.setPreferredSupervisor(henrikH);
|
||||||
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));
|
|
||||||
Result result = new GreedyMatchingAlgorithm().match(supervisorAvailability, unmatchedProjectIdeas, weights);
|
Result result = new GreedyMatchingAlgorithm().match(supervisorAvailability, unmatchedProjectIdeas, weights);
|
||||||
assertTrue(result.matches.size() > 0);
|
assertTrue(result.matches.size() > 0);
|
||||||
boolean foundMasterProjIdea = false;
|
assertTrue(result.matches.get(0).getPoints() == 10);
|
||||||
boolean foundMasterSuperVisor= false;
|
assertTrue(result.matches.get(1).getPoints() == 0);
|
||||||
|
assertTrue(result.matches.get(0).getSupervisor().equals(henrikH));
|
||||||
boolean foundBachelorProjIdea = false;
|
assertTrue(result.matches.get(1).getSupervisor().equals(davidH));
|
||||||
boolean foundBachelorSuperVisor= false;
|
assertTrue(result.matches.get(0).getProjectIdea().equals(masterProjectIdea));
|
||||||
|
assertTrue(result.matches.get(1).getProjectIdea().equals(bachelorProjectIdea));
|
||||||
for(Match match : result.matches) {
|
assertTrue(result.unmatched.size() == 0);
|
||||||
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); */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user