public SolutionTrajectory createSolutionTrajectory(final IStateCoderFactory stateCoderFactory) { List<Object> activationIds = new ArrayList<>(trajectory); List<BatchTransformationRule<?, ?>> copiedRules = new ArrayList<>(rules); return new SolutionTrajectory(activationIds, copiedRules, stateCoderFactory); }
/** * Transforms the given model along the trajectory. To initialize the model call the * {@link SolutionTrajectory#setModel(Notifier)} method. * * @throws Exception * If the activation to fire is not found. Possible problems: wrong model, bad state serializer. * @throws ViatraQueryRuntimeException * If the VIATRA Query fails to initialize. */ public void doTransformation() { while (doNextTransformation()); }
/** * Transforms the given model along the trajectory. * * @param modelRoot * The root of the model. * @throws ViatraQueryRuntimeException * If the VIATRA Query fails to initialize. */ public void doTransformation(Notifier modelRoot) { setModel(modelRoot); doTransformation(); }
/** * Transforms the given model along the trajectory. * <p> * The transformation will be reversible by creating an {@link EditingDomain} on the model. * * @param modelRoot * The root of the model. * @throws ViatraQueryRuntimeException * If the VIATRA Query fails to initialize. */ public void doTransformationUndoable(Notifier modelRoot) { setModelWithEditingDomain(modelRoot); doTransformation(); }
public void saveModels(Notifier model, ISolutionNameProvider solutionNameProvider) { try { for (Solution solution : solutions.values()) { SolutionTrajectory trajectory = solution.getArbitraryTrajectory(); trajectory.doTransformationUndoable(model); EMFHelper.saveModel(model, solutionNameProvider.getName()); trajectory.undoTransformation(); } } catch (ViatraQueryException e) { Logger.getLogger(SolutionStore.class).error("Exception happened during model saving.", e); } } }
if (!solution.getTrajectories().contains(solutionTrajectory)) { solution.addTrajectory(solutionTrajectory); solutionTrajectory.setSolution(solution); solutionSaved = true; trajectories.put(solutionTrajectory, lastFitness); solution = new Solution(id, solutionTrajectory); solutions.put(id, solution); solutionTrajectory.setSolution(solution); solutionSaved = true; trajectories.put(solutionTrajectory, lastFitness); Solution s = st.getSolution(); if (!s.getTrajectories().remove(st)) { throw new DSEException("Should not happen.");
public SolutionTrajectory getShortestTrajectory() { Iterator<SolutionTrajectory> iterator = trajectories.iterator(); SolutionTrajectory shortestTrajecotry = iterator.next(); int minSize = shortestTrajecotry.getTrajectoryLength(); while (iterator.hasNext()) { SolutionTrajectory traj = iterator.next(); int size = traj.getTrajectoryLength(); if (size < minSize) { shortestTrajecotry = traj; minSize = size; } } return shortestTrajecotry; }
/** * Initialize this SolutionTrajectory for transforming the given model along the trajectory. * <p> * The transformation will be reversible by creating an {@link EditingDomain} on the model. * * @param modelRoot * The root of the model. * @throws ViatraQueryRuntimeException * If the VIATRA Query fails to initialize. */ public void setModelWithEditingDomain(Notifier modelRoot) { setModel(modelRoot); editingDomain = EMFHelper.createEditingDomain(model); }
@Override public boolean saveSolution(ThreadContext context, Object id, SolutionTrajectory solutionTrajectory) { Solution solution = solutions.get(id); if (solution != null) { if (solution.getTrajectories().contains(solutionTrajectory)) { return false; } else { solution.addTrajectory(solutionTrajectory); solutionTrajectory.setSolution(solution); } } else { solution = new Solution(id, solutionTrajectory); solutions.put(id, solution); solutionTrajectory.setSolution(solution); } return true; } }
@Override public void solutionFound(ThreadContext context, SolutionTrajectory trajectory) { Object stateCode = trajectory.getSolution().getStateCode(); if (savedSolutions.contains(stateCode)) { return; } savedSolutions.add(stateCode); Notifier clonedModel = EMFHelper.clone(context.getModel()); EMFHelper.saveModel(clonedModel, solutionNameProvider.getName()); } }
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); } }
/** * Transforms the given model by one step to the solution (makes one step in the trajectory). To initialize the * model call the {@link SolutionTrajectory#setModel(Notifier)} method. * * @throws ViatraQueryRuntimeException */ public boolean doNextTransformation() { if (currentIndex >= activationCodes.size()) { return false; } else { doNextTransformation(currentIndex); currentIndex++; return true; } }