}
void encodeAllSATEncoder(CSolver *csolver, SATEncoder *This) {
- VectorBoolean *constraints = csolver->constraints;
- uint size = getSizeVectorBoolean(constraints);
- for (uint i = 0; i < size; i++) {
+ HSIteratorBoolean *iterator=iteratorBoolean(csolver->constraints);
+ while(hasNextBoolean(iterator)) {
+ Boolean *constraint = nextBoolean(iterator);
model_print("Encoding All ...\n\n");
- Boolean *constraint = getVectorBoolean(constraints, i);
Edge c = encodeConstraintSATEncoder(This, constraint);
model_print("Returned Constraint in EncodingAll:\n");
addConstraintCNF(This->cnf, c);
}
+ deleteIterBoolean(iterator);
}
Edge encodeConstraintSATEncoder(SATEncoder *This, Boolean *constraint) {
typedef struct HashSet ## Name HashSet ## Name; \
\
HashSet ## Name * allocHashSet ## Name (unsigned int initialcapacity, double factor); \
- void deleteHashSet ## Name(struct HashSet ## Name *set); \
+ HashSet ## Name * allocDefHashSet ## Name (); \
+ void deleteHashSet ## Name(struct HashSet ## Name *set); \
HashSet ## Name * copyHashSet ## Name(HashSet ## Name * set); \
void resetHashSet ## Name(HashSet ## Name * set); \
bool addHashSet ## Name(HashSet ## Name * set,_Key key); \
_Key k = hsit->last->key; \
removeHashSet ## Name(hsit->set, k); \
} \
- \
+ \
+ HashSet ## Name * allocDefHashSet ## Name () { \
+ return allocHashSet ## Name(16, 0.25); \
+ } \
+ \
HashSet ## Name * allocHashSet ## Name (unsigned int initialcapacity, double factor) { \
HashSet ## Name * set = (HashSet ## Name *)ourmalloc(sizeof(struct HashSet ## Name)); \
set->table = allocHashTable ## Name ## Set(initialcapacity, factor); \
return key1 == key2;
}
-static inline unsigned int order_pair_hash_Function(OrderPair *This) {
+static inline unsigned int order_pair_hash_function(OrderPair *This) {
return (uint) (This->first << 2) ^ This->second;
}
return key1->first == key2->first && key1->second == key2->second;
}
-static inline unsigned int table_entry_hash_Function(TableEntry *This) {
+static inline unsigned int table_entry_hash_function(TableEntry *This) {
unsigned int h = 0;
for (uint i = 0; i < This->inputSize; i++) {
h += This->inputs[i];
return true;
}
-static inline unsigned int order_node_hash_Function(OrderNode *This) {
+static inline unsigned int order_node_hash_function(OrderNode *This) {
return (uint) This->id;
}
return key1->id == key2->id;
}
-static inline unsigned int order_edge_hash_Function(OrderEdge *This) {
+static inline unsigned int order_edge_hash_function(OrderEdge *This) {
return (uint) (((uintptr_t)This->sink) ^ ((uintptr_t)This->source << 4));
}
return key1->sink == key2->sink && key1->source == key2->source;
}
-HashTableImpl(OrderPair, OrderPair *, OrderPair *, order_pair_hash_Function, order_pair_equals, ourfree);
+HashTableImpl(OrderPair, OrderPair *, OrderPair *, order_pair_hash_function, order_pair_equals, ourfree);
-HashSetImpl(TableEntry, TableEntry *, table_entry_hash_Function, table_entry_equals);
-HashSetImpl(OrderNode, OrderNode *, order_node_hash_Function, order_node_equals);
-HashSetImpl(OrderEdge, OrderEdge *, order_edge_hash_Function, order_edge_equals);
+HashSetImpl(Boolean, Boolean *, Ptr_hash_function, Ptr_equals);
+HashSetImpl(TableEntry, TableEntry *, table_entry_hash_function, table_entry_equals);
+HashSetImpl(OrderNode, OrderNode *, order_node_hash_function, order_node_equals);
+HashSetImpl(OrderEdge, OrderEdge *, order_edge_hash_function, order_edge_equals);
HashTableImpl(NodeToNodeSet, OrderNode *, HashSetOrderNode *, Ptr_hash_function, Ptr_equals, deleteHashSetOrderNode);
HashTableDef(Void, void *, void *);
HashTableDef(OrderPair, OrderPair *, OrderPair *);
-HashSetDef(Void, void *);
+HashSetDef(Boolean, Boolean *);
HashSetDef(TableEntry, TableEntry *);
HashSetDef(OrderNode, OrderNode *);
HashSetDef(OrderEdge, OrderEdge *);
#include <strings.h>
void naiveEncodingDecision(CSolver *This) {
- for (uint i = 0; i < getSizeVectorBoolean(This->constraints); i++) {
- Boolean *boolean = getVectorBoolean(This->constraints, i);
+ HSIteratorBoolean *iterator=iteratorBoolean(This->constraints);
+ while(hasNextBoolean(iterator)) {
+ Boolean *boolean = nextBoolean(iterator);
naiveEncodingConstraint(boolean);
}
+ deleteIterBoolean(iterator);
}
void naiveEncodingConstraint(Boolean *This) {
#include "csolver.h"
void computePolarities(CSolver *This) {
- for (uint i = 0; i < getSizeVectorBoolean(This->constraints); i++) {
- Boolean *boolean = getVectorBoolean(This->constraints, i);
+ HSIteratorBoolean *iterator=iteratorBoolean(This->constraints);
+ while(hasNextBoolean(iterator)) {
+ Boolean *boolean = nextBoolean(iterator);
updatePolarity(boolean, P_TRUE);
updateMustValue(boolean, BV_MUSTBETRUE);
computePolarityAndBooleanValue(boolean);
}
+ deleteIterBoolean(iterator);
}
void updatePolarity(Boolean *This, Polarity polarity) {
CSolver *allocCSolver() {
CSolver *This = (CSolver *) ourmalloc(sizeof(CSolver));
- This->constraints = allocDefVectorBoolean();
+ This->constraints = allocDefHashSetBoolean();
This->allBooleans = allocDefVectorBoolean();
This->allSets = allocDefVectorSet();
This->allElements = allocDefVectorElement();
/** This function tears down the solver and the entire AST */
void deleteSolver(CSolver *This) {
- deleteVectorBoolean(This->constraints);
+ deleteHashSetBoolean(This->constraints);
uint size = getSizeVectorBoolean(This->allBooleans);
for (uint i = 0; i < size; i++) {
}
void addConstraint(CSolver *This, Boolean *constraint) {
- pushVectorBoolean(This->constraints, constraint);
+ addHashSetBoolean(This->constraints, constraint);
}
Order *createOrder(CSolver *This, OrderType type, Set *set) {
struct CSolver {
SATEncoder *satEncoder;
/** This is a vector of constraints that must be satisfied. */
- VectorBoolean *constraints;
+ HashSetBoolean *constraints;
/** This is a vector of all boolean structs that we have allocated. */
VectorBoolean *allBooleans;