// return the string representation of the whole // tree rooted at this particular node // public string TreeToString(int sig, MyHashtable nameMap) { MyHashtable inqueue = new MyHashtable(); Queue todo = new Queue(); todo.Enqueue(sig); StringBuilder result = new StringBuilder(); while (todo.Count != 0) { int nd = (int)todo.Dequeue(); int l = LeftChild(nd); int r = RightChild(nd); NodeType tp = NdType(nd); if (tp == NodeType.AND || tp == NodeType.XOR) { if (!inqueue.Contains(l)) { todo.Enqueue(l); inqueue.Add(l, null); } if (!inqueue.Contains(r)) { todo.Enqueue(r); inqueue.Add(r, null); } } result.Append(ToString(nd, nameMap)); } return(result.ToString()); }
public void TestForContainMethodOfHash() { MyHashtable test2 = new MyHashtable(); test2.Add("test", 1); test2.Add("test", 2); test2.Add("test2", 3); test2.Add("test2", 4); Assert.True(test2.Contains("test")); Assert.True(test2.Contains("test2")); Assert.False(test2.Contains("test1")); }
public MyHashtable generate_unsat_core() { if (empty == null) { fatal("Not UNSAT, Cannot Generate Core"); } MyHashtable hash = new MyHashtable(); foreach (int uid in empty.reasons) { hash.Add(uid, null); } long oldpos = storage.Position; storage.Seek(0, SeekOrigin.End); while (storage.Position > 0) { ResolveNode nd = ResolveNode.DeSerializeBackward(storage); sharp_assert(!is_node(nd.uid)); if (hash.Contains(nd.uid)) { foreach (int id in nd.reasons) { int uid = id; if (is_node(id)) { uid = node_uid(id); } if (!hash.Contains(uid)) { hash.Add(uid, null); } } hash.Remove(nd.uid); } } storage.Seek(oldpos, SeekOrigin.Begin); return(hash); }
MyHashtable find_all_involved() { if (empty == null) { fatal("Not UNSAT, Cannot Generate Core"); } MyHashtable hash = new MyHashtable(); foreach (int uid in empty.reasons) { hash.Add(uid, 1); } long oldpos = storage.Position; storage.Seek(0, SeekOrigin.End); while (storage.Position > 0) { ResolveNode nd = ResolveNode.DeSerializeBackward(storage); if (hash.Contains(nd.uid)) { foreach (int uid in nd.reasons) { if (!hash.Contains(uid)) { hash[uid] = 1; } else { hash[uid] = (int)hash[uid] + 1; } } } } storage.Seek(oldpos, SeekOrigin.Begin); return(hash); }
void prepare_original_nodes(int a_flag, int b_flag, MyHashtable uid2lits, MyHashtable uid2sig, MyHashtable involved) { MyHashtable uid2vid = new MyHashtable(); for (int i = 1; i < solver.variables.size(); ++i) { Variable var = solver.variable(i); if (var != null && (var.flag(a_flag) || var.flag(b_flag))) { uid2vid[var.uid] = i; } } foreach (object obj in involved) { int uid = (int)((DictionaryEntry)obj).Key; if (!is_node(uid) || !uid2vid.Contains(node_uid(uid))) { continue; } int nid = node_uid(uid); int cls_id = cls_idx(uid); int vid = (int)uid2vid[nid]; int [] lits = get_cls(vid, cls_id); int sig; sharp_assert(solver.variable(vid).flag(a_flag) || solver.variable(vid).flag(b_flag)); if (solver.variable(vid).flag(b_flag)) { sig = solver.one(); } else { sig = solver.zero(); foreach (int lit in lits) { sharp_assert(solver.node(lit).flag(a_flag)); if (solver.node(lit).flag(b_flag)) { sig = solver.bor(sig, lit); } } } uid2lits[uid] = lits; uid2sig[uid] = sig; } }
public void insert(int n, NodeType op, int i1, int i2) { sharp_assert(op == NodeType.AND || op == NodeType.XOR); sharp_assert(i1 < i2); sharp_assert(!((op == NodeType.XOR) && (IS_NEGATED(i1) || IS_NEGATED(i2)))); sharp_assert(!IS_NEGATED(n)); int l, r; l = i1; r = i2; if (op == NodeType.XOR) { l += XOR_MARK; } NodeHashMapKey key = new NodeHashMapKey(l, r); // ulong key = ((ulong)l << 32) + (ulong) r; sharp_assert(!hash_table.Contains(key)); hash_table[key] = n; }
static void Main(string[] args) { MyHashtable ht = new MyHashtable(); ht.Add("one", 5); Console.WriteLine("Added => Key: one, value: 5 "); ht.Add("one", 15); Console.WriteLine("Added => Key: one, value: 15 "); ht.Add("two", 10); Console.WriteLine("Added => Key: two, value: 10 "); Console.WriteLine(); List <int> valueList = ht.Find("one"); Console.WriteLine("Key of 'one' contains following values: "); foreach (int val in valueList) { Console.WriteLine(val); } Console.WriteLine(); bool contain = ht.Contains("one"); bool contains = ht.Contains("One"); Console.WriteLine(); Console.WriteLine("Hastable contains a key of 'one': " + contain); Console.WriteLine("Hastable contains a key of 'One': " + contains); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Collision test of 'Cat' and 'Doe' : "); Console.WriteLine(); MyHashtable colsn = new MyHashtable(); colsn.Add("Cat", 50); Console.WriteLine("Added => Key: Cat, value: 50 "); colsn.Add("Doe", 100); Console.WriteLine("Added => Key: Doe, value: 100 "); List <int> catList = colsn.Find("Cat"); List <int> doeList = colsn.Find("Doe"); Console.WriteLine("Key: Cat holds following value(s): "); foreach (int i in catList) { Console.WriteLine(i); } Console.WriteLine(); Console.WriteLine("Key: Doe holds following value(s);"); foreach (int i in doeList) { Console.WriteLine(i); } Console.WriteLine(); bool containCat = colsn.Contains("Cat"); bool containDoe = colsn.Contains("Doe"); Console.WriteLine(); Console.WriteLine("Hastable contains a key of 'Cat': " + containCat); Console.WriteLine("Hastable contains a key of 'Doe': " + containDoe); }
// return the string representation of this particular node // public string ToString(int sig, MyHashtable nameMap) { string result = sig.ToString() + "\t= "; if (IsNegated(sig)) { int t = NonNegated(sig); result += "Not(" + t.ToString() + ")\n" + ToString(t, nameMap); } else { NodeType tp = NdType(sig); switch (tp) { case NodeType.UNKNOWN: case NodeType.FREE: case NodeType.CONSTANT: case NodeType.VARIABLE: result += "ERROR"; break; case NodeType.AND: case NodeType.XOR: int l = LeftChild(sig); int r = RightChild(sig); string lstr, rstr; lstr = l.ToString(); rstr = r.ToString(); if (tp == NodeType.AND) { result += "AND (" + lstr + ", " + rstr + ")"; } else { result += "XOR (" + lstr + ", " + rstr + ")"; } break; case NodeType.PI: int sig_pi = NodeToPI(sig); if (sig_pi != -1) { if (nameMap.Contains(sig_pi)) { result += nameMap[sig_pi]; } else { result += "PI" + sig_pi.ToString(); } } else { result += "ERROR"; } break; } result += "\n"; } return(result); }
// gretay -- change start public int gen_interpolant_from_signals_ex(int a_node, int a_cls_id, int b_node, int b_cls_id, int[] c_cls_id, int[] c_interp) { //solver.dump_file = new StreamWriter ("dump_file"); //solver.dump_file.WriteLine ("{0} = INIT_VARS", solver.num_variables()); int a_flag = solver.alloc_flag(); int b_flag = solver.alloc_flag(); solver.mark_transitive_fanins(a_node, a_flag); solver.mark_transitive_fanins(b_node, b_flag); assert(c_cls_id.Length == c_interp.Length); MyHashtable uid2lits = new MyHashtable(); MyHashtable uid2sig = new MyHashtable(); MyHashtable involved = find_all_involved(); prepare_original_nodes(a_flag, b_flag, uid2lits, uid2sig, involved); // init A info int a_uid = solver.clause(a_cls_id).uid; if (involved.Contains(a_uid)) { uid2lits[a_uid] = solver.clause(a_cls_id).literals; int s = solver.zero(); foreach (int lit in solver.clause(a_cls_id).literals) { sharp_assert(solver.node(lit).flag(a_flag)); if (solver.node(lit).flag(b_flag)) { s = solver.bor(s, lit); } } uid2sig[a_uid] = s; //uid2sig[a_uid] = a_node; } // init B info int b_uid = solver.clause(b_cls_id).uid; if (involved.Contains(b_uid)) { uid2lits[b_uid] = solver.clause(b_cls_id).literals; uid2sig[b_uid] = solver.one(); } // init C info for (int i = 0; i < c_cls_id.Length; i++) { Clause cl = solver.clause(c_cls_id[i]); if (involved.Contains(cl.uid)) { uid2lits[cl.uid] = cl.literals; uid2sig[cl.uid] = c_interp[i]; } } long oldpos = storage.Position; storage.Seek(0, SeekOrigin.Begin); while (storage.Position < storage.Length) { ResolveNode nd = ResolveNode.DeSerializeForward(storage); if (!involved.Contains(nd.uid)) { continue; } int [] lits; int signal; int uid = nd.reasons[0]; sharp_assert(involved.Contains(uid)); sharp_assert(uid2sig.Contains(uid)); lits = (int[])uid2lits[uid]; signal = (int)uid2sig[uid]; int count = (int)involved[uid] - 1; if (count == 0) { uid2lits.Remove(uid); uid2sig.Remove(uid); involved.Remove(uid); } else { involved[uid] = count; } for (int i = 1; i < nd.reasons.Length; ++i) { uid = nd.reasons[i]; sharp_assert(uid < (1 << 29)); sharp_assert(involved.Contains(uid)); sharp_assert(uid2lits.Contains(uid)); sharp_assert(uid2sig.Contains(uid)); int [] lits1 = (int[])uid2lits[uid]; int signal1 = (int)uid2sig[uid]; count = (int)involved[uid] - 1; if (count == 0) { uid2lits.Remove(uid); uid2sig.Remove(uid); involved.Remove(uid); } else { involved[uid] = count; } int pivot = find_pivot(lits, lits1); lits = resolve(lits, lits1); if ((solver.variable(pivot).flag(a_flag)) && (!solver.variable(pivot).flag(b_flag))) { signal = solver.bor(signal, signal1); } else { signal = solver.band(signal, signal1); } } if (!uid2lits.Contains(nd.uid)) { uid2lits[nd.uid] = lits; } sharp_assert(!uid2sig.Contains(nd.uid)); uid2sig[nd.uid] = signal; } storage.Seek(oldpos, SeekOrigin.Begin); { int uid = empty.reasons[0]; sharp_assert(involved.Contains(uid)); sharp_assert(uid2lits.Contains(uid)); sharp_assert(uid2sig.Contains(uid)); int [] lits = (int[])uid2lits[uid]; int signal = (int)uid2sig[uid]; int count = (int)involved[uid] - 1; if (count == 0) { uid2lits.Remove(uid); uid2sig.Remove(uid); involved.Remove(uid); } else { involved[uid] = count; } for (int i = 1; i < empty.reasons.Length; ++i) { uid = empty.reasons[i]; sharp_assert(involved.Contains(uid)); sharp_assert(uid2lits.Contains(uid)); sharp_assert(uid2sig.Contains(uid)); int [] lits1 = (int[])uid2lits[uid]; int signal1 = (int)uid2sig[uid]; count = (int)involved[uid] - 1; if (count == 0) { uid2lits.Remove(uid); uid2sig.Remove(uid); involved.Remove(uid); } else { involved[uid] = count; } int pivot = find_pivot(lits, lits1); lits = resolve(lits, lits1); if ((solver.variable(pivot).flag(a_flag)) && (!solver.variable(pivot).flag(b_flag))) { signal = solver.bor(signal, signal1); } else { signal = solver.band(signal, signal1); } } sharp_assert(lits.Length == 0); sharp_assert(involved.Count == 0); sharp_assert(uid2lits.Count == 0); sharp_assert(uid2sig.Count == 0); //solver.dump_file.WriteLine ("{0} = CONSTRAINT", signal); //solver.dump_file.Close(); solver.free_flag(a_flag); solver.free_flag(b_flag); //solver.free_flag(c_flag); return(signal); } }
public int gen_interpolant_from_clauses(int a_gid, int b_gid) { //solver.dump_file = new StreamWriter ("dump_file"); //solver.dump_file.WriteLine ("{0} = INIT_VARS", solver.num_variables()); sharp_assert(solver.is_pure_clause_based()); solver.convert_vars_to_pi(); MyHashtable uid2lits = new MyHashtable(); MyHashtable uid2sig = new MyHashtable(); MyHashtable involved = find_all_involved(); int [] var_flag = new int [solver.variables.size()]; prepare_original_clauses(a_gid, b_gid, uid2lits, uid2sig, involved, var_flag); long oldpos = storage.Position; storage.Seek(0, SeekOrigin.Begin); while (storage.Position < storage.Length) { ResolveNode nd = ResolveNode.DeSerializeForward(storage); if (!involved.Contains(nd.uid)) { continue; } int uid = nd.reasons[0]; sharp_assert(involved.Contains(uid)); sharp_assert(uid2lits.Contains(uid)); sharp_assert(uid2sig.Contains(uid)); int [] lits = (int[])uid2lits[uid]; int signal = (int)uid2sig[uid]; int count = (int)involved[uid] - 1; if (count == 0) { uid2lits.Remove(uid); uid2sig.Remove(uid); involved.Remove(uid); } else { involved[uid] = count; } for (int i = 1; i < nd.reasons.Length; ++i) { uid = nd.reasons[i]; sharp_assert(uid < (1 << 29)); sharp_assert(involved.Contains(uid)); sharp_assert(uid2lits.Contains(uid)); sharp_assert(uid2sig.Contains(uid)); int [] lits1 = (int[])uid2lits[uid]; int signal1 = (int)uid2sig[uid]; count = (int)involved[uid] - 1; if (count == 0) { uid2lits.Remove(uid); uid2sig.Remove(uid); involved.Remove(uid); } else { involved[uid] = count; } int pivot = find_pivot(lits, lits1); lits = resolve(lits, lits1); if (var_flag[pivot] == A_LOCAL) { signal = solver.bor(signal, signal1); } else { signal = solver.band(signal, signal1); } } if (!uid2lits.Contains(nd.uid)) { uid2lits[nd.uid] = lits; } sharp_assert(!uid2sig.Contains(nd.uid)); uid2sig[nd.uid] = signal; } storage.Seek(oldpos, SeekOrigin.Begin); { int uid = empty.reasons[0]; sharp_assert(involved.Contains(uid)); sharp_assert(uid2lits.Contains(uid)); sharp_assert(uid2sig.Contains(uid)); int [] lits = (int[])uid2lits[uid]; int signal = (int)uid2sig[uid]; int count = (int)involved[uid] - 1; if (count == 0) { uid2lits.Remove(uid); uid2sig.Remove(uid); involved.Remove(uid); } else { involved[uid] = count; } for (int i = 1; i < empty.reasons.Length; ++i) { uid = empty.reasons[i]; sharp_assert(involved.Contains(uid)); sharp_assert(uid2lits.Contains(uid)); sharp_assert(uid2sig.Contains(uid)); int [] lits1 = (int[])uid2lits[uid]; int signal1 = (int)uid2sig[uid]; count = (int)involved[uid] - 1; if (count == 0) { uid2lits.Remove(uid); uid2sig.Remove(uid); involved.Remove(uid); } else { involved[uid] = count; } int pivot = find_pivot(lits, lits1); lits = resolve(lits, lits1); if (var_flag[pivot] == A_LOCAL) { signal = solver.bor(signal, signal1); } else { signal = solver.band(signal, signal1); } } sharp_assert(lits.Length == 0); sharp_assert(involved.Count == 0); sharp_assert(uid2lits.Count == 0); sharp_assert(uid2sig.Count == 0); //solver.dump_file.WriteLine ("{0} = CONSTRAINT", signal); //solver.dump_file.Close(); return(signal); } }
void prepare_original_clauses(int a_gid, int b_gid, MyHashtable uid2lits, MyHashtable uid2sig, MyHashtable involved, int[] var_flag) { for (int i = 0; i < var_flag.Length; ++i) { var_flag[i] = 0; } for (int i = 0; i < solver.clauses.size(); ++i) { Clause cl = clause(i); if (cl == null || !involved.Contains(cl.uid)) { continue; } if (cl.type == ClType.ORIGINAL) { if (cl.gid(a_gid)) { sharp_assert(!cl.gid(b_gid)); foreach (int lit in cl.literals) { var_flag [VID(lit)] |= A_LOCAL; } } else { sharp_assert(cl.gid(b_gid)); foreach (int lit in cl.literals) { var_flag [VID(lit)] |= B_LOCAL; } } } uid2lits[cl.uid] = cl.literals; } for (int i = 0; i < solver.original_clauses.size(); ++i) { Clause cl = clause(solver.original_clauses[i]); sharp_assert(cl != null); sharp_assert(cl.type == ClType.ORIGINAL); if (!involved.Contains(cl.uid)) { continue; } int signal; if (cl.gid(a_gid)) { sharp_assert(!cl.gid(b_gid)); signal = solver.zero(); foreach (int lit in cl.literals) { if (var_flag[VID(lit)] == GLOBAL) { signal = solver.bor(signal, lit); } } } else { sharp_assert(cl.gid(b_gid)); signal = solver.one(); } uid2sig[cl.uid] = signal; } }