akmaxsat_1.1/akmaxsat.cpp0000600000176000017530000003777511622701542016147 0ustar kuegelmitarbeiter/* Copyright (C) 2010 Adrian Kuegel This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include #include #include #include #include #include #include #include #include #include "cnf_formula.hpp" using namespace std; //! \file akmaxsat.cpp Documentation of the maxsat solver #ifdef RBFS void rbfs(CNF_Formula &cf) { int *variable_stack = new int[cf.getNVars()]; int *todo = new int[cf.getNVars()]; ULL *f = new ULL[cf.getNVars()+1]; ULL *F = new ULL[cf.getNVars()+1]; ULL *f2 = new ULL[cf.getNVars()+1]; ULL *F2 = new ULL[cf.getNVars()+1]; ULL *b = new ULL[cf.getNVars()+1]; int *pos = new int[cf.getNVars() + 1]; int *variables = new int[cf.getNVars()]; int variable_stack_len = 0; b[0] = MAXWEIGHT; F[0] = f[0] = cf.bestMinusLowerBound(); int L, p; int branch_cnt = 0, propagate_cnt = 0; long double besthvalue; bool found; vector< pair > tv; for (int i=1; i<=cf.getNVars(); ++i) { double hv1 = cf.getBinaryLength(i)*2+cf.getUnitLength(i)+cf.getLength(i); double hv2 = cf.getBinaryLength(-i)*2+cf.getUnitLength(-i)+cf.getLength(-i); tv.push_back(make_pair(hv1*hv1+min(hv1, hv2), i)); } sort(tv.begin(), tv.end()); int sign = 0; int ind; int nvariables = cf.getNVars(); for (int i=0; i b[variable_stack_len]) { F[variable_stack_len] = f[variable_stack_len]; goto goback; } if (variable_stack_len == cf.getNVars()) break; #ifdef PROP_LIST L = cf.propagateLiteral(); if (L != 0) { if (!cf.assignLiteral(L)) goto goback; ++propagate_cnt; variable_stack[variable_stack_len] = abs(L); todo[variable_stack_len++] = 0; F[variable_stack_len] = f[variable_stack_len] = cf.bestMinusLowerBound(); b[variable_stack_len] = b[variable_stack_len-1]; if (f[variable_stack_len-1] < F[variable_stack_len-1] && F[variable_stack_len-1] > F[variable_stack_len]) F[variable_stack_len] = F[variable_stack_len-1]; p = pos[abs(L)]; assert(p >= 0); if (p != nvariables-1) { variables[p] = variables[nvariables-1]; pos[variables[p]] = p; } --nvariables; continue; } #endif found = false; if (nvariables < 5000) pit = variables + nvariables-1; if (pit >= variables + nvariables) pit = variables + nvariables-1; for (; pit>=variables; --pit) { long long lneg = cf.getLength(-*pit); long long lpos = cf.getLength(*pit); // check if -i can be discarded if (cf.getUnitLength(*pit) >= lneg) { if (!cf.assignLiteral(*pit)) goto goback; assert(pos[*pit] == pit - variables); ++propagate_cnt; variable_stack[variable_stack_len] = *pit; *pit = variables[nvariables-1]; pos[*pit] = pit - variables; --nvariables; todo[variable_stack_len++] = 0; b[variable_stack_len] = b[variable_stack_len-1]; F[variable_stack_len] = f[variable_stack_len] = cf.bestMinusLowerBound(); if (f[variable_stack_len-1] < F[variable_stack_len-1] && F[variable_stack_len-1] > F[variable_stack_len]) F[variable_stack_len] = F[variable_stack_len-1]; found = true; break; } // check if +i can be discarded else if (cf.getUnitLength(-*pit) >= lpos) { if (!cf.assignLiteral(-*pit)) goto goback; assert(pos[*pit] == pit - variables); ++propagate_cnt; variable_stack[variable_stack_len] = *pit; *pit = variables[nvariables-1]; pos[*pit] = pit - variables; --nvariables; todo[variable_stack_len++] = 0; b[variable_stack_len] = b[variable_stack_len-1]; F[variable_stack_len] = f[variable_stack_len] = cf.bestMinusLowerBound(); if (f[variable_stack_len-1] < F[variable_stack_len-1] && F[variable_stack_len-1] > F[variable_stack_len]) F[variable_stack_len] = F[variable_stack_len-1]; found = true; break; } } if (found) continue; ind = 0; if (nvariables >= 3000) { ind = variables[nvariables-1]; if (cf.getW_lb(ind) + cf.getUnitLength(ind) + cf.getBinaryLength(ind) > cf.getW_lb(-ind)+cf.getUnitLength(-ind)+cf.getBinaryLength(-ind)) sign = 1; else sign = -1; } else { besthvalue = -1; assert(nvariables > 0); for (int *it=variables+nvariables-1; it>=variables; --it) { assert(pos[*it] == it - variables); long long lneg = cf.getLength(-*it); long long lpos = cf.getLength(*it); long double hv1 = cf.getW_lb(*it) + cf.getBinaryLength(*it) + lpos; assert(hv1 >= 0); long double hv2 = cf.getW_lb(-*it) + cf.getBinaryLength(-*it) + lneg; assert(hv2 >= 0); if (hv1 * hv2 + min(lpos, lneg) >= besthvalue) { besthvalue = hv1 * hv2 + min(lpos, lneg); ind = *it; // if (lneg > lpos) if (hv2 > hv1) sign = -1; else sign = 1; } } } assert(ind != 0); todo[variable_stack_len] = sign * ind; variable_stack[variable_stack_len++] = ind; cf.assignLiteral(-sign * ind); F2[variable_stack_len] = f2[variable_stack_len] = cf.bestMinusLowerBound(); if (F[variable_stack_len-1] > f[variable_stack_len-1] && F[variable_stack_len-1] > F2[variable_stack_len]) F2[variable_stack_len] = F[variable_stack_len-1]; cf.unassignLiteral(); cf.assignLiteral(sign * ind); F[variable_stack_len] = f[variable_stack_len] = cf.bestMinusLowerBound(); if (F[variable_stack_len-1] > f[variable_stack_len-1] && F[variable_stack_len-1] > F[variable_stack_len]) F[variable_stack_len] = F[variable_stack_len-1]; if (F2[variable_stack_len] < F[variable_stack_len]) { todo[variable_stack_len-1] *= -1; swap(F2[variable_stack_len], F[variable_stack_len]); swap(f2[variable_stack_len], f[variable_stack_len]); cf.unassignLiteral(); cf.assignLiteral(-sign * ind); ULL temp = cf.bestMinusLowerBound(); if (temp > f[variable_stack_len]) { if (temp > f2[variable_stack_len]) temp = f2[variable_stack_len]; f[variable_stack_len] = temp; if (temp > F[variable_stack_len]) { F[variable_stack_len] = temp; if (F[variable_stack_len-1] > f[variable_stack_len-1] && F[variable_stack_len-1] > F[variable_stack_len]) F[variable_stack_len] = F[variable_stack_len-1]; } } } b[variable_stack_len] = min(b[variable_stack_len-1], F2[variable_stack_len]); ++branch_cnt; p = pos[ind]; assert(p >= 0); variables[p] = variables[nvariables-1]; pos[variables[p]] = p; --nvariables; continue; goback: while(variable_stack_len) { cf.unassignLiteral(); if (todo[variable_stack_len-1]) { if (F[variable_stack_len] > F2[variable_stack_len]) { swap(F[variable_stack_len], F2[variable_stack_len]); swap(f[variable_stack_len], f2[variable_stack_len]); if (F[variable_stack_len] <= b[variable_stack_len-1]) { todo[variable_stack_len-1] *= -1; b[variable_stack_len] = min(b[variable_stack_len-1], F2[variable_stack_len]); cf.assignLiteral(todo[variable_stack_len-1]); ULL temp = cf.bestMinusLowerBound(); if (temp > f[variable_stack_len]) { if (temp > f2[variable_stack_len]) temp = f2[variable_stack_len]; f[variable_stack_len] = temp; if (temp > F[variable_stack_len]) { F[variable_stack_len] = temp; if (F[variable_stack_len-1] > f[variable_stack_len-1] && F[variable_stack_len-1] > F[variable_stack_len]) F[variable_stack_len] = F[variable_stack_len-1]; } } break; } } else assert(F[variable_stack_len] > b[variable_stack_len-1]); } assert(F[variable_stack_len] > b[variable_stack_len]); assert(F[variable_stack_len] >= F[variable_stack_len-1]); F[variable_stack_len-1] = F[variable_stack_len]; --variable_stack_len; pos[variable_stack[variable_stack_len]] = nvariables; variables[nvariables++] = variable_stack[variable_stack_len]; } }while(variable_stack_len); printf("c %d branches %d propagates\n", branch_cnt, propagate_cnt); delete [] variable_stack; delete [] todo; delete [] F2; delete [] F; delete [] f2; delete [] f; delete [] b; delete [] variables; delete [] pos; } #else void fast_backtrack(CNF_Formula &cf) { int *variable_stack = new int[cf.getNVars()]; int *todo = new int[cf.getNVars()]; int *pos = new int[cf.getNVars() + 1]; int *variables = new int[cf.getNVars()]; int variable_stack_len = 0; int L, p; int branch_cnt = 0, propagate_cnt = 0; long double besthvalue; bool found; bool do_lb_calc = false;//cf.getNVars() <= 200 || (cf.getBestCost() < cf.getHardWeight()); bool firstlb = true; vector< pair > tv; for (int i=1; i<=cf.getNVars(); ++i) { double hv1 = cf.getBinaryLength(i)*2+cf.getUnitLength(i)+cf.getLength(i); double hv2 = cf.getBinaryLength(-i)*2+cf.getUnitLength(-i)+cf.getLength(-i); tv.push_back(make_pair(hv1*hv1+min(hv1, hv2), i)); } sort(tv.begin(), tv.end()); int sign = 0; int ind; int nvariables = cf.getNVars(); for (int i=0; i= 0); if (p != nvariables-1) { variables[p] = variables[nvariables-1]; pos[variables[p]] = p; } --nvariables; continue; } #endif firstlb = false; if (!cf.bestMinusLowerBound()) goto goback; #ifdef PROP_LIST L = cf.propagateLiteral(); if (L != 0) { if (!cf.assignLiteral(L)) goto goback; ++propagate_cnt; variable_stack[variable_stack_len] = abs(L); todo[variable_stack_len++] = 0; p = pos[abs(L)]; assert(p >= 0); if (p != nvariables-1) { variables[p] = variables[nvariables-1]; pos[variables[p]] = p; } --nvariables; continue; } #endif found = false; if (nvariables < 5000) pit = variables + nvariables-1; if (pit >= variables + nvariables) pit = variables + nvariables-1; for (; pit>=variables; --pit) { long long lneg = cf.getLength(-*pit); long long lpos = cf.getLength(*pit); // check if -i can be discarded if (cf.getUnitLength(*pit) >= lneg) { if (!cf.assignLiteral(*pit)) goto goback; assert(pos[*pit] == pit - variables); ++propagate_cnt; variable_stack[variable_stack_len] = *pit; *pit = variables[nvariables-1]; pos[*pit] = pit - variables; --nvariables; todo[variable_stack_len++] = 0; found = true; break; } // check if +i can be discarded else if (cf.getUnitLength(-*pit) >= lpos) { if (!cf.assignLiteral(-*pit)) goto goback; assert(pos[*pit] == pit - variables); ++propagate_cnt; variable_stack[variable_stack_len] = *pit; *pit = variables[nvariables-1]; pos[*pit] = pit - variables; --nvariables; todo[variable_stack_len++] = 0; found = true; break; } } if (found) continue; ind = 0; if (nvariables >= 3000) { ind = variables[nvariables-1]; if (cf.getW_lb(ind) + cf.getUnitLength(ind) + cf.getBinaryLength(ind) > cf.getW_lb(-ind)+cf.getUnitLength(-ind)+cf.getBinaryLength(-ind)) sign = 1; else sign = -1; } else { besthvalue = -1; assert(nvariables > 0); for (int *it=variables+nvariables-1; it>=variables; --it) { assert(pos[*it] == it - variables); long long lneg = cf.getLength(-*it); long long lpos = cf.getLength(*it); long double hv1 = cf.getW_lb(*it) + cf.getBinaryLength(*it) + lpos; assert(hv1 >= 0); long double hv2 = cf.getW_lb(-*it) + cf.getBinaryLength(-*it) + lneg; assert(hv2 >= 0); if (hv1 * hv2 + min(lpos, lneg) >= besthvalue) { besthvalue = hv1 * hv2 + min(lpos, lneg); ind = *it; // if (lneg > lpos) // todo: check what happens if we choose randomly the first 3 variables /* if (variable_stack_len <= 2) { if (rand() < RAND_MAX/2) sign = 1; else sign = -1; } else { */ if (hv2 > hv1) sign = -1; else sign = 1; // } } } } assert(ind != 0); todo[variable_stack_len] = -sign * ind; if (!cf.assignLiteral(ind * sign)) { if (!cf.assignLiteral(ind * -sign)) goto goback; todo[variable_stack_len] = 0; } ++branch_cnt; // if (branch_cnt % 10000 == 0) // printf("c sofar %d branches\n", branch_cnt); variable_stack[variable_stack_len++] = ind; p = pos[ind]; assert(p >= 0); variables[p] = variables[nvariables-1]; pos[variables[p]] = p; --nvariables; continue; goback: while(variable_stack_len) { --variable_stack_len; cf.unassignLiteral(); if (todo[variable_stack_len]) if (cf.assignLiteral(todo[variable_stack_len])) { todo[variable_stack_len++] = 0; break; } pos[variable_stack[variable_stack_len]] = nvariables; variables[nvariables++] = variable_stack[variable_stack_len]; } }while(variable_stack_len); printf("c %d branches %d propagates\n", branch_cnt, propagate_cnt); delete [] variable_stack; delete [] todo; delete [] variables; delete [] pos; } #endif int main(int argc, char **argv) { srand(time(0)); if (argc < 2) { printf("usage: %s [upper bound file]\n", argv[0]); return 1; } ifstream istr(argv[1]); CNF_Formula cf(istr); #ifdef FORCE_LS char command[1000]; char folder[1000]; char file[1000]; char *p = argv[1]; while(strchr(p, '/') != NULL) p = strchr(p, '/') + 1; sprintf(folder, "/tmp/akmaxsat %d %s/", getpid(), p); sprintf(command, "mkdir \"%s\"", folder); system(command); sprintf(file, "%s%s", folder,p); if (cf.isWeighted()) sprintf(command, "./ubcsat -alg irots -w -seed 0 -runs 10 -cutoff %d -r bestsol -r out /dev/null -inst %s > \"%s\"", min(100*cf.getNVars(), 100000), argv[1], file); else sprintf(command, "./ubcsat -alg irots -seed 0 -runs 10 -cutoff %d -r bestsol -r out /dev/null -inst %s > \"%s\"", min(100*cf.getNVars(), 100000), argv[1], file); system(command); ifstream istr2(file); #else if (argc > 2) { ifstream istr2(argv[2]); #endif ULL bestCost = cf.getHardWeight(); string s; istr2 >> s; #ifndef FORCE_LS if (s == "#") { #endif getline(istr2, s); ULL t; string best; for (int i=0; i<10; ++i) { istr2 >> s >> s >> t; if (t < bestCost) { istr2 >> best; bestCost = (ULL)t; } else istr2 >> s; } if (best.size() > 0) { char *bestA = new char[best.size() + 1]; for (int i=0; i<(int)best.size(); ++i) if (best[i] == '0') bestA[i + 1] = -1; else bestA[i + 1] = 1; cf.saveBest(bestCost, bestA); delete [] bestA; } #ifndef FORCE_LS } else { while(s != "Solution") istr2 >> s; ULL t; istr2 >> s >> t; while(istr2 >> s && s != "v"); if (t < bestCost) { bestCost = (ULL)t; char *bestA = new char[cf.getNVars() + 1]; for (int i=1; i<=cf.getNVars(); ++i) { int t; istr2 >> t; assert(t == i || t == -i); bestA[i] = (t > 0? 1 : -1); } cf.saveBest(bestCost, bestA); delete [] bestA; } } #endif cout << "c initialized bestCost to " << bestCost << endl; cout << "o " << bestCost << endl; #ifdef FORCE_LS remove(file); remove(folder); #else } #endif #ifdef RBFS rbfs(cf); #else fast_backtrack(cf); #endif cf.printSolution(); return 0; } akmaxsat_1.1/clauses.cpp0000600000176000017530000000370311516042602015752 0ustar kuegelmitarbeiter/* Copyright (C) 2010 Adrian Kuegel This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "clauses.hpp" ULL MAXWEIGHT = (1ULL<<63) - 1; //! doubles the amount of memory available to store clauses void Clauses::doubleStorage() { capacity <<= 1; ++logcapacity; int_c *clauses2 = new int_c[capacity]; assert(clauses2 != NULL); memcpy(clauses2, clauses, sizeof(int_c) * capacity/2); delete [] clauses; clauses = clauses2; int *headsFreeList2 = new int[logcapacity]; assert(headsFreeList2 != NULL); memcpy(headsFreeList2, headsFreeList, sizeof(int) * (logcapacity-1)); delete [] headsFreeList; headsFreeList = headsFreeList2; assert(headsFreeList[logcapacity-2] == 0); // add the new storage block to the buddy memory management headsFreeList[logcapacity-2] = capacity/2; headsFreeList[logcapacity-1] = 0; clauses[capacity/2] = 0; } //! Clauses constructor Clauses::Clauses() { assigned = NULL; logcapacity = 16; capacity = 1< Copyright (C) 2010 Adrian Kuegel This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef CLAUSES_HPP_INCLUDE #define CLAUSES_HPP_INCLUDE #include #include #include #include using namespace std; typedef int int_c; typedef unsigned long long ULL; extern ULL MAXWEIGHT; /*! \file clauses.hpp Documentation of class Clauses */ //! The class Clauses is a data structure which stores and maintains a list of clauses efficiently class Clauses { // private member variable //! clauses contains clauses in the format \ \ ... \ int_c *clauses; //! capacity of the array clauses - a power of 2 int capacity; //! capacity of the array headsFreeList - log2(capacity) int logcapacity; //! pointers to the first free block of size 2^i int *headsFreeList; //! stores which literals are currently assigned to false bool *assigned; //! number of variables int nVars; //! bit which indicates deletion of the clause const static int DELETED = 1<<30; //! bit which indicates a marker const static int MARKED = 1<<29; //! bit which indicates that the clause is special const static int SPECIAL = 1<<28; //! bit which indicates that a clause was changed since it was last traversed const static int CHANGED = 1<<27; //! maximum length of a clause const static int MAXLEN = (1<<27)-1; // private functions //! doubles the amount of memory available to store clauses void doubleStorage(); //! add a free memory block of size 2^list_id to the list of empty blocks inline void addFreeBlock(int pos, int list_id) { clauses[pos] = headsFreeList[list_id]; headsFreeList[list_id] = pos; } //! remove the first block of size 2^list_id from the list of empty blocks inline void popFreeBlock(int list_id) { assert(headsFreeList[list_id] > 0); headsFreeList[list_id] = clauses[headsFreeList[list_id]]; } //! add special flag to clause /*! \param clause_id The id of the clause to which a special flag should be added */ inline void addSpecialFlag2Clause(int clause_id) { assert(clause_id > 0 && clause_id < capacity && clauses[clause_id] > 0 && (clauses[clause_id] & SPECIAL) == 0); clauses[clause_id] |= SPECIAL; } //public functions public: //! Clauses constructor Clauses(); //! initialize the number of variables and the assigned array void init(int n) { assert(assigned == NULL); nVars = n; assigned = new bool[2 * nVars + 1]; memset(assigned, false, (2 * nVars + 1)*sizeof(bool)); assigned += nVars; } //! Add a clause to the list of clauses. /*! \param literals specifies the literals of the clause * \param length gives the length of the clause * \param weight gives the weight of the clause * \returns returns the clause id */ inline int addClause(int_c *literals, int length, ULL weight) { #ifdef DEBUG for (int i=0; i= 0 && length <= MAXLEN); // find a free block for storing the new clause int pos = 0, k; length += 5; for (k=2; k= length) { pos = headsFreeList[k]; if (pos) break; } // increase storage as long as no large enough block was found while(!pos) { doubleStorage(); // after doubling storage, the biggest available block has size 2^(logcapacity-2) if ((1 << (logcapacity - 2)) >= length) { pos = headsFreeList[logcapacity - 2]; assert(pos); k = logcapacity - 2; break; } } #ifdef DEBUG cout << "k = " << k << " pos = " << pos << endl; #endif popFreeBlock(k); // now split the block until its size is the smallest power of 2 >= length while(k > 0 && (1<<(k-1)) >= length) { --k; addFreeBlock(pos + (1< 0 && clause_id < capacity && (clauses[clause_id] & DELETED) == DELETED && (clauses[clause_id] & SPECIAL) == SPECIAL); int k = 2, w = getLength(clause_id) + 5; while((1< 0 && clause_id < capacity); assert(clauses[clause_id + 1] == 0); addSpecialFlag2Clause(clause_id); clauses[clause_id + 5] = getLength(clause_id); } //! decrease reference counter /*! \param clause_id The id of the clause. */ inline void decreaseCounter(int clause_id) { assert(clause_id > 0 && clause_id < capacity && (clauses[clause_id] & DELETED) == DELETED && (clauses[clause_id] & SPECIAL) == SPECIAL); if (--clauses[clause_id+5] == 0) deleteClause(clause_id); } //! Add a delete flag to a clause. /*! \param clause_id The id of the clause to be flagged */ inline void addDeleteFlag2Clause(int clause_id) { assert(clause_id > 0 && clause_id < capacity && (clauses[clause_id] & DELETED) == 0); clauses[clause_id] |= DELETED; } //! mark the clause. /*! \param clause_id The id of the clause to be marked */ inline void addMarker2Clause(int clause_id) { assert(clause_id > 0 && clause_id < capacity && clauses[clause_id] > 0 && (clauses[clause_id] & MARKED) == 0); clauses[clause_id] |= MARKED; } //! remove the special flag from a clause /*! \param clause_id The id of the clause */ inline void removeSpecialFlagFromClause(int clause_id) { assert(clause_id > 0 && clause_id < capacity && clauses[clause_id] > 0 && (clauses[clause_id] & SPECIAL)); clauses[clause_id] ^= SPECIAL; } //! Remove marker from a clause. /*! \param clause_id The id of the clause. */ inline void removeMarkerFromClause(int clause_id) { assert(clause_id > 0 && clause_id < capacity && clauses[clause_id] > 0 && (clauses[clause_id] & MARKED)); clauses[clause_id] ^= MARKED; } //! Remove a delete flag from a clause. /*! \param clause_id The id of the clause. */ inline void removeDeleteFlagFromClause(int clause_id) { assert(clause_id > 0 && clause_id < capacity && (clauses[clause_id] & DELETED)); clauses[clause_id] ^= DELETED; } //! Get the delete flag of a clause. /*! \param clause_id The id of the clause * \returns true if clause is marked as deleted, false otherwise */ inline bool getDeleteFlag(int clause_id) const { #ifdef DEBUG if (clauses[clause_id] == 0) printf("clause_id = %d\n", clause_id); #endif assert(clause_id > 0 && clause_id < capacity && clauses[clause_id] != 0); return clauses[clause_id] & DELETED; } //! Get the marker of a clause. /*! \param clause_id The id of the clause * \returns true if clause is marked, false otherwise */ inline bool getMarker(int clause_id) const { assert(clause_id > 0 && clause_id < capacity && clauses[clause_id] != 0); return clauses[clause_id] & MARKED; } //! Get the special flag of a clause. /*! \param clause_id The id of the clause * \returns true if clause is flagged as special, false otherwise */ inline bool getSpecialFlag(int clause_id) const { assert(clause_id > 0 && clause_id < capacity && clauses[clause_id] != 0); return clauses[clause_id] & SPECIAL; } //! Get a list of literals of a clause. /*! \param clause_id The id of the clause. */ inline const int_c *getLiterals(int clause_id) const { assert(clause_id > 0 && clause_id < capacity); // check if clause length has changed if (clauses[clause_id]&CHANGED) { // move the unassigned literals to the front clauses[clause_id] ^= CHANGED; int needed = getLength(clause_id); int *sptr = clauses + clause_id + 5; while(needed && !assigned[*sptr]) { ++sptr; --needed; } if (!needed) return clauses + clause_id + 5; int *ptr = sptr + 1; int c = needed; while(needed) { if (!assigned[*ptr++]) --needed; } --ptr; while(c--) { swap(*sptr, *ptr); if (!c) break; --ptr; while(assigned[*ptr]) --ptr; ++sptr; while(c && !assigned[*sptr]) { --c; ++sptr; } } } return clauses + clause_id + 5; } //! get the length of a clause. /*! \param clause_id The id of the clause. * \returns the length of the clause */ inline int getLength(int clause_id) const { assert(clause_id > 0 && clause_id < capacity && clauses[clause_id] != 0); return clauses[clause_id]&MAXLEN; } //! get the weight of a clause. /*! \param clause_id The id of the clause. * \returns the weight of the clause */ inline ULL getWeight(int clause_id) const { assert(clause_id > 0 && clause_id < capacity); return *((ULL*)&clauses[clause_id+1]); } //! get the saved weight of a clause. /*! \param clause_id The id of the clause. * \returns the weight of the clause */ inline ULL getSavedWeight(int clause_id) const { assert(clause_id > 0 && clause_id < capacity && getLength(clause_id) > 0); return *((ULL*)&clauses[clause_id+3]); } //! reset the weight of a clause to the saved weight. /*! \param clause_id The id of the clause. */ inline void resetWeight(int clause_id) { assert(clause_id > 0 && clause_id < capacity && getLength(clause_id) > 0); assert(!getSpecialFlag(clause_id)); if (getWeight(clause_id) == getSavedWeight(clause_id)) return; assert(getWeight(clause_id) < getSavedWeight(clause_id)); *((ULL*)&clauses[clause_id + 1]) = *((ULL*)&clauses[clause_id + 3]); assert(getWeight(clause_id) > 0); clauses[clause_id] &= ~DELETED; } //! save the current weight of a clause. /*! \param clause_id The id of the clause. * \remark saves a copy of the current weight */ inline void saveWeight(int clause_id) { assert(clause_id > 0 && clause_id < capacity && getLength(clause_id) > 0); *((ULL*)&clauses[clause_id+3]) = *((ULL*)&clauses[clause_id+1]); } //! increase the weight of a clause. /*! \param clause_id The id of the clause. * \param w The weight to be added (w != 0). */ inline void addWeight(int clause_id, ULL w, bool change_saved = false) { assert(clause_id > 0 && clause_id < capacity && w != 0); assert(!getSpecialFlag(clause_id)); if (getWeight(clause_id) == 0) { assert(getDeleteFlag(clause_id) && w > 0); removeDeleteFlagFromClause(clause_id); } assert(w <= MAXWEIGHT - getWeight(clause_id)); *((ULL*)&clauses[clause_id + 1]) += w; if (change_saved) *((ULL*)&clauses[clause_id + 3]) += w; } //! decrease the weight of a clause. /*! \param clause_id The id of the clause. * \param w The weight to be subtracted (w != 0). */ inline void subtractWeight(int clause_id, ULL w, bool change_saved = false) { assert(clause_id > 0 && clause_id < capacity && w != 0 && !getDeleteFlag(clause_id)); assert(!getSpecialFlag(clause_id)); *((ULL*)&clauses[clause_id + 1]) -= w; if (change_saved) { assert(getSavedWeight(clause_id) >= w); *((ULL*)&clauses[clause_id + 3]) -= w; } if (getWeight(clause_id) == 0) addDeleteFlag2Clause(clause_id); } ~Clauses(); }; #endif akmaxsat_1.1/cnf_formula.hpp0000600000176000017530000027657111622701534016636 0ustar kuegelmitarbeiter/* Copyright (C) 2010 Adrian Kuegel This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef CNF_FORMULA_HPP_INCLUDE #define CNF_FORMULA_HPP_INCLUDE #include "clauses.hpp" #include "restore_list.hpp" #include #include #include #include #include using namespace std; //! The class CNF_Formula maintains the states of the CNF_Formula during backtracking template class CNF_Formula { // private variables //! clause number to indicate a unit clause const static int UNIT_CLAUSE = 1; #ifdef FUIP vector bla; vector *tadj; int succ_cnt_fuip, total_cnt_fuip; int *Q2; char *visit2; int *ref_cnt; #endif #ifdef STATS int *explored; long long *sum_cost; #endif //! all clauses of the CNF formula Clauses all_clauses; //! boolean flag which indicates if the given formula has weighted clauses or default weight 1 bool isWcnf; //! number of Variables in the formula int nVars; //! contains a list of pointers to clauses in which literal i occurs vector *appears; //! contains a list of clauses implying unit literal i vector *unit_implication_list; //! contains the current size of each appears vector int *appears_len; //! contains the values assigned to the variables char *assigned_values; //! contains the best values assigned to the variables char *bestA; //! number of assigned literals int n_assigned; //! stack of assigned literals int *assigned_literals; //! timestamp long long timestamp; //! timestamps when appears array was last traversed long long *appears_traversed; //! weight of unit clauses which contain literal i TL *W_unit; //! weight of binary clauses which contain literal i TL *W_binary; //! weight of clauses of length > 2 which contain literal i TL *W_large; //! sum of clause weights of clauses containing literal i contained in inconsistent subformulas detected in lower bound calculation TL *W_lb; //! saved weight of unit clauses with literal i TL *W_unit_save; //! cost of current partial assignment ULL *cost; //! best cost of a complete assignment ULL bestCost; //! difference between current cost and bestCost ULL needed_for_skip; //! list of clauses which need to be reinserted restore_list rlist; //! stores data for each literal (depends on function) int *literal_data; //! stores the clause id of clauses which contain the variables (a, b) at position a * nVars + b int *ternary_clause_data; //! stores the literals in the order in which they should be selected for propagation pair *literal_order; //! length of literal_order list int l; //! stores a stack of processed variables during lower bound calculation with unit propagation int *vars; //! stores the number of variables on the vars stack int vars_top; //! stores a list of clauses processed during lower bound computation vector take_back; //! stores a list of variables processed during lower bound computation vector which; //! stores a list of clauses of cycle structures vector cycle_clauses; //! queue of variables used in the function detectConflict int *Q; //! head of queue int head; //! tail of queue int tail; //! old tail of queue int oldtail; //! hard clause weight (for partial maxsat) ULL hard; //! maximum input variable int maxVn; //! maps a variable in compacted variable numbering to the original variables int *mapping; //! number of an original variable in the compacted variable numbering int *maps_to; //! total number of generalized unit propagations performed int total_gup; //! number of generalized unit propagations which produced a lower bound >= bestCost int succ_gup; #ifdef PROP_LIST //! stack which contains literals which can be propagated int *propagation_stack; //! number of literals which can be propagated int propagation_stack_size; //! position of literal i on the propagation stack int *onstack; #endif //! list of clauses which were changed during lower bound calculation vector changed; // height transform vector psi; vector *ptr; // private functions //! Normalize the clause array and determine if it is a tautology inline bool normalize_clause_array(vector &clause) const { sort(clause.begin(), clause.end()); int len = 0; int last = 0; for (int i=0; i<(int)clause.size(); ++i) { if (clause[i] != last) { clause[len++] = clause[i]; last = clause[i]; } // check if the clause is a tautology (it contains clause[i] and -clause[i]) if (binary_search(clause.begin()+i, clause.end(), -clause[i])) return false; } clause.resize(len); return true; } //! delete clauses which are fulfilled by setting literal L to true inline void deleteFulfilled(int L) { #ifdef DEBUG cout << "delete fulfilled" << endl; #endif assert(!assigned_values[abs(L)]); vector &appears2 = appears[L]; assert(appears_len[L] == (int)appears2.size()); for (int i=appears2.size()-1; i>=0; --i) { int &it = appears2[i]; // remove clauses which already have a delete flag if (all_clauses.getDeleteFlag(it)) { if (all_clauses.getSpecialFlag(it)) all_clauses.decreaseCounter(it); it = appears2.back(); appears2.pop_back(); } else { // set the delete flag all_clauses.addDeleteFlag2Clause(it); assert(all_clauses.getLength(it) > 1); // update W_binary if (all_clauses.getLength(it) == 2) { const int_c *literals = all_clauses.getLiterals(it); assert(literals[0] == L || literals[1] == L); W_binary[literals[0]] -= all_clauses.getWeight(it); W_binary[literals[1]] -= all_clauses.getWeight(it); #ifdef PROP_LIST /* // the following lines can be used to find a propagation variable - usually it does not improve speed int i = 0; if (literals[0] == L) i = 1; if (onstack[-literals[i]] < 0 && getLength(literals[i]) <= W_unit[-literals[i]]) { onstack[-literals[i]] = propagation_stack_size; propagation_stack[propagation_stack_size++] = -literals[i]; } */ #endif } // update W_large else { const int_c *literals = all_clauses.getLiterals(it); ULL w = all_clauses.getWeight(it); #ifndef NDEBUG bool found = false; #endif for (int i=all_clauses.getLength(it)-1; i>=0; --i) { W_large[literals[i]] -= w; #ifndef NDEBUG if (literals[i] == L) found = true; #endif #ifdef PROP_LIST /* // the following lines can be used to find a propagation variable - usually it does not improve speed if (literals[i] != L && onstack[-literals[i]] < 0 && getLength(literals[i]) <= W_unit[-literals[i]]) { onstack[-literals[i]] = propagation_stack_size; propagation_stack[propagation_stack_size++] = -literals[i]; } */ #endif } assert(found); } } } appears_len[L] = (int)appears2.size(); // set new time stamp for the appears array appears_traversed[L] = timestamp++; } //! set a to min(a + b, bestCost) inline void saveAddition(ULL &a, TL b) const { if (a + b < bestCost) a = a + (ULL)b; else a = bestCost; } //! set a to min(a + b, bestCost) inline void saveAddition(ULL &a, ULL b) const { if (a + b < bestCost) a = a + (ULL)b; else a = bestCost; } //! set a to max(a - b, 0) inline void saveSubtraction(ULL &a, TL b) const { if ((TL)a >= b) a = a - (ULL)b; else a = 0; } //! set a to max(a - b, 0) inline void saveSubtraction(ULL &a, ULL b) const { if (a >= b) a = a - b; else a = 0; } //! remove literal L from clauses in the formula inline ULL removeLiteral(int L) { assert(L >= -nVars && L <= nVars && L != 0); #ifdef DEBUG cout << "trying to remove literal " << L << endl; #endif assert(W_unit_save[L] == W_unit[L]); int l; assert((int)appears[L].size() == appears_len[L]); appears_traversed[L] = timestamp++; vector &appears2 = appears[L]; for (int i=appears2.size()-1; i>=0; --i) { int &it = appears2[i]; // remove clause with delete flags if (all_clauses.getDeleteFlag(it)) { if (all_clauses.getSpecialFlag(it)) all_clauses.decreaseCounter(it); it = appears2.back(); appears2.pop_back(); } else { // remove the literal from the clause all_clauses.decreaseLength(it); l = all_clauses.getLength(it); // update W_binary and W_large if (l == 2) { const int_c *literals = all_clauses.getLiterals(it); ULL w = all_clauses.getWeight(it); W_binary[literals[0]] += w; W_binary[literals[1]] += w; W_large[literals[0]] -= w; W_large[literals[1]] -= w; W_large[L] -= w; } // update W_unit and W_binary else if (l == 1) { int literal = *all_clauses.getLiterals(it); W_binary[literal] -= all_clauses.getWeight(it); W_binary[L] -= all_clauses.getWeight(it); W_unit[literal] += all_clauses.getWeight(it); W_unit_save[literal] += all_clauses.getWeight(it); // unary resolution of literal, -literal may become possible unary_resolution(literal); assert(!assigned_values[abs(literal)]); #ifdef PROP_LIST // check if literal can be propagated if (onstack[literal] < 0 && W_unit[literal] + (TL)cost[n_assigned] >= (TL)bestCost) { onstack[literal] = propagation_stack_size; propagation_stack[propagation_stack_size++] = literal; } #endif // set delete flag for unit clauses all_clauses.addDeleteFlag2Clause(it); } } } appears_len[L] = (int)appears[L].size(); #ifndef NDEBUG for (vector::const_iterator it=appears[L].begin(); it < appears[L].end(); ++it) assert(all_clauses.getDeleteFlag(*it) == false || all_clauses.getLength(*it) == 1); #endif return W_unit[L] > (TL)MAXWEIGHT? MAXWEIGHT : (ULL)W_unit[L]; } //! propagate literal -L, set L to false inline int propagateLiteral(int L) { assert(vars_top >= 0 && L == -vars[vars_top]); assert(L >= -nVars && L <= nVars && L != 0); assert(!assigned_values[abs(L)]); #ifdef DEBUG printf("propagating %d\n", L); #endif all_clauses.assignVariable(L); vector &appears2 = appears[L]; #ifndef NDEBUG for (vector::reverse_iterator it=appears2.rbegin(); it::reverse_iterator it=appears2.rbegin() + ((int)appears2.size() - appears_len[L]); it conflict! if (literal_data[L] > 0) { assert(literal_data[L] != UNIT_CLAUSE && !all_clauses.getDeleteFlag(literal_data[L])); return literal_data[L]; } // if there is a unit literal L, it conflicts with propagating -L if (W_unit[L] > 0) return literal_data[L] = UNIT_CLAUSE; return 0; } //! add literal L back to clauses where it was removed inline void addLiteral(int L) { vector &appears2 = appears[L]; assert((int)appears2.size() == appears_len[L]); for (vector::reverse_iterator it=appears2.rbegin(); it= 0 && getUnitLength(literal) < getLength(-literal) && W_unit[literal] + (TL)cost[n_assigned + 1] < (TL)bestCost) { int pos = onstack[literal]; if (pos != propagation_stack_size-1) { propagation_stack[pos] = propagation_stack[propagation_stack_size-1]; onstack[propagation_stack[pos]] = pos; } onstack[literal] = -1; --propagation_stack_size; } */ #endif // check if the clause needs to be inserted into the appears list // this is the case if the appears list of literal was traversed after L was assigned false (which happened with time stamp appears_traversed[L] if (appears_traversed[literal] > appears_traversed[L]) { appears[literal].push_back(*it); ++appears_len[literal]; } } // update W_binary and W_large else if (all_clauses.getLength(*it) == 2) { const int_c *literals = all_clauses.getLiterals(*it); ULL w = all_clauses.getWeight(*it); W_binary[literals[0]] -= w; W_binary[literals[1]] -= w; W_large[literals[0]] += w; W_large[literals[1]] += w; W_large[L] += w; } // increase the length of the clause (literal L will be added back to the clause) all_clauses.increaseLength(*it); } // unassign literal L all_clauses.unassignVariable(L); } //! undo propagation of literal L inline void undoPropagateLiteral(int L) { vector &appears2 = appears[L]; for (vector::const_iterator it=appears2.begin(); it &appears2 = appears[L]; // count how many clauses in the inconsistent subformula depend on propagating L int propagated = 0; #ifdef FUIP bla.clear(); #endif for (vector::const_iterator it=appears2.begin(); it 0; return propagated; } //! apply resolution to pairs of binary clause (x_i, x_j) (x_i, -x_j) or ternary clauses (x_i, x_j, x_k) (x_i, x_j, -x_k) inline TL binary_ternary_resolution(int L) { int_c nC[2]; TL cnt = 0; int other1, other2, id; const int_c *literals; // store in literal_data[i] the clause consisting of literals L and i // store in ternary_clause_data[(L1+nVars)*(2*nVars+1)+L2+nVars] the clause consisting of literals L, L1 and L2 for (int i=appears[L].size()-1; i>=0; --i) { int &it = appears[L][i]; if (all_clauses.getDeleteFlag(it)) { // remove clause pointers which should be deleted if (all_clauses.getSpecialFlag(it)) all_clauses.decreaseCounter(it); it = appears[L].back(); appears[L].pop_back(); } else { assert(all_clauses.getWeight(it) > 0); assert(!all_clauses.getSpecialFlag(it)); all_clauses.saveWeight(it); if (all_clauses.getLength(it) == 2) { literals = all_clauses.getLiterals(it); other1 = (literals[0] == L? literals[1] : literals[0]); // check if there was an identical binary clause if (literal_data[other1] > 0) { assert(literal_data[other1] != it); ULL w = all_clauses.getWeight(it); assert(all_clauses.getWeight(literal_data[other1]) > 0); // add weight of clause to previous same clause all_clauses.addWeight(literal_data[other1], w); all_clauses.subtractWeight(it, w, true); rlist.addEntry(it); rlist.commit(timestamp++, w, false); } else { assert(all_clauses.getWeight(it) > 0); literal_data[other1] = it; } } else if (ternary_clause_data != NULL && all_clauses.getLength(it) == 3) { literals = all_clauses.getLiterals(it); other1 = other2 = 0; // determine the other two literals other1 and other2 which appear together with literal L in the clause for (int i=0; i<3; ++i) if (literals[i] != L) { if (!other1) other1 = literals[i]; else other2 = literals[i]; } if (other1 > other2) swap(other1, other2); // calculate a unique id for a clause containing literal L and literal other1 and literal other2 id = (other1 + nVars) * (nVars * 2 + 1) + other2 + nVars; // check if we can merge the clause if (ternary_clause_data[id] > 0) { assert(ternary_clause_data[id] != it); ULL w = all_clauses.getWeight(it); assert(all_clauses.getWeight(ternary_clause_data[id]) > 0); all_clauses.addWeight(ternary_clause_data[id], w); all_clauses.subtractWeight(it, w, true); rlist.addEntry(it); rlist.commit(timestamp++, w, false); } else { assert(all_clauses.getWeight(it) > 0); ternary_clause_data[id] = it; } } } } // now do the resolution using literal_data and ternary_clause_data arrays for (int i=appears[L].size()-1; i>=0; --i) { int &it = appears[L][i]; assert(!all_clauses.getSpecialFlag(it)); if (all_clauses.getDeleteFlag(it)) { // in this case it can only be a clause which was deleted because it is the same as another clause, and its weight was added to the other clause // we only need to delete the clause pointer it = appears[L].back(); appears[L].pop_back(); } else { if (all_clauses.getLength(it) == 2) { literals = all_clauses.getLiterals(it); other1 = (literals[0] == L)? literals[1] : literals[0]; if (literal_data[other1] != it) { assert(all_clauses.getWeight(it) == all_clauses.getSavedWeight(it)); continue; } literal_data[other1] = 0; ULL w = all_clauses.getWeight(it); // check if we changed the weight of the clause if (all_clauses.getSavedWeight(it) != w) { assert(all_clauses.getSavedWeight(it) < w); rlist.addEntry(it); rlist.commit(timestamp++, w - all_clauses.getSavedWeight(it), true); all_clauses.saveWeight(it); } // check if there is also a clause consisting of L and -other1 -> resolution of (L, other1) with (L, -other1) if (literal_data[-other1] > 0) { int c = literal_data[-other1]; literal_data[-other1] = 0; ULL w2 = all_clauses.getWeight(c); // check if we changed the weight if (all_clauses.getSavedWeight(c) != w2) { assert(all_clauses.getSavedWeight(c) < w2); rlist.addEntry(c); rlist.commit(timestamp++, w2 - all_clauses.getSavedWeight(c), true); all_clauses.saveWeight(c); } ULL wmin = min(w, w2); assert(wmin > 0); all_clauses.subtractWeight(c, wmin, true); all_clauses.subtractWeight(it, wmin, true); W_binary[other1] -= wmin; W_binary[-other1] -= wmin; W_binary[L] -= wmin; W_binary[L] -= wmin; rlist.addEntry(c); rlist.addEntry(it); rlist.commit(timestamp++, wmin, false); cnt += wmin; if (w == wmin) { // if the complete weight of the clause was subtracted, the clause pointer can be deleted it = appears[L].back(); appears[L].pop_back(); continue; } } } else if (ternary_clause_data != NULL && all_clauses.getLength(it) == 3) { literals = all_clauses.getLiterals(it); other1 = other2 = 0; // determine the other two literals other1 and other2 which appear together with literal L in the clause for (int i=0; i<3; ++i) if (literals[i] != L) { if (!other1) other1 = literals[i]; else other2 = literals[i]; } if (other1 > other2) swap(other1, other2); id = (other1 + nVars) * (nVars * 2 + 1) + other2 + nVars; if (ternary_clause_data[id] <= 0) continue; assert(ternary_clause_data[id] == it); ternary_clause_data[id] = 0; ULL w = all_clauses.getWeight(it); // check if we changed the weight if (all_clauses.getSavedWeight(it) != w) { assert(all_clauses.getSavedWeight(it) < w); rlist.addEntry(it); rlist.commit(timestamp++, w - all_clauses.getSavedWeight(it), true); all_clauses.saveWeight(it); } // first negate other1 int other3 = -other1, other4 = other2; if (other3 > other4) swap(other3, other4); id = (other3 + nVars) * (nVars * 2 + 1) + other4 + nVars; // check if there exists a clause (L, -other1, other2) // -> resolution with (L, other1, other2) possible if (ternary_clause_data[id] > 0) { int c = ternary_clause_data[id]; ULL w2 = all_clauses.getWeight(c); if (all_clauses.getSavedWeight(c) != w2) { assert(all_clauses.getSavedWeight(c) < w2); rlist.addEntry(c); rlist.commit(timestamp++, w2 - all_clauses.getSavedWeight(c), true); all_clauses.saveWeight(c); } ULL wmin = min(w, w2); assert(wmin > 0); if (wmin == w2) ternary_clause_data[id] = 0; all_clauses.subtractWeight(c, wmin, true); all_clauses.subtractWeight(it, wmin, true); rlist.addEntry(c); rlist.addEntry(it); rlist.commit(timestamp++, wmin, false); // adjust weights W_binary[L] += wmin; W_binary[other2] += wmin; W_large[L] -= wmin; W_large[L] -= wmin; W_large[other2] -= wmin; W_large[other2] -= wmin; W_large[other1] -= wmin; W_large[-other1] -= wmin; if (literal_data[other2] > 0) { assert(all_clauses.getWeight(literal_data[other2]) > 0); all_clauses.addWeight(literal_data[other2], wmin); } else { nC[0] = L; nC[1] = other2; c = all_clauses.addClause(nC, 2, wmin); take_back.push_back(c); appears[other2].push_back(c); ++appears_len[other2]; rlist.addEntry(c); rlist.commit(timestamp++, wmin, true); } // if clause weight has become zero, the clause pointer can be deleted if (w == wmin) { it = appears[L].back(); appears[L].pop_back(); continue; } w -= wmin; } // then negate other2 other3 = other1; other4 = -other2; if (other3 > other4) swap(other3, other4); id = (other3 + nVars) * (nVars * 2 + 1) + other4 + nVars; // check if there exists a clause (L, other1, -other2) // -> resolution with (L, other1, other2) possible if (ternary_clause_data[id] > 0) { int c = ternary_clause_data[id]; ULL w2 = all_clauses.getWeight(c); if (all_clauses.getSavedWeight(c) != w2) { assert(all_clauses.getSavedWeight(c) < w2); rlist.addEntry(c); rlist.commit(timestamp++, w2 - all_clauses.getSavedWeight(c), true); all_clauses.saveWeight(c); } ULL wmin = min(w, w2); assert(wmin > 0); if (wmin == w2) ternary_clause_data[id] = 0; all_clauses.subtractWeight(c, wmin, true); all_clauses.subtractWeight(it, wmin, true); // adjust weights W_binary[L] += wmin; W_binary[other1] += wmin; W_large[L] -= wmin; W_large[L] -= wmin; W_large[other1] -= wmin; W_large[other1] -= wmin; W_large[other2] -= wmin; W_large[-other2] -= wmin; rlist.addEntry(c); rlist.addEntry(it); rlist.commit(timestamp++, wmin, false); if (literal_data[other1] > 0) { assert(all_clauses.getWeight(literal_data[other1]) > 0); all_clauses.addWeight(literal_data[other1], wmin); } else { nC[0] = L; nC[1] = other1; c = all_clauses.addClause(nC, 2, wmin); take_back.push_back(c); appears[other1].push_back(c); ++appears_len[other1]; rlist.addEntry(c); rlist.commit(timestamp++, wmin, true); } // if weight of the clause has become zero, the clause pointer can be deleted if (w == wmin) { it = appears[L].back(); appears[L].pop_back(); continue; } } } } } // take_back contains the binary clauses created by resolution of ternary clauses if (!take_back.empty()) { appears[L].insert(appears[L].end(), take_back.begin(), take_back.end()); take_back.clear(); } appears_len[L] = (int)appears[L].size(); appears_traversed[L] = timestamp++; #ifndef NDEBUG for (vector::const_iterator it=appears[L].begin(); it!=appears[L].end(); ++it) assert(all_clauses.getDeleteFlag(*it) == false); #endif assert(!assigned_values[abs(L)]); return cnt; } //! insert clause c into the appears list of L inline void do_insert(int L, int c) { appears[L].push_back(c); assert((int)appears[L].size() > appears_len[L]); swap(appears[L].back(), appears[L][appears_len[L]]); ++appears_len[L]; } //! remove inconsistent subformula (possibly use inference rules for transformation) void resolveConflict() { #ifdef DEBUG cout << "resolveConflict" << endl; #endif int t, pos = -1, other = 0; // first extract inconsistent subformula -> stored in take_back assert(take_back.empty()); assert(vars_top >= 0); assert(literal_data[-vars[vars_top]] > 0); // add the conflict clause to the inconsistent subformula and mark it take_back.push_back(literal_data[-vars[vars_top]]); literal_data[-vars[vars_top]] = 0; if (take_back.back() != UNIT_CLAUSE) all_clauses.addMarker2Clause(take_back.back()); else take_back.back() = -vars[vars_top] - nVars; assert(which.empty()); // pos2 is either -1 or indicates that we may shorten the inconsistent subformula by taking only the first "pos2" entries and adding a unit literal "var" int pos2 = -1, pcnt = 0, var, maxt = 1; ULL minweight = MAXWEIGHT; // process the propagation stack in reverse order for (int *it=vars + vars_top; it >= vars; --it) { #ifdef DEBUG if (literal_data[*it] == 0) for (int i=0; i<=vars_top; ++i) printf("vars[%d] = %d\n", i, vars[i]); #endif assert(literal_data[*it] > 0); // check if literal -*it occurred in marked clauses (i. e. *it needs to be propagated to yield the conflict clause) if ((t = addLiteralConflict(-*it))) { // add literal to the list of literals which need to be propagated to yield the conflict clause which.push_back(*it); if (t > maxt) maxt = t; if (t == 2) { // this means that the literal -*it occured in two marked clauses // this may be the "starting point" of a cycle structure // save the position if (take_back.size() == 3) pos = 3; // save the literal other = *it; } // if -*it occurs in more than one marked clause, we may not shorten the inconsistent subformula after this point if (t > 1) pos2 = -1; if (literal_data[*it] != UNIT_CLAUSE) { // check if there exists a unit literal which could be used for propagation instead of the current clause if (W_unit[*it] > 0 && pos2 < 0 && take_back.size() > 2) { pos2 = take_back.size(); pcnt = 0; var = *it - nVars; } if (all_clauses.getWeight(literal_data[*it]) < minweight) minweight = all_clauses.getWeight(literal_data[*it]); assert(!all_clauses.getMarker(literal_data[*it])); // mark the clause and add it to the list of clauses of the inconsistent subformula all_clauses.addMarker2Clause(literal_data[*it]); take_back.push_back(literal_data[*it]); } else { if (W_unit[*it] < (TL)minweight) minweight = W_unit[*it]; // represent a unit literal by *it - nVars // it holds -nVars <= *it <= nVars, thus *it - nVars <= 0 < UNIT_CLAUSE take_back.push_back(*it - nVars); // if we encounter another used unit literal, we cannot shorten the inconsistent subformula beyond that if (pos2 >= 0) { ++pcnt; if (pcnt > 1) pos2 = -1; } } } literal_data[*it] = 0; } // check if inconsistent subformula can be shortened if (pos2 >= 2 && pos2+1<(int)take_back.size() && W_unit[var+nVars] >= (TL)minweight) { int cnt = -1; while((int)take_back.size() > pos2) { ++cnt; if (take_back.back() > UNIT_CLAUSE) all_clauses.removeMarkerFromClause(take_back.back()); take_back.pop_back(); } assert(var <= 0 && cnt >= 0); which.resize(which.size()-cnt); take_back.push_back(var); } vars_top = -1; int first_large_clause = -1; int cnt = 0; minweight = MAXWEIGHT; // determine the minimum weight of a clause belonging to the inconsistent subformula // also determine the position of the first clause with more than two literals for (vector::const_iterator it=take_back.begin(); it!=take_back.end(); ++it) if (*it > UNIT_CLAUSE) { minweight = min(minweight, all_clauses.getWeight(*it)); assert(all_clauses.getLength(*it) > 1); if (first_large_clause < 0 && all_clauses.getLength(*it) > 2) first_large_clause = distance((vector::const_iterator)take_back.begin(), it); } else { if (W_unit[*it + nVars] < (TL)minweight) minweight = (ULL)W_unit[*it + nVars]; ++cnt; } // remove the markers from the clauses and subtract the weight from unit clauses for (vector::const_iterator it=take_back.begin(); it!=take_back.end(); ++it) { if (*it <= 0) { W_unit[*it + nVars] -= minweight; assert(W_unit[*it + nVars] >= 0); } else all_clauses.removeMarkerFromClause(*it); } assert(take_back.back() <= 0); if (first_large_clause >= 0) { which.clear(); // check if we can use cycle resolution if (first_large_clause > 2 && take_back.size() > 3) { int c[3] = {take_back[0], take_back[1], take_back[2]}; // check that the first three clauses are binary clauses if (c[0] > UNIT_CLAUSE && all_clauses.getLength(c[0]) == 2 && c[1] > UNIT_CLAUSE && all_clauses.getLength(c[1]) == 2 && c[2] > UNIT_CLAUSE && all_clauses.getLength(c[2]) == 2) { int other = which[2]; const int_c *literals1 = all_clauses.getLiterals(c[0]); const int_c *literals2 = all_clauses.getLiterals(c[1]); // the conflict clause should not contain -other const int_c *literals3 = all_clauses.getLiterals(c[2]); // first find common literals in literals2 and literals3 int i1 = -1, i2; if (literals2[0] == literals3[0]) i1 = i2 = 0; else if (literals2[0] == literals3[1]) { i1 = 0; i2 = 1; } else if (literals2[1] == literals3[0]) { i1 = 1; i2 = 0; } else if (literals2[1] == literals3[1]) i1 = i2 = 1; if (i1 >= 0 && ((literals1[0] == -literals2[1-i1] && literals1[1] == -literals3[1-i2]) || (literals1[0] == -literals3[1-i2] && literals1[1] == -literals2[1-i1]))) { assert(literals1[0] != -other && literals1[1] != -other); assert(literals2[i1] == -other); other = literals2[i1]; assert(pos == 3); // do cycle resolution if (process_cycle_clauses(c[0], c[1], c[2], literals2[i1], literals1[0], literals1[1])) { // in the special case of unit propagation, we do not need to include the newly generated ternary clauses in the inconsistent subformula take_back.pop_back(); take_back.pop_back(); // remove the binary clauses which were used in the resolution take_back.erase(take_back.begin(), take_back.begin() + 3); assert(W_unit[other] >= minweight); W_unit[other] -= minweight; unary_resolution(other); cycle_clauses.clear(); } } else assert(pos != 3); } } // remove inconsistent subformula for (vector::const_iterator it=take_back.begin(); it!=take_back.end(); ++it) if (*it > 0) { assert(!all_clauses.getDeleteFlag(*it)); if (all_clauses.getLength(*it) == 2) { const int *literals = all_clauses.getLiterals(*it); W_binary[literals[0]] -= minweight; W_binary[literals[1]] -= minweight; } else { const int *literals = all_clauses.getLiterals(*it); for (int j=all_clauses.getLength(*it)-1; j>=0; --j) W_large[literals[j]] -= minweight; } changed.push_back(*it); all_clauses.subtractWeight(*it, minweight); } take_back.clear(); saveSubtraction(needed_for_skip, minweight); return; } // check if we can apply a transformation if (cnt == 2) { // it is a chain of binary clauses int_c nC[2]; bool added = false; for (vector::const_iterator it=take_back.begin(); it < take_back.end(); ++it) if (*it > UNIT_CLAUSE) { all_clauses.subtractWeight(*it, minweight, true); assert(all_clauses.getLength(*it) == 2); const int_c *literals = all_clauses.getLiterals(*it); W_binary[literals[0]] -= minweight; W_binary[literals[1]] -= minweight; W_binary[-literals[0]] += minweight; W_binary[-literals[1]] += minweight; nC[0] = -literals[0]; nC[1] = -literals[1]; int c = all_clauses.addClause(nC, 2, minweight); do_insert(nC[0], c); do_insert(nC[1], c); rlist.addEntry(c); added = true; } else { W_unit_save[*it + nVars] -= minweight; assert(*it == take_back[0] || *it == take_back.back()); } if (added) rlist.commit(timestamp++, minweight, true); saveAddition(cost[n_assigned], minweight); saveSubtraction(needed_for_skip, minweight); for (vector::const_iterator it=take_back.begin(); it!=take_back.end(); ++it) rlist.addEntry(*it); rlist.commit(timestamp++, minweight, false); minweight = 0; } else if (pos == 3) { assert(cnt == 1 && take_back.size() >= 3); // cycle resolution can be applied int_c nC[3]; const int_c *literals; assert(cnt == 1); literals = all_clauses.getLiterals(take_back[0]); assert(literals[0] != other && literals[1] != other && literals[0] != -other && literals[1] != -other); ULL mw = min(all_clauses.getWeight(take_back[0]), min(all_clauses.getWeight(take_back[1]), all_clauses.getWeight(take_back[2]))); assert(mw >= minweight); if (mw > minweight) { W_unit[-other] += mw - minweight; W_unit_save[-other] += mw - minweight; rlist.addEntry(-other - nVars); rlist.commit(timestamp++, mw - minweight, true); } literals = all_clauses.getLiterals(take_back[0]); assert(literals[0] != other && literals[1] != other); nC[0] = other; nC[1] = literals[0]; nC[2] = literals[1]; W_binary[-other] -= mw; W_binary[-other] -= mw; W_binary[literals[0]] -= mw; W_binary[-literals[0]] -= mw; W_binary[literals[1]] -= mw; W_binary[-literals[1]] -= mw; W_large[nC[0]] += mw; W_large[nC[1]] += mw; W_large[nC[2]] += mw; int c = all_clauses.addClause(nC, 3, mw); do_insert(nC[0], c); do_insert(nC[1], c); do_insert(nC[2], c); rlist.addEntry(c); nC[0] *= -1; nC[1] *= -1; nC[2] *= -1; W_large[nC[0]] += mw; W_large[nC[1]] += mw; W_large[nC[2]] += mw; c = all_clauses.addClause(nC, 3, mw); do_insert(nC[0], c); do_insert(nC[1], c); do_insert(nC[2], c); rlist.addEntry(c); if (mw > minweight) rlist.commit(timestamp++, mw, true); bool added = false; for (vector::const_iterator it=take_back.begin()+3; it+1 minweight) { assert(take_back.size() > 3); all_clauses.subtractWeight(take_back[0], mw, true); all_clauses.subtractWeight(take_back[1], mw, true); all_clauses.subtractWeight(take_back[2], mw, true); rlist.addEntry(take_back[0]); rlist.addEntry(take_back[1]); rlist.addEntry(take_back[2]); rlist.commit(timestamp++, mw, false); for (vector::const_iterator it=take_back.begin() + 3; it!=take_back.end(); ++it) { rlist.addEntry(*it); if (*it > 0) all_clauses.subtractWeight(*it, minweight, true); // otherwise it was already subtracted else assert(*it == take_back.back()); } } else { for (vector::const_iterator it=take_back.begin(); it!=take_back.end(); ++it) { rlist.addEntry(*it); if (*it > 0) all_clauses.subtractWeight(*it, minweight, true); // otherwise it was already subtracted else assert(*it == take_back.back()); } } rlist.commit(timestamp++, minweight, false); saveAddition(cost[n_assigned], minweight); saveSubtraction(needed_for_skip, minweight); minweight = 0; unary_resolution(other); #ifdef PROP_LIST if (onstack[-other] < 0 && W_unit[-other] + (TL)cost[n_assigned] >= (TL)bestCost) { onstack[-other] = propagation_stack_size; propagation_stack[propagation_stack_size++] = -other; } #endif } /* // the following lines can be used to do Max-SAT resolution yielding an empty clause else if (take_back.size() <= 5) { bool added = false; int len = take_back[0] > UNIT_CLAUSE?all_clauses.getLength(take_back[0]):1; int maxlen = 100, maxlen2 = 100, len2; if (len > maxlen) maxlen = len; int *nclause = new int[maxlen]; int *nclause2 = new int[maxlen2]; const int *literals; if (len == 1) nclause[0] = take_back[0]+nVars; else memcpy(nclause, all_clauses.getLiterals(take_back[0]), len*sizeof(int)); vector::const_iterator it, it2; // now do resolution for (it=which.begin(), it2=take_back.begin()+1; it!=which.end(); ++it,++it2) { assert(len > 0); len2 = *it2 > UNIT_CLAUSE?all_clauses.getLength(*it2) : 1; if (len2 > maxlen2) { maxlen2 *= 2; while(len2 > maxlen2) maxlen2 *= 2; delete [] nclause2; nclause2 = new int[maxlen2]; } if (len2 == 1) { assert(*it2 <= UNIT_CLAUSE); nclause2[0] = *it2 + nVars; } else { literals = all_clauses.getLiterals(*it2); memcpy(nclause2, literals, len2 * sizeof(int)); } // move literal *it to the end #ifndef NDEBUG bool found = false; #endif for (int i=0; i=0 && j>=0; ) { if (nclause[i] == nclause2[j]) { swap(nclause[l--], nclause[i--]); nclause2[j--] = nclause2[--len2]; } else if (nclause[i] < nclause2[j]) --j; else --i; } if (len + len2 + 1 > maxlen) { maxlen *= 2; while(len + len2 + 1 > maxlen) maxlen *= 2; int *temp = new int[maxlen]; memcpy(temp, nclause, sizeof(int) * len); swap(nclause, temp); delete [] temp; } // add compensation clauses if (len2 > 0) { memcpy(nclause+len+1, nclause2, len2*sizeof(int)); assert(nclause[len] == -*it); for (int i=len+1; i<=len+len2; ++i) { nclause[i] = -nclause[i]; if (i > len+1) nclause[i-1] = -nclause[i-1]; int c = all_clauses.addClause(nclause, i+1, minweight); for (int j=0; j<=i; ++j) { if (i+1 == 2) W_binary[nclause[j]] += minweight; else W_large[nclause[j]] += minweight; do_insert(nclause[j], c); } rlist.addEntry(c); added = true; } nclause[len + len2] = -nclause[len + len2]; #ifndef NDEBUG for (int i=0; i=0; --i) { nclause[i] = -nclause[i]; if (i < l) nclause[i+1] = -nclause[i+1]; int c = all_clauses.addClause(nclause+i, len+len2+1-i, minweight); for (int j=i; j<=len+len2; ++j) { if (len+len2+1-i == 2) W_binary[nclause[j]] += minweight; else W_large[nclause[j]] += minweight; do_insert(nclause[j], c); } rlist.addEntry(c); added = true; } if (l >= 0) nclause[0] = -nclause[0]; nclause[len] = nclause[len+len2]; len += len2; } assert(it == which.end() && it2 == take_back.end()); #ifdef DEBUG if (len > 0) { printf("len = %d\n", len); for (int i=0; i 0); if (added) rlist.commit(timestamp++, minweight, true); saveAddition(cost[n_assigned], minweight); saveSubtraction(needed_for_skip, minweight); for (vector::const_iterator it=take_back.begin(); it!=take_back.end(); ++it) { rlist.addEntry(*it); if (*it > 0) { if (all_clauses.getLength(*it) == 2) { const int *literals = all_clauses.getLiterals(*it); W_binary[literals[0]] -= minweight; W_binary[literals[1]] -= minweight; } else { const int *literals = all_clauses.getLiterals(*it); for (int j=all_clauses.getLength(*it)-1; j>=0; --j) W_large[literals[j]] -= minweight; } all_clauses.subtractWeight(*it, minweight, true); } else { assert(W_unit[*it + nVars] >= 0); W_unit_save[*it + nVars] -= minweight; } } rlist.commit(timestamp++, minweight, false); take_back.clear(); return; } */ else { // no transformation, just remove inconsistent subformula for (vector::const_iterator it=take_back.begin(); it!=take_back.end(); ++it) if (*it > 0) { if (all_clauses.getLength(*it) == 2) { const int *literals = all_clauses.getLiterals(*it); W_binary[literals[0]] -= minweight; W_binary[literals[1]] -= minweight; } else { const int *literals = all_clauses.getLiterals(*it); for (int j=all_clauses.getLength(*it)-1; j>=0; --j) W_large[literals[j]] -= minweight; } changed.push_back(*it); all_clauses.subtractWeight(*it, minweight); } } which.clear(); take_back.clear(); saveSubtraction(needed_for_skip, minweight); } //! restore the clauses changed by the lowerbound function void restoreClauses(int L) { #ifdef DEBUG cout << "restoreClauses" << endl; #endif int length; long long deletion_time; ULL minweight; bool sign; const int *rclauses; // get the clauses which need to be changed back to their previous state while( (rclauses = rlist.retrieve(appears_traversed[L], length, deletion_time, minweight, sign)) != NULL) { while(length > 0) { --length; int clause_id = rclauses[length]; if (clause_id <= 0) { // in that case, we have a unit clause with a unit literal clause_id + nVars clause_id += nVars; assert(!assigned_values[abs(clause_id)]); assert(W_unit[clause_id] == W_unit_save[clause_id]); if (sign) { W_unit[clause_id] -= minweight; W_unit_save[clause_id] -= minweight; assert(W_unit_save[clause_id] >= 0); } else { W_unit[clause_id] += minweight; W_unit_save[clause_id] += minweight; } continue; } assert(!all_clauses.getSpecialFlag(clause_id)); bool wasDeleted = all_clauses.getDeleteFlag(clause_id); if (sign) all_clauses.subtractWeight(clause_id, minweight, true); else all_clauses.addWeight(clause_id, minweight, true); // adjust the weights W_binary or W_total, respectively if (all_clauses.getLength(clause_id) == 2) { const int_c *literals = all_clauses.getLiterals(clause_id); if (sign) { W_binary[literals[0]] -= minweight; W_binary[literals[1]] -= minweight; } else { W_binary[literals[0]] += minweight; W_binary[literals[1]] += minweight; } } else if (all_clauses.getLength(clause_id) >= 3) { const int_c *literals = all_clauses.getLiterals(clause_id); for (int i=all_clauses.getLength(clause_id)-1; i>=0; --i) if (sign) W_large[literals[i]] -= minweight; else W_large[literals[i]] += minweight; } if (all_clauses.getDeleteFlag(clause_id)) { assert(!wasDeleted); // in that case the clause can be permanently deleted #ifndef NDEBUG const int_c *literals = all_clauses.getLiterals(clause_id); for (int i=all_clauses.getLength(clause_id)-1; i>=0; --i) { int cnt = 0; for (vector::const_iterator it=appears[literals[i]].begin(); it!=appears[literals[i]].end(); ++it) if (*it == clause_id) ++cnt; assert(cnt == 1); } for (int i=-nVars; i<=nVars; ++i) { bool valid = (i != 0); for (int j=all_clauses.getLength(clause_id)-1; j>=0; --j) if (literals[j] == i) valid = false; if (!valid) continue; for (vector::const_iterator it=appears[i].begin(); it!=appears[i].end(); ++it) assert(*it != clause_id); } #endif // call the prepareDelete function which stores the number of active references to the clause all_clauses.prepareDelete(clause_id); assert(all_clauses.getWeight(clause_id) == all_clauses.getSavedWeight(clause_id) && all_clauses.getSpecialFlag(clause_id) && all_clauses.getDeleteFlag(clause_id)); continue; } if (!wasDeleted) continue; int l = all_clauses.getLength(clause_id); assert(l > 1); const int_c *literals = all_clauses.getLiterals(clause_id); // reinsert clause pointers into the appears lists where needed for (int i=0; i::const_iterator it=appears[literals[i]].begin(); it!=appears[literals[i]].end(); ++it) if (*it == clause_id) { found = true; break; } #endif assert(appears_len[literals[i]] == (int)appears[literals[i]].size()); if (appears_traversed[literals[i]] > deletion_time) { #ifndef NDEBUG if (found) cout << "here with " << literals[i] << " " << all_clauses.getLength(clause_id) << " " << appears_traversed[literals[i]] << " " << deletion_time << endl; assert(!found); #endif appears[literals[i]].push_back(clause_id); ++appears_len[literals[i]]; } #ifndef NDEBUG else { if (!found) cout << "here2 " << all_clauses.getLength(clause_id) << " " << appears_traversed[literals[i]] << " " << deletion_time << endl; assert(found); } #endif } } } } // process clauses (l1 l2) (l1 l3) (-l2 -l3) which imply -l1 inline bool process_cycle_clauses(int c1, int c2, int c3, int l1, int l2, int l3) { int_c nC[3]; if (l1 == l2 || l1 == l3 || l2 == -l3) return false; assert(l1 != l2 && l1 != -l2 && l1 != l3 && l1 != -l3 && l2 != l3 && l2 != -l3); assert(all_clauses.getLength(c1) == 2 && all_clauses.getLength(c2) == 2 && all_clauses.getLength(c3) == 2); if (!all_clauses.getDeleteFlag(c1) && !all_clauses.getDeleteFlag(c2) && !all_clauses.getDeleteFlag(c3)) { ULL minweight = min(all_clauses.getWeight(c1), min(all_clauses.getWeight(c2), all_clauses.getWeight(c3))); assert(minweight > 0); // save the clause pointers to clauses involved in the cycle resolution cycle_clauses.push_back(c1); cycle_clauses.push_back(c2); cycle_clauses.push_back(c3); // save the information in the restore list rlist.addEntry(c1); all_clauses.subtractWeight(c1, minweight, true); rlist.addEntry(c2); all_clauses.subtractWeight(c2, minweight, true); rlist.addEntry(c3); all_clauses.subtractWeight(c3, minweight, true); rlist.commit(timestamp++, minweight, false); assert(l1 >= -nVars && l1 <= nVars && l1 != 0 && !assigned_values[abs(l1)]); W_unit[l1] += minweight; W_unit_save[l1] += minweight; #ifdef PROP_LIST // check if the literal l1 can be propagated if (onstack[l1] < 0 && W_unit[l1] + (TL)cost[n_assigned] >= (TL)bestCost) { onstack[l1] = propagation_stack_size; propagation_stack[propagation_stack_size++] = l1; } #endif rlist.addEntry(l1 - nVars); // add compensation clauses (-l1, l2, l3) and (l1, -l2, -l3) // also update the weights according to the new clauses nC[0] = -l1; nC[1] = l2; nC[2] = l3; W_binary[-nC[0]] -= minweight; W_binary[-nC[0]] -= minweight; W_binary[nC[1]] -= minweight; W_binary[-nC[1]] -= minweight; W_binary[nC[2]] -= minweight; W_binary[-nC[2]] -= minweight; W_large[nC[0]] += minweight; W_large[nC[1]] += minweight; W_large[nC[2]] += minweight; int c = all_clauses.addClause(nC, 3, minweight); take_back.push_back(c); do_insert(nC[0], c); do_insert(nC[1], c); do_insert(nC[2], c); rlist.addEntry(c); nC[0] = -nC[0]; nC[1] = -nC[1]; nC[2] = -nC[2]; W_large[nC[0]] += minweight; W_large[nC[1]] += minweight; W_large[nC[2]] += minweight; c = all_clauses.addClause(nC, 3, minweight); take_back.push_back(c); do_insert(nC[0], c); do_insert(nC[1], c); do_insert(nC[2], c); rlist.addEntry(c); rlist.commit(timestamp++, minweight, true); return true; } return false; } //! sort the appears list by weight of the clauses void do_sort(int i) { vector< pair > temp; temp.reserve(appears[i].size()); for (vector::const_iterator it=appears[i].begin(); it!=appears[i].end(); ++it) temp.push_back(make_pair(all_clauses.getWeight(*it), *it)); sort(temp.begin(), temp.end()); vector::iterator it2=appears[i].begin(); for (vector< pair >::iterator it=temp.begin(); it!=temp.end(); ++it) *it2++ = it->second; } //! check if literal L is a failed literal inline bool detectFailedLiteral(int L) { #ifdef DEBUG cout << "detectFailedLiteral L = " << L << endl; #endif // propagated literal L vars[++vars_top] = L; assert(literal_data[L] <= 0); literal_data[L] = UNIT_CLAUSE; if (propagateLiteral(-L)) return true; // continue propagation to see if propagating L results in a conflict // -> L is a failed literal while(head != tail) { int nexti = Q[head++]; assert(nexti != 0); assert(head < 2 * nVars); assert(literal_data[nexti] > 0); vars[++vars_top] = nexti; if (propagateLiteral(-nexti)) { // clear the queue while(head != tail) { if (Q[head] != -nexti) literal_data[Q[head]] = 0; ++head; } return true; } assert(literal_data[-nexti] <= 0); } return false; } //! resolution of clauses L and -L void unary_resolution(int L) { // this should usually be executed only once while(W_unit[L] > 0 && W_unit[-L] > 0) { ULL s; if (W_unit[-L] < W_unit[L]) s = (W_unit[-L] > (TL)MAXWEIGHT? MAXWEIGHT : (ULL)W_unit[-L]); else s = (W_unit[L] > (TL)MAXWEIGHT? MAXWEIGHT : (ULL)W_unit[L]); W_unit[L] -= s; W_unit[-L] -= s; W_unit_save[L] -= s; W_unit_save[-L] -= s; saveAddition(cost[n_assigned], s); saveSubtraction(needed_for_skip, s); rlist.addEntry(-L - nVars); rlist.addEntry(L - nVars); rlist.commit(timestamp++, s, false); } } //! check if there is a conflict using generalized unit propagation bool detectConflictFl(bool &fl, int &iv, int &iv2) { #ifdef DEBUG cout << "detectConflictFl" << endl; #endif head = tail = 0; int L, fL; fl = false; assert(vars_top == -1); int minii = l-1, minv = l-1; while(1) { bool found = false; // look for a literal in a unit clause // start at position iv2 for (int ii=0,tiv=iv2; !found && ii 0 && literal_data[i] <= 0) { Q[tail++] = i; literal_data[i] = UNIT_CLAUSE; found = true; break; } } // uncomment the following two lines if only unit propagation and failed literal detection should be used #ifdef NO_GUP if (!found && fl) break; #endif if (!found) { int save_head = head; int save_vars_top = vars_top; // look for a failed literal // start at position iv for (int ii=0, tiv=iv; !found && ii W_binary[i] || (W_binary[-i] == W_binary[i] && W_large[-i] > W_large[i])) i = -i; assert(!assigned_values[abs(i)]); minii = ii; if (literal_data[i] > 0 || literal_data[-i] > 0) continue; if (detectFailedLiteral(i)) { L = resolveFailedLiteral(save_vars_top); head = save_head; tail = head + 1; Q[head] = -L; assert(literal_data[-L] <= 0); literal_data[-L] = UNIT_CLAUSE; found = true; fl = true; fL = L; break; } assert(head == tail); head = tail = save_head; for (int *it=vars + vars_top; it > vars + save_vars_top; --it) { undoPropagateLiteral(-*it); literal_data[*it] = 0; } vars_top = save_vars_top; } if (!found) break; } // if we are here we have at least one literal to be propagated assert(tail <= 2 * nVars); oldtail = head; // propagate in breadth-first search order while(head != tail) { // for unit propagation, move a unit literal towards the front which yields an immediate conflict // first check that the literal at the front of the queue does not yield an immediate conflict if (!fl && W_unit[-Q[head]] == 0 && literal_data[-Q[head]] <= 0) { for (int i=head+1; i 0) { swap(Q[head], Q[i]); break; } } assert(oldtail == head); oldtail = tail; while(head != oldtail) { L = Q[head++]; assert(literal_data[L]); assert(!assigned_values[abs(L)]); vars[++vars_top] = L; if (propagateLiteral(-L)) { // this means a conflict was found // reset the literal_data array to 0 at positions still in the queue while(head != tail) { if (Q[head] != -L) literal_data[Q[head]] = 0; ++head; } iv -= (1+minii); if (iv < 0) iv += l; iv2 += minv+1; if (iv2 >= l) iv2 -= l; return true; } } } } assert(vars_top == -1 || literal_data[-vars[vars_top]] <= 0); assert(head == tail); // if we are here this means no conflict was found // undo the propagations for (int *it=vars + vars_top; it >= vars; --it) { undoPropagateLiteral(-*it); literal_data[*it] = 0; } for (int *it=vars; it<=vars+vars_top; ++it) { // check if we can apply cycle resolution if (unit_implication_list[-*it].size() >= 3) { int c1 = unit_implication_list[-*it][0]; if (c1 <= UNIT_CLAUSE || all_clauses.getDeleteFlag(c1)) { unit_implication_list[-*it].clear(); continue; } int c2 = unit_implication_list[-*it][1]; if (c2 <= UNIT_CLAUSE || all_clauses.getDeleteFlag(c2)) { unit_implication_list[-*it].clear(); continue; } int c3 = unit_implication_list[-*it][2]; if (c3 <= UNIT_CLAUSE || all_clauses.getDeleteFlag(c3)) { unit_implication_list[-*it].clear(); continue; } if (all_clauses.getLength(c1) == 2 && all_clauses.getLength(c2) == 2 && all_clauses.getLength(c3) == 2) { const int_c *literals1 = all_clauses.getLiterals(c1); const int_c *literals2 = all_clauses.getLiterals(c2); const int_c *literals3 = all_clauses.getLiterals(c3); // first find common literals in literals2 and literals3 int i1 = -1, i2; if (literals2[0] == literals3[0]) i1 = i2 = 0; else if (literals2[0] == literals3[1]) { i1 = 0; i2 = 1; } else if (literals2[1] == literals3[0]) { i1 = 1; i2 = 0; } else if (literals2[1] == literals3[1]) i1 = i2 = 1; if (i1 >= 0 && ((literals1[0] == -literals2[1-i1] && literals1[1] == -literals3[1-i2]) || (literals1[0] == -literals3[1-i2] && literals1[1] == -literals2[1-i1]))) { #ifdef DEBUG const int *literals = all_clauses.getLiterals(c1); printf("(%d %d) ", literals[0], literals[1]); literals = all_clauses.getLiterals(c2); printf("(%d %d) ", literals[0], literals[1]); literals = all_clauses.getLiterals(c3); printf("(%d %d) -> %d +-(%d %d %d)\n", literals[0], literals[1], literals2[i1], -literals2[i1], literals1[0], literals1[1]); #endif int other = literals2[i1]; if (process_cycle_clauses(c1, c2, c3, literals2[i1], literals1[0], literals1[1])) unary_resolution(other); } } } unit_implication_list[-*it].clear(); } cycle_clauses.clear(); take_back.clear(); vars_top = -1; return false; } //! resolve the conflict and extract inconsistent subformula void resolveConflictFl() { #ifdef DEBUG cout << "resolveConflictFl" << endl; #endif assert(vars_top >= 0); assert(literal_data[-vars[vars_top]] > 0); assert(take_back.empty()); // add the conflict clause to the inconsistent subformula to be constructed take_back.push_back(literal_data[-vars[vars_top]]); literal_data[-vars[vars_top]] = 0; int t, pos = 0; int_c c[3]; // set the marker to indicate it belongs to the inconsistent subformula if (take_back.back() != UNIT_CLAUSE) { all_clauses.addMarker2Clause(take_back.back()); c[pos++] = take_back.back(); } else { pos = -1; take_back.back() = -vars[vars_top] - nVars; assert(W_unit[-vars[vars_top]] > 0); } assert(which.empty()); // go through the propagation stack in reverse order // undo propagations, thereby checking if the clause was needed for deriving the conflict clause for (int *it=vars + vars_top; it >= vars; --it) { #ifdef DEBUG printf("cur = %d implication_list.size() = %d\n", *it, (int)unit_implication_list[-*it].size()); if (literal_data[*it] == 0) for (int i=0; i<=vars_top; ++i) printf("vars[%d] = %d %d\n", i, vars[i], (int)unit_implication_list[-vars[i]].size()); #endif assert(literal_data[*it] > 0); if ((t = addLiteralConflict(-*it))) { // t indicates the number of marked clauses which include literal -*it // this means that t > 0 implies the current clause is needed to derive the conflict clause if (literal_data[*it] != UNIT_CLAUSE) { assert(!all_clauses.getMarker(literal_data[*it])); all_clauses.addMarker2Clause(literal_data[*it]); take_back.push_back(literal_data[*it]); // collect the first three clauses to check for cycle resolution if (pos >= 0 && pos < 3) c[pos++] = take_back.back(); } else if (W_unit[*it] > 0) { if (pos < 3) pos = -1; take_back.push_back(*it - nVars); } else { if (pos < 3) pos = -1; assert(!unit_implication_list[-*it].empty()); which.push_back(-*it); for (vector::const_iterator it2=unit_implication_list[-*it].begin(); it2!=unit_implication_list[-*it].end(); ++it2) { assert(*it2 > UNIT_CLAUSE && !all_clauses.getDeleteFlag(*it2)); if (!all_clauses.getMarker(*it2)) { all_clauses.addMarker2Clause(*it2); take_back.push_back(*it2); } } } } literal_data[*it] = 0; } ULL minw = bestCost; for (vector::const_iterator it=take_back.begin(); it!=take_back.end(); ++it) if (*it <= 0) { if (W_unit[*it + nVars] < (TL)minw) minw = (ULL)W_unit[*it + nVars]; literal_data[*it + nVars] = 1; } else { assert(!all_clauses.getDeleteFlag(*it)); minw = min(minw, all_clauses.getWeight(*it)); all_clauses.removeMarkerFromClause(*it); } assert(minw > 0); // process unit implication lists belonging to the inconsistent subformula and look for clauses forming a cycle for (vector::const_reverse_iterator it=which.rbegin(); it!=which.rend(); ++it) { if (unit_implication_list[*it].size() >= 3) { // check if the three clauses form a cycle int c1 = unit_implication_list[*it][0]; if (c1 <= UNIT_CLAUSE || find(cycle_clauses.begin(), cycle_clauses.end(), c1)!=cycle_clauses.end()) { unit_implication_list[*it].clear(); continue; } int c2 = unit_implication_list[*it][1]; if (c2 <= UNIT_CLAUSE || find(cycle_clauses.begin(), cycle_clauses.end(), c2)!=cycle_clauses.end()) { unit_implication_list[*it].clear(); continue; } int c3 = unit_implication_list[*it][2]; if (c3 <= UNIT_CLAUSE || find(cycle_clauses.begin(), cycle_clauses.end(), c3)!=cycle_clauses.end()) { unit_implication_list[*it].clear(); continue; } if (all_clauses.getLength(c1) == 2 && all_clauses.getLength(c2) == 2 && all_clauses.getLength(c3) == 2) { const int_c *literals1 = all_clauses.getLiterals(c1); const int_c *literals2 = all_clauses.getLiterals(c2); const int_c *literals3 = all_clauses.getLiterals(c3); // first find common literals in literals2 and literals3 int i1 = -1, i2; if (literals2[0] == literals3[0]) i1 = i2 = 0; else if (literals2[0] == literals3[1]) { i1 = 0; i2 = 1; } else if (literals2[1] == literals3[0]) { i1 = 1; i2 = 0; } else if (literals2[1] == literals3[1]) i1 = i2 = 1; if (i1 >= 0 && ((literals1[0] == -literals2[1-i1] && literals1[1] == -literals3[1-i2]) || (literals1[0] == -literals3[1-i2] && literals1[1] == -literals2[1-i1]))) { int other = literals2[i1]; // do cycle resolution if (process_cycle_clauses(c1, c2, c3, literals2[i1], literals1[0], literals1[1])) { assert(W_unit[other] >= minw); literal_data[other] = 0; W_unit[other] -= minw; unary_resolution(other); } } } } unit_implication_list[*it].clear(); } sort(cycle_clauses.begin(), cycle_clauses.end()); // check if we can use cycle resolution if (pos == 3 && all_clauses.getLength(c[0]) == 2 && all_clauses.getLength(c[1]) == 2 && all_clauses.getLength(c[2]) == 2 && !binary_search(cycle_clauses.begin(), cycle_clauses.end(), c[0]) && !binary_search(cycle_clauses.begin(), cycle_clauses.end(), c[1]) && !binary_search(cycle_clauses.begin(), cycle_clauses.end(), c[2])) { const int_c *literals1 = all_clauses.getLiterals(c[0]); const int_c *literals2 = all_clauses.getLiterals(c[1]); const int_c *literals3 = all_clauses.getLiterals(c[2]); // first find common literals in literals2 and literals3 int i1 = -1, i2; if (literals2[0] == literals3[0]) i1 = i2 = 0; else if (literals2[0] == literals3[1]) { i1 = 0; i2 = 1; } else if (literals2[1] == literals3[0]) { i1 = 1; i2 = 0; } else if (literals2[1] == literals3[1]) i1 = i2 = 1; if (i1 >= 0 && ((literals1[0] == -literals2[1-i1] && literals1[1] == -literals3[1-i2]) || (literals1[0] == -literals3[1-i2] && literals1[1] == -literals2[1-i1]))) { int other = literals2[i1]; // do cycle resolution if (process_cycle_clauses(c[0], c[1], c[2], literals2[i1], literals1[0], literals1[1])) { assert(W_unit[other] >= minw); literal_data[other] = 0; W_unit[other] -= minw; unary_resolution(other); } } } sort(cycle_clauses.begin(), cycle_clauses.end()); which.clear(); // subtract minw from all clauses belonging to the inconsistent subformula for (vector::const_iterator it=take_back.begin(); it!=take_back.end(); ++it) if (*it <= 0) { if (literal_data[*it + nVars] == 1) { assert(W_unit[*it + nVars] >= minw); W_unit[*it + nVars] -= minw; literal_data[*it + nVars] = 0; } } else if (!binary_search(cycle_clauses.begin(), cycle_clauses.end(), *it)) { if (all_clauses.getWeight(*it) >= bestCost) continue; assert(all_clauses.getWeight(*it) >= minw); changed.push_back(*it); all_clauses.subtractWeight(*it, minw); if (all_clauses.getLength(*it) == 2) { const int *literals = all_clauses.getLiterals(*it); W_binary[literals[0]] -= minw; W_binary[literals[1]] -= minw; } else { const int *literals = all_clauses.getLiterals(*it); for (int i=all_clauses.getLength(*it)-1; i>=0; --i) W_large[literals[i]] -= minw; } } // now process all remaining unit implication lists and look for clauses forming a cycle for (int *it=vars+vars_top; it>=vars; --it) { // check if we can use cycle resolution if (unit_implication_list[-*it].size() >= 3) { int c1 = unit_implication_list[-*it][0]; if (c1 <= UNIT_CLAUSE || all_clauses.getDeleteFlag(c1)) { unit_implication_list[-*it].clear(); continue; } int c2 = unit_implication_list[-*it][1]; if (c2 <= UNIT_CLAUSE || all_clauses.getDeleteFlag(c2)) { unit_implication_list[-*it].clear(); continue; } int c3 = unit_implication_list[-*it][2]; if (c3 <= UNIT_CLAUSE || all_clauses.getDeleteFlag(c3)) { unit_implication_list[-*it].clear(); continue; } if (all_clauses.getLength(c1) == 2 && all_clauses.getLength(c2) == 2 && all_clauses.getLength(c3) == 2) { const int_c *literals1 = all_clauses.getLiterals(c1); const int_c *literals2 = all_clauses.getLiterals(c2); const int_c *literals3 = all_clauses.getLiterals(c3); // first find common literals in literals2 and literals3 int i1 = -1, i2; if (literals2[0] == literals3[0]) i1 = i2 = 0; else if (literals2[0] == literals3[1]) { i1 = 0; i2 = 1; } else if (literals2[1] == literals3[0]) { i1 = 1; i2 = 0; } else if (literals2[1] == literals3[1]) i1 = i2 = 1; if (i1 >= 0 && ((literals1[0] == -literals2[1-i1] && literals1[1] == -literals3[1-i2]) || (literals1[0] == -literals3[1-i2] && literals1[1] == -literals2[1-i1]))) { #ifdef DEBUG const int *literals = all_clauses.getLiterals(c1); printf("(%d %d) ", literals[0], literals[1]); literals = all_clauses.getLiterals(c2); printf("(%d %d) ", literals[0], literals[1]); literals = all_clauses.getLiterals(c3); printf("(%d %d) -> %d +-(%d %d %d)\n", literals[0], literals[1], literals2[i1], -literals2[i1], literals1[0], literals1[1]); #endif int other = literals2[i1]; if (process_cycle_clauses(c1, c2, c3, literals2[i1], literals1[0], literals1[1])) unary_resolution(other); } } } unit_implication_list[-*it].clear(); } cycle_clauses.clear(); take_back.clear(); vars_top = -1; saveSubtraction(needed_for_skip, minw); } //! extract clauses which are in conflict with the failed literal int resolveFailedLiteral(int save_vars_top) { #ifdef DEBUG cout << "resolveFailedLiteral" << endl; #endif assert(vars_top > save_vars_top); assert(literal_data[-vars[vars_top]] > 0); assert(which.empty()); which.push_back(literal_data[-vars[vars_top]]); #ifndef NDEBUG for (int *it=vars; it<=vars+vars_top; ++it) assert(*it != -vars[vars_top]); #endif literal_data[-vars[vars_top]] = 0; assert(which.back() != UNIT_CLAUSE); all_clauses.addMarker2Clause(which.back()); int t, var = 0, pos = 0; vector vars2; #ifdef FUIP int pos2 = 0; ref_cnt[0] = 0; #endif // process propagation stack in reverse order for (int *it=vars + vars_top; it > vars + save_vars_top; --it) { #ifdef DEBUG if (literal_data[*it] == 0) for (int i=0; i<=vars_top; ++i) printf("vars[%d] = %d\n", i, vars[i]); #endif assert(literal_data[*it] > 0); if ((t = addLiteralConflict(-*it))) { if (t > 1) { pos = which.size(); var = *it; } #ifdef FUIP vars2.push_back(*it); int cur = which.size(); ref_cnt[cur] = 0; for (vector::const_iterator it2=bla.begin(); it2!=bla.end(); ++it2) { int t = distance(which.begin(), find(which.begin(), which.end(), *it2)); tadj[cur].push_back(t); ++ref_cnt[t]; } #endif which.push_back(literal_data[*it]); assert(it == vars+save_vars_top+1 || literal_data[*it] != UNIT_CLAUSE); if (literal_data[*it] != UNIT_CLAUSE) { assert(!all_clauses.getMarker(literal_data[*it])); all_clauses.addMarker2Clause(literal_data[*it]); } else which.back() = *it - nVars; } literal_data[*it] = 0; } #ifdef FUIP int l2 = 0; for (int i=0; i<(int)which.size(); ++i) { if (ref_cnt[i] == 0) Q2[l2++] = i; visit2[i] = 0; } int work_cnt = 0; for (int i=0; i::const_iterator it=tadj[cur].begin(); it!=tadj[cur].end(); ++it) { if (!visit2[*it]) { ++work_cnt; visit2[*it] = 1; } if (--ref_cnt[*it] == 0) { Q2[l2++] = *it; --work_cnt; } } tadj[cur].clear(); } if (pos < (int)which.size()-1) ++total_cnt_fuip; if (pos < pos2) fprintf(stderr, "error: here with pos = %d, pos2 = %d\n", pos, pos2); else if (pos > pos2) { ++succ_cnt_fuip; } #endif // no FUIP - uncomment next line #ifdef NO_FUIP pos = which.size()-1; #endif assert(var != 0); assert(head == tail); vars_top = save_vars_top; assert(which.back() < UNIT_CLAUSE); assert(unit_implication_list[var].empty()); for (vector::const_iterator it=which.begin(); it+1 < which.end(); ++it) { assert(*it > UNIT_CLAUSE && all_clauses.getLength(*it) > 1 && all_clauses.getWeight(*it) > 0); all_clauses.removeMarkerFromClause(*it); } which.resize(pos); unit_implication_list[var] = which; which.clear(); return var; } double clause_height(int start, int skip, int satisfied) { double wa = (double)psi[start++]; int len = (int)psi[start++] * 2; double potential = 0; for (int i=0; i difference) return wa - potential - difference; return -potential; } //! generalized unit propagation to find inconsistent subformulas void generalized_unit_propagation() { l = 0; for (int i=1; i<=nVars; ++i) { if (!assigned_values[i]) { literal_order[l].second = i; literal_order[l].first = (W_binary[i] + W_large[i]) * (W_binary[-i] + W_large[-i]); ++l; } } sort(literal_order, literal_order + l); bool fl; int iv = l-1, iv2 = l/2; while(needed_for_skip > 0) { if (!detectConflictFl(fl, iv, iv2)) break; // check if failed literals were used; if not, transformation rules can possibly be applied fl?resolveConflictFl():resolveConflict(); } ++total_gup; if (!needed_for_skip) { ++succ_gup; return; } #ifdef CALC_MH reverse(literal_order, literal_order+l); psi.clear(); for (int ii=0; ii 0) { ++c; ++c2; ptr[i].push_back(psi.size()+2); ptr[i].push_back(psi.size()); psi.push_back(W_unit[i]); psi.push_back(1); psi.push_back(0); psi.push_back(0); } if (W_unit[-i] > 0) { ++c; ++c2; ptr[i].push_back(psi.size()+3); ptr[i].push_back(psi.size()); psi.push_back(W_unit[-i]); psi.push_back(1); psi.push_back(0); psi.push_back(0); } for (vector::iterator it=appears[i].begin(); it!=appears[i].end(); ++it) { if (all_clauses.getDeleteFlag(*it)) continue; ++c; const int_c *literals = all_clauses.getLiterals(*it); if (*literals != i) continue; ++c2; int start = psi.size(); psi.push_back(all_clauses.getWeight(*it)); psi.push_back(all_clauses.getLength(*it)); for (int j=all_clauses.getLength(*it)-1; j>=0; --j) { int ii = abs(literals[j]); ptr[ii].push_back(psi.size() + (literals[j] < 0)); ptr[ii].push_back(start); psi.push_back(0); psi.push_back(0); } } for (vector::iterator it=appears[-i].begin(); it!=appears[-i].end(); ++it) { if (all_clauses.getDeleteFlag(*it)) continue; ++c; const int_c *literals = all_clauses.getLiterals(*it); if (*literals != -i) continue; ++c2; int start = psi.size(); psi.push_back(all_clauses.getWeight(*it)); psi.push_back(all_clauses.getLength(*it)); for (int j=all_clauses.getLength(*it)-1; j>=0; --j) { int ii = abs(literals[j]); ptr[ii].push_back(psi.size() + (literals[j] < 0)); ptr[ii].push_back(start); psi.push_back(0); psi.push_back(0); } } } if ((c+c2)*2 != (int)psi.size()) printf("%d %d\n", (c+c2)*2, (int)psi.size()); bool stop = false; vector old; int iter = 0; double maxdiff; while(!stop && (iter++<100 || (!n_assigned && iter++<1000))) { stop = true; maxdiff = 1e-6; for (int ii=0; ii::iterator it=ptr[i].begin(); it!=ptr[i].end(); ++it) { int isneg = (*it & 1); int p = *it++ - isneg; old.push_back(psi[p]); old.push_back(psi[p + 1]); psi[p] = clause_height(*it, p, 1); psi[p + 1] = clause_height(*it, p, 0); if (isneg) { m1 += psi[p + 1]; m2 += psi[p]; } else { m1 += psi[p]; m2 += psi[p + 1]; } } m1 /= (ptr[i].size()/2); m2 /= (ptr[i].size()/2); vector::iterator it2 = old.begin(); double sum1 = 0, sum2 = 0; for (vector::iterator it=ptr[i].begin(); it!=ptr[i].end(); ++it) { int isneg = (*it & 1); int p = *it++ - isneg; if (isneg) { psi[p+1] -= m1; psi[p] -= m2; sum1 += psi[p+1]; sum2 += psi[p]; } else { psi[p] -= m1; psi[p + 1] -= m2; sum1 += psi[p]; sum2 += psi[p+1]; } if (fabs(psi[p] - *it2) > maxdiff) { maxdiff = fabs(psi[p]- *it2); stop = false; } ++it2; if (fabs(psi[p + 1] - *it2) > maxdiff) { maxdiff = fabs(psi[p + 1] - *it2); stop = false; } ++it2; } if (fabs(sum1) > 1e-7 || fabs(sum2) > 1e-7) { printf("%lf %lf\n", sum1, sum2); exit(1); } } } double lb = 0; for (int i=0; i<(int)psi.size();) { lb += psi[i] - clause_height(i, -1, 0); i += psi[i+1] * 2 + 2; } lb = ceil(lb - 1e-9); if (lb >= needed_for_skip) { // printf("success in depth %d\n", n_assigned); needed_for_skip = 0; return; } if (n_assigned == 0) printf("%lf iter=%d maxdiff=%lf\n", lb, iter, maxdiff); needed_for_skip -= (long long)lb; #endif #ifndef NDEBUG for (int i=1; i<=nVars; ++i) assert(literal_data[i] == 0 && literal_data[-i] == 0); #endif } // public functions public: //! CNF_Formula constructor /*! \param istr the input stream from which the formula can be read */ CNF_Formula(istream &istr) { total_gup = succ_gup = 0; string line; int nClauses, t = 0; char type[100]; // parse the input file while(getline(istr, line)) { // look for the parameter line if (line[0] == 'p' && line[1] == ' ') { t = sscanf(line.c_str(), "p %s %d %d %llu", type, &maxVn, &nClauses, &hard); if (t >= 3) break; } } if (t < 3) fprintf(stderr, "Parse error: did not find the parameter line\n"); assert(t >= 3); if (t == 3 || !hard) hard = MAXWEIGHT; // check if the formula contains weighted clauses or not if (!strcmp(type, "wcnf")) isWcnf = true; else { assert(!strcmp(type, "cnf")); isWcnf = false; } vector lengths, literals; vector weights; maps_to = new int[maxVn + 1]; memset(maps_to, -1, sizeof(int) * (maxVn + 1)); nVars = 0; int var; // read the clauses and construct the formula data structures for (int i=0; i clause; ULL weight = 1; if (isWcnf) { // read the weight istr >> weight; assert(weight > 0 && weight <= MAXWEIGHT); } // read the literals in the clause while(istr >> var && var) clause.push_back(var); // now remove duplicate literals, and check if the clause is a tautology if (normalize_clause_array(clause)) { // if it is not a tautology, store the clause data for (vector::iterator it=clause.begin(); it!=clause.end(); ++it) { int sign = 1; int var = *it; if (var < 0) { var = -var; sign = -1; } // remap the variables to values between 1 and nVars if (maps_to[var] < 0) { ++nVars; maps_to[var] = nVars; } // first, all literals from all clauses are put into the literals vector literals.push_back(maps_to[var] * sign); } // store the number of literals in the current clause lengths.push_back((int)clause.size()); // store the weight of the clause weights.push_back(weight); } // in this case the clause is a tautology and can be ignored else { --i; --nClauses; } } if (nVars != maxVn) printf("c Number of variables occuring in the formula: %d max variable = %d -> remapping\n", nVars, maxVn); // store in mapping the original variable number of each new variable mapping = new int[nVars + 1]; #ifdef STATS explored = new int[nVars + 1]; sum_cost = new long long[nVars + 1]; memset(explored, 0, sizeof(int) * (nVars+1)); memset(sum_cost, 0, sizeof(long long) * (nVars + 1)); #endif for (int i=1; i<=maxVn; ++i) { if (maps_to[i] < 0) continue; assert(maps_to[i] > 0 && maps_to[i] <= nVars); mapping[maps_to[i]] = i; } vars_top = -1; #ifdef FUIP tadj = new vector[2*nVars]; succ_cnt_fuip = total_cnt_fuip = 0; ref_cnt = new int[2*nVars]; Q2 = new int[2*nVars]; visit2 = new char[2*nVars]; #endif ptr = new vector[2 * nVars + 1]; vars = new int[2 * nVars]; Q = new int[2 * nVars]; cost = new ULL[nVars + 1]; cost[0] = 0; #ifdef PROP_LIST propagation_stack = new int[nVars * 2]; propagation_stack_size = 0; onstack = new int[nVars * 2 + 1]; memset(onstack, -1, sizeof(int) * (2 * nVars + 1)); onstack += nVars; #endif W_unit = new TL[2 * nVars + 1]; W_binary = new TL[2 * nVars + 1]; W_large = new TL[2 * nVars + 1]; W_lb = new TL[2 * nVars + 1]; W_unit_save = new TL[2 * nVars + 1]; memset(W_unit, 0, sizeof(TL) * (2 * nVars + 1)); memset(W_binary, 0, sizeof(TL) * (2 * nVars + 1)); memset(W_large, 0, sizeof(TL) * (2 * nVars + 1)); memset(W_unit_save, 0, sizeof(TL) * (2 * nVars + 1)); literal_data = new int[2 * nVars + 1]; ternary_clause_data = (nVars > 5000? NULL : new int[(2 * nVars + 1) * (2 * nVars + 1)]); literal_order = new pair [2 * nVars]; memset(literal_data, 0, sizeof(int) * (2 * nVars + 1)); appears = new vector[2 * nVars + 1]; unit_implication_list = new vector[2 * nVars + 1]; appears_len = new int[2 * nVars + 1]; memset(appears_len, 0, sizeof(int) * (2 * nVars + 1)); appears_len += nVars; appears_traversed = new long long[2 * nVars + 1]; memset(appears_traversed, -1, sizeof(long long) * (2 * nVars + 1)); if (ternary_clause_data != NULL) memset(ternary_clause_data, 0, sizeof(int) * (2 * nVars + 1) * (2 * nVars + 1)); assigned_values = new char[nVars + 1]; bestA = new char[nVars + 1]; memset(assigned_values, 0, sizeof(char)* (nVars + 1)); memset(bestA, 0, sizeof(char) * (nVars + 1)); assigned_literals = new int[nVars + 1]; // since we want to index with values in the range [-nVars, nVars], add +nVars to the pointers W_unit += nVars; W_binary += nVars; W_large += nVars; W_unit_save += nVars; W_lb += nVars; appears += nVars; unit_implication_list += nVars; appears_traversed += nVars; literal_data += nVars; n_assigned = 0; timestamp = 0; assert(nClauses == (int)lengths.size()); assert(nClauses == (int)weights.size()); // initialize additional variables of the clauses data structure all_clauses.init(nVars); vector::iterator it=literals.begin(); // construct the formula data structures for (int i=0; i UNIT_CLAUSE); assert(all_clauses.getLength(clause_id) == len); // add clause pointers to the appears array for (int j=0; j 2) W_large[clause_array[j]] += weight; ++appears_len[clause_array[j]]; appears[clause_array[j]].push_back(clause_id); } delete [] clause_array; } bestCost = hard; assert(it >= literals.end()); for (int i=1; i<=nVars; ++i) { do_sort(i); do_sort(-i); } } //! get the weight of clauses containing i used in inconsistent subformulas /*! \param i the literal for which the weight should be returned */ inline TL getW_lb(int i) const { return W_lb[i]; } //! get number of variables inline int getNVars() const { return nVars; } //! get the type of the instance inline bool isWeighted() const { return isWcnf; } //! print the optimal solution in the maxsat evaluation format inline void printSolution() const { printf("c total generalized unit propagation = %d, success = %.2lf%%\n", total_gup, 100.0*succ_gup/total_gup); #ifdef STATS printf("c number of nodes expanded per level:\n"); for (int i=1; i<=nVars; ++i) { if (explored[i] > 0) printf("c depth %d: %d %lld\n", i, explored[i], sum_cost[i]/explored[i]); } #endif if (bestCost == hard) { puts("s UNSATISFIABLE"); return; } // we assume here that printSolution is only called at the end puts("s OPTIMUM FOUND"); printf("c Optimal Solution = %llu\nv", bestCost); int j = 0; set used; for (int i=1; i<=nVars; ++i) used.insert(mapping[i]); for (int i=1; i<=maxVn; ++i) // if variable i did not occur in the formula, assign it to true if (used.find(i) == used.end()) printf(" %d", i); // otherwise take sign from the best assignment found (bestA) else { ++j; assert(j <= nVars); printf(" %d", (int)bestA[j] * mapping[j]); } assert(j == nVars); putchar('\n'); } //! get number of clauses of literal L /*! \param L literal to which the number of clauses should be returned */ inline TL getLength(int L) const { assert(!assigned_values[abs(L)]); #ifndef NDEBUG TL sum = 0; for (vector::const_iterator it=appears[L].begin(); it!=appears[L].end(); ++it) if (all_clauses.getDeleteFlag(*it) == false && all_clauses.getLength(*it) > 1) sum += all_clauses.getWeight(*it); assert(sum == W_binary[L] + W_large[L]); #endif return W_large[L] + W_binary[L] + W_unit[L]; } //! get number of unit clauses involving literal L /*! \param L literal L */ inline TL getUnitLength(int L) const { assert(W_unit[L] >= 0); return W_unit[L]; } //! get number of binary clauses involving literal L /*! \param L literal L */ inline TL getBinaryLength(int L) const { #ifndef NDEBUG TL sum = 0; for (vector::const_iterator it=appears[L].begin(); it!=appears[L].end(); ++it) if (!all_clauses.getDeleteFlag(*it) && all_clauses.getLength(*it) == 2) sum += all_clauses.getWeight(*it); assert(W_binary[L] == sum); #endif return W_binary[L]; } //! check if an assignment of L exceeds bestCost /*! \param L the literal to be checked * \returns true iff assignment of L leads to costs < bestCost */ inline bool assignmentPossible(int L) const { return (TL)cost[n_assigned] + W_unit[-L] < (TL)bestCost; } //! assign literal L the value true /*! \param L literal to be assigned * \returns true iff assignment does not lead to costs >= bestCost */ inline bool assignLiteral(int L) { if (!assignmentPossible(L)) return false; #ifdef DEBUG cout << "assign literal " << L << endl; #endif assert(-nVars <= L && L <= nVars && L != 0 && assigned_values[abs(L)] == 0); assert(W_unit[-L] == W_unit_save[-L]); cost[n_assigned+1] = cost[n_assigned] + (ULL)W_unit[-L]; deleteFulfilled(L); // remove literal -L from clauses assigned_values[abs(L)] = L > 0? 1 : -1; assigned_literals[n_assigned++] = L; all_clauses.assignVariable(-L); removeLiteral(-L); #ifdef STATS ++explored[n_assigned]; sum_cost[n_assigned] += cost[n_assigned]; if (n_assigned == nVars) { int mexpl = 0; for (int i=1; i<=nVars; ++i) { if (explored[i] >= explored[mexpl]) mexpl = i; /* if (explored[i] > 0) printf("c depth %d: %d %llu\n", i, explored[i], sum_cost[i]/explored[i]); */ } printf("c maximum explored in depth %d\n", mexpl); // for (int i=1; i<=nVars; ++i) // sum_cost[i] = explored[i] = 0; } #endif // is it a complete assignment? if (n_assigned == nVars) { memcpy(bestA, assigned_values, sizeof(char) * (nVars + 1)); bestCost = cost[n_assigned]; printf("o %llu\n", bestCost); // for debugging reasons one may print intermediate solutions // printSolution(); fflush(stdout); } return true; } //! unassign literal V /*! \param L literal which is reset */ void unassignLiteral() { assert(n_assigned > 0); int L = assigned_literals[n_assigned-1]; #ifdef DEBUG cout << "unassign literal " << L << endl; #endif restoreClauses(L); --n_assigned; assigned_values[abs(L)] = 0; assert(appears_len[L] == (int)appears[L].size()); // add literal -L back to clauses addLiteral(-L); // remove delete flag from clauses which become unfulfilled for (vector::const_iterator it=appears[L].begin(); it!=appears[L].end(); ++it) { int l = all_clauses.getLength(*it); if (l == 1) { assert(!all_clauses.getDeleteFlag(*it)); continue; } assert(l > 1); assert(all_clauses.getDeleteFlag(*it)); assert(!all_clauses.getSpecialFlag(*it)); const int_c *literals = all_clauses.getLiterals(*it); assert(all_clauses.getWeight(*it) > 0); if (l == 2) { W_binary[literals[0]] += all_clauses.getWeight(*it); W_binary[literals[1]] += all_clauses.getWeight(*it); } else if (l >= 3) { ULL w = all_clauses.getWeight(*it); for (int i=0; i::const_iterator it2=appears[literals[i]].begin(); it2!=appears[literals[i]].end(); ++it2) if (*it2 == *it) { found = true; break; } #endif assert(appears_len[literals[i]] == (int)appears[literals[i]].size()); if (appears_traversed[literals[i]] > appears_traversed[L]) { #ifndef NDEBUG if (found) printf("%d %llu %lld %lld\n", l, all_clauses.getWeight(*it), appears_traversed[literals[i]], appears_traversed[L]); assert(!found); #endif appears[literals[i]].push_back(*it); ++appears_len[literals[i]]; } #ifndef NDEBUG else assert(found); #endif } } } //! compute lower bound (plus inference rules) /*! \returns true iff lower bound plus current cost exceeds the best solution * \remark cost may be increased resulting from formula transformations with inference rules */ ULL bestMinusLowerBound() { #ifdef RBFS if (n_assigned == nVars) return cost[n_assigned]; needed_for_skip = MAXWEIGHT - cost[n_assigned]; #else needed_for_skip = bestCost - cost[n_assigned]; #endif changed.clear(); assert(n_assigned < nVars); if (!needed_for_skip) return 0; ++timestamp; #ifdef DEBUG cout << "compute lower bound" << endl; #endif #ifndef NDEBUG for (int i=1; i<=nVars; ++i) if (!assigned_values[i]) assert(literal_data[i] <= 0 && literal_data[-i] <= 0); #endif // binary resolution of clauses (i, x) and (-i, x) // ternary resolution of clauses (i, x, y) (-i, x, y) for (int i=1; i<=nVars; ++i) { if (assigned_values[i]) continue; W_lb[i] = W_lb[-i] = 0; assert(W_unit[i] == W_unit_save[i]); // if (n_assigned <= nVars/3) { W_unit[i] += binary_ternary_resolution(i); #ifdef PROP_LIST // check if the literal i can be propagated if (onstack[i] < 0 && W_unit[i] + (TL)cost[n_assigned] >= (TL)bestCost) { onstack[i] = propagation_stack_size; propagation_stack[propagation_stack_size++] = i; } #endif assert(W_unit[-i] == W_unit_save[-i]); W_unit[-i] += binary_ternary_resolution(-i); #ifdef PROP_LIST // check if the literal -i can be propagated if (onstack[-i] < 0 && W_unit[i] + (TL)cost[n_assigned] >= (TL)bestCost) { onstack[-i] = propagation_stack_size; propagation_stack[propagation_stack_size++] = -i; } #endif // } } // now save information to be able to restore the old clause data // if (n_assigned <= nVars/3) for (int i=1; i<=nVars && needed_for_skip > 0; ++i) { if (assigned_values[i]) continue; TL mw = min(W_unit[i], W_unit[-i]); TL t1 = W_unit[i] - W_unit_save[i]; TL t2 = W_unit[-i] - W_unit_save[-i]; if (mw > 0) { saveAddition(cost[n_assigned], mw); saveSubtraction(needed_for_skip, mw); W_unit[i] -= mw; W_unit[-i] -= mw; } TL diff; if (mw != t1) { bool sign = false; if (mw > t1) diff = mw - t1; else { diff = t1 - mw; sign = true; } while(diff > 0) { TL t = min(diff, (TL)MAXWEIGHT); diff -= t; rlist.addEntry(i - nVars); rlist.commit(timestamp++, (ULL)t, sign); } } if (mw != t2) { bool sign = false; if (mw > t2) diff = mw - t2; else { diff = t2 - mw; sign = true; } while(diff > 0) { TL t = min(diff, (TL)MAXWEIGHT); diff -= t; rlist.addEntry(-i - nVars); rlist.commit(timestamp++, (ULL)t, sign); } } W_unit_save[i] = W_unit[i]; W_unit_save[-i] = W_unit[-i]; } // now use generalized unit propagation to increase the lower bound if (needed_for_skip > 0) generalized_unit_propagation(); // go through all changed clauses and reset their weights which were possibly changed by the generalized unit propagation ULL diff; for (vector::const_iterator it=changed.begin(); it!=changed.end(); ++it) { if ((diff = all_clauses.getSavedWeight(*it)-all_clauses.getWeight(*it)) == 0) continue; const int_c *literals = all_clauses.getLiterals(*it); assert(*literals >= -nVars && *literals <= nVars && *literals != 0); // reset weight assert(diff > 0); if (all_clauses.getLength(*it) == 2) { W_binary[literals[0]] += diff; W_binary[literals[1]] += diff; W_lb[literals[0]] += diff; W_lb[literals[1]] += diff; } else { for (int j=all_clauses.getLength(*it)-1; j>=0; --j) { W_large[literals[j]] += diff; W_lb[literals[j]] += diff; } } all_clauses.resetWeight(*it); assert(!all_clauses.getDeleteFlag(*it)); } ULL ret = needed_for_skip; for (int i=1; i<=nVars; ++i) { if (assigned_values[i]) continue; #ifndef NDEBUG for (vector::const_iterator it=appears[i].begin(); it!=appears[i].end(); ++it) assert(all_clauses.getSavedWeight(*it) == all_clauses.getWeight(*it)); for (vector::const_iterator it=appears[-i].begin(); it!=appears[-i].end(); ++it) assert(all_clauses.getSavedWeight(*it) == all_clauses.getWeight(*it)); #endif if (appears_len[i] < (int)appears[i].size()) { reverse(appears[i].begin() + appears_len[i], appears[i].end()); appears_len[i] = appears[i].size(); } if (appears_len[-i] < (int)appears[-i].size()) { reverse(appears[-i].begin() + appears_len[-i], appears[-i].end()); appears_len[-i] = appears[-i].size(); } W_lb[i] += W_unit_save[i] - W_unit[i]; W_lb[-i] += W_unit_save[-i] - W_unit[-i]; W_unit[i] = W_unit_save[i]; assert(W_unit[i] >= 0); W_unit[-i] = W_unit_save[-i]; assert(W_unit[-i] >= 0); // it may be possible that we still can do unary resolution here unary_resolution(i); } if (n_assigned == 0) printf("c first lower bound: %llu\n", (unsigned long long)(bestCost - ret)); #ifdef RBFS return MAXWEIGHT - ret; #endif return ret; } //! CNF_Formula destructor ~CNF_Formula() { #ifdef DEBUG printf("c finished with timestamp %lld\n", timestamp); #endif #ifdef FUIP printf("c fuip statistics: %.2lf%% cases had improvements\n", (100.0*succ_cnt_fuip)/total_cnt_fuip); delete [] tadj; delete [] visit2; delete [] Q2; delete [] ref_cnt; #endif #ifdef STATS delete [] sum_cost; delete [] explored; #endif // subtract nVars to get to the beginning of the arrays W_unit -= nVars; W_binary -= nVars; W_large -= nVars; W_unit_save -= nVars; appears -= nVars; unit_implication_list -= nVars; appears_traversed -= nVars; literal_data -= nVars; W_lb -= nVars; appears_len -= nVars; // delete all arrays delete [] appears_len; delete [] vars; delete [] Q; delete [] literal_order; delete [] literal_data; delete [] ternary_clause_data; delete [] assigned_values; delete [] W_binary; delete [] W_large; delete [] W_unit_save; delete [] appears_traversed; delete [] appears; delete [] unit_implication_list; delete [] assigned_literals; delete [] W_unit; delete [] mapping; delete [] maps_to; delete [] bestA; delete [] W_lb; delete [] cost; #ifdef PROP_LIST onstack -= nVars; delete [] onstack; delete [] propagation_stack; #endif } inline ULL getHardWeight() const { return hard; } //! return the best cost of a complete assignment found so far inline ULL getBestCost() const { return bestCost; } //! initialize the best assignment to the assignment of besta inline void saveBest(ULL best, char *besta) { assert(best <= bestCost); bestCost = best; for (int i=1; i<=maxVn; ++i) if (maps_to[i] > 0) bestA[maps_to[i]] = besta[i]; } #ifdef PROP_LIST //! check if a literal can be propagated because there is a hard unit clause inline int propagateLiteral() { int L; // check the literals on the propagation stack if they can still be propagated while(propagation_stack_size > 0) { // remove the top literal L = propagation_stack[propagation_stack_size-1]; --propagation_stack_size; onstack[L] = -1; if ((TL)W_unit[L] + (TL)cost[n_assigned] >= (TL)bestCost/* || getLength(-L) <= W_unit[L]*/) { assert(!assigned_values[abs(L)]); return L; } } return 0; } #endif }; #endif akmaxsat_1.1/COPYRIGHT0000600000176000017530000010451311516041454015107 0ustar kuegelmitarbeiter GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . akmaxsat_1.1/Doxyfile0000600000176000017530000002366311516041436015330 0ustar kuegelmitarbeiter# Doxyfile 1.5.0 #--------------------------------------------------------------------------- # Project related configuration options #--------------------------------------------------------------------------- PROJECT_NAME = akmaxsat PROJECT_NUMBER = 0.1 OUTPUT_DIRECTORY = /home/kuegel/maxsat/akmaxsat CREATE_SUBDIRS = NO OUTPUT_LANGUAGE = English USE_WINDOWS_ENCODING = NO BRIEF_MEMBER_DESC = YES REPEAT_BRIEF = YES ABBREVIATE_BRIEF = "The $name class" \ "The $name widget" \ "The $name file" \ is \ provides \ specifies \ contains \ represents \ a \ an \ the ALWAYS_DETAILED_SEC = NO INLINE_INHERITED_MEMB = NO FULL_PATH_NAMES = YES STRIP_FROM_PATH = /home/kuegel/maxsat/akmaxsat/ STRIP_FROM_INC_PATH = SHORT_NAMES = NO JAVADOC_AUTOBRIEF = NO MULTILINE_CPP_IS_BRIEF = NO DETAILS_AT_TOP = NO INHERIT_DOCS = YES SEPARATE_MEMBER_PAGES = NO TAB_SIZE = 8 ALIASES = OPTIMIZE_OUTPUT_FOR_C = NO OPTIMIZE_OUTPUT_JAVA = NO BUILTIN_STL_SUPPORT = NO DISTRIBUTE_GROUP_DOC = NO SUBGROUPING = YES #--------------------------------------------------------------------------- # Build related configuration options #--------------------------------------------------------------------------- EXTRACT_ALL = NO EXTRACT_PRIVATE = YES EXTRACT_STATIC = NO EXTRACT_LOCAL_CLASSES = YES EXTRACT_LOCAL_METHODS = NO HIDE_UNDOC_MEMBERS = YES HIDE_UNDOC_CLASSES = YES HIDE_FRIEND_COMPOUNDS = NO HIDE_IN_BODY_DOCS = NO INTERNAL_DOCS = NO CASE_SENSE_NAMES = YES HIDE_SCOPE_NAMES = NO SHOW_INCLUDE_FILES = NO INLINE_INFO = YES SORT_MEMBER_DOCS = YES SORT_BRIEF_DOCS = NO SORT_BY_SCOPE_NAME = NO GENERATE_TODOLIST = YES GENERATE_TESTLIST = YES GENERATE_BUGLIST = YES GENERATE_DEPRECATEDLIST= YES ENABLED_SECTIONS = MAX_INITIALIZER_LINES = 30 SHOW_USED_FILES = YES SHOW_DIRECTORIES = NO FILE_VERSION_FILTER = #--------------------------------------------------------------------------- # configuration options related to warning and progress messages #--------------------------------------------------------------------------- QUIET = NO WARNINGS = YES WARN_IF_UNDOCUMENTED = YES WARN_IF_DOC_ERROR = YES WARN_NO_PARAMDOC = NO WARN_FORMAT = "$file:$line: $text" WARN_LOGFILE = #--------------------------------------------------------------------------- # configuration options related to the input files #--------------------------------------------------------------------------- INPUT = /home/kuegel/maxsat/akmaxsat FILE_PATTERNS = *.c \ *.cc \ *.cxx \ *.cpp \ *.c++ \ *.d \ *.java \ *.ii \ *.ixx \ *.ipp \ *.i++ \ *.inl \ *.h \ *.hh \ *.hxx \ *.hpp \ *.h++ \ *.idl \ *.odl \ *.cs \ *.php \ *.php3 \ *.inc \ *.m \ *.mm \ *.dox \ *.py \ *.C \ *.CC \ *.C++ \ *.II \ *.I++ \ *.H \ *.HH \ *.H++ \ *.CS \ *.PHP \ *.PHP3 \ *.M \ *.MM \ *.PY RECURSIVE = NO EXCLUDE = EXCLUDE_SYMLINKS = NO EXCLUDE_PATTERNS = EXAMPLE_PATH = EXAMPLE_PATTERNS = * EXAMPLE_RECURSIVE = NO IMAGE_PATH = INPUT_FILTER = FILTER_PATTERNS = FILTER_SOURCE_FILES = NO #--------------------------------------------------------------------------- # configuration options related to source browsing #--------------------------------------------------------------------------- SOURCE_BROWSER = NO INLINE_SOURCES = NO STRIP_CODE_COMMENTS = YES REFERENCED_BY_RELATION = NO REFERENCES_RELATION = NO REFERENCES_LINK_SOURCE = YES USE_HTAGS = NO VERBATIM_HEADERS = NO #--------------------------------------------------------------------------- # configuration options related to the alphabetical class index #--------------------------------------------------------------------------- ALPHABETICAL_INDEX = NO COLS_IN_ALPHA_INDEX = 5 IGNORE_PREFIX = #--------------------------------------------------------------------------- # configuration options related to the HTML output #--------------------------------------------------------------------------- GENERATE_HTML = YES HTML_OUTPUT = html HTML_FILE_EXTENSION = .html HTML_HEADER = HTML_FOOTER = HTML_STYLESHEET = HTML_ALIGN_MEMBERS = YES GENERATE_HTMLHELP = NO CHM_FILE = HHC_LOCATION = GENERATE_CHI = NO BINARY_TOC = NO TOC_EXPAND = NO DISABLE_INDEX = NO ENUM_VALUES_PER_LINE = 4 GENERATE_TREEVIEW = YES TREEVIEW_WIDTH = 250 #--------------------------------------------------------------------------- # configuration options related to the LaTeX output #--------------------------------------------------------------------------- GENERATE_LATEX = YES LATEX_OUTPUT = latex LATEX_CMD_NAME = latex MAKEINDEX_CMD_NAME = makeindex COMPACT_LATEX = NO PAPER_TYPE = a4wide EXTRA_PACKAGES = LATEX_HEADER = PDF_HYPERLINKS = NO USE_PDFLATEX = YES LATEX_BATCHMODE = NO LATEX_HIDE_INDICES = NO #--------------------------------------------------------------------------- # configuration options related to the RTF output #--------------------------------------------------------------------------- GENERATE_RTF = NO RTF_OUTPUT = rtf COMPACT_RTF = NO RTF_HYPERLINKS = NO RTF_STYLESHEET_FILE = RTF_EXTENSIONS_FILE = #--------------------------------------------------------------------------- # configuration options related to the man page output #--------------------------------------------------------------------------- GENERATE_MAN = NO MAN_OUTPUT = man MAN_EXTENSION = .3 MAN_LINKS = NO #--------------------------------------------------------------------------- # configuration options related to the XML output #--------------------------------------------------------------------------- GENERATE_XML = NO XML_OUTPUT = xml XML_SCHEMA = XML_DTD = XML_PROGRAMLISTING = YES #--------------------------------------------------------------------------- # configuration options for the AutoGen Definitions output #--------------------------------------------------------------------------- GENERATE_AUTOGEN_DEF = NO #--------------------------------------------------------------------------- # configuration options related to the Perl module output #--------------------------------------------------------------------------- GENERATE_PERLMOD = NO PERLMOD_LATEX = NO PERLMOD_PRETTY = YES PERLMOD_MAKEVAR_PREFIX = #--------------------------------------------------------------------------- # Configuration options related to the preprocessor #--------------------------------------------------------------------------- ENABLE_PREPROCESSING = YES MACRO_EXPANSION = NO EXPAND_ONLY_PREDEF = NO SEARCH_INCLUDES = YES INCLUDE_PATH = INCLUDE_FILE_PATTERNS = PREDEFINED = EXPAND_AS_DEFINED = SKIP_FUNCTION_MACROS = YES #--------------------------------------------------------------------------- # Configuration::additions related to external references #--------------------------------------------------------------------------- TAGFILES = GENERATE_TAGFILE = ALLEXTERNALS = NO EXTERNAL_GROUPS = YES PERL_PATH = /usr/bin/perl #--------------------------------------------------------------------------- # Configuration options related to the dot tool #--------------------------------------------------------------------------- CLASS_DIAGRAMS = YES HIDE_UNDOC_RELATIONS = YES HAVE_DOT = NO CLASS_GRAPH = YES COLLABORATION_GRAPH = YES GROUP_GRAPHS = YES UML_LOOK = NO TEMPLATE_RELATIONS = NO INCLUDE_GRAPH = YES INCLUDED_BY_GRAPH = YES CALL_GRAPH = NO CALLER_GRAPH = NO GRAPHICAL_HIERARCHY = YES DIRECTORY_GRAPH = YES DOT_IMAGE_FORMAT = png DOT_PATH = DOTFILE_DIRS = MAX_DOT_GRAPH_WIDTH = 1024 MAX_DOT_GRAPH_HEIGHT = 1024 MAX_DOT_GRAPH_DEPTH = 1000 DOT_TRANSPARENT = NO DOT_MULTI_TARGETS = NO GENERATE_LEGEND = YES DOT_CLEANUP = YES #--------------------------------------------------------------------------- # Configuration::additions related to the search engine #--------------------------------------------------------------------------- SEARCHENGINE = NO akmaxsat_1.1/FILE-FORMAT0000600000176000017530000001471411516041467015253 0ustar kuegelmitarbeiterInput format The input file must be read from the file given in parameter. For example: ./mysolver Max-SAT input format The input file format for Max-SAT will be in DIMACS format: c c comments Max-SAT c p cnf 3 4 1 -2 0 -1 2 -3 0 -3 2 0 1 3 0 The file can start with comments, that is lines beginning with the character 'c'. Right after the comments, there is the line "p cnf nbvar nbclauses" indicating that the instance is in CNF format; nbvar is the number of a variables appearing in the file; nbclauses is the exact number of clauses contained in the file. Then the clauses follow. Each clause is a sequence of distinct non-null numbers between -nbvar and nbvar ending with 0 on the same line. Positive numbers denote the corresponding variables. Negative numbers denote the negations of the corresponding variables. Weighted Max-SAT input format In Weighted Max-SAT, the parameters line is "p wcnf nbvar nbclauses". The weights of each clause will be identified by the first integer in each clause line. The weight of each clause is an integer greater than or equal to 1, and smaller than 263. Example of Weighted Max-SAT formula: c c comments Weighted Max-SAT c p wcnf 3 4 10 1 -2 0 3 -1 2 -3 0 8 -3 2 0 5 1 3 0 Partial Max-SAT input format In Partial Max-SAT, the parameters line is "p wcnf nbvar nbclauses top". We associate a weight with each clause, wich is the first integer in the clause. Weigths must be greater than or equal to 1, and smaller than 263. Hard clauses have weigth top and soft clauses have weigth 1. We assure that top is a weight always greater than the sum of the weights of violated soft clauses. Example of Partial Max-SAT formula: c c comments Partial Max-SAT c p wcnf 4 5 15 15 1 -2 4 0 15 -1 -2 3 0 1 -2 -4 0 1 -3 2 0 1 1 3 0 Weigthed Partial Max-SAT input format In Weigthed Partial Max-SAT, the parameters line is "p wcnf nbvar nbclauses top". We associate a weight with each clause, wich is the first integer in the clause. Weigths must be greater than or equal to 1, and smaller than 263. Hard clauses have weigth top and soft clauses have a weigth smaller than top. We assure that top is a weight always greater than the sum of the weights of violated soft clauses. Example of Weigthed Partial Max-SAT formula: c c comments Weigthed Partial Max-SAT c p wcnf 4 5 16 16 1 -2 4 0 16 -1 -2 3 0 8 -2 -4 0 4 -3 2 0 3 1 3 0 Output format The solvers must output messages on the standard output that will be used to check the results. The output format is inspired by the DIMACS output specification of the SAT competition and may be used to manually check some results. The solver cannot write to any files except standard output and standard error (only standard output will be parsed for results, but both output and error will be memorized during the whole evaluation process, for all executions). Messages Comments ("c " lines): These lines start by the two characters: lower case 'c' followed by a space (ASCII code 32). These lines are optional and may appear anywhere in the solver output. They contain any information that authors want to emphasize, such as #backtracks, #flips,... or internal cpu-time. Submitters are advised to avoid outputting comment lines which may be useful in an interactive environment but otherwise useless in a batch environment. Current optimal solution ("o " lines): These lines start by the two characters: lower case 'o' followed by a space (ASCII code 32). An "o " line must contain the lower case 'o' followed by a space and then by an integer which represents the better solution found so far, i.e., the minimum number of unsatisfied clauses by the current solution for Max-SAT or the minimum sum of weights of unsatisfied clauses for Weighted Max-SAT. These lines are mandatory and solvers must output them as soon as they find a new best solution. Programmers are advised to flush immediately the output stream. The evaluation environment will take as optimal solution by the solver the last "o " line in the output stream. Solution ("s " line): This line starts by the two characters: lower case 's' followed by a space (ASCII code 32). Only one such line is allowed. It is mandatory. This line gives the answer of the solver. It must be one of the following answers: s OPTIMUM FOUND This line must be output when the solver has checked that the last "o " line is the optimal solution. The integer in the last "o " line must be the minimum number (or the minimum sum of weights for Weighted Max-SAT) of unsatisfied clauses when we give a complete assignment to the variables of the formula. s UNSATISFIABLE This line must be output when the solves has checked that the set of hard clauses is unsatisfiable. s UNKNOWN This line must be output in any other case, i.e. when the solver is not able to tell anything about the formula. It is of uttermost importance to respect the exact spelling of these answers. Any mistake in the writing of these lines will cause the answer to be disregarded. If the solver does not display a solution line (or if the solution line is not valid), then UNKNOWN will be assumed. Values ("v " lines): These lines start by the two characters: lower case 'v' followed by a space (ASCII code 32). More than one "v " line is allowed but the evaluation environment will act as if their content was merged. It is mandatory. If the solver finds an optimal solution (it outputs "s OPTIMUM FOUND"), it must provide a truth assignment to the variables of the instance that will be used to check the correctness of the answer, i.e., it must provide a list of non-complementary literals which, when interpreted to true, unsatisfy the minimal number of clauses of the input formula (or minimizes the sum of weights of unsatisfied clauses for Weighted Max-SAT). A literal is denoted by an integer that identifies the variable and the negation of a literal is denoted by a minus sign immediately followed by the integer of the variable. The solution line must define the value of each variable. The order of literals does not matter. If the solver does not output a value line, or if the value line is misspelled, then UNKNOWN will be assumed. All the lines must be ended by a standard Unix end of line character ('\n'); Examples c ----------------- c My Max-SAT Solver c ----------------- o 10 o 7 o 6 o 5 s OPTIMUM FOUND v -1 2 3 -4 -5 6 -7 8 9 10 -11 -12 13 -14 -15 c -------------------------- c My Weighted Max-SAT Solver c -------------------------- o 481 o 245 o 146 o 145 o 144 o 143 s OPTIMUM FOUND v -1 2 3 -4 -5 6 -7 8 9 10 -11 -12 13 -14 -15 16 -17 18 19 20 akmaxsat_1.1/Makefile0000600000176000017530000000067111567214212015254 0ustar kuegelmitarbeiterFLAG = -O3 -static -Wall -ansi -fomit-frame-pointer -funroll-loops -DNDEBUG #-DFORCE_LS #-DRBFS #-DFORCE_LS # -DFUIP akmaxsat: akmaxsat.cpp restore_list.o cnf_formula.hpp clauses.o g++ $(FLAG) akmaxsat.cpp -o akmaxsat restore_list.o clauses.o clauses.o: clauses.cpp clauses.hpp g++ $(FLAG) clauses.cpp -c -o clauses.o restore_list.o: restore_list.cpp restore_list.hpp g++ $(FLAG) restore_list.cpp -c -o restore_list.o clean: rm *.o akmaxsat_1.1/README0000600000176000017530000000561211622701453014474 0ustar kuegelmitarbeiterakmaxsat is a MAX-SAT solver based on the description in "Improved Exact Solver for the Weighted Max-SAT Problem" (presented at the PoS10 workshop, to appear in Easychair electronic proceedings). The license for the software is described in the file COPYRIGHT The following files are in the original distribution: akmaxsat.cpp cnf_formula.hpp clauses.cpp clauses.hpp restore_list.cpp restore_list.hpp Makefile Doxyfile COPYRIGHT README FILE-FORMAT Type make to get the executable called akmaxsat. The makefile can be adjusted to include the macro FORCE_LS, which results in akmaxsat calling the stochastic local search solver ubcsat ( http://www.satlib.org/ubcsat/ ) in order to get an initial upper bound on the solution (akmaxsat expects the executable of ubcsat in the same directory as akmaxsat). In most cases this yields an overall speedup. Type doxygen to generate the code documentation (you need to update the file paths in Doxyfile first to make this work correctly). akmaxsat has one compulsory and one optional parameter: the first parameter is the path to the file containing a formula in cnf/wcnf format as specified for the MAX-SAT evaluations (see http://www.maxsat.udl.cat/10/requirements/) a copy of these can be found in the file FILE-FORMAT; the second (optional) parameter is the path to a file produced by the stochastic local search solver ubcsat (version 1.1) when called for example with the following parameters: ubcsat -alg irots [-w] -runs 10 -inst -r bestsol -r out /dev/null where the -w option is used for weighted formulas only. Of course, additional parameters may be used, for further information read the documentation of ubcsat. Following variants of akmaxsat can be compiled: The variants of akmaxsat mentioned in the paper "How to Improve Exact Solvers for the Max-SAT Problem" can be compiled as follows: no_gup add -DNO_GUP in the Makefile no_prop_list remove -DPROP_LIST in the Makefile no_fuip add -DNO_FUIP in the Makefile no_gup is sometimes faster on crafted Max-SAT instances, no_prop_list and no_fuip are slower than akmaxsat in most cases. When adding -DFUIP in the Makefile a real FUIP detection is done instead of the optimized detection of _some_ unique implication point. This is usually slower. When adding -DRBFS in the Makefile a recursive best-first search Branch-and-Bound algorithm is used instead of depth-first search Branch-and-Bound. This is faster in some cases. When adding -DCALC_MH in the Makefile a method from the paper "Computing Equivalent Transformations for Combinatorial Optimization by Branch-and-Bound Search" is used to improve the lower bound further. It seems, however, that it usually is not able to improve the lower bound. Personal communication with the author revealed that this method does in fact not work as well as claimed in his paper, there was some mistake in the test results. Send questions and bug reports to akuegel@googlemail.com akmaxsat_1.1/restore_list.cpp0000600000176000017530000000246511516041404017034 0ustar kuegelmitarbeiter/* Copyright (C) 2010 Adrian Kuegel This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include #include "restore_list.hpp" //! constructor of class restore_list restore_list::restore_list() { size = 10000; pos = data = new int[size]; end = data + size; added = 0; } //! destructor of the class restore_list restore_list::~restore_list() { delete [] data; } //! doubles the amount of available positions in data void restore_list::increase_data() { size *= 2; int *data_new = new int[size]; memcpy(data_new, data, sizeof(int) * size / 2); pos = data_new + (pos - data); delete [] data; data = data_new; end = data + size; } akmaxsat_1.1/restore_list.hpp0000600000176000017530000000657611535132726017061 0ustar kuegelmitarbeiter/* Copyright (C) 2010 Adrian Kuegel This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef RESTORE_LIST_HPP_INCLUDE #define RESTORE_LIST_HPP_INCLUDE #include "clauses.hpp" /*! \file restore_list.hpp Documentation of class restore_list */ //! the class restore_list maintains a list of clauses which need to be restored when backtracking class restore_list { private: //! data contains data entries of the following form: pointer to clause c1, c2, ..., ck, weight, k, time_stamp int *data; //! pos points to one element after the last entry in data int *pos; //! end contains a pointer to the last allocated position in data int *end; //! size is the number of allocated positions in data int size; //! added counts the number of clauses added so far to the current data entry int added; //! doubles the amount of position available in the data array void increase_data(); public: //! constructor of class restore_list restore_list(); //! destructor of class restore_list ~restore_list(); //! add clause to current data entry /*! \param clause_id is the id of the clause to be added */ inline void addEntry(int clause_id) { if (pos == end) increase_data(); *pos++ = clause_id; ++added; } //! retrieve a data entry /*! \param timestamp we restore only clauses which were deleted after time timestamp \param length is set to the number of clauses belonging to the data entry \param deletion_time is the timestamp of the time when the deletion happened \param weight is the weight which should be added to the clauses belonging to this data entry \param sign indicates if we need to subtract or add the weight \returns NULL if no more data entry with timestamp > timestamp is available, otherwise a pointer to the first clause of the data entry is returned */ inline const int *retrieve(long long timestamp, int &length, long long &deletion_time, ULL &weight, bool &sign) { assert(added == 0); if (pos == data) return NULL; assert(pos >= data + 5); deletion_time = *((ULL*)(pos-2)); if (deletion_time > timestamp) { length = *(pos-3); if (length & (1<<30)) { length ^= 1<<30; sign = true; } else sign = false; weight = *((ULL*)(pos-5)); pos -= (5 + length); return pos; } return NULL; } //! commit a data entry /*! \param timestamp the time of the deletion \param weight the weight which was subtracted or added to the clauses \param sign indicates if the weight was added or subtracted */ inline void commit(long long timestamp, ULL weight, bool sign) { assert(added > 0); if (pos + 5 > end) increase_data(); *((ULL *)pos) = weight; pos += 2; if (sign) added |= 1 << 30; *pos++ = added; added = 0; *((ULL *)pos) = timestamp; pos += 2; } }; #endif