Main Page   Class Hierarchy   Compound List   File List   Contact   Download   Symbolic Constraints   Examples  

Boolean_Functions

This example shows the proper handling of the class SCIL::boolfunction.

We first create a new instance IP of an SCIL::ILP_Problem. (In this example it is a maximization problem)

   ILP_Problem IP(Optsense_Max);
Then we add some variables to the IP with different objective function coefficients.
   var x0 = IP.add_binary_variable(0.);
   var x1 = IP.add_binary_variable(2.);
   var x2 = IP.add_binary_variable(0.);
   var x3 = IP.add_binary_variable(0.);
   var x4 = IP.add_binary_variable(1.);
Now we create a boolean function $ bf_1 = \neg x_0 $. The last parameter is true, if the created boolean function should be negated.
   boolfunction* bf1 = new boolfunction(x0, true);
The other boolean functions in this example are created with two variables and one operator. If the last boolean parameter has been omitted the boolean function is not negated. The created boolean functions are:
$ \\ bf_2 = \neg (x_1 \vee x_2) \\ bf_3 = x_3 \oplus x_4 \\ bf_4 = x_0 \Rightarrow x_3 \\ bf_5 = x_0 \Rightarrow x_4 $
   boolfunction* bf2 = new boolfunction(x1, x2, OR, true);
   boolfunction* bf3 = new boolfunction(x3, x4, XOR);
   boolfunction* bf4 = new boolfunction(x0, x3, IMP);
   boolfunction* bf5 = new boolfunction(x0, x4, IMP);
Existing boolean functions can be connected with SCIL::boolfunction::add. $ bf_1 $ is set to $ (bf_1 \Rightarrow bf_2) $ and $ bf_2 $ is set to $ (bf_2 \wedge bf_3) $. Because $ bf_2 $ is changed after adding it to $ bf_1 $ this change has no effect on $ bf_1 $ .
   bf1->add(IMP, bf2);
   bf2->add(AND, bf3);
Then we add two boolean functions $ bf_1 $ and $ bf_2 $ to the objective function of IP.
   IP.add_boolfunction(bf1, 1.);
   IP.add_boolfunction(bf2, 10.);
Finally we construct a boolean constraint of type C1 which means that every boolean function in the given list must be true for every feasible solution.
   list<boolfunction*> cl;
   cl.push_back(bf4);
   cl.push_back(bf5);
   IP.add_bool_constraint(cl, C1);
Now we can compute an optimal solution by calling optimize.
   IP.optimize();
After all we have to delete every created boolfunction which has not been added to the ILP_Problem in any way. In this example this only holds for $ bf_3 $ .
   delete bf3;

Generated on Mon Mar 28 22:03:46 2011 for SCIL by  doxygen 1.6.3