2016-04-28 11 views
0

我一直在試圖學習雅各布解決我的約束滿足問題。除了Api之外,我找不到任何其他教程。如何在Java中使用JaCop使用SumInt?

所以我想測試它的方法是如何工作的。

例如使用SumInt。 我正在計算一個數字出現在列表中的次數。我怎樣才能使用JaCop?

一樣,如果我有一個列表中的這些數據:10,20,10,30,10,50,40

怎麼能指望我多少次,10,20,30,40,50使用JaCop出現? 這是一個我從Api頁面在線獲得的例子。但那看起來不像我想要做的。

Store store = new Store(); 
    IntVar a = new IntVar(store, "a", 1, 3); 
    IntVar b = new IntVar(store, "b", 1, 3); 
    IntVar c = new IntVar(store, "c", 1, 3); 
    IntVar sum = new IntVar(store, "sum", 1, 10); 
    IntVar[] v = {a, b, c}; 
    Constraint ctr = new SumInt(store,v, "==", sum); 
    store.impose(ctr); 

回答

0

您可以使用CountAmong約束。