public boolean isCurentStateInTrajectory() { Object currentStateId = trajectory.getCurrentStateId(); List<Object> stateTrajectory = trajectory.getStateTrajectory(); int size = stateTrajectory.size(); for (int i = 0; i < size - 1; i++) { Object stateId = stateTrajectory.get(i); if (currentStateId.equals(stateId)) { return true; } } return false; }
public List<Object> getTrajectoryFromRoot() { return trajectory.getTrajectory(); }
@Override public int getDepth() { return designSpaceManager.getTrajectoryInfo().getDepth(); }
@Override public Double getFitness(ThreadContext context) { DesignSpaceManager dsm = context.getDesignSpaceManager(); TrajectoryInfo trajectoryInfo = dsm.getTrajectoryInfo(); List<Object> trajectory = trajectoryInfo.getTrajectory(); List<BatchTransformationRule<?, ?>> rules = trajectoryInfo.getRules(); double result = 0; for (int i = 0; i < trajectory.size(); i++) { BatchTransformationRule<?, ?> rule = rules.get(i); Double cost = fixCosts.get(rule); if (cost != null) { result += cost; } Map<String, Double> costs = trajectoryInfo.getMeasuredCosts().get(i); if (costs != null) { cost = costs.get(name); if (cost != null) { result += cost; } } } if (calculateTrajectoryLengthWeight) { result += trajectory.size() * trajectoryLengthWeight; } return result; }
public int backtrackUntilLastCommonActivation(Object[] newTrajectory) { Iterator<Object> currentTrajectoryIterator = trajectory.getTrajectory().iterator(); if (!currentTrajectoryIterator.hasNext()) { return 0; } int indexOfLastCommonActivation = 0; for (Object activationCode : newTrajectory) { if (currentTrajectoryIterator.hasNext()) { Object activationCodeFromCurrent = currentTrajectoryIterator.next(); if (activationCodeFromCurrent.equals(activationCode)) { indexOfLastCommonActivation++; } else { break; } } else { // current trajectory is smaller break; } } int numberOfBacktracks = trajectory.getDepth() - indexOfLastCommonActivation; if (numberOfBacktracks > 0) { for (int i = numberOfBacktracks; i > 0; i--) { domain.getCommandStack().undo(); trajectory.backtrack(); } activationCodes.updateActivationCodes(); } logger.debug("Backtracked " + numberOfBacktracks + " times."); return indexOfLastCommonActivation; }
public TrajectoryWithStateFitness(TrajectoryInfo trajectoryInfo, Fitness fitness) { super(trajectoryInfo, fitness); state = trajectoryInfo.getCurrentStateId(); }
public boolean undoLastTransformation() { if (!trajectory.canStepBack()) { return false; } domain.getCommandStack().undo(); activationCodes.updateActivationCodes(); Object lastActivationId = trajectory.getLastActivationId(); trajectory.backtrack(); if (handlers != null) { for (IExploreEventHandler iExploreEventHandler : handlers) { iExploreEventHandler.undo(lastActivationId); } } logger.debug("Backtrack."); return true; }
Object previousState = trajectory.getCurrentStateId(); trajectory.addStep(transition, rule, newStateId, measureCosts);
public void undoUntilRoot() { while(trajectory.canStepBack()) { domain.getCommandStack().undo(); trajectory.backtrack(); } activationCodes.updateActivationCodes(); logger.debug("Backtracked to root."); }
trajectory.addStep(activationId, rule, newStateId, measureCosts); trajectory.modifyLastStateCode(stateCoder.createStateCode());
public SolutionTrajectory createSolutionTrajectroy() { return trajectory.createSolutionTrajectory(context.getGlobalContext().getStateCoderFactory()); }
public void backtrackXTimes(int steps) { for (int i = steps; i > 0; i--) { domain.getCommandStack().undo(); trajectory.backtrack(); } activationCodes.updateActivationCodes(); logger.debug("Backtracked " + steps + " times."); }
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); }
public Object getCurrentState() { return trajectory.getCurrentStateId(); }
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); } }
/** * Creates a {@link TrajectoryFitness} with the full trajectory. * @param trajectoryInfo The trajectory. * @param fitness The fitness. */ public TrajectoryFitness(TrajectoryInfo trajectoryInfo, Fitness fitness) { this.fitness = fitness; List<Object> fullTraj = trajectoryInfo.getTrajectory(); trajectory = fullTraj.toArray(new Object[fullTraj.size()]); }
@Override public Object getCurrentStateId() { return designSpaceManager.getTrajectoryInfo().getCurrentStateId(); }
if (trajectoryInfo.getDepth() < maxDepth) {
private void addPermutation(DesignSpaceManager dsm, TrajectoryInfo trajectoryInfo, Object[] parent) { outerLoop: for (Object transitionToAddId : parent) { for (Object childTransition : trajectoryInfo.getTrajectory()) { Object id = childTransition; if (transitionToAddId.equals(id)) { continue outerLoop; } } GeneticHelper.tryFireRightTransition(dsm, transitionToAddId); } }