From f889dea154c57fd1831abc0db766f367665c0f60 Mon Sep 17 00:00:00 2001 From: Attila Ficsor Date: Tue, 8 Aug 2023 13:20:07 +0200 Subject: Improve performance of best first earch --- .../tools/refinery/store/dse/objectives/Fitness.java | 1 + .../store/dse/strategy/BestFirstStrategy.java | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) (limited to 'subprojects/store-dse/src/main') diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/objectives/Fitness.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/objectives/Fitness.java index 0bf956d2..b1dc4442 100644 --- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/objectives/Fitness.java +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/objectives/Fitness.java @@ -32,6 +32,7 @@ public class Fitness extends HashMap { public boolean equals(Object other) { if (other == null) return false; if (getClass() != other.getClass()) return false; + if (!super.equals(other)) return false; return satisfiesHardObjectives == ((Fitness) other).satisfiesHardObjectives; } diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/strategy/BestFirstStrategy.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/strategy/BestFirstStrategy.java index 98af5695..0883d3d7 100644 --- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/strategy/BestFirstStrategy.java +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/strategy/BestFirstStrategy.java @@ -16,10 +16,7 @@ import tools.refinery.store.dse.internal.Activation; import tools.refinery.store.dse.objectives.Fitness; import tools.refinery.store.dse.objectives.ObjectiveComparatorHelper; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.PriorityQueue; +import java.util.*; public class BestFirstStrategy implements Strategy { @@ -37,6 +34,20 @@ public class BestFirstStrategy implements Strategy { public String toString() { return trajectory.toString() + fitness.toString(); } + + @Override + public int hashCode() { + return trajectory.get(trajectory.size() - 1).hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof TrajectoryWithFitness other) { + return Objects.equals(trajectory.get(trajectory.size() - 1), other.trajectory.get(other.trajectory.size() - 1)); +// return trajectory.equals(((TrajectoryWithFitness) obj).trajectory); + } + return false; + } } public BestFirstStrategy() { -- cgit v1.2.3-54-g00ecf