本文整理汇总了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();
}
}
示例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());
}
}
示例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);
}
}
示例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;
}
}