]> git.donarmstrong.com Git - lilypond.git/commitdiff
lilypond-0.0.2
authorfred <fred>
Wed, 9 Oct 1996 12:59:17 +0000 (12:59 +0000)
committerfred <fred>
Wed, 9 Oct 1996 12:59:17 +0000 (12:59 +0000)
dstream.hh
qlpsolve.cc

index 3a47a84784a77e43c29debf4c2f1712dfbf48327..24673695f244242ea16014e483b7a6c13c175ec2 100644 (file)
@@ -4,26 +4,34 @@
 #define DSTREAM_HH
 
 #include "string.hh"
+#include "assoc.hh"
 
 const char eol= '\n';
 
 /// debug stream
-class dstream
+class Dstream
 {
     ostream *os;
     int indentlvl;
-
+    Assoc<String, bool> silent;
+    bool local_silence;
+    String classname;
     /// indent of each level 
     const INDTAB = 3;
+
 public:
-    dstream(ostream &r){
-       os = &r;
-       indentlvl = 0;  
-    }
-    dstream &operator << (String s);
+    Dstream(ostream &r, const char  * = 0);
+    Dstream &identify_as(String s);
+    void switch_output(String s,bool);
+    Dstream &operator << (String s);
 };
  /**
    a class for providing debug output of nested structures,
-   with indents according to \{\}()[]
-  */     
+   with indents according to \{\}()[].
+
+   Using identify_as() one can turn on and off specific messages. Init
+   for these can be given in a rc file
+   
+  */
 #endif
+
index 0884223e6c7a24dd4d2f63c21af801b048d3a3ef..c3e9176dbd912b3d6c616d66090e4403109c30e6 100644 (file)
@@ -12,7 +12,7 @@ Active_constraints::status() const
        s += String(active[i]) + " ";
     }
 
-    s+="|";
+    s+="| ";
     for (int i=0; i< inactive.sz(); i++) {
        s += String(inactive[i]) + " ";
     }
@@ -66,12 +66,24 @@ Active_constraints::add(int k)
     // update of matrices
     Vector Ha = H*a;
     Real aHa = a*Ha;
+    if (ABS(aHa) > EPS) {
+       /*
+         a != 0, so if Ha = O(EPS), then
+         Ha * aH / aHa = O(EPS^2/EPS)
+
+         if H*a == 0, the constraints are dependent.
+         */
+       H -= Matrix(Ha , Ha)/(aHa);
+    
 
-    H -= Matrix(Ha , Ha)/(aHa);
-
-    Vector addrow(Ha/(aHa));
-    A -= Matrix(A*a, addrow);
-    A.insert_row(addrow,A.rows());        
+       /*
+         sorry, don't know how to justify this. ..
+         */
+       Vector addrow(Ha/(aHa));
+       A -= Matrix(A*a, addrow);
+       A.insert_row(addrow,A.rows());
+    }else
+       WARN << "degenerate constraints";
 }
 
 void
@@ -86,9 +98,14 @@ Active_constraints::drop(int k)
     active.pop();
 
     Vector a(A.row(q));
-    H += Matrix(a,a)/(a*opt->quad*a);
-    A -= A*opt->quad*Matrix(a,a)/(a*opt->quad*a);
-
+    if (a.norm() > EPS) {
+       /*
+        
+        */
+       H += Matrix(a,a)/(a*opt->quad*a);
+       A -= A*opt->quad*Matrix(a,a)/(a*opt->quad*a);
+    }else
+       WARN << "degenerate constraints";
     Vector rem_row(A.row(q));
     assert(rem_row.norm() < EPS);    
     A.delete_row(q);
@@ -121,11 +138,13 @@ int
 min_elt_index(Vector v)
 {
     Real m=INFTY; int idx=-1;
-    for (int i = 0; i < v.dim(); i++)
+    for (int i = 0; i < v.dim(); i++){
        if (v(i) < m) {
            idx = i;
            m = v(i);
        }
+       assert(v(i) <= INFTY);
+    }
     return idx;
 }
 
@@ -149,10 +168,10 @@ Ineq_constrained_qp::solve(Vector start) const
     while (iterations++ < MAXITER) {
        Vector direction= - act.find_active_optimum(gradient);
                
-       //      mtor << "gradient "<< gradient<< "\ndirection " << direction<<"\n";
+       mtor << "gradient "<< gradient<< "\ndirection " << direction<<"\n";
        
        if (direction.norm() > EPS) {
-           //  mtor << act.status() << '\n';
+           mtor << act.status() << '\n';
            
            Real minalf = INFTY;
 
@@ -183,12 +202,13 @@ Ineq_constrained_qp::solve(Vector start) const
            x += deltax;            
            gradient += optimal_step * (quad * deltax);
            
-           //mtor << "step = " << optimal_step<< " (|dx| = " <<
-           //deltax.norm() << ")\n";       
+           mtor << "step = " << optimal_step<< " (|dx| = " <<
+               deltax.norm() << ")\n";     
           
            if (minalf < unbounded_alfa) {
                /* bumped into an edge. try again, in smaller space. */
                act.add(minidx.idx());
+               mtor << "adding cons "<< minidx.idx()<<'\n';
                continue;
            }
            /*ASSERT: we are at optimal solution for this "plane"*/
@@ -201,7 +221,9 @@ Ineq_constrained_qp::solve(Vector start) const
        
        if (m>=0 && lagrange_mult(m) > 0) {
            break;              // optimal sol.
-       } else if (m<0 && gradient.norm() < EPS) {
+       } else if (m<0) {
+           assert(gradient.norm() < EPS) ;
+           
            break;
        }
        
@@ -211,7 +233,7 @@ Ineq_constrained_qp::solve(Vector start) const
     if (iterations >= MAXITER)
        WARN<<"didn't converge!\n";
     
-    //    mtor <<  ": found " << x<<" in " << iterations <<" iterations\n";
+    mtor <<  ": found " << x<<" in " << iterations <<" iterations\n";
     assert_solution(x);
     return x;
 } 
@@ -221,10 +243,12 @@ Ineq_constrained_qp::solve(Vector start) const
 
     Section 13.3
 
-    This is a "projected gradient" algorithm. Starting
-    from a point x the next point is found in a direction determined by
-    projecting the gradient onto the active constraints.  */
-    
-/*
-    thoroughly hacked to barely living tiny pieces by HW
+    This is a "projected gradient" algorithm. Starting from a point x
+    the next point is found in a direction determined by projecting
+    the gradient onto the active constraints.  (well, not really the
+    gradient. The optimal solution obeying the active constraints is
+    tried. This is why H = Q^-1 in initialisation) )
+
+
     */
+