]> git.donarmstrong.com Git - lilypond.git/commitdiff
lilypond-0.0.78
authorfred <fred>
Sun, 24 Mar 2002 19:49:49 +0000 (19:49 +0000)
committerfred <fred>
Sun, 24 Mar 2002 19:49:49 +0000 (19:49 +0000)
lily/include/ineq-constrained-qp.hh [new file with mode: 0644]
lily/include/qlpsolve.hh
lily/qlp.cc

diff --git a/lily/include/ineq-constrained-qp.hh b/lily/include/ineq-constrained-qp.hh
new file mode 100644 (file)
index 0000000..161bc51
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+  ineq-constrained-qp.hh -- declare Ineq_constrained_qp
+
+  source file of the GNU LilyPond music typesetter
+
+  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+
+#ifndef INEQ_CONSTRAINED_QP_HH
+#define INEQ_CONSTRAINED_QP_HH
+
+
+
+#include "matrix.hh"
+
+/// inequality constrained quadratic program
+class Ineq_constrained_qp {
+    friend class Active_constraints;
+
+    Array<Vector> cons;
+    Array<Real> consrhs;
+public:
+    Matrix quad;
+    Vector lin;
+    Real const_term;
+
+
+    /**
+      use a KKT method to assert optimality of sol
+      */
+    void assert_solution(Vector sol) const;
+    /// solve the problem using a projected gradient method
+    Vector solve(Vector start) const;
+    
+    /**
+      @return the number of variables in the problem
+      */
+    int dim() const{
+       return lin.dim();
+    }
+
+    /**
+      add a constraint
+
+
+        c*vars >= r
+
+      PRE
+      c.dim() == dim();
+       
+      */
+    void add_inequality_cons(Vector c, double r);
+    
+    /** set up matrices to go with the problem. */
+    Ineq_constrained_qp(int novars);
+    
+    /**
+    evaluate the quadratic function for input #v#
+    */
+    Real eval(Vector v);
+
+    void eliminate_var(int idx, Real value);
+    void OK()const;
+    void print() const;
+
+};
+
+// ugh
+const Real EPS=1e-7;           
+
+#endif // INEQ_CONSTRAINED_QP_HH
index c7a54b1eca33d76715c9435fdff8b327811edf89..56b84e2e16f9ed215cfb1b554f7632bc8db7f222 100644 (file)
@@ -9,7 +9,7 @@
 
 #ifndef QLPSOLVE_HH
 #define QLPSOLVE_HH
-#include "qlp.hh"
+
 #include "matrix.hh"
 
 
index 7eac50596c3ef030d3f1332886d7778f994c014e..833a76f4e4da68af02609526f23b22e0f29f545a 100644 (file)
@@ -1,8 +1,17 @@
+/*
+  qlp.cc -- implement Mixed_qp
+
+  source file of the GNU LilyPond music typesetter
+
+  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
 #include "debug.hh"
 #include "const.hh"
 #include "qlp.hh"
 #include "choleski.hh"
 
+
 void
 Mixed_qp::add_equality_cons(Vector , double )
 {
@@ -16,36 +25,6 @@ Mixed_qp::add_fixed_var(int i, Real r)
     eq_consrhs.push(r);
 }
 
-void
-Ineq_constrained_qp::add_inequality_cons(Vector c, double r)
-{
-    cons.push(c);
-    consrhs.push(r);
-}
-
-Ineq_constrained_qp::Ineq_constrained_qp(int novars):
-    quad(novars),
-    lin(novars),
-    const_term (0.0)
-{
-}
-
-void
-Ineq_constrained_qp::OK() const
-{
-#ifndef NDEBUG    
-    assert(cons.size() == consrhs.size());
-    Matrix Qdif= quad - quad.transposed();
-    assert(Qdif.norm()/quad.norm() < EPS);
-#endif    
-}
-     
-
-Real
-Ineq_constrained_qp::eval (Vector v)
-{
-    return v * quad * v + lin * v + const_term;
-}
 
 /**
     eliminate appropriate variables, until we have a Ineq_constrained_qp
@@ -74,32 +53,6 @@ Mixed_qp::solve(Vector start) const
     return sol;
 }
 
-/*
-    assume x(idx) == value, and adjust constraints, lin and quad accordingly
-
-    TODO: add const_term
-    */
-void
-Ineq_constrained_qp::eliminate_var(int idx, Real value)
-{
-    Vector row(quad.row(idx));
-    row*= value;
-
-    quad.delete_row(idx);
-
-    quad.delete_column(idx);
-
-    lin.del(idx);
-    row.del(idx);
-    lin +=row ;
-
-   for (int i=0; i < cons.size(); i++) {
-      consrhs[i] -= cons[i](idx) *value;
-      cons[i].del(idx);
-   }
-}
-
-
 
 void
 Ineq_constrained_qp::assert_solution(Vector sol) const
@@ -129,8 +82,6 @@ Ineq_constrained_qp::print() const
 #endif
 }
 
-/* *************** */
-
 Mixed_qp::Mixed_qp(int n)
     : Ineq_constrained_qp(n)
 {