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


Java SolverFactory.buildSolver方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: createSolver

import org.optaplanner.core.api.solver.SolverFactory; //导入方法依赖的package包/类
protected Solver<Solution_> createSolver() {
    SolverFactory<Solution_> solverFactory = SolverFactory.createFromXmlResource(solverConfig);
    return solverFactory.buildSolver();
}
 
开发者ID:xmlking,项目名称:ml-experiments,代码行数:5,代码来源:CommonApp.java

示例10: createSolverFactory

import org.optaplanner.core.api.solver.SolverFactory; //导入方法依赖的package包/类
private ValidationMessage createSolverFactory(final Path resourcePath,
                                              final KieProject kieWorkbenchProject,
                                              final boolean runSolver) {
    final InternalKieModule kieModule = (InternalKieModule) buildInfoService.getBuildInfo(kieWorkbenchProject).getKieModuleIgnoringErrors();
    final org.drools.compiler.kie.builder.impl.KieProject kieProject = new KieModuleKieProject(kieModule,
                                                                                               null);
    final KieContainer kieContainer = new KieContainerImpl(kieProject,
                                                           KieServices.Factory.get().getRepository());

    try {

        final String solverConfigResource = getSolverConfigResource(resourcePath,
                                                                    kieWorkbenchProject);

        SolverFactory<Object> solverFactory = SolverFactory.createFromKieContainerXmlResource(kieContainer,
                                                                                              solverConfigResource);

        if (runSolver) {
            String projectName = resolveProjectName(resourcePath);
            if (!SMOKE_TEST_SUPPORTED_PROJECTS.contains(projectName)) {
                throw new IllegalStateException("Running a smoke test for project (" + projectName + ") is not supported.");
            }

            solverFactory.getSolverConfig().getTerminationConfig().shortenTimeMillisSpentLimit(SMOKE_TEST_MILLISECONDS_SPENT_LIMIT);
            if (solverFactory.getSolverConfig().getScoreDirectorFactoryConfig().getKsessionName() == null) {
                solverFactory.getSolverConfig().getScoreDirectorFactoryConfig().setKsessionName(kieProject.getDefaultKieSession().getName());
            }
            Solver<Object> solver = solverFactory.buildSolver();

            XStreamSolutionImporter solutionImporter = new XStreamSolutionImporter(kieContainer.getClassLoader());
            Object solution = solutionImporter.read(getClass().getClassLoader().getResourceAsStream("org/optaplanner/workbench/screens/solver/backend/server/solution/" + projectName + ".xml"));

            solver.solve(solution);
        } else {
            solverFactory.buildSolver();
        }
    } catch (Exception e) {
        e.printStackTrace();
        return make(e,
                    resourcePath);
    }

    return null;
}
 
开发者ID:kiegroup,项目名称:optaplanner-wb,代码行数:45,代码来源:SolverValidator.java

示例11: createSolver

import org.optaplanner.core.api.solver.SolverFactory; //导入方法依赖的package包/类
@Override
protected Solver createSolver() {
    SolverFactory solverFactory = SolverFactory.createFromXmlResource(SOLVER_CONFIG);
    return solverFactory.buildSolver();
}
 
开发者ID:ge0ffrey,项目名称:coursera-discrete-optimization,代码行数:6,代码来源:ColoringApp.java

示例12: testCrash

import org.optaplanner.core.api.solver.SolverFactory; //导入方法依赖的package包/类
/**
 * Test evaluation exception in Drools when using Optaplanner 6.1.0-SNAPSHOT
 */
@Test
public void testCrash() {
    SolverFactory solverFactory = SolverFactory.createFromXmlResource("org/ovirt/optimizer/test/rules/solver.xml");
    Solver solver = solverFactory.buildSolver();

    // Create new solution space
    OptimalDistributionStepsSolution bestSolution = new OptimalDistributionStepsSolution();
    bestSolution.setHosts(new HashSet<Host>());
    bestSolution.setInstances(new HashSet<Instance>());
    bestSolution.setOtherFacts(new HashSet<Object>());
    bestSolution.setFixedFacts(new HashSet<Object>());
    bestSolution.setVms(new HashMap<String, VM>());

    // Create cluster
    Cluster c = new Cluster();
    c.setId("test-cluster");
    MemoryPolicy m = new MemoryPolicy();
    m.setBallooning(true);
    c.setMemoryPolicy(m);

    // Create host
    Host h = new Host();
    h.setMemory(1024L);
    h.setId("test-host");
    h.setCluster(c);

    // Create VM
    VM vm = new VM();
    vm.setId("test-vm");
    vm.setCluster(c);
    vm.setMemory(512L);
    vm.setHost(h);
    MemoryPolicy memoryPolicy = new MemoryPolicy();
    memoryPolicy.setGuaranteed(256L);
    vm.setMemoryPolicy(memoryPolicy);

    // Add facts
    bestSolution.getHosts().add(h);
    bestSolution.getInstances().add(new Instance(vm.getId()));
    bestSolution.getVms().put(vm.getId(), vm);

    // Prepare the step placeholders
    ClusterSituation last = bestSolution;
    List<Migration> migrationSteps = new ArrayList<>();
    for (int i = 0; i < 5; i++) {
        final Migration mg = new Migration();
        mg.recomputeSituationAfter(last);
        last = mg;
        migrationSteps.add(mg);

    }
    bestSolution.setSteps(migrationSteps);
    bestSolution.establishStepOrdering();

    solver.solve(bestSolution);
}
 
