簡體   English   中英

可以在Choco?的解決方案之間創建約束嗎?

[英]It is possible to create constraints between solutions in Choco?

我有這個問題:

在具有以下屬性的字母W = {A,C,G,T}上找到長度為8的一組最大長度為8的字符串(單詞)S:

  1. S中的每個單詞都有{ C,G } 4個符號

  2. S中每對不同的詞在至少4個位置不同。

我做了第一點。 我說過8個變量的取值范圍是1到4,而1和2必須出現在4個地方:

V = {x1, x2, x3, x4, x5, x6, x7, x8}
D = {1, 2, 3, 4}
C = {1 and 2 must appear in 4 places; I uses `ICF.among()` function}

現在,第二點,我不知道。 也許我的開始方式是錯誤的。 我不知道是否可以在解決方案之間創建約束。

我使用了choco3,這是代碼:

Solver s = new Solver("My pb");
IntVar[] var = new IntVar[8];

for(int i=0;i<8;i++)


var[i]=VariableFactory.bounded("Letter"+i, 1, 4, s);

IntVar o = VariableFactory.bounded("Occurence", 4, 4, s);
int[] ind = {1,2};
int[] ind1={3,4};

s.post(ICF.among(o, var, ind));
s.findSolution();   
do{
    for(int i=0;i<8;i++){
        System.out.print(s.getVar(i)+" ");
    }
    System.out.println();
}while(s.nextSolution());

當然,您可以在搜索過程中添加約束。 甚至可以指定是否要在回溯時將其刪除。

暫無
暫無

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

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