当前位置: 首页>>代码示例>>Java>>正文


Java Solver类代码示例

本文整理汇总了Java中org.optaplanner.core.api.solver.Solver的典型用法代码示例。如果您正苦于以下问题:Java Solver类的具体用法?Java Solver怎么用?Java Solver使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Solver类属于org.optaplanner.core.api.solver包,在下文中一共展示了Solver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getScoreOnlySolver

import org.optaplanner.core.api.solver.Solver; //导入依赖的package包/类
/**
 * Return new or cached score only solver. Detect changes to the rule list
 * and re-create the solver in that case.
 *
 * @param customDrlFiles the list of user provided DRL files
 * @return score only solver
 */
public static Solver getScoreOnlySolver(List<Path> customDrlFiles) {
    Set<Path> changeDetector = new HashSet<>(customDrlFiles);
    changeDetector.retainAll(recordedCustomDrlFiles);

    if (scoreOnlySolver != null
            && customDrlFiles.size() == changeDetector.size()
            && recordedCustomDrlFiles.size() == changeDetector.size()) {
        return scoreOnlySolver;
    }

    SolverFactory solverFactory =
            SolverFactory.createFromXmlResource("org/ovirt/optimizer/solver/rules/scoreonly.xml");
    addCustomDrlFiles(solverFactory.getSolverConfig().getScoreDirectorFactoryConfig(), customDrlFiles);
    scoreOnlySolver = solverFactory.buildSolver();
    recordedCustomDrlFiles = customDrlFiles;
    return scoreOnlySolver;
}
 
开发者ID:oVirt,项目名称:ovirt-optimizer,代码行数:25,代码来源:SolverUtils.java

示例2: recomputeScoreUsingScoreDirector

import org.optaplanner.core.api.solver.Solver; //导入依赖的package包/类
/**
 * Recompute solution's score and log all rules that affected it (in debug mode)
 * This method uses new score director from the passed solver
 *
 * @param solver
 * @param solution
 */
public static void recomputeScoreUsingScoreDirector(Solver solver, OptimalDistributionStepsSolution solution) {
    ScoreDirector director = solver.getScoreDirectorFactory().buildScoreDirector();
    director.setWorkingSolution(solution);
    Score score = director.calculateScore();

    for (ConstraintMatchTotal constraintMatchTotal : director.getConstraintMatchTotals()) {
        String constraintName = constraintMatchTotal.getConstraintName();
        Number weightTotal = constraintMatchTotal.getWeightTotalAsNumber();
        for (ConstraintMatch constraintMatch : constraintMatchTotal.getConstraintMatchSet()) {
            List<Object> justificationList = constraintMatch.getJustificationList();
            Number weight = constraintMatch.getWeightAsNumber();
            log.debug("Constraint match {} with weight {}", constraintMatch, weight);
            for (Object item : justificationList) {
                log.debug("Justified by {}", item);
            }
        }
    }
    log.debug("Final score {}", score);
}
 
开发者ID:oVirt,项目名称:ovirt-optimizer,代码行数:27,代码来源:SolverUtils.java

示例3: main

import org.optaplanner.core.api.solver.Solver; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
    DevoxxImporter devoxxImporter = new DevoxxImporter();
    SolverFactory<Conference> solverFactory = SolverFactory.createFromXmlResource(
            OptaConfPlanner.SOLVER_CONFIG);

    Conference conference = devoxxImporter.importConference(false);
    logger.info("Imported.");

    Solver<Conference> solver = solverFactory.buildSolver();
    conference = solver.solve(conference);
    logger.info("Solved.");

    ConferenceFileIO fileIO = new ConferenceFileIO();
    File outputFile = File.createTempFile("devoxx2016-", "." + fileIO.getOutputFileExtension());
    fileIO.write(conference, outputFile);
    logger.info("Written.");
    Desktop.getDesktop().open(outputFile);
}
 
开发者ID:ge0ffrey,项目名称:optaconf,代码行数:19,代码来源:OptaConfPlannerApp.java

示例4: plan

