@Override public void explore() { while (!(isInterrupted || initialPopulation.size() >= populationSize)) { while (lengthRemaining > 0) { lengthRemaining--; context.executeRandomActivationId(); boolean gcSatisfied = context.checkGlobalConstraints(); if (!gcSatisfied) { context.backtrack(); lengthRemaining++; } } initialPopulation.add(new TrajectoryWithStateFitness(dsm.getTrajectoryInfo(), context.calculateFitness())); dsm.undoUntilRoot(); lengthRemaining = newLength(); } }
protected void savePopulationsAsSolutions(List<TrajectoryFitness> survivedPopulation) { for (TrajectoryFitness trajectoryFitness : survivedPopulation) { if (trajectoryFitness.rank == 1) { context.backtrackUntilRoot(); for (Object transition : trajectoryFitness.trajectory) { context.executeAcitvationId(transition); } context.calculateFitness(); context.newSolution(); } } }
private void saveSolutionAndBacktrack() { context.calculateFitness(); context.newSolution(); logger.debug("Found solution: " + context.getTrajectoryInfo().toString()); logger.debug("Backtrack for more solutions, if needed."); context.backtrackUntilRoot(); }
@Override public void initStrategy(ThreadContext context) { this.context = context; if (context.getSharedObject() == null) { context.setSharedObject(new Object()); logger.info("Depth-first exploration strategy is initied."); startThreads(); } }
@Override public void explore() { final ObjectiveComparatorHelper objectiveComparatorHelper = context.getObjectiveComparatorHelper(); boolean globalConstraintsAreSatisfied = context.checkGlobalConstraints(); if (!globalConstraintsAreSatisfied) { logger.info("Global contraint is not satisifed in the first state. Terminate."); final Fitness firstFittness = context.calculateFitness(); if (firstFittness.isSatisifiesHardObjectives()) { context.newSolution(); logger.info("First state is a solution. Terminate."); return; final Object[] firstTrajectory = context.getTrajectory().toArray(new Object[0]); TrajectoryWithFitness currentTrajectoryWithFittness = new TrajectoryWithFitness(firstTrajectory, firstFittness); trajectoiresToExplore.add(currentTrajectoryWithFittness); context.getDesignSpaceManager().executeTrajectoryWithMinimalBacktrackWithoutStateCoding(currentTrajectoryWithFittness.trajectory); Collection<Object> activationIds = context.getUntraversedActivationIds(); Iterator<Object> iterator = activationIds.iterator(); context.executeAcitvationId(nextActivation); if (context.isCurrentStateAlreadyTraversed()) { logger.info("The new state is already visited."); context.backtrack(); } else if (!context.checkGlobalConstraints()) { logger.debug("Global contraint is not satisifed."); context.backtrack();
boolean globalConstraintsAreSatisfied = context.checkGlobalConstraints(); if (!globalConstraintsAreSatisfied) { logger.info("Global contraint is not satisifed in the first state. Terminate."); Fitness fitness = context.calculateFitness(); if (fitness.isSatisifiesHardObjectives()) { context.newSolution(); logger.info("First state is a solution. Terminate."); return; Object[] currentTrajectory = context.getTrajectory().toArray(new Object[0]); context.backtrackUntilRoot(); context.executeTrajectory(next); Collection<Object> activationIds = context.getCurrentActivationIds(); int i = activationIds.size() - 1; context.executeAcitvationId(activationIdToTry); if (context.isCurrentStateAlreadyTraversed()) { logger.info("The new state is already visited."); } else if (!context.checkGlobalConstraints()) { logger.debug("Global contraint is not satisifed."); } else if (context.calculateFitness().isSatisifiesHardObjectives()) { solutionStore.newSolution(context); logger.debug("Found a solution."); } else if (context.getDepth() >= maxDepth) {
boolean globalConstraintsAreSatisfied = context.checkGlobalConstraints(); if (!globalConstraintsAreSatisfied) { boolean isSuccessfulUndo = context.backtrack(); if (!isSuccessfulUndo) { logger.info("Global contraint is not satisifed and cannot backtrack."); Fitness fitness = context.calculateFitness(); if (fitness.isSatisifiesHardObjectives()) { context.newSolution(); boolean isSuccessfulUndo = context.backtrack(); if (!isSuccessfulUndo) { logger.info("Found a solution but cannot backtrack."); if (context.getDepth() >= maxDepth) { boolean isSuccessfulUndo = context.backtrack(); if (!isSuccessfulUndo) { logger.info("Reached max depth but cannot bactrack."); transitions = bestPriorityInState.get(context.getCurrentStateId()); Integer bestPriority = getBestPriority(context.getCurrentActivationIds()); transitions = Lists.newArrayList(); for (Object iTransition : context.getCurrentActivationIds()) { Integer integer = priorities.get(context.getRuleByActivationId(iTransition)); if (integer == null) { integer = Integer.valueOf(0); bestPriorityInState.put(context.getCurrentStateId(), transitions);
boolean globalConstraintsAreSatisfied = context.checkGlobalConstraints(); if (!globalConstraintsAreSatisfied) { boolean isSuccessfulUndo = context.backtrack(); if (!isSuccessfulUndo) { logger.info("Global contraint is not satisifed and cannot backtrack."); Fitness fitness = context.calculateFitness(); if (fitness.isSatisifiesHardObjectives()) { context.newSolution(); boolean isSuccessfulUndo = context.backtrack(); if (!isSuccessfulUndo) { logger.info("Found a solution but cannot backtrack."); Collection<Object> transitions = context.getCurrentActivationIds(); int index = rnd.nextInt(transitions.size()); Object transition = getByIndex(transitions, index); context.executeAcitvationId(transition); if (nth > 0) { context.backtrackUntilRoot(); maxDepth = rnd.nextInt(shared.maxDepth - shared.minDepth) + shared.minDepth; boolean loopInTrajectory = context.isCurrentStateInTrajectory(); if (loopInTrajectory) { boolean isSuccessfulUndo = context.backtrack(); if (!isSuccessfulUndo) { throw new DSEException(
boolean globalConstraintsAreSatisfied = context.checkGlobalConstraints(); if (!globalConstraintsAreSatisfied) { boolean isSuccessfulUndo = context.backtrack(); if (!isSuccessfulUndo) { logger.info("Global contraint is not satisifed and cannot backtrack."); Fitness fitness = context.calculateFitness(); if (fitness.isSatisifiesHardObjectives()) { context.newSolution(); if (backTrackIfSolution) { boolean isSuccessfulUndo = context.backtrack(); if (!isSuccessfulUndo) { logger.info("Found a solution but cannot backtrack."); if (context.getDepth() >= maxDepth) { boolean isSuccessfulUndo = context.backtrack(); if (!isSuccessfulUndo) { logger.info("Reached max depth but cannot bactrack."); activationIds = context.getUntraversedActivationIds(); if (activationIds.isEmpty()) { boolean isSuccessfulUndo = context.backtrack(); if (!isSuccessfulUndo) { logger.info("No more transitions from current state and cannot backtrack."); context.executeAcitvationId(activationId); boolean loopInTrajectory = context.isCurrentStateInTrajectory(); if (loopInTrajectory) {
boolean globalConstraintsAreSatisfied = context.checkGlobalConstraints(); if (!globalConstraintsAreSatisfied) { boolean isSuccessfulUndo = context.backtrack(); if (!isSuccessfulUndo) { logger.info("Global contraint is not satisifed and cannot backtrack."); Fitness previousFitness = context.calculateFitness(); logger.debug("Current depth: " + context.getDepth() + " Fitness: " + previousFitness); Collection<Object> transitionsFromCurrentState = context.getCurrentActivationIds(); context.executeAcitvationId(transition); if (!context.checkGlobalConstraints()) { logger.debug("Global contraint is not satisifed, backtrack."); context.backtrack(); continue; if (context.isCurrentStateInTrajectory()) { logger.debug("Current state is in trajectory, backtrack."); context.backtrack(); continue; Fitness fitness = context.calculateFitness(); objectiveComparatorHelper.addTrajectoryFitness( new TrajectoryFitness(context.getTrajectoryInfo().getLastActivationId(), fitness)); context.backtrack();
public DesignSpaceManager(ThreadContext context) { this.context = context; model = context.getModel(); designSpace = context.getGlobalContext().getDesignSpace(); domain = context.getEditingDomain(); conflictSet = context.getConflictResolver().getLastCreatedConflictSet(); stateCoder = context.getStateCoder(); Object initialStateId = stateCoder.createStateCode(); designSpace.addState(null, null, initialStateId); activationCodes = context.getActivationCodesConflictSet(); this.trajectory = new TrajectoryInfo(initialStateId); logger.debug("DesignSpaceManager initialized with initial model: " + initialStateId); }
@Override public void initStrategy(ThreadContext context) { this.context = context; dsm = context.getDesignSpaceManager(); if (context.getSharedObject() == null) { context.setSharedObject(so); so.evaluationStrategy.init(context); localParentSelector = so.parentSelectionStrategy; so = (EvolutionaryStrategySharedObject) context.getSharedObject(); localParentSelector = so.parentSelectionStrategy.createNew(); for (IMutation mutation : so.mutations) {
/** * Starts the design space exploration. Returns only when the {@link IStrategy#explore()} method returns. */ public void run() { GlobalContext globalContext = threadContext.getGlobalContext(); try { threadContext.init(); strategy.initStrategy(threadContext); strategy.explore(); threadContext.backtrackUntilRoot(); } catch (Throwable e) { Logger.getLogger(IStrategy.class).error("Thread stopped unexpectedly!", e); globalContext.registerException(e); } finally { globalContext.strategyFinished(this); dispose(); } }
@Override public void initStrategy(ThreadContext context) { this.context = context; dsm = context.getDesignSpaceManager(); initialPopulation = new HashSet<TrajectoryFitness>(populationSize); Objects.requireNonNull(objective, "Hard objective is missing for FixedPriorityInitialSelector."); Preconditions.checkState(objective.isHardObjective(), "Given objective is not hard objective for FixedPriorityInitialSelector."); for (BatchTransformationRule<?, ?> batchTransformationRule : context.getGlobalContext().getTransformations()) { if (!priorities.containsKey(batchTransformationRule)) { throw new IllegalStateException("Missing rule priority for FixedPriorityInitialSelector."); } } FixedPriorityConflictResolver fixedPriorityResolver = ConflictResolvers.createFixedPriorityResolver(); for (Entry<BatchTransformationRule<?, ?>, Integer> entry : priorities.entrySet()) { fixedPriorityResolver.setPriority(entry.getKey().getRuleSpecification(), entry.getValue()); } context.changeActivationOrdering(fixedPriorityResolver.createConflictSet()); objective.init(context); logger.info("FixedPriorityInitialSelector inited."); }
@Override public void initStrategy(ThreadContext context) { this.context = context; dsm = context.getDesignSpaceManager(); lengthRemaining = newLength(); initialPopulation = new HashSet<TrajectoryFitness>(populationSize); }
public synchronized void newSolution(ThreadContext context) { solutionSaver.setSolutionsCollection(solutions); Fitness fitness = context.getLastFitness(); DesignSpaceManager dsm = context.getDesignSpaceManager(); Object id = dsm.getCurrentState(); IStateCoderFactory stateCoderFactory = context.getGlobalContext().getStateCoderFactory(); SolutionTrajectory solutionTrajectory = dsm.getTrajectoryInfo().createSolutionTrajectory(stateCoderFactory); solutionTrajectory.setFitness(fitness); if (acceptOnlyGoalSolutions && !fitness.isSatisifiesHardObjectives()) { unsavedSolutionCallbacks(context, solutionTrajectory); return; } boolean solutionSaved = solutionSaver.saveSolution(context, id, solutionTrajectory); if (solutionSaved) { enoughSolutions.solutionFound(context, solutionTrajectory); savedSolutionCallbacks(context, solutionTrajectory); if (enoughSolutions.enoughSolutions()) { context.getGlobalContext().stopAllThreads(); } } else { unsavedSolutionCallbacks(context, solutionTrajectory); } }
stateCoder = getGlobalContext().getStateCoderFactory().createStateCoder(); stateCoder.init(model); stateCoder.createStateCode(); DseIdPoolHelper.INSTANCE.registerRules(new GetRuleExecutionsImpl(getDesignSpaceManager().getTrajectoryInfo().getRules()), getRules());
@Override public void initStrategy(ThreadContext context) { this.context = context; this.solutionStore = context.getGlobalContext().getSolutionStore(); final ObjectiveComparatorHelper objectiveComparatorHelper = context.getObjectiveComparatorHelper(); trajectoiresToExplore = new PriorityQueue<TrajectoryWithFitness>(11, (o1, o2) -> objectiveComparatorHelper.compare(o2.fitness, o1.fitness)); }
@Override public void initStrategy(ThreadContext context) { this.context = context; trajectoryInfo = context.getTrajectoryInfo(); GlobalContext gc = context.getGlobalContext(); Object sharedObject = gc.getSharedObject(); if (sharedObject == null) { gc.setSharedObject(shared); logger.info("Random exploration strategy is initied."); startThreads(); } else { shared = (SharedData) sharedObject; } maxDepth = rnd.nextInt(shared.maxDepth - shared.minDepth) + shared.minDepth; }