本文整理汇总了Java中org.optaplanner.core.api.solver.SolverFactory.createFromXmlResource方法的典型用法代码示例。如果您正苦于以下问题:Java SolverFactory.createFromXmlResource方法的具体用法?Java SolverFactory.createFromXmlResource怎么用?Java SolverFactory.createFromXmlResource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.optaplanner.core.api.solver.SolverFactory
的用法示例。
在下文中一共展示了SolverFactory.createFromXmlResource方法的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);
}
示例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;
}
示例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);
}
示例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);
}
}
}
示例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();
}
示例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;
}
示例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());
}
示例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);
}
示例10: 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();
}
示例11: 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);
}
示例12: main
import org.optaplanner.core.api.solver.SolverFactory; //导入方法依赖的package包/类
public static void main(String[] args){
/* Cria a fabrica de solucionadores */
SolverFactory<Controller> solver_factory = SolverFactory.createFromXmlResource(SOLVER_CONFIGURATION_FILEPATH);
/* Cria a configuracao do solucionador */
SolverConfig solver_config = criarSolverConfig();
SolverConfigContext solver_config_context = new SolverConfigContext();
solver_config_context.setClassLoader(BundleBalancerIncrementalScoreCalculator.class.getClassLoader());
/* Cria o solucionador */
//Solver<Controller> solver = solver_factory.buildSolver(); /* FORMATO RECOMENDADO */
Solver<Controller> solver = solver_config.buildSolver(solver_config_context); /* FORMATO NÃO RECOMENDADO */
/*
OBS.: Um solucionador pode ser construído de duas formas, que são através de um arquivo XML de configuração
que é o metodo recomendado pelo optaplanner e progamaticamente, através da instanciação das configurações
o que não é recomendado porém é um artíficio para contexto aonde o arquivo de configuração não esteja
funcionando como em alguns containers OSGi como é o caso do KARAF.
Para outros contextos deve se utilizar a forma padrão através de uma fábrica de solucionadores e um
um arquivo de configuração, mas para fins didáticos são apresentadas as duas formas.
*/
/* Cria um solucionador desorganizado */
Controller unsolvedController = new Controller();
System.out.println("Iniciamento Rotinas de Balanceamento teste");
/* Adiciona alguns hosts e bundles */
Host _temp_host1 = new Host("A", 5);
Host _temp_host2 = new Host("B", 5);
Bundle _temp_bundle1 = new Bundle("1", 3);
Bundle _temp_bundle2 = new Bundle("2", 2);
unsolvedController.addHost(_temp_host1);
unsolvedController.addHost(_temp_host2);
unsolvedController.addBundle(_temp_bundle1);
unsolvedController.addBundle(_temp_bundle2);
/* A CONFIGURAÇÃO FINAL DEVE SER HOST A { BUNDLE 1 } HOST B { BUNDLE 2 } */
/* Tempo inicio */
long millis_inicio = System.currentTimeMillis();
/* Soluciona o arranjo */
Controller solvedController = solver.solve(unsolvedController);
/* Tempo execução */
long millis_fim = System.currentTimeMillis() - millis_inicio;
String tempo_execucao = String.format("%02d:%02d.%04d",
TimeUnit.MILLISECONDS.toMinutes(millis_fim),
TimeUnit.MILLISECONDS.toSeconds(millis_fim) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis_fim)),
(millis_fim % 1000)
);
System.out.println("\nRotina de Balanceamento finalizada em " + tempo_execucao + " min");
/* Mostra o resultado */
System.out.println("Controlador sem balanceamento");
unsolvedController.displayResultado();
System.out.println("\nControlador com balanceamento");
solvedController.displayResultado();
}
示例13: setUpSolverFactory
import org.optaplanner.core.api.solver.SolverFactory; //导入方法依赖的package包/类
@PostConstruct
public void setUpSolverFactory() {
solverFactory = SolverFactory.createFromXmlResource(
"org/optaplanner/openshift/employeerostering/server/solver/employeeRosteringSolverConfig.xml");
}
示例14: createSolver
import org.optaplanner.core.api.solver.SolverFactory; //导入方法依赖的package包/类
protected Solver<Solution_> createSolver() {
SolverFactory<Solution_> solverFactory = SolverFactory.createFromXmlResource(solverConfig);
return solverFactory.buildSolver();
}
示例15: OptaPlannerEndpoint
import org.optaplanner.core.api.solver.SolverFactory; //导入方法依赖的package包/类
public OptaPlannerEndpoint(String uri, Component component, OptaPlannerConfiguration configuration) {
super(uri, component);
this.configuration = configuration;
solverFactory = SolverFactory.createFromXmlResource(configuration.getConfigFile());
}