Package org.optaplanner.core.api.domain.solution

Examples of org.optaplanner.core.api.domain.solution.Solution


    @Override
    protected void onExchange(Exchange exchange) throws Exception {
        ObjectHelper.notNull(solverFactory, "solverFactory");
        Solver solver = solverFactory.buildSolver();

        Solution planningProblem = exchange.getIn().getMandatoryBody(Solution.class);

        solver.solve(planningProblem);
        Solution bestSolution = solver.getBestSolution();

        exchange.getOut().setBody(bestSolution);
        // propagate headers and attachments
        exchange.getOut().setHeaders(exchange.getIn().getHeaders());
        exchange.getOut().setAttachments(exchange.getIn().getAttachments());
View Full Code Here


            this.mutationCounter = mutationCounter;
        }

        public void bestSolutionChanged(BestSolutionChangedEvent<Solution> event) {
            int mutationCount;
            Solution newBestSolution = event.getNewBestSolution();
            if (oldBestSolution == null) {
                mutationCount = 0;
            } else {
                mutationCount = mutationCounter.countMutations(oldBestSolution, newBestSolution);
            }
View Full Code Here

    public String getOutputFileExtension() {
        return FILE_EXTENSION;
    }

    public Solution read(File inputSolutionFile) {
        Solution unsolvedSolution;
        Reader reader = null;
        try {
            // xStream.fromXml(InputStream) does not use UTF-8
            reader = new InputStreamReader(new FileInputStream(inputSolutionFile), "UTF-8");
            unsolvedSolution = (Solution) xStream.fromXML(reader);
View Full Code Here

    public SingleBenchmarkRunner call() {
        MDC.put(NAME_MDC, singleBenchmarkResult.getName());
        Runtime runtime = Runtime.getRuntime();
        ProblemBenchmarkResult problemBenchmarkResult = singleBenchmarkResult.getProblemBenchmarkResult();
        Solution inputSolution = problemBenchmarkResult.readPlanningProblem();
        if (!problemBenchmarkResult.getPlannerBenchmarkResult().hasMultipleParallelBenchmarks()) {
            runtime.gc();
            singleBenchmarkResult.setUsedMemoryAfterInputSolution(runtime.totalMemory() - runtime.freeMemory());
        }
        logger.trace("Benchmark inputSolution has been read for singleBenchmarkResult ({}).",
                singleBenchmarkResult.getName());

        // Intentionally create a fresh solver for every SingleBenchmarkResult to reset Random, tabu lists, ...
        Solver solver = singleBenchmarkResult.getSolverBenchmarkResult().getSolverConfig().buildSolver();

        for (SingleStatistic singleStatistic : singleBenchmarkResult.getEffectiveSingleStatisticMap().values()) {
            singleStatistic.open(solver);
        }

        solver.solve(inputSolution);
        long timeMillisSpent = solver.getTimeMillisSpent();
        Solution outputSolution = solver.getBestSolution();

        DefaultSolverScope solverScope = ((DefaultSolver) solver).getSolverScope();
        SolutionDescriptor solutionDescriptor = solverScope.getSolutionDescriptor();
        problemBenchmarkResult.registerScale(solutionDescriptor.getEntityCount(outputSolution),
                solutionDescriptor.getVariableCount(outputSolution),
                solutionDescriptor.getProblemScale(outputSolution));
        singleBenchmarkResult.setScore(outputSolution.getScore());
        singleBenchmarkResult.setTimeMillisSpent(timeMillisSpent);
        singleBenchmarkResult.setCalculateCount(solverScope.getCalculateCount());

        for (SingleStatistic singleStatistic : singleBenchmarkResult.getEffectiveSingleStatisticMap().values()) {
            singleStatistic.close(solver);
View Full Code Here

            Object rightValue = variableDescriptor.getValue(rightPillar.get(0));
            if (!ObjectUtils.equals(leftValue, rightValue)) {
                movable = true;
                if (!variableDescriptor.isValueRangeEntityIndependent()) {
                    ValueRangeDescriptor valueRangeDescriptor = variableDescriptor.getValueRangeDescriptor();
                    Solution workingSolution = scoreDirector.getWorkingSolution();
                    for (Object rightEntity : rightPillar) {
                        ValueRange rightValueRange = valueRangeDescriptor.extractValueRange(workingSolution, rightEntity);
                        if (!rightValueRange.contains(leftValue)) {
                            return false;
                        }
View Full Code Here

                        + ") is not implemented.");
        }
    }

    public void sort(ScoreDirector scoreDirector, List<T> selectionList) {
        Solution solution = scoreDirector.getWorkingSolution();
        SortedMap<Comparable, T> selectionMap = new TreeMap<Comparable, T>(appliedWeightComparator);
        for (T selection : selectionList) {
            Comparable difficultyWeight = selectionSorterWeightFactory.createSorterWeight(solution, selection);
            T previous = selectionMap.put(difficultyWeight, selection);
            if (previous != null) {
View Full Code Here

            bestScoreImproved = uninitializedVariableCount < bestUninitializedVariableCount;
        }
        stepScope.setBestScoreImproved(bestScoreImproved);
        if (bestScoreImproved) {
            phaseScope.setBestSolutionStepIndex(stepScope.getStepIndex());
            Solution newBestSolution = stepScope.createOrGetClonedSolution();
            updateBestSolution(solverScope, newBestSolution, uninitializedVariableCount);
        } else if (assertBestScoreIsUnmodified) {
            solverScope.assertScoreFromScratch(solverScope.getBestSolution());
        }
    }
View Full Code Here

        if (bestScoreImproved) {
            stepScope.setBestScoreImproved(bestScoreImproved);
        }
        if (bestScoreImproved) {
            phaseScope.setBestSolutionStepIndex(stepScope.getStepIndex());
            Solution newBestSolution = solverScope.getScoreDirector().cloneWorkingSolution();
            updateBestSolution(solverScope, newBestSolution, uninitializedVariableCount);
        } else if (assertBestScoreIsUnmodified) {
            solverScope.assertScoreFromScratch(solverScope.getBestSolution());
        }
    }
View Full Code Here

        if (ObjectUtils.equals(oldValue, toPlanningValue)) {
            return false;
        }
        if (!variableDescriptor.isValueRangeEntityIndependent()) {
            ValueRangeDescriptor valueRangeDescriptor = variableDescriptor.getValueRangeDescriptor();
            Solution workingSolution = scoreDirector.getWorkingSolution();
            for (Object entity : pillar) {
                ValueRange rightValueRange = valueRangeDescriptor.extractValueRange(workingSolution, entity);
                if (!rightValueRange.contains(toPlanningValue)) {
                    return false;
                }
View Full Code Here

                score = doProblemFactChange(problemFactChange, stepIndex);
                stepIndex++;
                problemFactChange = problemFactChangeQueue.poll();
            }
            basicPlumbingTermination.endProblemFactChangesProcessing();
            Solution newBestSolution = solverScope.getScoreDirector().cloneWorkingSolution();
            // TODO BestSolutionRecaller.solverStarted() already calls countUninitializedVariables()
            int newBestUninitializedVariableCount = solverScope.getSolutionDescriptor()
                    .countUninitializedVariables(newBestSolution);
            bestSolutionRecaller.updateBestSolution(solverScope,
                    newBestSolution, newBestUninitializedVariableCount);
View Full Code Here

TOP

Related Classes of org.optaplanner.core.api.domain.solution.Solution

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.