import org.optaplanner.core.api.solver.Solver; //导入依赖的package包/类
public List<ShiftAssignment> plan() {
    SolverFactory<Solution> solverFactory = SolverFactory.createFromXmlResource("planner/EmployeeRosteringSolverConfig.xml");
    Solver solver = solverFactory.buildSolver();

    EmployeeRoster employeeRoster = new EmployeeRoster();
    employeeRoster.setCode("TEST");
    employeeRoster.setSkillList(employeeRepository.listSkills());
    employeeRoster.setShiftTypeList(shiftRepository.listShiftTypes());
    employeeRoster.setShiftTypeSkillRequirementList(generateShiftTypeSkillRequirements());
    employeeRoster.setPatternList(patternsRepository.listAll());
    employeeRoster.setContractList(contractRepository.listAll());
    employeeRoster.setContractLineList(generateContractLines());
    employeeRoster.setPatternContractLineList(generateContractPatternList());
    employeeRoster.setEmployeeList(employeeRepository.listAll());
    employeeRoster.setSkillProficiencyList(generateSkillProficiency());
    employeeRoster.setShiftDateList(shiftRepository.listShiftDates());
    employeeRoster.setShiftList(shiftRepository.listShifts());
    employeeRoster.setDayOffRequestList(employeeRepository.listDayOffRequests());
    employeeRoster.setDayOnRequestList(employeeRepository.listDayOnRequests());
    employeeRoster.setShiftOffRequestList(employeeRepository.listShiftOffRequests());
    employeeRoster.setShiftOnRequestList(employeeRepository.listShiftOnRequests());
    employeeRoster.setEmployeeRosterParametrization(generateEmployeeRosterInfo());
    employeeRoster.setShiftAssignmentList(generateAssigments());

    employeeRoster = (EmployeeRoster) solver.solve(employeeRoster);
    final HardSoftScore score = employeeRoster.getScore();
    for (ShiftAssignment shiftAssignment : employeeRoster.getShiftAssignmentList()) {
        shiftRepository.createShiftAssignment(shiftAssignment.getShift(), shiftAssignment.getEmployee());
    }
    messageService.informUser(String.format("'%s' score ", score.toString()));

    return shiftRepository.listShiftAssignments();
}
 
开发者ID:bibryam,项目名称:rotabuilder,代码行数:34,代码来源:ShiftService.java

示例5: terminate

import org.optaplanner.core.api.solver.Solver; //导入依赖的package包/类
public void terminate(Integer tenantId) {
    Solver<Roster> solver = tenantIdToSolverMap.get(tenantId);
    if (null != solver) {
        solver.terminateEarly();
    }
    else {
        throw new IllegalStateException("The roster with tenantId (" + tenantId
                + ") is not being solved currently.");
    }
}
 
开发者ID:kiegroup,项目名称:optashift-employee-rostering,代码行数:11,代码来源:WannabeSolverManager.java

示例6: solve

import org.optaplanner.core.api.solver.Solver; //导入依赖的package包/类
public void solve(Integer tenantId) {
    logger.info("Scheduling solver for tenantId ({})...", tenantId);
    // No 2 solve() calls of the same dataset in parallel
    tenantIdToSolverStateMap.compute(tenantId, (k, solverStatus) -> {
        if (solverStatus != null && solverStatus != SolverStatus.TERMINATED) {
            throw new IllegalStateException("The roster with tenantId (" + tenantId
                    + ") is already solving with solverStatus (" + solverStatus + ").");
        }
        return SolverStatus.SCHEDULED;
    });
    executorService.submit(() -> {
        try {
            Solver<Roster> solver = solverFactory.buildSolver();
            tenantIdToSolverMap.put(tenantId, solver);
            solver.addEventListener(event -> {
                if (event.isEveryProblemFactChangeProcessed()) {
                    logger.info("  New best solution found for tenantId ({}).", tenantId);
                    Roster newBestRoster = event.getNewBestSolution();
                    // TODO if this throws an OptimisticLockingException, does it kill the solver?
                    rosterRestService.updateShiftsOfRoster(newBestRoster);
                }
            });
            Roster roster = rosterRestService.buildRoster(tenantId);
            try {
                tenantIdToSolverStateMap.put(tenantId, SolverStatus.SOLVING);
                // TODO No need to store the returned roster because the SolverEventListener already does it?
                solver.solve(roster);
            } finally {
                tenantIdToSolverMap.remove(tenantId);
                tenantIdToSolverStateMap.put(tenantId, SolverStatus.TERMINATED);
            }
        } catch (Throwable e) {
            // TODO handle errors through Thread'sExceptionHandler
            logger.error("Error solving for tenantId (" + tenantId + ").", e);
        }
    });
}
 
