From: <jen...@us...> - 2009-02-18 17:13:14
|
Revision: 1613 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1613&view=rev Author: jenslehmann Date: 2009-02-18 17:13:11 +0000 (Wed, 18 Feb 2009) Log Message: ----------- continued ontology engineering algorithm Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/EvaluatedDescriptionClass.java trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java trunk/src/dl-learner/org/dllearner/algorithms/celoe/OENode.java trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java trunk/src/dl-learner/org/dllearner/learningproblems/ClassScore.java trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionComparator.java trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionSet.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/EvaluatedDescriptionClass.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/EvaluatedDescriptionClass.java 2009-02-18 13:09:16 UTC (rev 1612) +++ trunk/src/dl-learner/org/dllearner/algorithms/EvaluatedDescriptionClass.java 2009-02-18 17:13:11 UTC (rev 1613) @@ -39,5 +39,5 @@ public EvaluatedDescriptionClass(Description description, ClassScore score) { super(description, score); } - + } Modified: trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java 2009-02-18 13:09:16 UTC (rev 1612) +++ trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java 2009-02-18 17:13:11 UTC (rev 1613) @@ -142,6 +142,8 @@ // create refinement operator operator = new RhoDRDown(reasoner, classHierarchy, configurator); + baseURI = reasoner.getBaseURI(); + prefixes = reasoner.getPrefixes(); // we put important parameters in class variables minAcc = configurator.getNoisePercentage()/100d; @@ -194,9 +196,11 @@ int loop = 0; while (!terminationCriteriaSatisfied()) { +// System.out.println(startNode.toTreeString(baseURI)); + if(bestEvaluatedDescriptions.getBest().getAccuracy() > highestAccuracy) { highestAccuracy = bestEvaluatedDescriptions.getBest().getAccuracy(); - logger.info("more accurate (" + dfPercent.format(100*highestAccuracy) + ") class expression found: " + descriptionToString(bestEvaluatedDescriptions.getBest().getDescription())); + logger.info("more accurate (" + dfPercent.format(highestAccuracy) + ") class expression found: " + descriptionToString(bestEvaluatedDescriptions.getBest().getDescription())); } // chose best node according to heuristics @@ -204,7 +208,6 @@ int horizExp = bestNode.getHorizontalExpansion(); // apply operator - System.out.println(bestNode.getDescription()); TreeSet<Description> refinements = refineNode(bestNode); while(refinements.size() != 0) { @@ -213,7 +216,8 @@ int length = refinement.getLength(); // we ignore all refinements with lower length and too high depth - if(length >= horizExp && refinement.getDepth() <= maxDepth) { + // (this also avoids duplicate node children) + if(length > horizExp && refinement.getDepth() <= maxDepth) { boolean added = addNode(refinement, bestNode); @@ -239,7 +243,8 @@ } // print solution(s) - logger.info("solution : " + bestDescriptionToString()); +// logger.info("solution : " + bestDescriptionToString()); + logger.info(getSolutionString()); isRunning = false; } @@ -285,6 +290,7 @@ // maybe add to best descriptions (method keeps set size fixed) if(checkNode(node)) { bestEvaluatedDescriptions.add(description, accuracy, learningProblem); +// System.out.println(bestEvaluatedDescriptions.toString()); } return true; @@ -302,8 +308,7 @@ } private boolean terminationCriteriaSatisfied() { -// double runtimeSec = (System.nanoTime() - nanoStartTime; - return stop || (System.nanoTime() - nanoStartTime >= (configurator.getMaxExecutionTimeInSeconds()*1000000000)); + return stop || ((System.nanoTime() - nanoStartTime) >= (configurator.getMaxExecutionTimeInSeconds()*1000000000l)); } private void reset() { @@ -334,8 +339,23 @@ return description.toManchesterSyntaxString(baseURI, prefixes); } + @SuppressWarnings("unused") private String bestDescriptionToString() { EvaluatedDescription best = bestEvaluatedDescriptions.getBest(); - return best.getDescription().toManchesterSyntaxString(baseURI, prefixes) + " (accuracy: " + dfPercent.format(best.getAccuracy()*100) + ")"; + return best.getDescription().toManchesterSyntaxString(baseURI, prefixes) + " (accuracy: " + dfPercent.format(best.getAccuracy()) + ")"; } + + private String getSolutionString() { + int max = 10; + int current = 1; + String str = ""; + for(EvaluatedDescription ed : bestEvaluatedDescriptions.getSet().descendingSet()) { + str += current + ": " + descriptionToString(ed.getDescription()) + " " + dfPercent.format(ed.getAccuracy()) + "\n"; + current++; + if(current == max) { + break; + } + } + return str; + } } Modified: trunk/src/dl-learner/org/dllearner/algorithms/celoe/OENode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/celoe/OENode.java 2009-02-18 13:09:16 UTC (rev 1612) +++ trunk/src/dl-learner/org/dllearner/algorithms/celoe/OENode.java 2009-02-18 17:13:11 UTC (rev 1613) @@ -19,9 +19,12 @@ */ package org.dllearner.algorithms.celoe; +import java.text.DecimalFormat; import java.util.LinkedList; import java.util.List; +import org.dllearner.algorithms.refinement2.ExampleBasedNode; +import org.dllearner.algorithms.refinement2.MultiHeuristic; import org.dllearner.core.owl.Description; /** @@ -50,11 +53,13 @@ private OENode parent; private List<OENode> children = new LinkedList<OENode>(); + DecimalFormat dfPercent = new DecimalFormat("0.00%"); + public OENode(OENode parentNode, Description description, double accuracy) { this.parent = parentNode; this.description = description; this.accuracy = accuracy; - horizontalExpansion = 0; + horizontalExpansion = description.getLength()-1; } public void addChild(OENode node) { @@ -104,4 +109,32 @@ return horizontalExpansion; } + public String getShortDescription(String baseURI) { + String ret = description.toString(baseURI,null) + " ["; + ret += "acc:" + dfPercent.format(accuracy) + ", "; + ret += "he:" + horizontalExpansion + ", "; + ret += "c:" + children.size() + "]"; + return ret; + } + + public String toTreeString() { + return toTreeString(0, null).toString(); + } + + public String toTreeString(String baseURI) { + return toTreeString(0, baseURI).toString(); + } + + private StringBuilder toTreeString(int depth, String baseURI) { + StringBuilder treeString = new StringBuilder(); + for(int i=0; i<depth-1; i++) + treeString.append(" "); + if(depth!=0) + treeString.append("|--> "); + treeString.append(getShortDescription(baseURI)+"\n"); + for(OENode child : children) { + treeString.append(child.toTreeString(depth+1,baseURI)); + } + return treeString; + } } Modified: trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java 2009-02-18 13:09:16 UTC (rev 1612) +++ trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java 2009-02-18 17:13:11 UTC (rev 1613) @@ -19,6 +19,8 @@ */ package org.dllearner.core; +import java.text.DecimalFormat; + import org.dllearner.core.owl.Description; import org.dllearner.kb.sparql.SparqlQueryDescriptionConvertVisitor; import org.dllearner.utilities.owl.OWLAPIDescriptionConvertVisitor; @@ -39,6 +41,8 @@ protected Description description; protected Score score; + protected static DecimalFormat dfPercent = new DecimalFormat("0.00%"); + /** * Constructs an evaluated description using its score. * @param description The description, which was evaluated. @@ -124,5 +128,10 @@ return null; } } + + @Override + public String toString() { + return description.toString() + " " + dfPercent.format(getAccuracy()); + } } Modified: trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java 2009-02-18 13:09:16 UTC (rev 1612) +++ trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java 2009-02-18 17:13:11 UTC (rev 1613) @@ -95,19 +95,26 @@ public ClassScore computeScore(Description description) { Set<Individual> retrieval = reasoner.getIndividuals(description); +// int instancesProtused = 0; +// +// for(Individual ind : retrieval) { +// if(classInstances.contains(ind)) { +// instancesCovered++; +// } else { +// instancesProtused++; +// } +// } + int instancesCovered = 0; - int instancesProtused = 0; - for(Individual ind : retrieval) { - if(classInstances.contains(ind)) { + for(Individual ind : classInstances) { + if(retrieval.contains(ind)) { instancesCovered++; - } else { - instancesProtused++; } } double coverage = instancesCovered/(double)classInstances.size(); - double protusion = instancesCovered/(double)(instancesCovered + instancesProtused); + double protusion = instancesCovered/(double)retrieval.size(); return new ClassScore(coverage, protusion); } @@ -121,8 +128,19 @@ */ @Override public double getAccuracy(Description description) { - // TODO Auto-generated method stub - return 0; + Set<Individual> retrieval = reasoner.getIndividuals(description); + int instancesCovered = 0; + + for(Individual ind : classInstances) { + if(retrieval.contains(ind)) { + instancesCovered++; + } + } + + double coverage = instancesCovered/(double)classInstances.size(); + double protusion = instancesCovered/(double)retrieval.size(); + + return 0.5d * (coverage + protusion); } /* (non-Javadoc) @@ -130,8 +148,14 @@ */ @Override public double getAccuracyOrTooWeak(Description description, double minAccuracy) { - // TODO Auto-generated method stub - return 0; + // since we have to perform a retrieval operation anyway, we cannot easily + // get a benefit from the accuracy limit + double accuracy = getAccuracy(description); + if(accuracy >= minAccuracy) { + return accuracy; + } else { + return -1; + } } /** Modified: trunk/src/dl-learner/org/dllearner/learningproblems/ClassScore.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/ClassScore.java 2009-02-18 13:09:16 UTC (rev 1612) +++ trunk/src/dl-learner/org/dllearner/learningproblems/ClassScore.java 2009-02-18 17:13:11 UTC (rev 1613) @@ -19,10 +19,7 @@ */ package org.dllearner.learningproblems; -import java.util.Set; - import org.dllearner.core.Score; -import org.dllearner.core.owl.Individual; /** * The score of a class in ontology engineering. @@ -59,8 +56,7 @@ */ @Override public double getAccuracy() { - // TODO Auto-generated method stub - return 0; + return 0.5 * (coverage + protusion); } } Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2009-02-18 13:09:16 UTC (rev 1612) +++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2009-02-18 17:13:11 UTC (rev 1613) @@ -110,7 +110,7 @@ private SortedSet<DatatypeProperty> booleanDatatypeProperties = new TreeSet<DatatypeProperty>(); private SortedSet<DatatypeProperty> doubleDatatypeProperties = new TreeSet<DatatypeProperty>(); private SortedSet<DatatypeProperty> intDatatypeProperties = new TreeSet<DatatypeProperty>(); - private SortedSet<Individual> individuals; + private TreeSet<Individual> individuals; // private ReasonerComponent rs; private OWLAPIReasoner rc; @@ -118,14 +118,14 @@ // we use sorted sets (map indices) here, because they have only log(n) // complexity for checking whether an element is contained in them // instances of classes - private Map<NamedClass, SortedSet<Individual>> classInstancesPos = new TreeMap<NamedClass, SortedSet<Individual>>(); - private Map<NamedClass, SortedSet<Individual>> classInstancesNeg = new TreeMap<NamedClass, SortedSet<Individual>>(); + private Map<NamedClass, TreeSet<Individual>> classInstancesPos = new TreeMap<NamedClass, TreeSet<Individual>>(); + private Map<NamedClass, TreeSet<Individual>> classInstancesNeg = new TreeMap<NamedClass, TreeSet<Individual>>(); // object property mappings private Map<ObjectProperty, Map<Individual, SortedSet<Individual>>> opPos = new TreeMap<ObjectProperty, Map<Individual, SortedSet<Individual>>>(); // datatype property mappings // we have one mapping for true and false for efficiency reasons - private Map<DatatypeProperty, SortedSet<Individual>> bdPos = new TreeMap<DatatypeProperty, SortedSet<Individual>>(); - private Map<DatatypeProperty, SortedSet<Individual>> bdNeg = new TreeMap<DatatypeProperty, SortedSet<Individual>>(); + private Map<DatatypeProperty, TreeSet<Individual>> bdPos = new TreeMap<DatatypeProperty, TreeSet<Individual>>(); + private Map<DatatypeProperty, TreeSet<Individual>> bdNeg = new TreeMap<DatatypeProperty, TreeSet<Individual>>(); // for int and double we assume that a property can have several values, // althoug this should be rare, // e.g. hasValue(object,2) and hasValue(object,3) @@ -200,7 +200,7 @@ doubleDatatypeProperties = rc.getDoubleDatatypeProperties(); intDatatypeProperties = rc.getIntDatatypeProperties(); atomicRoles = rc.getObjectProperties(); - individuals = rc.getIndividuals(); + individuals = (TreeSet<Individual>) rc.getIndividuals(); // rs = new ReasonerComponent(rc); @@ -215,10 +215,10 @@ for (NamedClass atomicConcept : rc.getNamedClasses()) { SortedSet<Individual> pos = rc.getIndividuals(atomicConcept); - classInstancesPos.put(atomicConcept, pos); + classInstancesPos.put(atomicConcept, (TreeSet<Individual>) pos); if (configurator.getDefaultNegation()) { - classInstancesNeg.put(atomicConcept, Helper.difference(individuals, pos)); + classInstancesNeg.put(atomicConcept, (TreeSet<Individual>) Helper.difference(individuals, pos)); } else { // Pellet needs approximately infinite time to answer // negated queries @@ -226,7 +226,7 @@ // we have to // be careful here Negation negatedAtomicConcept = new Negation(atomicConcept); - classInstancesNeg.put(atomicConcept, rc.getIndividuals(negatedAtomicConcept)); + classInstancesNeg.put(atomicConcept, (TreeSet<Individual>) rc.getIndividuals(negatedAtomicConcept)); } } @@ -240,8 +240,8 @@ logger.debug("dematerialising datatype properties"); for (DatatypeProperty dp : booleanDatatypeProperties) { - bdPos.put(dp, rc.getTrueDatatypeMembers(dp)); - bdNeg.put(dp, rc.getFalseDatatypeMembers(dp)); + bdPos.put(dp, (TreeSet<Individual>) rc.getTrueDatatypeMembers(dp)); + bdNeg.put(dp, (TreeSet<Individual>) rc.getFalseDatatypeMembers(dp)); } for (DatatypeProperty dp : intDatatypeProperties) { @@ -495,16 +495,17 @@ } @Override + @SuppressWarnings("unchecked") public SortedSet<Individual> getIndividualsImpl(Description description) throws ReasoningMethodUnsupportedException { // policy: returned sets are clones, i.e. can be modified // (of course we only have to clone the leafs of a class description tree) if (description instanceof NamedClass) { - return new TreeSet<Individual>(classInstancesPos.get((NamedClass) description)); + return (TreeSet<Individual>) classInstancesPos.get((NamedClass) description).clone(); } else if (description instanceof Negation && description.getChild(0) instanceof NamedClass) { - return new TreeSet<Individual>(classInstancesNeg.get((NamedClass) description.getChild(0))); + return (TreeSet<Individual>) classInstancesNeg.get((NamedClass) description.getChild(0)).clone(); } else if (description instanceof Thing) { - return new TreeSet<Individual>(individuals); + return (TreeSet<Individual>) individuals.clone(); } else if (description instanceof Nothing) { return new TreeSet<Individual>(); } else if (description instanceof Union) { @@ -535,7 +536,7 @@ ObjectPropertyExpression ope = ((ObjectSomeRestriction) description).getRole(); if (!(ope instanceof ObjectProperty)) { - throw new ReasoningMethodUnsupportedException("Instance check for description " + throw new ReasoningMethodUnsupportedException("Retrieval for description " + description + " unsupported. Inverse object properties not supported."); } ObjectProperty op = (ObjectProperty) ope; @@ -553,6 +554,7 @@ } } } + return returnSet; } else if (description instanceof ObjectAllRestriction) { // \forall restrictions are difficult to handle; assume we want to check // \forall hasChild.male with domain(hasChild)=Person; then for all non-persons @@ -587,6 +589,138 @@ } } } + return returnSet; + } else if (description instanceof ObjectMinCardinalityRestriction) { + ObjectPropertyExpression ope = ((ObjectCardinalityRestriction) description).getRole(); + if (!(ope instanceof ObjectProperty)) { + throw new ReasoningMethodUnsupportedException("Instance check for description " + + description + " unsupported. Inverse object properties not supported."); + } + ObjectProperty op = (ObjectProperty) ope; + Description child = description.getChild(0); + Map<Individual, SortedSet<Individual>> mapping = opPos.get(op); + SortedSet<Individual> targetSet = getIndividualsImpl(description.getChild(0)); + SortedSet<Individual> returnSet = new TreeSet<Individual>(); + + int number = ((ObjectCardinalityRestriction) description).getNumber(); + + for(Entry<Individual, SortedSet<Individual>> entry : mapping.entrySet()) { + int nrOfFillers = 0; + int index = 0; + SortedSet<Individual> inds = entry.getValue(); + + // we do not need to run tests if there are not sufficiently many fillers + if(inds.size() < number) { + continue; + } + + for(Individual ind : inds) { + // stop inner loop when nr of fillers is reached + if(nrOfFillers >= number) { + returnSet.add(entry.getKey()); + break; + } + // early abort when too many instance checks failed + if (inds.size() - index < number) { + break; + } + if(targetSet.contains(ind)) { + nrOfFillers++; + } + index++; + } + } + + return returnSet; + } else if (description instanceof ObjectMaxCardinalityRestriction) { + ObjectPropertyExpression ope = ((ObjectCardinalityRestriction) description).getRole(); + if (!(ope instanceof ObjectProperty)) { + throw new ReasoningMethodUnsupportedException("Instance check for description " + + description + " unsupported. Inverse object properties not supported."); + } + ObjectProperty op = (ObjectProperty) ope; + Description child = description.getChild(0); + Map<Individual, SortedSet<Individual>> mapping = opPos.get(op); + SortedSet<Individual> targetSet = getIndividualsImpl(description.getChild(0)); + // initially all individuals are in the return set and we then remove those + // with too many fillers + SortedSet<Individual> returnSet = (SortedSet<Individual>) individuals.clone(); + + int number = ((ObjectCardinalityRestriction) description).getNumber(); + + for(Entry<Individual, SortedSet<Individual>> entry : mapping.entrySet()) { + int nrOfFillers = 0; + int index = 0; + SortedSet<Individual> inds = entry.getValue(); + + // we do not need to run tests if there are not sufficiently many fillers + if(number < inds.size()) { + returnSet.add(entry.getKey()); + continue; + } + + for(Individual ind : inds) { + // stop inner loop when nr of fillers is reached + if(nrOfFillers >= number) { + break; + } + // early abort when too many instance are true already + if (inds.size() - index < number) { + returnSet.add(entry.getKey()); + break; + } + if(targetSet.contains(ind)) { + nrOfFillers++; + } + index++; + } + } + + return returnSet; + } else if (description instanceof ObjectValueRestriction) { + Individual i = ((ObjectValueRestriction)description).getIndividual(); + ObjectProperty op = (ObjectProperty) ((ObjectValueRestriction)description).getRestrictedPropertyExpression(); + + Map<Individual, SortedSet<Individual>> mapping = opPos.get(op); + SortedSet<Individual> returnSet = new TreeSet<Individual>(); + + for(Entry<Individual, SortedSet<Individual>> entry : mapping.entrySet()) { + if(entry.getValue().contains(i)) { + returnSet.add(entry.getKey()); + } + } + return returnSet; + } else if (description instanceof BooleanValueRestriction) { + DatatypeProperty dp = ((BooleanValueRestriction) description) + .getRestrictedPropertyExpresssion(); + boolean value = ((BooleanValueRestriction) description).getBooleanValue(); + + if (value) { + return (TreeSet<Individual>) bdPos.get(dp).clone(); + } else { + return (TreeSet<Individual>) bdNeg.get(dp).clone(); + } + } else if (description instanceof DatatypeSomeRestriction) { + DatatypeSomeRestriction dsr = (DatatypeSomeRestriction) description; + DatatypeProperty dp = (DatatypeProperty) dsr.getRestrictedPropertyExpression(); + DataRange dr = dsr.getDataRange(); + + Map<Individual, SortedSet<Double>> mapping = dd.get(dp); + SortedSet<Individual> returnSet = new TreeSet<Individual>(); + + if (dr instanceof DoubleMaxValue) { + for(Entry<Individual, SortedSet<Double>> entry : mapping.entrySet()) { + if(entry.getValue().first() <= ((DoubleMaxValue)dr).getValue()) { + returnSet.add(entry.getKey()); + } + } + } else if (dr instanceof DoubleMinValue) { + for(Entry<Individual, SortedSet<Double>> entry : mapping.entrySet()) { + if(entry.getValue().last() >= ((DoubleMinValue)dr).getValue()) { + returnSet.add(entry.getKey()); + } + } + } } throw new ReasoningMethodUnsupportedException("Retrieval for description " Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2009-02-18 13:09:16 UTC (rev 1612) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2009-02-18 17:13:11 UTC (rev 1613) @@ -341,6 +341,10 @@ @Override public Set<Description> refine(Description description, int maxLength) { + // check that maxLength is valid + if(maxLength < description.getLength()) { + throw new Error("length has to be at least description length (description: " + description + ", max length: " + maxLength + ")"); + } return refine(description, maxLength, null, startClass); } Modified: trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionComparator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionComparator.java 2009-02-18 13:09:16 UTC (rev 1612) +++ trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionComparator.java 2009-02-18 17:13:11 UTC (rev 1613) @@ -43,16 +43,16 @@ double acc1 = ed1.getAccuracy(); double acc2 = ed2.getAccuracy(); if(acc1 > acc2) + return 1; + else if(acc1 < acc2) return -1; - else if(acc1 < acc2) - return 1; else { int length1 = ed1.getDescriptionLength(); int length2 = ed2.getDescriptionLength(); if(length1 < length2) + return 1; + else if(length1 > length2) return -1; - else if(length1 > length2) - return 1; else return cc.compare(ed1.getDescription(), ed2.getDescription()); } Modified: trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionSet.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionSet.java 2009-02-18 13:09:16 UTC (rev 1612) +++ trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionSet.java 2009-02-18 17:13:11 UTC (rev 1613) @@ -43,7 +43,7 @@ private EvaluatedDescriptionComparator comp = new EvaluatedDescriptionComparator(); - private SortedSet<EvaluatedDescription> set = new TreeSet<EvaluatedDescription>(comp); + private TreeSet<EvaluatedDescription> set = new TreeSet<EvaluatedDescription>(comp); private int maxSize; @@ -56,6 +56,7 @@ set.add(problem.evaluate(description)); } if(set.size()>maxSize) { + // delete the worst element Iterator<EvaluatedDescription> it = set.iterator(); it.next(); it.remove(); @@ -82,17 +83,17 @@ } public EvaluatedDescription getBest() { - return set.first(); + return set.last(); } public EvaluatedDescription getWorst() { - return set.last(); + return set.first(); } /** * @return the set */ - public SortedSet<EvaluatedDescription> getSet() { + public TreeSet<EvaluatedDescription> getSet() { return set; } @@ -103,4 +104,9 @@ } return list; } + + @Override + public String toString() { + return set.toString(); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |