use of org.cpsolver.ifs.util.DataProperties in project cpsolver by UniTime.
the class StudentSwapSectioning method switchStudents.
@Override
public void switchStudents(Solution<Lecture, Placement> solution, TerminationCondition<Lecture, Placement> termination) {
long it = 0, lastImp = 0;
double t0 = JProf.currentTimeMillis();
DataProperties cfg = ((TimetableModel) solution.getModel()).getProperties();
long maxIdle = cfg.getPropertyInt("StudentSwaps.MaxIdle", 100000);
getProgress().setStatus("Student Sectioning...");
getProgress().info("Student Conflicts: " + sDF2.format(objective(solution)) + " (group: " + sDF2.format(gp(solution)) + "%)");
getProgress().setPhase("Swapping students [HC]...", 1000);
StudentSwapGenerator g = new StudentSwapGenerator();
while ((it - lastImp) < maxIdle && (termination == null || termination.canContinue(solution))) {
it++;
if ((it % 1000) == 0) {
long prg = Math.round(1000.0 * (it - lastImp) / maxIdle);
if (getProgress().getProgress() < prg)
getProgress().setProgress(prg);
if ((it % 10000) == 0)
getProgress().info("Iter=" + (it / 1000) + "k, Idle=" + sDF2.format((it - lastImp) / 1000.0) + "k, Speed=" + sDF2.format(1000.0 * it / (JProf.currentTimeMillis() - t0)) + " it/s" + ", Value=" + sDF2.format(value(solution)) + ", Objective=" + sDF2.format(objective(solution)) + ", Group=" + sDF2.format(gp(solution)) + "%");
}
Neighbour<Lecture, Placement> n = g.selectNeighbour(solution);
if (n == null)
continue;
double v = value(n, solution.getAssignment());
if (v < -sEps) {
lastImp = it;
}
if (v <= 0) {
n.assign(solution.getAssignment(), it);
}
}
getProgress().info("Student Conflicts: " + sDF2.format(objective(solution)) + " (group: " + sDF2.format(gp(solution)) + "%)");
double f = cfg.getPropertyDouble("StudentSwaps.Deluge.Factor", 0.9999999);
double ub = cfg.getPropertyDouble("StudentSwaps.Deluge.UpperBound", 1.10);
double lb = cfg.getPropertyDouble("StudentSwaps.Deluge.LowerBound", 0.90);
double total = value(solution);
double bound = ub * total;
double best = total;
it = 0;
lastImp = 0;
t0 = JProf.currentTimeMillis();
getProgress().setPhase("Swapping students [GD]...", 1000);
while (bound > lb * total && total > 0 && (termination == null || termination.canContinue(solution))) {
Neighbour<Lecture, Placement> n = g.selectNeighbour(solution);
if (n != null) {
double value = value(n, solution.getAssignment());
if (value < 0) {
lastImp = it;
}
if (value <= 0.0 || total + value < bound) {
n.assign(solution.getAssignment(), it);
if (total + value < best) {
best = total + value;
}
total += value;
}
}
bound *= f;
it++;
if ((it % 1000) == 0) {
long prg = 1000 - Math.round(1000.0 * (bound - lb * best) / (ub * best - lb * best));
if (getProgress().getProgress() < prg)
getProgress().setProgress(prg);
if ((it % 10000) == 0) {
getProgress().info("Iter=" + (it / 1000) + "k, Idle=" + sDF2.format((it - lastImp) / 1000.0) + "k, Speed=" + sDF2.format(1000.0 * it / (JProf.currentTimeMillis() - t0)) + " it/s" + ", Value=" + sDF2.format(value(solution)) + ", Objective=" + sDF2.format(objective(solution)) + ", Group=" + sDF2.format(gp(solution)) + "%");
getProgress().info("Bound is " + sDF2.format(bound) + ", " + "best value is " + sDF2.format(best) + " (" + sDF2.format(100.0 * bound / best) + "%), " + "current value is " + sDF2.format(total) + " (" + sDF2.format(100.0 * bound / total) + "%)");
}
}
}
getProgress().info("Student Conflicts: " + sDF2.format(objective(solution)) + " (group: " + sDF2.format(gp(solution)) + "%)");
}
use of org.cpsolver.ifs.util.DataProperties in project cpsolver by UniTime.
the class TimetableModel method main.
public static void main(String[] args) {
try {
// Configure logging
ToolBox.configureLogging();
// 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();
}
}
use of org.cpsolver.ifs.util.DataProperties in project cpsolver by UniTime.
the class Test method test.
public static void test(File inputCfg, String name, String include, String regexp, String outDir) throws Exception {
if (regexp != null) {
String incFile;
if (regexp.indexOf(';') > 0) {
incFile = regexp.substring(0, regexp.indexOf(';'));
regexp = regexp.substring(regexp.indexOf(';') + 1);
} else {
incFile = regexp;
regexp = null;
}
if (incFile.startsWith("[") && incFile.endsWith("]")) {
test(inputCfg, name, include, regexp, outDir);
incFile = incFile.substring(1, incFile.length() - 1);
}
if (incFile.indexOf('{') >= 0 && incFile.indexOf('}') >= 0) {
String prefix = incFile.substring(0, incFile.indexOf('{'));
StringTokenizer middle = new StringTokenizer(incFile.substring(incFile.indexOf('{') + 1, incFile.indexOf('}')), "|");
String sufix = incFile.substring(incFile.indexOf('}') + 1);
while (middle.hasMoreTokens()) {
String m = middle.nextToken();
test(inputCfg, (name == null ? "" : name + "_") + m, (include == null ? "" : include + ";") + prefix + m + sufix, regexp, outDir);
}
} else {
test(inputCfg, name, (include == null ? "" : include + ";") + incFile, regexp, outDir);
}
} else {
DataProperties properties = ToolBox.loadProperties(inputCfg);
StringTokenizer inc = new StringTokenizer(include, ";");
while (inc.hasMoreTokens()) {
String aFile = inc.nextToken();
System.out.println(" Loading included file '" + aFile + "' ... ");
FileInputStream is = null;
if ((new File(aFile)).exists()) {
is = new FileInputStream(aFile);
}
if ((new File(inputCfg.getParent() + File.separator + aFile)).exists()) {
is = new FileInputStream(inputCfg.getParent() + File.separator + aFile);
}
if (is == null) {
System.err.println("Unable to find include file '" + aFile + "'.");
}
properties.load(is);
is.close();
}
String outDirThisTest = (outDir == null ? properties.getProperty("General.Output", ".") : outDir) + File.separator + name + File.separator + sDateFormat.format(new Date());
properties.setProperty("General.Output", outDirThisTest.toString());
System.out.println("Output folder: " + properties.getProperty("General.Output"));
(new File(outDirThisTest)).mkdirs();
ToolBox.configureLogging(outDirThisTest, null);
FileOutputStream fos = new FileOutputStream(outDirThisTest + File.separator + "rcsp.conf");
properties.store(fos, "Random CSP problem configuration file");
fos.flush();
fos.close();
test2(properties);
}
}
use of org.cpsolver.ifs.util.DataProperties in project cpsolver by UniTime.
the class Test method main.
public static void main(String[] args) {
try {
Progress.getInstance().addProgressListener(new ProgressWriter(System.out));
if (args.length == 0) {
ToolBox.configureLogging();
DataProperties config = new DataProperties(System.getProperties());
config.setProperty("Termination.StopWhenComplete", "false");
config.setProperty("Termination.TimeOut", "60");
config.setProperty("General.Output", System.getProperty("user.dir"));
test2(config);
return;
}
File inputCfg = new File(args[0]);
DataProperties properties = ToolBox.loadProperties(inputCfg);
if (args.length == 3) {
File xmlFile = new File(args[1]);
String outDir = args[2] + File.separator + (sDateFormat.format(new Date()));
properties.setProperty("General.Output", outDir.toString());
System.out.println("Input file: " + xmlFile);
System.out.println("Output folder: " + properties.getProperty("General.Output"));
(new File(outDir)).mkdirs();
ToolBox.configureLogging(outDir, null);
test3(properties, xmlFile);
} else if (properties.getProperty("INCLUDE_REGEXP") != null) {
test(inputCfg, null, null, properties.getProperty("INCLUDE_REGEXP"), (args.length > 1 ? args[1] : null));
} else {
String outDir = properties.getProperty("General.Output", ".") + File.separator + inputCfg.getName().substring(0, inputCfg.getName().lastIndexOf('.')) + File.separator + sDateFormat.format(new Date());
if (args.length > 1)
outDir = args[1] + File.separator + (sDateFormat.format(new Date()));
properties.setProperty("General.Output", outDir.toString());
System.out.println("Output folder: " + properties.getProperty("General.Output"));
(new File(outDir)).mkdirs();
ToolBox.configureLogging(outDir, null);
test2(properties);
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.cpsolver.ifs.util.DataProperties in project cpsolver by UniTime.
the class Test method main.
public static void main(String[] args) throws Exception {
ToolBox.configureLogging();
DataProperties config = new DataProperties();
if (System.getProperty("config") == null) {
config.load(Test.class.getClass().getResourceAsStream("/org/cpsolver/instructor/default.properties"));
} else {
config.load(new FileInputStream(System.getProperty("config")));
}
config.putAll(System.getProperties());
new Test(config).execute();
}
Aggregations