From 92bdfd0241de243ba2cad4f76ca7c3e9f18be33e Mon Sep 17 00:00:00 2001
From: Steve Tonneau <stonneau@axle.laas.fr>
Date: Tue, 9 Aug 2016 16:02:59 +0200
Subject: [PATCH] added option to canonicalize generators matrix

---
 include/robust-equilibrium-lib/util.hh |  3 ++-
 src/util.cpp                           | 13 ++++++++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/include/robust-equilibrium-lib/util.hh b/include/robust-equilibrium-lib/util.hh
index d540d1d..522f8d8 100644
--- a/include/robust-equilibrium-lib/util.hh
+++ b/include/robust-equilibrium-lib/util.hh
@@ -101,10 +101,11 @@ namespace robust_equilibrium
   /**
  * Convert the specified list of rays from Eigen to cdd format.
  * @param input The mXn input Eigen matrix contains m rays of dimension n.
+ * @param bool whether to remove redundant inequalities
  * @return The mX(n+1) output cdd matrix, which contains an additional column,
  * the first one, with all zeros.
  */
-  dd_MatrixPtr cone_span_eigen_to_cdd(Cref_matrixXX input);
+  dd_MatrixPtr cone_span_eigen_to_cdd(Cref_matrixXX input, const bool canonicalize=false);
 
   /**
  * Compute the cross-product skew-symmetric matrix associated to the specified vector.
diff --git a/src/util.cpp b/src/util.cpp
index 7ffb2ae..9b0770d 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -12,7 +12,7 @@
 namespace robust_equilibrium
 {
 
-dd_MatrixPtr cone_span_eigen_to_cdd(Cref_matrixXX input)
+dd_MatrixPtr cone_span_eigen_to_cdd(Cref_matrixXX input, const bool canonicalize)
 {
   dd_debug = false;
   dd_MatrixPtr M=NULL;
@@ -40,6 +40,17 @@ dd_MatrixPtr cone_span_eigen_to_cdd(Cref_matrixXX input)
     }
   }
   dd_clear(value);
+  if(canonicalize)
+  {
+    dd_ErrorType error = dd_NoError;
+    dd_rowset redset,impl_linset;
+    dd_rowindex newpos;
+    dd_MatrixCanonicalize(&M, &impl_linset, &redset, &newpos, &error);
+    set_free(redset);
+    set_free(impl_linset);
+    free(newpos);
+  }
+
   return M;
 }
 
-- 
GitLab