本文整理汇总了Java中org.cpsolver.ifs.assignment.DefaultSingleAssignment类的典型用法代码示例。如果您正苦于以下问题:Java DefaultSingleAssignment类的具体用法?Java DefaultSingleAssignment怎么用?Java DefaultSingleAssignment使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DefaultSingleAssignment类属于org.cpsolver.ifs.assignment包,在下文中一共展示了DefaultSingleAssignment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInfoOfASolution
import org.cpsolver.ifs.assignment.DefaultSingleAssignment; //导入依赖的package包/类
public static HashMap<String, String> getInfoOfASolution(File file) {
try {
DataProperties properties = new DataProperties();
properties.setProperty("General.Input", file.getPath());
TimetableXMLLoader loader = new TimetableXMLLoader(new TimetableModel(properties), new DefaultSingleAssignment<Lecture, Placement>());
loader.load();
File newOutputFile = new File(file.getParentFile(), "new-output.csv");
Test.saveOutputCSV(new Solution<Lecture, Placement>(loader.getModel(), loader.getAssignment()), newOutputFile);
Progress.removeInstance(loader.getModel());
System.out.println(" Reading " + newOutputFile + " ...");
HashMap<String, String> info = getInfo(newOutputFile);
File outputFile = new File(file.getParentFile(), "output.csv");
if (outputFile.exists()) {
System.out.println(" Reading " + outputFile + " ...");
HashMap<String, String> info2 = getInfo(outputFile);
if (info2.containsKey("000.002 Time [sec]"))
info.put("000.002 Time [sec]", info2.get("000.002 Time [sec]"));
}
return info;
} catch (Exception e) {
System.err.println("Error reading info, message: " + e.getMessage());
e.printStackTrace();
return null;
}
}
示例2: main
import org.cpsolver.ifs.assignment.DefaultSingleAssignment; //导入依赖的package包/类
public static void main(String[] args) {
try {
// Configure logging
org.apache.log4j.BasicConfigurator.configure();
// Load properties (take first argument as input file, containing key=value lines)
DataProperties properties = new DataProperties();
properties.load(new FileInputStream(args[0]));
// Generate model
Assignment<Activity, Location> assignment = new DefaultSingleAssignment<Activity, Location>();
TimetableModel model = TimetableModel.generate(new DataProperties(), assignment);
System.out.println(model.getInfo(assignment));
// Save solution (take second argument as output file)
model.saveAsXML(properties, true, new Solution<Activity, Location>(model, assignment), assignment, new File(args[1]));
} catch (Exception e) {
e.printStackTrace();
}
}
示例3: main
import org.cpsolver.ifs.assignment.DefaultSingleAssignment; //导入依赖的package包/类
public static void main(String[] args) {
try {
ToolBox.configureLogging();
StudentSectioningModel model = new StudentSectioningModel(new DataProperties());
Assignment<Request, Enrollment> assignment = new DefaultSingleAssignment<Request, Enrollment>();
StudentSectioningXMLLoader xmlLoad = new StudentSectioningXMLLoader(model, assignment);
xmlLoad.setInputFile(new File(args[0]));
xmlLoad.load();
Document document = exportModel(assignment, model);
FileOutputStream fos = new FileOutputStream(new File(args[1]));
(new XMLWriter(fos, OutputFormat.createPrettyPrint())).write(document);
fos.flush();
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
示例4: main
import org.cpsolver.ifs.assignment.DefaultSingleAssignment; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
ToolBox.configureLogging();
DataProperties properties = ToolBox.loadProperties(new java.io.File(args[0]));
properties.putAll(System.getProperties());
TimetableModel model = new TimetableModel(properties);
Assignment<Lecture, Placement> assignment = new DefaultSingleAssignment<Lecture, Placement>();
TimetableXMLLoader loader = new TimetableXMLLoader(model, assignment);
loader.setInputFile(new File(args[1]));
loader.load();
Solution<Lecture, Placement> solution = new Solution<Lecture, Placement>(model, assignment);
Test.saveOutputCSV(solution, new File(args[2]));
}
示例5: DomainChart
import org.cpsolver.ifs.assignment.DefaultSingleAssignment; //导入依赖的package包/类
public DomainChart(String name, TimetableModel model, int sizeX, int sizeY) {
iModel = model;
iAssignment = new DefaultSingleAssignment<Lecture, Placement>();
iName = name;
iSizeX = sizeX;
iSizeY = sizeY;
}
示例6: getDefaultAssignment
import org.cpsolver.ifs.assignment.DefaultSingleAssignment; //导入依赖的package包/类
/**
* Return default assignment that is using the old {@link Variable#getAssignment()} assignments.
* @return as instance of {@link DefaultSingleAssignment}
*/
@Deprecated
public Assignment<V, T> getDefaultAssignment() {
if (iAssignment == null)
iAssignment = new DefaultSingleAssignment<V, T>();
return iAssignment;
}
示例7: setInitalSolution
import org.cpsolver.ifs.assignment.DefaultSingleAssignment; //导入依赖的package包/类
/** Sets initial solution */
@Override
public void setInitalSolution(Model<V, T> model) {
int nrSolvers = Math.min(Math.abs(getProperties().getPropertyInt("Parallel.NrSolvers", 4)), CanHoldContext.sMaxSize - 1);
boolean updateMasterSolution = getProperties().getPropertyBoolean("Parallel.UpdateMasterSolution", true);
setInitalSolution(new Solution<V, T>(model, nrSolvers > 1 ? new DefaultParallelAssignment<V, T>(updateMasterSolution ? 1 : 0) : new DefaultSingleAssignment<V, T>(), 0, 0));
}
示例8: getSolution
import org.cpsolver.ifs.assignment.DefaultSingleAssignment; //导入依赖的package包/类
/**
* Compute and return the sectioning solution. It contains only the given
* student with his/her schedule
* @return current solution
*/
public Solution<Request, Enrollment> getSolution() {
if (iSolution == null) {
iSolution = new Solution<Request, Enrollment>(this, new DefaultSingleAssignment<Request, Enrollment>());
BranchBoundSelection.Selection selection = new BranchBoundSelection(new DataProperties()).getSelection(iSolution.getAssignment(), getStudent());
Neighbour<Request, Enrollment> neighbour = selection.select();
if (neighbour != null)
neighbour.assign(iSolution.getAssignment(), 0);
iTime = selection.getTime();
iTimeoutReached = selection.isTimeoutReached();
}
return iSolution;
}
示例9: Test
import org.cpsolver.ifs.assignment.DefaultSingleAssignment; //导入依赖的package包/类
public Test(DataProperties config) {
iModel = new TestModel(config);
iModel.setDistanceConflict(new DistanceConflict(new DistanceMetric(iModel.getProperties()), iModel.getProperties()));
iModel.getDistanceConflict().register(iModel);
iModel.getDistanceConflict().setAssignmentContextReference(iModel.createReference(iModel.getDistanceConflict()));
iModel.setTimeOverlaps(new TimeOverlapsCounter(null, iModel.getProperties()));
iModel.getTimeOverlaps().register(iModel);
iModel.getTimeOverlaps().setAssignmentContextReference(iModel.createReference(iModel.getTimeOverlaps()));
iModel.setStudentWeights(new StudentSchedulingAssistantWeights(iModel.getProperties()));
iAssignment = new DefaultSingleAssignment<Request, Enrollment>();
iSuggestions = "true".equals(System.getProperty("suggestions", iSuggestions ? "true" : "false"));
String overexp = System.getProperty("overexp");
if (overexp != null) {
boolean bal = false;
if (overexp.startsWith("b")) {
bal = true;
overexp = overexp.substring(1);
}
String[] x = overexp.split("[/\\-]");
if (x.length == 1) {
iModel.setOverExpectedCriterion(new PercentageOverExpected(Double.valueOf(x[0])));
} else if (x.length == 2) {
iModel.setOverExpectedCriterion(bal ? new AvoidUnbalancedWhenNoExpectations(Double.valueOf(x[0]), Double.valueOf(x[1]) / 100.0) :
new FractionallyOverExpected(Double.valueOf(x[0]), Double.valueOf(x[1])));
} else {
iModel.setOverExpectedCriterion(new FractionallyUnbalancedWhenNoExpectations(Double.valueOf(x[0]),
Double.valueOf(x[1]), Double.valueOf(x[2]) / 100.0));
}
}
sLog.info("Using " + (config.getPropertyBoolean("StudentWeights.MultiCriteria", true) ? "multi-criteria " : "")
+ (config.getPropertyBoolean("StudentWeights.PriorityWeighting", true) ? "priority" : "equal")
+ " weighting model" + " with over-expected " + iModel.getOverExpectedCriterion()
+ (iSuggestions ? ", suggestions" : "") + ", " + System.getProperty("sort", "shuffle") + " order"
+ " and " + config.getPropertyInt("Neighbour.BranchAndBoundTimeout", 1000) + " ms time limit.");
}
示例10: convert
import org.cpsolver.ifs.assignment.DefaultSingleAssignment; //导入依赖的package包/类
public static Enrollment convert(XCourseRequest request, OnlineSectioningServer server) {
Assignment<Request, Enrollment> assignment = new DefaultSingleAssignment<Request, Enrollment>();
CourseRequest cr = convert(assignment, server.getStudent(request.getStudentId()), request, server, null, null);
return assignment.getValue(cr);
}
示例11: main
import org.cpsolver.ifs.assignment.DefaultSingleAssignment; //导入依赖的package包/类
public static void main(String[] args) {
try {
Logger.getRootLogger().setLevel(Level.DEBUG);
List<CurStudent> students = new ArrayList<CurStudent>();
for (int i = 0; i < 20; i++)
students.add(new CurStudent(new Long(1 + i), (i < 10 ? 0.5f: 2f)));
CurModel m = new CurModel(students);
for (int i = 1; i <= 10; i++)
m.addCourse((long)i, "C" + i, 2 * i, null);
for (int i = 1; i < 10; i++)
for (int j = i + 1; j <= 10; j++)
m.setTargetShare((long)i, (long)j, i, false);
m.setStudentLimits();
Document d0 = DocumentHelper.createDocument();
Assignment<CurVariable, CurValue> a = new DefaultSingleAssignment<CurVariable, CurValue>();
m.saveAsXml(d0.addElement("curriculum"), a);
sLog.info(d0.asXML());
sLog.info("Loaded: " + ToolBox.dict2string(m.getInfo(a), 2));
m.solve(a);
sLog.info("Solution: " + ToolBox.dict2string(m.getInfo(a), 2));
Document d1 = DocumentHelper.createDocument();
m.saveAsXml(d1.addElement("curriculum"), a);
sLog.info(d1.asXML());
Solution<CurVariable, CurValue> x = loadFromXml(d1.getRootElement());
sLog.info("Reloaded: " + ToolBox.dict2string(x.getInfo(), 2));
TreeSet<CurCourse> courses = new TreeSet<CurCourse>(new Comparator<CurCourse>() {
public int compare(CurCourse c1, CurCourse c2) {
int cmp = c1.getCourseName().compareTo(c2.getCourseName());
if (cmp != 0) return cmp;
return c1.getCourseId().compareTo(c2.getCourseId());
}
});
courses.addAll(m.getCourses());
int penalty = 0;
for (CurCourse course: courses) {
sLog.info(course.getCourseName() + ": " + m.getCourse(course.getCourseId()).getStudents(a) + " (" + course.getSize(a) + "/" + course.getOriginalMaxSize() + ")");
for (CurCourse other: courses) {
if (other.getCourseId() <= course.getCourseId()) continue;
double share = course.share(a, other);
double target = course.getTargetShare(other.getCourseId());
sLog.info(" " + other.getCourseName() + ": share=" + share + ", target=" + target + ", penalty=" + Math.abs(target - share));
penalty += Math.abs(target - share);
}
}
sLog.info("Total penalty: " + penalty);
Document doc = DocumentHelper.createDocument();
m.saveAsXml(doc.addElement("curriculum"), a);
FileOutputStream fos = new FileOutputStream("/Users/muller/solution.xml");
(new XMLWriter(fos, OutputFormat.createPrettyPrint())).write(doc);
fos.flush();
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
示例12: setInitalSolution
import org.cpsolver.ifs.assignment.DefaultSingleAssignment; //导入依赖的package包/类
@Override
public void setInitalSolution(Model<Request, Enrollment> model) {
setInitalSolution(new Solution(model, new DefaultSingleAssignment<Request, Enrollment>()));
}
示例13: afterAssigned
import org.cpsolver.ifs.assignment.DefaultSingleAssignment; //导入依赖的package包/类
/**
* {@link FinalSectioning#resection(Assignment, Lecture, boolean, boolean)} is called
* when given iteration number is greater than zero.
*/
@Override
public void afterAssigned(Assignment<Lecture, Placement> assignment, long iteration, Placement value) {
if (iteration > 0 && assignment instanceof DefaultSingleAssignment)
iModel.getStudentSectioning().resection(assignment, value.variable(), iRecursive, iConfigAsWell);
}
示例14: setInitalSolution
import org.cpsolver.ifs.assignment.DefaultSingleAssignment; //导入依赖的package包/类
/** Sets initial solution
* @param model problem model
**/
public void setInitalSolution(Model<V, T> model) {
setInitalSolution(new Solution<V, T>(model, new DefaultSingleAssignment<V, T>(), 0, 0));
}
示例15: hasSingleSolution
import org.cpsolver.ifs.assignment.DefaultSingleAssignment; //导入依赖的package包/类
/**
* Returns true if the solver works only with one solution (regardless the number of threads it is using)
* @return true if the current solution is {@link DefaultSingleAssignment}
*/
@Override
public boolean hasSingleSolution() {
return iCurrentSolution.getAssignment() instanceof DefaultSingleAssignment;
}