Java源码示例:org.optaplanner.core.api.solver.SolverFactory

示例1
@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());
}
 
示例2
@Test
public void test_whenCustomJavaSolver() {

    SolverFactory<CourseSchedule> solverFactory = SolverFactory.createFromXmlResource("courseScheduleSolverConfiguration.xml");
    Solver<CourseSchedule> solver = solverFactory.buildSolver();
    CourseSchedule solvedCourseSchedule = solver.solve(unsolvedCourseSchedule);

    Assert.assertNotNull(solvedCourseSchedule.getScore());
    Assert.assertEquals(-4, solvedCourseSchedule.getScore().getHardScore());
}
 
示例3
@Test
public void test_whenDroolsSolver() {

    SolverFactory<CourseSchedule> solverFactory = SolverFactory.createFromXmlResource("courseScheduleSolverConfigDrools.xml");
    Solver<CourseSchedule> solver = solverFactory.buildSolver();
    CourseSchedule solvedCourseSchedule = solver.solve(unsolvedCourseSchedule);

    Assert.assertNotNull(solvedCourseSchedule.getScore());
    Assert.assertEquals(0, solvedCourseSchedule.getScore().getHardScore());
}
 
示例4
@Test
public void test_whenCustomJavaSolver() {

    SolverFactory<CourseSchedule> solverFactory = SolverFactory.createFromXmlResource("courseScheduleSolverConfiguration.xml");
    Solver<CourseSchedule> solver = solverFactory.buildSolver();
    CourseSchedule solvedCourseSchedule = solver.solve(unsolvedCourseSchedule);

    Assert.assertNotNull(solvedCourseSchedule.getScore());
    Assert.assertEquals(-4, solvedCourseSchedule.getScore().getHardScore());
}
 
示例5
@Test
public void test_whenDroolsSolver() {

    SolverFactory<CourseSchedule> solverFactory = SolverFactory.createFromXmlResource("courseScheduleSolverConfigDrools.xml");
    Solver<CourseSchedule> solver = solverFactory.buildSolver();
    CourseSchedule solvedCourseSchedule = solver.solve(unsolvedCourseSchedule);

    Assert.assertNotNull(solvedCourseSchedule.getScore());
    Assert.assertEquals(0, solvedCourseSchedule.getScore().getHardScore());
}