我正在努力学习,并试图让此处gecode
找到的示例起作用。
// To use integer variables and constraints
#include <gecode/int.hh>
// To make modeling more comfortable
#include <gecode/minimodel.hh> // To use search engines
#include <gecode/search.hh>
// To avoid typing Gecode:: all the time
using namespace Gecode;
class SendMoreMoney : public Space {
protected:
IntVarArray x;
public:
SendMoreMoney() : x(*this, 8, 0, 9) {
IntVar s(x[0]), e(x[1]), n(x[2]), d(x[3]), m(x[4]), o(x[5]), r(x[6]),
y(x[7]);
rel(*this, s != 0);
rel(*this, m != 0);
distinct(*this, x);
rel(*this,
1000 * s + 100 * e + 10 * n + d + 1000 * m + 100 * o + 10 * r + e ==
10000 * m + 1000 * o + 100 * n + 10 * e + y);
branch(*this, x, INT_VAR_SIZE_MIN(), INT_VAL_MIN());
}
SendMoreMoney(SendMoreMoney& s) : Space(s) { x.update(*this, s.x); }
virtual Space* copy() { return new SendMoreMoney(*this); }
void print() const { std::cout << x << std::endl; }
};
int main() {
SendMoreMoney* m = new SendMoreMoney;
DFS<SendMoreMoney> e(m);
delete m;
while (SendMoreMoney s = e.next()) {
s->print();
delete s;
}
}
我最终得到以下编译错误。
error: no matching function for call to 'Gecode::IntVarArray::update(SendMoreMoney&, Gecode::IntVarArray&)'
27 | x.update(*this, s.x);
| ^
和
error: invalid new-expression of abstract class type 'SendMoreMoney'
30 | return new SendMoreMoney(*this);
|
我不明白这些是从哪里来的。IntVarArray 当然有一个更新函数,它的第一个参数是一个 Space 对象,而 SendMoreMoney 继承自 Space 那么问题是什么?这段代码是我发现的示例中的逐字记录,所以它应该可以按原样工作。