]> git.donarmstrong.com Git - lilypond.git/commitdiff
lilypond-0.0.2
authorfred <fred>
Thu, 10 Oct 1996 11:27:44 +0000 (11:27 +0000)
committerfred <fred>
Thu, 10 Oct 1996 11:27:44 +0000 (11:27 +0000)
linespace.cc
linespace.hh

index 7892cefa3da1ee1599a34284bb71781e3d231299..91b0e3009cca11a1f9f353cfb00e5daa4691d331 100644 (file)
@@ -118,7 +118,7 @@ Spacing_problem::find_initial_solution() const
 }
 // generate the matrices
 void
-Spacing_problem::make_matrices(Matrix &quad, Vector &lin) const
+Spacing_problem::make_matrices(Matrix &quad, Vector &lin, Real &c) const
 {
     quad.fill(0);
     lin.fill(0);
@@ -134,6 +134,8 @@ Spacing_problem::make_matrices(Matrix &quad, Vector &lin) const
 
        lin(r) -= i->space*i->hooke;
        lin(l) += i->space*i->hooke;
+
+       c += sqr(i->space);
     }
 }
 
@@ -141,29 +143,20 @@ Spacing_problem::make_matrices(Matrix &quad, Vector &lin) const
 void
 Spacing_problem::make_constraints(Optimisation_problem& lp) const
 {    
-    for (int j=0; j < cols.sz(); j++) {
+    int dim=cols.sz();
+    for (int j=0; j < dim; j++) {
        Colinfo *c=&(cols[j]);
-       int dim=cols.sz();
-               
        if (c->fixed) {
-           lp.add_fixed_var(j,c->fixpos);
-           continue;
-       }else {
-
+           lp.add_fixed_var(j,c->fixpos);          
+       }
+       if (j > 0){
            Vector c1(dim);
-           Vector c2(dim);
            
               
            c1(j)=1.0 ;
            c1(j-1)=-1.0 ;
            lp.add_inequality_cons(c1, cols[j-1].minright() +
                                   cols[j].minleft());
-
-           c2(j)=-1.0 ;
-           c2(j+1)=1.0;
-           lp.add_inequality_cons(c2,
-                                  cols[j+1].minleft() +
-                                  cols[j].minright());
        }
     }
 }
@@ -173,16 +166,16 @@ Spacing_problem::solve() const
 {
     OK();
     assert(check_feasible());
-    //    print();
+    print();
     
     /* optimalisatiefunctie */        
     Optimisation_problem lp(cols.sz());
-    make_matrices(lp.quad,lp.lin);
+    make_matrices(lp.quad,lp.lin, lp.const_term);
     make_constraints(lp);    
     Vector start=find_initial_solution();    
     Vector sol(lp.solve(start));
     if (!check_constraints(sol)) {
-       error( "solution doesn't solve. Sorry");        
+       WARN << "solution doesn't satisfy constraints.\n" ;
     }
        
 
index c2f8b5255fc7bd0bee1866e2c25fdb78c3b9153b..5a3c4edeb88303aec5b17f51592aed9d54f5bee8 100644 (file)
@@ -39,7 +39,7 @@ class Spacing_problem {
     bool contains(const PCol *w);
 
     /// make the energy function
-    void make_matrices(Matrix &quad, Vector &lin) const;
+    void make_matrices(Matrix &quad, Vector &lin,Real&) const;
 
     /// generate the LP constraints
     void make_constraints(Optimisation_problem& lp) const;