开发者ID:kiegroup,项目名称:optashift-employee-rostering,代码行数:38,代码来源:WannabeSolverManager.java

示例7: getShortStatus

import org.optaplanner.core.api.solver.Solver; //导入依赖的package包/类
public String getShortStatus() {
    Solver<ConferenceData> solver = this.solver;
    String status = solver == null || !solver.isSolving() ? "idle" : "solving";
    if (solver != null) {
        status += ", best score " + solver.getBestScore();
    }
    return status;
}
 
开发者ID:vlsi,项目名称:confplanner,代码行数:9,代码来源:SolverAction.java

示例8: describeBest

import org.optaplanner.core.api.solver.Solver; //导入依赖的package包/类
public String describeBest() {
    Solver<ConferenceData> solver = this.solver;
    if (solver == null) {
        return "";
    }
    ConferenceData currentBest = solver.getBestSolution();
    if (currentBest == prevBest) {
        return prevBestDescr;
    }
    prevBest = currentBest;
    currentBest.sort();

    StringWriter sw = new StringWriter();

    ScoreDirector<ConferenceData> scorer = solver.getScoreDirectorFactory().buildScoreDirector();
    scorer.setWorkingSolution(currentBest);
    Collection<ConstraintMatchTotal> totals = scorer.getConstraintMatchTotals();
    Map<Object, Indictment> map = scorer.getIndictmentMap();

    sw.append("<html><body style='font-family:monospace'>");
    for (ConstraintMatchTotal total : totals) {
        sw.append(String.valueOf(total.getScoreTotal())).append("\t").append(total.getConstraintName()).append("<br>");
    }
    sw.append("<br>");
    currentBest.print(sw, map);
    sw.append("</body></html>");
    prevBestDescr = sw.toString();
    return prevBestDescr;
}
 
开发者ID:vlsi,项目名称:confplanner,代码行数:30,代码来源:SolverAction.java

示例9: solveProblem

import org.optaplanner.core.api.solver.Solver; //导入依赖的package包/类
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public ProblemSolution solveProblem(ProblemDescription problemDescription) {
    logger.info("Received request to route: " + problemDescription);
    SolverFactory solverFactory = SolverFactory.createFromXmlResource(SOLVER_CONFIG);
    Solver solver = solverFactory.buildSolver();
    RoutingSolution routingSolution = problemDescription.createEmptyRoutingSolution();
    solver.solve(routingSolution);
    return ProblemSolution.create((RoutingSolution) solver.getBestSolution());
}
 
开发者ID:CSSE497,项目名称:pathfinder-routing,代码行数:12,代码来源:RoutingService.java

示例10: run

import org.optaplanner.core.api.solver.Solver; //导入依赖的package包/类
@Override
public void run() {
    SolverFactory sF = SolverFactory.createFromXmlResource("solver/tabuSearch_solverConfig.xml");
    Solver solver = sF.buildSolver();
    AlocacaoHorario bestSolution;

    solver.addEventListener(event -> {
        if (event.isEveryProblemFactChangeProcessed()) {
            AlocacaoHorario newBestSolution;
            System.out.println("Encontrou nova solução.");

            newBestSolution = (AlocacaoHorario) event.getNewBestSolution();

            logarSolucao(newBestSolution);

            listenner.update(Resolvedor.this, event.getNewBestSolution());
        }
    });

    solver.solve(alocacaoHorario);

    bestSolution = (AlocacaoHorario) solver.getBestSolution();

    logarSolucao(bestSolution);

    listenner.update(this, bestSolution);
}
 
