當前位置: 首頁>>代碼示例>>Java>>正文


Java Solver.setInitalSolution方法代碼示例

本文整理匯總了Java中org.cpsolver.ifs.solver.Solver.setInitalSolution方法的典型用法代碼示例。如果您正苦於以下問題:Java Solver.setInitalSolution方法的具體用法?Java Solver.setInitalSolution怎麽用?Java Solver.setInitalSolution使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.cpsolver.ifs.solver.Solver的用法示例。


在下文中一共展示了Solver.setInitalSolution方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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

示例3: main

import org.cpsolver.ifs.solver.Solver; //導入方法依賴的package包/類
public static void main(String[] args) {
    try {
        System.setProperty("jprof", "cpu");
        BasicConfigurator.configure();

        DataProperties cfg = new DataProperties();
        cfg.setProperty("Neighbour.BranchAndBoundTimeout", "5000");
        cfg.setProperty("Suggestions.Timeout", "1000");
        cfg.setProperty("Extensions.Classes", DistanceConflict.class.getName() + ";" + TimeOverlapsCounter.class.getName());
        cfg.setProperty("StudentWeights.Class", StudentSchedulingAssistantWeights.class.getName());
        cfg.setProperty("StudentWeights.PriorityWeighting", "true");
        cfg.setProperty("StudentWeights.LeftoverSpread", "true");
        cfg.setProperty("StudentWeights.BalancingFactor", "0.0");
        cfg.setProperty("Reservation.CanAssignOverTheLimit", "true");
        cfg.setProperty("Distances.Ellipsoid", DistanceMetric.Ellipsoid.WGS84.name());
        cfg.setProperty("StudentWeights.MultiCriteria", "true");
        cfg.setProperty("CourseRequest.SameTimePrecise", "true");

        cfg.setProperty("log4j.rootLogger", "INFO, A1");
        cfg.setProperty("log4j.appender.A1", "org.apache.log4j.ConsoleAppender");
        cfg.setProperty("log4j.appender.A1.layout", "org.apache.log4j.PatternLayout");
        cfg.setProperty("log4j.appender.A1.layout.ConversionPattern", "%-5p %c{2}: %m%n");
        cfg.setProperty("log4j.logger.org.hibernate", "INFO");
        cfg.setProperty("log4j.logger.org.hibernate.cfg", "WARN");
        cfg.setProperty("log4j.logger.org.hibernate.cache.EhCacheProvider", "ERROR");
        cfg.setProperty("log4j.logger.org.unitime.commons.hibernate", "INFO");
        cfg.setProperty("log4j.logger.net", "INFO");

        cfg.setProperty("Xml.LoadBest", "false");
        cfg.setProperty("Xml.LoadCurrent", "false");

        cfg.putAll(System.getProperties());

        PropertyConfigurator.configure(cfg);

        final Test test = new Test(cfg);

        final File input = new File(args[0]);
        StudentSectioningXMLLoader loader = new StudentSectioningXMLLoader(test.model(), test.assignment());
        loader.setInputFile(input);
        loader.load();

        test.run();

        Solver<Request, Enrollment> s = new Solver<Request, Enrollment>(cfg);
        s.setInitalSolution(test.model());
        StudentSectioningXMLSaver saver = new StudentSectioningXMLSaver(s);
        File output = new File(input.getParentFile(), input.getName().substring(0, input.getName().lastIndexOf('.')) +
                "-" + cfg.getProperty("run", "r0") + ".xml");
        saver.save(output);

        test.stats(input);
    } catch (Exception e) {
        sLog.error("Test failed: " + e.getMessage(), e);
    }
}
 
開發者ID:UniTime,項目名稱:cpsolver,代碼行數:57,代碼來源:Test.java

示例4: combineStudents

import org.cpsolver.ifs.solver.Solver; //導入方法依賴的package包/類
/** Combine students from the provided two files 
 * @param cfg solver configuration
 * @param lastLikeStudentData a file containing last-like student data
 * @param realStudentData a file containing real student data
 * @return combined solution
 **/
public static Solution<Request, Enrollment> combineStudents(DataProperties cfg, File lastLikeStudentData, File realStudentData) {
    try {
        RandomStudentFilter rnd = new RandomStudentFilter(1.0);

        StudentSectioningModel model = null;
        Assignment<Request, Enrollment> assignment = new DefaultSingleAssignment<Request, Enrollment>();

        for (StringTokenizer stk = new StringTokenizer(cfg.getProperty("Test.CombineAcceptProb", "1.0"), ","); stk.hasMoreTokens();) {
            double acceptProb = Double.parseDouble(stk.nextToken());
            sLog.info("Test.CombineAcceptProb=" + acceptProb);
            rnd.setProbability(acceptProb);

            StudentFilter batchFilter = new CombinedStudentFilter(new ReverseStudentFilter(
                    new FreshmanStudentFilter()), rnd, CombinedStudentFilter.OP_AND);

            model = new StudentSectioningModel(cfg);
            StudentSectioningXMLLoader loader = new StudentSectioningXMLLoader(model, assignment);
            loader.setLoadStudents(false);
            loader.load();

            StudentSectioningXMLLoader lastLikeLoader = new StudentSectioningXMLLoader(model, assignment);
            lastLikeLoader.setInputFile(lastLikeStudentData);
            lastLikeLoader.setLoadOfferings(false);
            lastLikeLoader.setLoadStudents(true);
            lastLikeLoader.load();

            StudentSectioningXMLLoader realLoader = new StudentSectioningXMLLoader(model, assignment);
            realLoader.setInputFile(realStudentData);
            realLoader.setLoadOfferings(false);
            realLoader.setLoadStudents(true);
            realLoader.setStudentFilter(batchFilter);
            realLoader.load();

            fixWeights(model);

            fixPriorities(model);

            Solver<Request, Enrollment> solver = new Solver<Request, Enrollment>(model.getProperties());
            solver.setInitalSolution(model);
            new StudentSectioningXMLSaver(solver).save(new File(new File(model.getProperties().getProperty(
                    "General.Output", ".")), "solution-r" + ((int) (100.0 * acceptProb)) + ".xml"));

        }

        return model == null ? null : new Solution<Request, Enrollment>(model, assignment);

    } catch (Exception e) {
        sLog.error("Unable to combine students, reason: " + e.getMessage(), e);
        return null;
    }
}
 
開發者ID:UniTime,項目名稱:cpsolver,代碼行數:58,代碼來源:Test.java


注:本文中的org.cpsolver.ifs.solver.Solver.setInitalSolution方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。