diff --git a/softwareconfiguration/hasco/src/main/java/hasco/core/HASCO.java b/softwareconfiguration/hasco/src/main/java/hasco/core/HASCO.java index 1d2ed36e51..4c274a33f6 100644 --- a/softwareconfiguration/hasco/src/main/java/hasco/core/HASCO.java +++ b/softwareconfiguration/hasco/src/main/java/hasco/core/HASCO.java @@ -6,6 +6,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeoutException; import java.util.stream.Collectors; @@ -74,7 +75,7 @@ public class HASCO, N, A, V extends Compa private final List> listOfAllRecognizedSolutions = new ArrayList<>(); private int numUnparametrizedSolutions = -1; private final Set returnedUnparametrizedComponentInstances = new HashSet<>(); - private Map, HASCOSolutionEvent> hascoSolutionEventCache = new HashMap<>(); + private Map, HASCOSolutionEvent> hascoSolutionEventCache = new ConcurrentHashMap<>(); /* runtime variables of algorithm */ private final TimeRecordingEvaluationWrapper timeGrabbingEvaluationWrapper; @@ -168,6 +169,8 @@ public void receiveSearchEvent(final AlgorithmEvent event) { @Subscribe public void receiveSolutionCandidateFoundEvent(final EvaluatedSearchSolutionCandidateFoundEvent solutionEvent) throws InterruptedException, TimeoutException, AlgorithmException { + + System.err.println(Thread.currentThread().getName() + ": Received solution event in search listener " + solutionEvent); EvaluatedSearchGraphPath searchPath = solutionEvent.getSolutionCandidate(); Plan plan = HASCO.this.planningGraphGeneratorDeriver.getPlan(searchPath.getNodes()); ComponentInstance objectInstance = Util.getSolutionCompositionForPlan(HASCO.this.getInput().getComponents(), HASCO.this.planningProblem.getCorePlanningProblem().getInit(), plan, true); @@ -190,6 +193,8 @@ public void receiveSolutionCandidateFoundEvent(final EvaluatedSearchSolutionCand HASCO.this.updateBestSeenSolution(solution); HASCO.this.listOfAllRecognizedSolutions.add(solution); HASCOSolutionEvent hascoSolutionEvent = new HASCOSolutionEvent<>(HASCO.this.getId(), solution); + HASCO.this.hascoSolutionEventCache.put(solutionEvent, hascoSolutionEvent); + System.err.println(Thread.currentThread().getName() + ": Post solution event in search listener " + solutionEvent); HASCO.this.post(hascoSolutionEvent); } @@ -221,8 +226,12 @@ public void receiveSolutionCandidateFoundEvent(final EvaluatedSearchSolutionCand /* otherwise, if a solution has been found, we announce this finding to our listeners and memorize if it is a new best candidate */ else if (searchEvent instanceof EvaluatedSearchSolutionCandidateFoundEvent) { + System.err.println(Thread.currentThread().getName() + ": Solution event in HASCO.nextWithException " + searchEvent); HASCOSolutionEvent hascoSolutionEvent = this.hascoSolutionEventCache.remove(searchEvent); - assert (hascoSolutionEvent != null) : "Hasco solution event has not been seen yet or cannot be retrieved from cache."; + assert (hascoSolutionEvent != null) : "Hasco solution event has not been seen yet or cannot be retrieved from cache. " + this.hascoSolutionEventCache; + if (hascoSolutionEvent == null) { + System.exit(0); + } this.logger.info("Received new solution with score {} from search, communicating this solution to the HASCO listeners. Number of returned unparametrized solutions is now {}/{}.", hascoSolutionEvent.getScore(), this.returnedUnparametrizedComponentInstances.size(), this.numUnparametrizedSolutions); return hascoSolutionEvent;