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

poltest2.cc

00001 #include<fstream>
00002 #include<scil/scil.h>
00003 #include<scil/constraints/cut.h>
00004 #include<scil/core/polynomial.h>
00005 
00006 #define LEPS 1e-4
00007 using namespace SCIL;
00008 
00009 int main(int argc, char** argv) {
00010    
00011    //Initialize the ILP
00012    ILP_Problem IP(Optsense_Max);
00013 
00014    //Add some variables to the ILP
00015    var a = IP.add_binary_variable(0.);
00016    var b = IP.add_binary_variable(0.);
00017    var c = IP.add_binary_variable(0.);
00018 
00019    //Create some polynomials
00020    polynomial p1 = a*b + a + 3*a*b*c;
00021    polynomial p2 = p1 - 3*a*b;
00022    polynomial p3 = a*b*c;
00023    p3 -= b*c*a;
00024 
00025    //normalize the polynomials
00026    polynomial p1n(p1);
00027    polynomial p2n(p2);
00028    polynomial p3n(p3);
00029    polynomial p3nc(p3);
00030    p1n.normalize();
00031    p2n.normalize();
00032    p3n.normalize();
00033    p3nc.normalize(true);
00034 
00035    //add polynomials to the objective function
00036    IP.add_polynomial(p1);
00037    IP.add_polynomial(2*b);
00038 
00039    //add polynomial constraint
00040    polynomial p_cons = c*b + 2*c;
00041    IP.add_pol_constraint(p_cons <= 1.);
00042 
00043    //solve the ILP
00044    IP.optimize();
00045 
00046    //output the polynomials
00047    cerr << "p1: " << p1 << "   normalized: " << p1n << endl;
00048    cerr << "p2: " << p2 << "   normalized: " << p2n << endl;
00049    cerr << "p3: " << p3 << "   normalized: " << p3n << "   normalized with clean=true: " << p3nc << endl;
00050    
00051    //output objective function coefficient
00052    cerr << "objective function coefficients:" << endl;
00053    cerr << "a: " << IP.get_obj_coefficient(a) << " b: " << IP.get_obj_coefficient(b) << " c: " << IP.get_obj_coefficient(c) << endl; 
00054 
00055    //output solution
00056    solution sol = IP.get_solution();
00057    cerr << "solution:" << endl;
00058    cerr << "a: " << sol.value(a) << " b: " << sol.value(b) << " c: " << sol.value(c) << endl;
00059 
00060    return 0;
00061 }
00062 
Generated on Mon Mar 28 22:03:49 2011 for SCIL by  doxygen 1.6.3