【问题标题】:OptaPlanner for Vehicle Routing用于车辆路线的 OptaPlanner
【发布时间】:2020-08-04 15:46:06
【问题描述】:

我正在尝试使用 OptaPlanner 解决 VRP。我用约束提供者、规划实体和规划解决方案等编写了所有代码。问题是,我试图通过

        SolverConfig solverConfig = new SolverConfig();
        solverConfig.withSolutionClass(Solution.class);
        solverConfig.withEntityClasses(Stop.class, Standstill.class);
        ScoreDirectorFactoryConfig scoreDirectorFactoryConfig = new ScoreDirectorFactoryConfig();
        scoreDirectorFactoryConfig.setConstraintProviderClass(VrpConstraintProvider.class);

        solverConfig.withScoreDirectorFactory(scoreDirectorFactoryConfig);

        SolverFactory<Solution> solverFactory = SolverFactory.create(solverConfig);
        Solver<Solution> solver = solverFactory.buildSolver();

        Solution solution = solver.solve(solutionDef);

但这会导致无休止的等待解决方案。有什么想法是什么原因吗?提前致谢。

【问题讨论】:

    标签: optaplanner vehicle-routing


    【解决方案1】:

    您尚未配置求解器终止条件。例如,如果您希望求解器求解 60 秒,请添加以下内容:

    solverConfig.withTerminationConfig(new TerminationConfig().withSecondsSpentLimit(60L));
    

    请注意,在您提供的示例中,求解器在主线程上运行并阻塞它,直到满足终止条件并自动停止求解。由于您的示例中没有这样的条件,它会永远解决并阻塞线程。

    或者,使用SolverManager API 异步解决问题(在工作线程上):

    int problemId = 1;
    SolverManager<Solution, Integer> solverManager = SolverManager.create(
            solverConfig, new SolverManagerConfig());
    SolverJob<Solution, Integer> solverJob = solverManager.solve(problemId, solutionDef);
    // wait some time, then terminate solver manager
    solverManager.terminateEarly(problemId);
    Solution bestSolution = solverJob.getFinalBestSolution();
    

    【讨论】:

      猜你喜欢
      • 2014-04-12
      • 1970-01-01
      • 1970-01-01
      • 2020-07-25
      • 1970-01-01
      • 1970-01-01
      • 2020-08-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多