开发者ID:oVirt,项目名称:ovirt-optimizer,代码行数:60,代码来源:TestDroolsJITCrash.java

示例13: createOptaplannerSolver

import org.optaplanner.core.api.solver.SolverFactory; //导入方法依赖的package包/类
static org.optaplanner.core.api.solver.Solver createOptaplannerSolver(
    Builder builder, long seed) {
  final SolverConfig config = builder.getSolverConfig();

  config.setEntityClassList(
    ImmutableList.<Class<?>>of(ParcelVisit.class, Visit.class));
  config.setSolutionClass(PDPSolution.class);

  final TerminationConfig terminationConfig = new TerminationConfig();
  terminationConfig
    .setTerminationCompositionStyle(TerminationCompositionStyle.AND);
  terminationConfig.setBestScoreFeasible(true);

  if (builder.getUnimprovedMsLimit() > 0) {
    terminationConfig
      .setUnimprovedMillisecondsSpentLimit(builder.getUnimprovedMsLimit());
    config.setTerminationConfig(terminationConfig);
  } else if (builder.getUnimprovedStepCountLimit() > 0) {
    terminationConfig
      .setUnimprovedStepCountLimit(builder.getUnimprovedStepCountLimit());
    for (final PhaseConfig phase : config.getPhaseConfigList()) {
      if (phase instanceof LocalSearchPhaseConfig) {
        phase.setTerminationConfig(terminationConfig);
      }
    }
  }

  final ScoreDirectorFactoryConfig scoreConfig =
    new ScoreDirectorFactoryConfig();
  scoreConfig.setScoreDefinitionType(ScoreDefinitionType.HARD_SOFT_LONG);
  scoreConfig.setIncrementalScoreCalculatorClass(ScoreCalculator.class);
  config.setScoreDirectorFactoryConfig(scoreConfig);

  config.setRandomSeed(seed);
  config.setRandomType(RandomType.MERSENNE_TWISTER);
  config.setEnvironmentMode(
    builder.isValidated() ? EnvironmentMode.FULL_ASSERT
      : EnvironmentMode.REPRODUCIBLE);

  final SolverFactory<PDPSolution> factory = SolverFactory.createEmpty();
  factory.getSolverConfig().inherit(config);
  return factory.buildSolver();
}
 
开发者ID:rinde,项目名称:RinLog,代码行数:44,代码来源:OptaplannerSolvers.java

示例14: resolver

import org.optaplanner.core.api.solver.SolverFactory; //导入方法依赖的package包/类
public static AlocacaoHorario resolver(String solverConfig, AlocacaoHorario problema) {
    SolverFactory sF = SolverFactory.createFromXmlResource(solverConfig);
    Solver solver = sF.buildSolver();

    solver.solve(problema);

    AlocacaoHorario solucao = (AlocacaoHorario) solver.getBestSolution();

    logarSolucao(solucao);
    printResultSolution(solucao);

    return solucao;
}
 
开发者ID:Sakamotto,项目名称:Projeto-Flash,代码行数:14,代码来源:Resolvedor.java

示例15: main

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

        SolverFactory solverFactory = SolverFactory.createFromXmlResource(XML_CONFIG);
        Solver solver = solverFactory.buildSolver();

        ProblemDefinition unsolvedProblemDefinition = ProblemDefinitionGenerator.generate();
        System.out.println("Unsolved: " + unsolvedProblemDefinition);

        solver.solve(unsolvedProblemDefinition);

		ProblemDefinition solvedProblemDefinition = (ProblemDefinition) solver.getBestSolution();

        System.out.println("Solved: " + solvedProblemDefinition);
	}
 
开发者ID:bibryam,项目名称:employee-task-assignment,代码行数:15,代码来源:PlannerApp.java


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