00001 #include<scil/scil.h>
00002 #include<scil/core/monomial.h>
00003
00004 #define STRONG
00005
00006 #include <iostream>
00007
00008 using namespace SCIL;
00009 using namespace std;
00010
00011 int main() {
00012
00013 int num_vars,num_edges,num_cons;
00014
00015 int i,j;
00016 double w;
00017
00018
00019
00020 cin>>num_vars>>num_edges>>num_cons;
00021
00022
00023
00024 ILP_Problem IP(Optsense_Min);
00025 vector<var> bvar(num_vars);
00026 for(int v = 0; v < num_vars; v++) {
00027 bvar[v] = IP.add_binary_variable(0);
00028 }
00029
00030
00031 for(int e = 0; e < num_edges; e++) {
00032 cin>>i>>j>>w;
00033 if(i < 1 || i > num_vars) {
00034 cerr<<"error in input: node "<<i<<" out of range!"<<endl;
00035 exit(1);
00036 }
00037 if(j < 1 || j > num_vars) {
00038 cerr<<"error in input: node "<<j<<" out of range!"<<endl;
00039 exit(1);
00040 }
00041 if(i == j) {
00042 cerr<<"error in input: loops not allowed!"<<endl;
00043 exit(1);
00044 }
00045 if(i < j) {
00046 IP.add_polynomial(bvar[i-1]*bvar[j-1]*w);
00047 }
00048 else {
00049 IP.add_polynomial(bvar[j-1]*bvar[i-1]*w);
00050 }
00051 }
00052
00053
00054
00055 int s;
00056 vector<int> cvar(num_vars);
00057 for(int c = 0; c < num_cons; c++) {
00058 row r;
00059 cin>>s;
00060 for(int d = 0; d < s; d++) {
00061 cin>>cvar[d];
00062 r += bvar[cvar[d]-1];
00063 }
00064 IP.add_basic_constraint(r == 1.0,Static);
00065
00066 #ifdef STRONG
00067 for(int d1 = 0; d1 < s-1; d1++) {
00068 for(int d2 = d1+1; d2 < s; d2++) {
00069 row r;
00070 r = IP.add_polynomial(bvar[cvar[d1]-1]*bvar[cvar[d2]-1]* 0.);
00071 IP.add_basic_constraint(r == 0.0,Static);
00072 }
00073 }
00074 #endif
00075
00076 }
00077
00078
00079
00080
00081
00082 IP.optimize();
00083
00084
00085
00086 for(int v = 0; v < num_vars; v++) {
00087 if(IP.get_solution(bvar[v])>0.5) {
00088 cout<<"var "<<v<<endl;
00089 }
00090 }
00091
00092
00093
00094 return 0;
00095 }