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


Java SolverFactory类代码示例

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


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

示例1: applyCustomProperties

import org.optaplanner.core.api.solver.SolverFactory; //导入依赖的package包/类
@Override
public void applyCustomProperties(Map<String, String> customPropertyMap) {
    String partitionSolverConfigResource = customPropertyMap.get(PARTITION_SOLVER_CONFIG_RESOURCE_PROPERTY);
    if (partitionSolverConfigResource == null) {
        throw new IllegalArgumentException("A customProperty (" + PARTITION_SOLVER_CONFIG_RESOURCE_PROPERTY
                + ") is missing from the solver configuration.");
    }
    String partitionCountString = customPropertyMap.get(PARTITION_COUNT_PROPERTY);
    if (partitionCountString == null) {
        throw new IllegalArgumentException("A customProperty (" + PARTITION_COUNT_PROPERTY
                + ") is missing from the solver configuration.");
    }
    try {
        partitionCount = Integer.parseInt(partitionCountString);
    } catch (NumberFormatException e) {
        throw new IllegalArgumentException("The customProperty (" + PARTITION_COUNT_PROPERTY
                + ")'s value (" + partitionCount + ") is not a valid int.", e);
    }
    if (customPropertyMap.size() != 2) {
        throw new IllegalArgumentException("The customPropertyMap's size (" + customPropertyMap.size()
                + ") is not 1.");
    }
    solverFactory = SolverFactory.createFromXmlResource(partitionSolverConfigResource);
}
 
开发者ID:ge0ffrey,项目名称:santas-stolen-sleigh,代码行数:25,代码来源:ReindeerRoutingPartitioningCustomPhase.java

示例2: getScoreOnlySolver

import org.optaplanner.core.api.solver.SolverFactory; //导入依赖的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

示例3: main

import org.optaplanner.core.api.solver.SolverFactory; //导入依赖的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: main

