From 812ddc5d19b22c9f53afc9effb84f8cc69c3cf51 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thorsten=20Wi=C3=9Fmann?= <uni@thorsten-wissmann.de>
Date: Mon, 13 Jan 2014 13:09:57 +0100
Subject: [PATCH] More helper functions

---
 CoAlgLogics.ml | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/CoAlgLogics.ml b/CoAlgLogics.ml
index 561ca96..fb71722 100644
--- a/CoAlgLogics.ml
+++ b/CoAlgLogics.ml
@@ -152,6 +152,54 @@ let subset (a: bset) (b: bset) : bool =
     bsetIter f a;
     !res && (bsetlen a < bsetlen b)
 
+let bsetFilter (a: bset) (f: CoAlgMisc.localFormula -> bool) : bset =
+    let res = bsetMake () in
+    bsetIter (fun form -> if (f form) then bsetAdd res form else ()) a;
+    res
+
+let bsetForall (a: bset) (f: CoAlgMisc.localFormula -> bool) : bool =
+    let res = ref (true) in
+    let helper formula =
+        if (f formula) then () else res := false
+    in
+    bsetIter helper a;
+    !res
+
+let bsetExists (a: bset) (f: CoAlgMisc.localFormula -> bool) : bool =
+    not (bsetForall a (fun x -> not (f x)))
+
+let elemArray (x: 'a) (arr: 'a array) =
+    let res = ref (false) in
+    let f y = if (x == y) then res := true else () in
+    Array.iter f arr;
+    !res
+
+let disjointAgents sort (a: CoAlgMisc.localFormula) (b: CoAlgMisc.localFormula) : bool =
+    assert (lfGetType sort a = EnforcesF || lfGetType sort a = AllowsF);
+    assert (lfGetType sort b = EnforcesF || lfGetType sort b = AllowsF);
+    let la = lfGetDestAg sort a in
+    let lb = lfGetDestAg sort b in
+    let res = ref (true) in
+    let f idx =
+        if (elemArray idx lb) then res := false
+        else ()
+    in
+    Array.iter f la;
+    !res
+
+
+(*
+let maxDisjoints (a: bset) : bset list =
+    let f formula acc =
+        let g cc acc' =
+            if (compatible cc formula)
+            then new bset with formula and cc and then prepend it to acc'
+        in
+        List.fold acc g acc
+    in
+    bsetFold a f [bsetMake ()]
+*)
+
 (*
     CoalitionLogic: tableau rules for satisfiability
 
-- 
GitLab