当前位置: 首页>>代码示例>>Java>>正文


Java Solver.start方法代码示例

本文整理汇总了Java中org.cpsolver.ifs.solver.Solver.start方法的典型用法代码示例。如果您正苦于以下问题:Java Solver.start方法的具体用法?Java Solver.start怎么用?Java Solver.start使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.cpsolver.ifs.solver.Solver的用法示例。


在下文中一共展示了Solver.start方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test

import org.cpsolver.ifs.solver.Solver; //导入方法依赖的package包/类
public static void test(DataProperties properties) {
    try {
        String inputFile = properties.getProperty("General.Input");
        JobShopModel model = JobShopModel.loadModel(inputFile);
        Solver<Operation, Location> s = new Solver<Operation, Location>(properties);
        s.setInitalSolution(model);
        s.start();
        s.getSolverThread().join();
        Solution<Operation, Location> best = s.currentSolution();
        best.restoreBest();
        sLogger.info("Best solution info:" + best.getInfo());
        sLogger.info("Best solution:" + model.toString());
        model.save(best.getAssignment(), properties.getProperty("General.Output") + File.separator + "solution.txt");
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:18,代码来源:Test.java

示例2: main

import org.cpsolver.ifs.solver.Solver; //导入方法依赖的package包/类
/**
 * run the test
 * @param args program arguments
 */
public static void main(String[] args) {
    org.apache.log4j.BasicConfigurator.configure();
    int nrVariables = 25;
    int nrValues = 12;
    int nrConstraints = 198;
    double tigtness = 0.25;
    int nrAllPairs = nrValues * nrValues;
    int nrCompatiblePairs = (int) ((1.0 - tigtness) * nrAllPairs);
    long seed = System.currentTimeMillis();
    System.out.println("CSP(" + nrVariables + "," + nrValues + "," + nrConstraints + "/"
            + ((nrVariables * (nrVariables - 1)) / 2) + "," + (nrAllPairs - nrCompatiblePairs) + "/" + nrAllPairs
            + ")");

    org.cpsolver.ifs.util.DataProperties cfg = new org.cpsolver.ifs.util.DataProperties();
    cfg.setProperty("Termination.Class", "org.cpsolver.ifs.termination.GeneralTerminationCondition");
    cfg.setProperty("Termination.StopWhenComplete", "false");
    cfg.setProperty("Termination.TimeOut", "60");
    cfg.setProperty("Comparator.Class", "org.cpsolver.ifs.solution.GeneralSolutionComparator");
    cfg.setProperty("Value.Class", "org.cpsolver.ifs.heuristics.GeneralValueSelection");
    cfg.setProperty("Value.WeightConflicts", "1");
    cfg.setProperty("Variable.Class", "org.cpsolver.ifs.heuristics.GeneralVariableSelection");
    cfg.setProperty("Extensions.Classes", "org.cpsolver.ifs.extension.ConflictStatistics");

    CSPModel model = new CSPModel(nrVariables, nrValues, nrConstraints, nrCompatiblePairs, seed);
    Solver<CSPVariable, CSPValue> solver = new Solver<CSPVariable, CSPValue>(cfg);
    solver.setInitalSolution(model);

    solver.start();
    try {
        solver.getSolverThread().join();
    } catch (InterruptedException e) {
    }

    Solution<CSPVariable, CSPValue> solution = solver.lastSolution();
    solution.restoreBest();

    System.out.println("Best solution found after " + solution.getBestTime() + " seconds ("
            + solution.getBestIteration() + " iterations).");
    System.out.println("Number of assigned variables is " + solution.getAssignment().nrAssignedVariables());
    System.out.println("Total value of the solution is " + solution.getModel().getTotalValue(solution.getAssignment()));

    int idx = 1;
    for (CSPVariable v : solution.getModel().variables()) {
        CSPValue a = solution.getAssignment().getValue(v);
        if (a != null)
            System.out.println("Var" + (idx++) + "=" + a.toDouble());
    }
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:53,代码来源:SimpleTest.java


注:本文中的org.cpsolver.ifs.solver.Solver.start方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。