1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 | SoftStore softStore =
new SoftStore(SoftStore.Semiring.FUZZY);
int varNum = 5000;
int localDomainMax = 4;
int localDomainMin = 0;
IntVar[] list = new IntVar[varNum];
SoftXltC ucon;
for(int i=0; i< list.length; i++){
list[i] = new IntVar(softStore, "X"+i,
localDomainMin,
localDomainMax);
if(i%2==0){
ucon = new SoftXltC(list[i], localDomainMax);
ucon.impose(softStore, new
WeightUnaryProportional(150));
} else {
ucon = new SoftXltC(list[i], localDomainMax);
ucon.impose(softStore, new
WeightUnaryProportional(1));
}
}
softStore.softArcConsistency();
softStore.imposeWeights();
Search<IntVar> label = new
DepthFirstSearch<IntVar>();
SelectChoicePoint<IntVar> select = new
SimpleSelect<IntVar>(list,
new SmallestDomain<IntVar>(),
new IndomainMin<IntVar>());
label.getSolutionListener().searchAll(true);
label.getSolutionListener().recordSolutions(true);
label.labeling(softStore, select, softStore.getCost());
for (int i = 1;
i <= label.getSolutionListener().solutionsNo();
i++) {
System.out.print("Soluzione " + i + ": ");
for (int j = 0;
j < label.getSolution(i).length;
j++) {
System.out.print(label.getSolution(i)[j]);
}
System.out.println();
}
|