00001
00002
00003
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;
00023 file >> n;
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;
00031 file >> c;
00032
00033 std::vector<var> a(nv);
00034 for( int j = 0; j < nv; j++ ) {
00035 file >> ind;
00036 if( vm.find(ind) == vm.end() ) {
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
00052 ILP_Problem IP(Optsense_Max);
00053
00054
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
00063 IP.add_polynomial(p);
00064
00065
00066 IP.optimize();
00067
00068
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