Repository: tulip-control/dd (language: python)

Issue:
Cudd pick_iter reordering
The current implementation of pick_iter in the cudd wrapper sets reordering to true before terminating instead of setting it to the original configuration.
Cudd pick_iter reordering
The current implementation of pick_iter in the cudd wrapper sets reordering to true before terminating instead of setting it to the original configuration.


Discussion / hints:
@ericskim sorry, I missed this issue. I am checking it now.
confirmed. I will create a PR now.
@ericskim sorry, I missed this issue. I am checking it now.
confirmed. I will create a PR now.

Fix patch:
diff --git a/dd/cudd.pyx b/dd/cudd.pyx
index 9befb2e9..15fc294d 100644
--- a/dd/cudd.pyx
+++ b/dd/cudd.pyx
@@ -850,7 +850,7 @@ cdef class BDD(object):
                 'Missing bits:  '
                 'support - care_vars = {missing}').format(
                     missing=missing))
-        self.configure(reordering=False)
+        config = self.configure(reordering=False)
         gen = Cudd_FirstCube(self.manager, u.node, &cube, &value)
         assert gen != NULL, 'first cube failed'
         try:
@@ -863,7 +863,7 @@ cdef class BDD(object):
                 r = Cudd_NextCube(gen, &cube, &value)
         finally:
             Cudd_GenFree(gen)
-        self.configure(reordering=True)
+        self.configure(reordering=config['reordering'])
 
     cpdef Function apply(
             self,


Test patch:
diff --git a/tests/regressions_test.py b/tests/regressions_test.py
new file mode 100644
index 00000000..ecf119e8
--- /dev/null
+++ b/tests/regressions_test.py
@@ -0,0 +1,22 @@
+from dd import cudd
+
+
+def test_reordering_setting_restore():
+    # Original report at https://github.com/tulip-control/dd/issues/40
+    b = cudd.BDD()
+    b.configure(reordering=False)
+    b.add_var('x')
+    b.add_var('y')
+    # x /\ y
+    s = '~ x /\ y'
+    u = b.add_expr(s)
+    assert not b.configure()['reordering']
+    g = b.pick_iter(u)
+    m = list(g)
+    m_ = [dict(x=False, y=True)]
+    assert m == m_, (m, m_)
+    assert not b.configure()['reordering']
+
+
+if __name__ == '__main__':
+    test_reordering_setting_restore()