我正在做一个 Gecode 项目,代码应该输出一个如下所示的文件:
n: 17
x: {0, 0, 16, 18, 17, 31, 32, 0, 34, 10, 30, 37, 38, 30, 30, 10}
y: {0, 27, 28, 14, 0, 31, 20, 17, 11, 17, 0, 0, 6, 7, 11, 25}
s: 43
runtime: 0.137
failure: 127
以上是代码应输出的示例。我尝试执行以下代码:
virtual void
print(std::ostream& os) const {
string filename = "project1-t15-n" + n + ".txt";
ofstream myfile;
myfile.open (filename);
myfile << "n: " << n << std::endl;
myfile << "x: {";
for (int i = 0; i < x.size(); i++) {
if (i != 0) {
myfile << ", ";
}
myfile << x[i];
}
myfile << "}" << std::endl;
myfile << "y: {";
for (int i = 0; i < y.size(); i++) {
if (i != 0) {
myfile << ", ";
}
myfile << y[i];
}
myfile << "}" << std::endl;
myfile << "s: " << s << std::endl;
//???????????????????????????????? print runtime and failures
myfile.close();
}
我知道 n、s、x 和 y 是正确的,但我有两个问题:
1:print(std::ostream& os) const
打印到文件时使用正确吗?
2:如何从 Gecode 输出中获取运行时和故障?他们内置的打印功能可以做到这一点。