import org.optaplanner.core.api.solver.SolverFactory; //导入依赖的package包/类
public static void main(String[] args) {
    String filename = "roster-10spots-28days";
    WorkerRosteringSolutionFileIO solutionFileIO = new WorkerRosteringSolutionFileIO();
    Roster roster = solutionFileIO.read(new File("data/workerrostering/import/" + filename + ".xlsx"));
    // WorkerRosteringGenerator generator = new WorkerRosteringGenerator();
    // Roster roster = generator.generateRoster(10, 28);

    // LAB-SOLUTION-START
    SolverFactory<Roster> solverFactory = SolverFactory.createFromXmlResource(
            "org/optaplanner/training/workerrostering/solver/workerRosteringSolverConfig.xml");
    roster = solverFactory.buildSolver().solve(roster);
    // LAB-SOLUTION-END

    File outputSolutionFile = new File("data/workerrostering/export/" + filename + "-solved"
            + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss", Locale.ENGLISH)) + ".xlsx");
    solutionFileIO.write(roster, outputSolutionFile);
    Desktop desktop = Desktop.getDesktop();
    if (desktop.isSupported(Desktop.Action.OPEN)) {
        try {
            desktop.open(outputSolutionFile);
        } catch (IOException e) {
            throw new IllegalArgumentException("Could not open outputSolutionFile (" + outputSolutionFile
                    + ") on this operation system.", e);
        }
    }
}
 
开发者ID:kiegroup,项目名称:optaplanner-training,代码行数:27,代码来源:WorkerRosteringApp.java

示例5: plan

import org.optaplanner.core.api.solver.SolverFactory; //导入依赖的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

示例6: main

import org.optaplanner.core.api.solver.SolverFactory; //导入依赖的package包/类
public static void main(String[] args) {
    List<Roster> rosterList = generateRosters();

    SolverFactory<Roster> solverFactory = SolverFactory.createFromXmlResource(
            "org/optaplanner/openshift/employeerostering/server/solver/employeeRosteringSolverConfig.xml");
    PlannerBenchmarkFactory benchmarkFactory = PlannerBenchmarkFactory.createFromSolverFactory(solverFactory);
    PlannerBenchmark plannerBenchmark = benchmarkFactory.buildPlannerBenchmark(rosterList);
    plannerBenchmark.benchmark();
}
 
开发者ID:kiegroup,项目名称:optashift-employee-rostering,代码行数:10,代码来源:OptaShiftEmployeeRosteringBenchmarkApp.java

示例7: call

import org.optaplanner.core.api.solver.SolverFactory; //导入依赖的package包/类
@Override
public Boolean call() throws Exception {
    ObjectMapper mapper = ObjectMapperFactory.getInstance();
    ConferenceData data;
    data = mapper.readValue(yml, ConferenceData.class);
    data.setRoomCapacityFactor(capacityFactor);
    SolverFactory<ConferenceData> solverFactory = SolverFactory.createFromXmlResource(SOLVER_CONFIG);
    solverFactory.getSolverConfig().getTerminationConfig().setSecondsSpentLimit((long) duration);
    solver = solverFactory.buildSolver();
    solver.solve(data);
    System.out.println("solver.getBestScore() = " + solver.getBestScore());
    return true;
}
 
开发者ID:vlsi,项目名称:confplanner,代码行数:14,代码来源:SolverAction.java

示例8: solveProblem

import org.optaplanner.core.api.solver.SolverFactory; //导入依赖的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

示例9: run

import org.optaplanner.core.api.solver.SolverFactory; //导入依赖的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

示例10: split

import org.optaplanner.core.api.solver.SolverFactory; //导入依赖的package包/类
private void split(int partitionCount,String sliceOrChunk) {
    File inputFile = new File(importer.getInputDir(), "gifts.csv");
    ReindeerRoutingSolution originalSolution = (ReindeerRoutingSolution) importer.readSolution(inputFile);
    ScoreDirector scoreDirector = SolverFactory.createFromXmlResource(ReindeerRoutingApp.SOLVER_CONFIG)
            .buildSolver().getScoreDirectorFactory().buildScoreDirector();

    ReindeerRoutingSolution cloneSolution = (ReindeerRoutingSolution) ((InnerScoreDirector) scoreDirector).cloneSolution(originalSolution);
    WeightFactorySelectionSorter<ReindeerRoutingSolution, GiftAssignment> sorter = new WeightFactorySelectionSorter<ReindeerRoutingSolution, GiftAssignment>(
            new NorthPoleAngleGiftAssignmentDifficultyWeightFactory(), SelectionSorterOrder.ASCENDING);
    sorter.sort(cloneSolution, cloneSolution.getGiftAssignmentList());

    int giftSize = cloneSolution.getGiftList().size();
    for (int i = 0; i < partitionCount; i++) {
        ReindeerRoutingSolution partitionSolution = new ReindeerRoutingSolution();
        partitionSolution.setId(cloneSolution.getId());
        int giftSubSize = giftSize / partitionCount;
        List<GiftAssignment> partitionGiftAssignmentList = cloneSolution.getGiftAssignmentList().subList(giftSubSize * i, giftSubSize * (i + 1));
        List<Gift> partitionGiftList = new ArrayList<Gift>(giftSubSize);
        for (GiftAssignment partitionGiftAssignment : partitionGiftAssignmentList) {
            partitionGiftList.add(partitionGiftAssignment.getGift());
        }
        partitionSolution.setGiftList(partitionGiftList);
        int reindeerSubSize = cloneSolution.getReindeerList().size() / partitionCount;
        partitionSolution.setReindeerList(cloneSolution.getReindeerList().subList(reindeerSubSize * i, reindeerSubSize * (i + 1)));
        partitionSolution.setGiftAssignmentList(partitionGiftAssignmentList);
        File outputFile = new File (importer.getInputDir(), sliceOrChunk + "s/gifts_" + sliceOrChunk + i + ".csv");
        writeSolutionButGiftsOnly(partitionSolution, outputFile);
    }
}
 
开发者ID:ge0ffrey,项目名称:santas-stolen-sleigh,代码行数:30,代码来源:ReindeerRoutingSlicerAndChunker.java

示例11: main

import org.optaplanner.core.api.solver.SolverFactory; //导入依赖的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

示例12: getSolverFactory

import org.optaplanner.core.api.solver.SolverFactory; //导入依赖的package包/类
public SolverFactory getSolverFactory() {
    // The solver is built from an XML that contains a basic configuration.
    // This should be a bit simpler than building the solver from scratch.
    SolverFactory solverFactory = new XmlSolverFactory(BASE_SOLVER_XML_PATH);
    configureSolver(solverFactory.getSolverConfig(), vmPlacementConfig);
    return solverFactory;
}
 
开发者ID:davidor,项目名称:clopla,代码行数:8,代码来源:VmPlacementSolverFactory.java

示例13: doInBackground

import org.optaplanner.core.api.solver.SolverFactory; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
protected VehicleRoutingSolution doInBackground(VehicleRoutingSolution... vrs) {
    Log.d(TAG, "Building solver.");

    // creates solver
    try {
        InputStream is = fragment.getActivity().getAssets().open("solvers/" + algorithm);
        SolverFactory solverFactory = SolverFactory.createFromXmlInputStream(is);
        solverFactory.getSolverConfig().getTerminationConfig().setSecondsSpentLimit(timeLimit);
        solver = solverFactory.buildSolver();
    } catch (IOException e) {
        e.printStackTrace();
    }

    // adds solver listener for new best solution
    solver.addEventListener(new SolverEventListener() {
        @Override
        public void bestSolutionChanged(BestSolutionChangedEvent event) {
            if (running) {
                publishProgress((VehicleRoutingSolution) event.getNewBestSolution());
            }
        }
    });

    // starts solver
    Log.d(TAG, "Solver built, running solver.");
    solver.solve(vrs[0]);

    // end of calculation
    running = false;
    return (VehicleRoutingSolution) solver.getBestSolution();
}
 
开发者ID:tomasdavidorg,项目名称:android-vehicle-routing-problem,代码行数:36,代码来源:VrpSolverTask.java

示例14: interpretXml

import org.optaplanner.core.api.solver.SolverFactory; //导入依赖的package包/类
Builder interpretXml() {
  if (isBenchmark()) {
    configs = getConfigsFromBenchmark(verifyNotNull(getSolverXml()));
  } else {
    final SolverFactory factory =
      SolverFactory.createFromXmlReader(new StringReader(getSolverXml()));
    configs = ImmutableMap.<String, SolverConfig>builder()
      .put(SINGLE_SOLVER_KEY, factory.getSolverConfig())
      .build();
  }
  if (getSolverKey() != null) {
    checkArgument(verifyNotNull(configs).containsKey(getSolverKey()));
  }
  return this;
}
 
开发者ID:rinde,项目名称:RinLog,代码行数:16,代码来源:OptaplannerSolvers.java

示例15: main

import org.optaplanner.core.api.solver.SolverFactory; //导入依赖的package包/类
public static void main(String[] args) {
    Election election = readElection();

    // LAB-SOLUTION-START
    SolverFactory<Election> solverFactory = SolverFactory.createFromXmlResource(
            "org/optaplanner/training/election/solver/electionSolverConfig.xml");
    election = solverFactory.buildSolver().solve(election);
    // LAB-SOLUTION-END

    printElection(election);
}
 
开发者ID:kiegroup,项目名称:optaplanner-training,代码行数:12,代码来源:ElectionApp.java


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