當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。