本文整理汇总了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;
}
示例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);
}
示例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();
}
示例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;
}
示例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());
}
示例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);
}
示例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();
}
示例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();
}
示例9: createSolver
import org.optaplanner.core.api.solver.SolverFactory; //导入方法依赖的package包/类
protected Solver<Solution_> createSolver() {
SolverFactory<Solution_> solverFactory = SolverFactory.createFromXmlResource(solverConfig);
return solverFactory.buildSolver();
}
示例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;
}
示例11: createSolver
import org.optaplanner.core.api.solver.SolverFactory; //导入方法依赖的package包/类
@Override
protected Solver createSolver() {
SolverFactory solverFactory = SolverFactory.createFromXmlResource(SOLVER_CONFIG);
return solverFactory.buildSolver();
}
示例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);
}
示例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();
}
示例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;
}
示例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);
}