Softlib

Examples


As you can see from the following example, using the Softlib is extremely simple:

 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();
}

In this example we build the variables contraints graph as a chain, the number of the nodes is specified by the varNum variable and their domain's bounds are specified by the localDomainMin and localDomainMax variables. The constraint used to link together the nodes is the SoftXltC and the weight contraint used is WeightUnaryProportional. In this sample we want to perform the soft arc consistency operation so, as you know, the semiring type parameter in the SoftStore object creation must be FUZZY.
So simple, uh?