/* MAXIMAL INDEPENDENT SETS 26 SEPTEMBER 2001 PRECONDITIONS: 0. ILOG Solver 5.0. 1. A hypergraph read in in the following format: ************************************* number_of_vertices arity_1 vertex_1 vertex_2 ... arity_2 vertex_1 vertex_8 ... ... -1 ************************************* Here number_of_vertices is the overall number of vertices in the hypergraph. Each following line (except the last one containing -1) corresponds to an hyperedge, the first number is its arity (i.e., how many vertices it has), the following numbers are the vertices of this edge. 2. output file. 3. Size k of the desired (maximal) independent set (i.e., it should be known how many vertices make up the desired set). 4. Whether or not to consider maximality <0/1>; 5. The index of encoding <1..6>: Encodings 1 to 3 : independence is implemented using the IloSum function; they have no difference if maximality is not considered; Encodings 4 to 6 : independence is implemented using the IloDistribute function; they have no difference if maximality is not considered; If maximality is considered: Encoding 1 or 4, called max1 : maximality is encoded using P <-> Q; Encoding 2 or 5, called max2 : maximality is encoded using (P -> Q) ^ (Q -> P); Encoding 3 or 6, called max3 : maximality is encoded using (P ^ Q) V (not(P) ^ not(Q)); Here P is v_i = 1 (v_i is the Boolean variable corresponding to a vertex of the hypergraph, it is equal to 1 iff the vertex is in the desired set), whereas Q is the statement that for the given hyperedge e the sum of the variables v_k (k = [1..arity(e)] such that k!=i) is less than the arity of this hyperedge, i.e. arity(e). POSTCONDITION: The first solution, a (maximal) independent set of size k and some statistics (number of fails, number of nodes, etc.) */ #include #include ILOSTLBEGIN //max number of edges in the hypergraph const nbEdgesMax = 1000; //number of backtracks and number of nodes in the search tree unsigned long int NbFails, NbNodes; const IloInt max1 = 1; const IloInt max2 = 2; const IloInt max3 = 3; int main(int argc, char *argv[]) { NbFails = 0; NbNodes = 0; IloEnv env; try { /////////////////////////////////////////////////////////////////////////// // // READING DATA // /////////////////////////////////////////////////////////////////////////// IloModel mdl(env); int i=0,j=0,k=0; ifstream infile; ofstream outfile; char * datafile; char * output; if (argc ==6) { datafile = argv[1]; output = argv[2]; } else { env.out() << "Usage: *.exe datafile resfile size maximalityOn <0/1> encoding <1..6>"<> nbVertices; IloNumArray vertices(env,nbVertices); for (i=0;i> currArity; if (currArity==-1) break; arityArr[j] = currArity; nbEdges++; for (int i=0;i> DataArray[j][i]; } j++; } if (isOutputOn) cout<<"Your hypergraph has "< EDGE MAPPING // //////////////////////////////////////////////////////////////////////////// //If vertex i is in hyperedge j, //EdgeLists[i][j]=1, otherwise 0. int **EdgeLists; EdgeLists = new int *[nbVertices]; for (i=0;i=1); } } /////////////////////////////////////////////////////////// // // 3. maximality constraints // /////////////////////////////////////////////////////////// if (MaximalityConstraintOn) { IloConstraint constraint_Q, constraint_notQ, c, not_c; IloBool flag; // encoding max1: p <-> q, see comments above; // encoding max2: (p -> q) && (q->p); // encoding max3: (p&&q)||(not(p)&¬(q)); expr.remove(vertexPresent); if (Encoding==max1 || Encoding==max2) { for (i=0;i