簡體   English   中英

為什么這個簡單的 Gecode 示例無法編譯?

[英]why does this simple Gecode example not compile?

我正在嘗試學習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 那么有什么問題呢? 這段代碼是我發現的示例中的逐字逐句,所以大概它應該按原樣工作。

e.next()返回克隆空間的指針 ( SendMoreMoney )。 您必須使用while (SendMoreMoney* s = e.next())

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM