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

poltest.cc

00001 //TODO unite korrekt?
00002 /* Tue Nov  4 11:55:20 CET 2008
00003  * baumann
00004  */
00005 
00006 #include<fstream>
00007 #include<scil/scil.h>
00008 #include<scil/constraints/cut.h>
00009 #include<scil/core/polynomial.h>
00010 #include<vector>
00011 #include<boost/unordered_map.hpp>
00012 
00013 #define LEPS 1e-4
00014 using namespace SCIL;
00015 
00016 bool read_instance(char* file_name, unordered_map<int, var>& vm, polynomial& pol, ILP_Problem& IP) {
00017 
00018    ifstream file;
00019    file.open(file_name);
00020 
00021    int n;
00022    file >> n; //read the number of variables (and discard)
00023    file >> n; //read the number of monomials in the obj. function
00024 
00025    int nv;
00026    int ind;
00027    double c;
00028    int ns = 0;
00029    for( int i = 0; i < n; i++ ) {
00030       file >> nv; //read the number of variables in the monomial
00031       file >> c; //read the coefficient of the monomial
00032 
00033       std::vector<var> a(nv);
00034       for( int j = 0; j < nv; j++ ) {
00035          file >> ind; //read the index of the variable
00036          if( vm.find(ind) == vm.end() ) {       // if vm[ind] not yet defined
00037             ns++;
00038             vm[ind] = IP.add_binary_variable(0.);
00039          }
00040          a[j] = vm[ind];
00041       }
00042       pol += monomial(c, a);
00043    }
00044 
00045    cout << "singletons:" << ns << endl;
00046 
00047    return true;
00048 }
00049 
00050 int main(int argc, char** argv) {
00051    //initialize the ILP
00052    ILP_Problem IP(Optsense_Max);
00053 
00054    //read the polynomial from file
00055    unordered_map<int,var> vm;
00056    polynomial p;
00057    read_instance(argv[1], vm, p, IP);
00058 
00059    std::cerr << IP.number_of_variables() << endl;
00060    std::cerr << IP.number_of_constraints() << endl;
00061 
00062    //add the polynomial to the objective function
00063    IP.add_polynomial(p);
00064 
00065    //solve the problem
00066    IP.optimize();
00067 
00068    //output the solution
00069    solution sol = IP.get_solution();
00070    var v;
00071    int i;
00072    unordered_map<int, var>::const_iterator iv;
00073    foreach(iv, vm) 
00074       if( sol.value(iv->second) > .9 )
00075          std::cout << iv->first << " ";
00076    std::cout << endl;
00077 
00078    return 0;
00079 }
00080 
Generated on Mon Mar 28 22:03:49 2011 for SCIL by  doxygen 1.6.3