ich finde leider im Folgenden meinen Fehler nicht:
Code: Alles auswählen
public void checkInvariant() throws InvalidInvariantException{
//Check if source node is in PrioQueue
if(getPriorityQueue().contains(getSourceNode())){
throw new InvalidInvariantException("source node isnt allowed to be in prio queue");
}
//Check if all setteld nodes have distance != inf
for(Node<N, E> n: getSettled()){
if(getComparator().compare(getDistances().get(n), getComparator().getMax())==0){
throw new InvalidInvariantException("settled nodes shouldn't have distance inf");
}
}
//every unsettled node, which is not in prioqueue, should have distance max
for(Node<N, E> n: getGraph().getNodeList()){
if(getSettled().contains(n)==false){
if(getPriorityQueue().contains(n)==false){
if(getComparator().compare(getDistances().get(n),getComparator().getMax())!=0){
throw new InvalidInvariantException("unsettled nodes should have distance max if no in prioqueue");
}
}
}
}
//check, if the amount of iterations equals the amount of setteld nodes
if(getIterations() != getSettled().size()){
throw new InvalidInvariantException("the amount of iterations should equal the amount of settled nodes");
}
}
Ich bin eigentlich der Meinung das ich die Spezifikation erfülle und alles funktionieren sollte.It seems like the method default throws the exception
Code: Alles auswählen
//Check if source node is in PrioQueue
if(getPriorityQueue().contains(getSourceNode())){
throw new InvalidInvariantException("source node isnt allowed to be in prio queue");
}
Code: Alles auswählen
//Check if all setteld nodes have distance != inf
for(Node<N, E> n: getSettled()){
if(getComparator().compare(getDistances().get(n), getComparator().getMax())==0){
throw new InvalidInvariantException("settled nodes shouldn't have distance inf");
}
}
Code: Alles auswählen
//every unsettled node, which is not in prioqueue, should have distance max
for(Node<N, E> n: getGraph().getNodeList()){
if(getSettled().contains(n)==false){
if(getPriorityQueue().contains(n)==false){
if(getComparator().compare(getDistances().get(n),getComparator().getMax())!=0){
throw new InvalidInvariantException("unsettled nodes should have distance max if no in prioqueue");
}
}
}
}
Code: Alles auswählen
//check, if the amount of iterations equals the amount of setteld nodes
if(getIterations() != getSettled().size()){
throw new InvalidInvariantException("the amount of iterations should equal the amount of settled nodes");
}
Wie bereits gesagt, ich konnte meinen Fehler leider nicht finden und würde mich sehr freuen, falls jemandem etwas auffällt.
Ich hoffe ich konnte meinen Code gut erläutern und würde mich sehr über Antwort und Hilfe freuen.
Liebe Grüße
kommiker