Uploaded image for project: 'OptaPlanner'
  1. OptaPlanner
  2. PLANNER-489

Avoid getBestSolution() cast by generifying Solver and SolverFactory and return the best solution from solve()

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Done
    • Icon: Major Major
    • 6.4.0.Beta1
    • None
    • optaplanner-core
    • None
    • NEW
    • NEW

      BEFORE

              SolverFactory solverFactory = SolverFactory.createFromXmlResource(
                      "org/optaplanner/examples/cloudbalancing/solver/cloudBalancingSolverConfig.xml");
              Solver solver = solverFactory.buildSolver();
              CloudBalance unsolvedCloudBalance = ...;
              
              solver.solve(unsolvedCloudBalance);
              CloudBalance solvedCloudBalance = (CloudBalance) solver.getBestSolution();
      

      AFTER version 1

              SolverFactory<CloudBalance> solverFactory = SolverFactory.createFromXmlResource(
                      "org/optaplanner/examples/cloudbalancing/solver/cloudBalancingSolverConfig.xml");
              Solver<CloudBalance> solver = solverFactory.buildSolver();
              CloudBalance unsolvedCloudBalance = ...;
      
              solver.solve(unsolvedCloudBalance);
              CloudBalance solvedCloudBalance = solver.getBestSolution();
      

      AFTER version 2

              SolverFactory<CloudBalance> solverFactory = SolverFactory.createFromXmlResource(
                      "org/optaplanner/examples/cloudbalancing/solver/cloudBalancingSolverConfig.xml");
              Solver<CloudBalance> solver = solverFactory.buildSolver();
              CloudBalance unsolvedCloudBalance = ...;
              
              CloudBalance solvedCloudBalance = solver.solve(unsolvedCloudBalance);
      

      Note: all this is backwards compatible, BEFORE client code still works too!

              gdesmet@redhat.com Geoffrey De Smet (Inactive)
              gdesmet@redhat.com Geoffrey De Smet (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: