@Override public TrajectoryInfo getTrajectoryInfo() { return designSpaceManager.getTrajectoryInfo(); }
@Override public List<Object> getTrajectory() { return designSpaceManager.getTrajectoryInfo().getTrajectory(); }
@Override public void initStrategy(ThreadContext context) { this.context = context; initialPopulation = new HashSet<TrajectoryFitness>(populationSize); dsm = context.getDesignSpaceManager(); trajectoryInfo = dsm.getTrajectoryInfo(); }
@Override public int getDepth() { return designSpaceManager.getTrajectoryInfo().getDepth(); }
@Override public Object getCurrentStateId() { return designSpaceManager.getTrajectoryInfo().getCurrentStateId(); }
private void saveTrajectory() { TrajectoryWithStateFitness traj = new TrajectoryWithStateFitness(dsm.getTrajectoryInfo(), context.calculateFitness()); initialPopulation.add(traj); logger.debug("Initial trajectory found: " + traj.toString()); }
@Override public boolean mutate(TrajectoryFitness parent1, TrajectoryFitness parent2, ThreadContext context) { DesignSpaceManager dsm = context.getDesignSpaceManager(); TrajectoryInfo trajectoryInfo = dsm.getTrajectoryInfo(); parent1t = parent1.trajectory; parent2t = parent2.trajectory; p1Size = parent1t.length; p2Size = parent2t.length; if (p1Size < 2 || p2Size < 2) { return false; } int minSize = Math.min(p1Size, p2Size); index = random.nextInt(minSize); dsm.executeTrajectoryWithMinimalBacktrackWithoutStateCoding(parent1t, index); addPermutation(dsm, trajectoryInfo, parent2t); return true; }
@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; }
@Override public boolean mutateAlternate(TrajectoryFitness parent1, TrajectoryFitness parent2, ThreadContext context) { DesignSpaceManager dsm = context.getDesignSpaceManager(); dsm.executeTrajectoryWithMinimalBacktrackWithoutStateCoding(parent2t, index); addPermutation(dsm, dsm.getTrajectoryInfo(), parent1t); return true; }
@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(); } }
DseIdPoolHelper.INSTANCE.registerRules(new GetRuleExecutionsImpl(getDesignSpaceManager().getTrajectoryInfo().getRules()), getRules());
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); } }