开发者ID:Sakamotto,项目名称:Projeto-Flash,代码行数:28,代码来源:Resolvedor.java

示例11: populateResult

import org.optaplanner.core.api.solver.Solver; //导入依赖的package包/类
private void populateResult(Exchange exchange, Solver solver) {
    exchange.getIn().setBody(solver.getBestSolution());
    exchange.getIn().setHeader(OptaPlannerConstants.TIME_SPENT, solver.getTimeMillisSpent());
    exchange.getIn().setHeader(OptaPlannerConstants.IS_EVERY_PROBLEM_FACT_CHANGE_PROCESSED, solver.isEveryProblemFactChangeProcessed());
    exchange.getIn().setHeader(OptaPlannerConstants.IS_TERMINATE_EARLY, solver.isTerminateEarly());
    exchange.getIn().setHeader(OptaPlannerConstants.IS_SOLVING, solver.isSolving());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:8,代码来源:OptaPlannerProducer.java

示例12: getOrCreateSolver

import org.optaplanner.core.api.solver.Solver; //导入依赖的package包/类
protected Solver getOrCreateSolver(String solverId) throws Exception {
    synchronized (SOLVERS) {
        Solver solver = SOLVERS.get(solverId);
        if (solver == null) {
            solver = createSolver();
            SOLVERS.put(solverId, solver);
        }
        return solver;
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:11,代码来源:OptaPlannerEndpoint.java

示例13: doStop

import org.optaplanner.core.api.solver.Solver; //导入依赖的package包/类
@Override
protected void doStop() throws Exception {
    synchronized (SOLVERS) {
        for (Solver solver : SOLVERS.values()) {
            solver.terminateEarly();
            SOLVERS.remove(solver);
        }
    }
    super.doStop();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:11,代码来源:OptaPlannerEndpoint.java

示例14: main

import org.optaplanner.core.api.solver.Solver; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
    System.setProperty("logback.level.org.optaplanner", "info"); // don't waste time logging too much

    // Build the Solver
    // TODO cli arg
    SolverFactory<ReindeerRoutingSolution> solverFactory = SolverFactory.createFromXmlResource(SOLVER_CONFIG);
    final Solver<ReindeerRoutingSolution> solver = solverFactory.buildSolver();

    // Load the problem
    final ReindeerRoutingSolution unsolvedReindeerRoutingSolution = (ReindeerRoutingSolution) (new ReindeerRoutingImporter().readSolution(new File("data/sss/import/gifts.csv")));

    // Solve the problem in the background
    System.out.println("OptaPlanner is working hard on your problem. Press any key to stop.");
    Runnable solving = new Runnable() {
        @Override
        public void run() {
            solver.solve(unsolvedReindeerRoutingSolution);
        }
    };
    E.submit(solving);

    // wait for the user to terminate
    System.in.read();
    System.out.println("OptaPlanner will now terminate.");

    // terminate on keypress and write the solution
    new ReindeerRoutingExporter().writeSolution(solver.getBestSolution(), new File("data/sss/solved/solution.csv")); // TODO cli arg
    System.out.println("Solution safely stored.");
    solver.terminateEarly();
    E.shutdownNow();
}
 
开发者ID:ge0ffrey,项目名称:santas-stolen-sleigh,代码行数:32,代码来源:ReindeerRoutingHelloWorld.java

示例15: getBestSolution

import org.optaplanner.core.api.solver.Solver; //导入依赖的package包/类
/**
 * This function returns the best solution to the problem.
 *
 * @return the state of a cluster after solving the placement problem
 */
public ClusterState getBestSolution() {
    Solver solver = vmPlacementSolver.buildSolver();
    solver.setPlanningProblem(getInitialState());
    solver.solve();
    ClusterState result = (ClusterState) solver.getBestSolution();
    cleanThreadLocals(); // to avoid memory leaks
    return result;
}
 
开发者ID:davidor,项目名称:clopla,代码行数:14,代码来源:VmPlacementProblem.java


注:本文中的org.optaplanner.core.api.solver.Solver类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。