lilypond-0.1.57
[lilypond.git] / lily / linear-programming.cc
blob83c4823db133b4d3c7c539ef9c1631909352ddc4
1 /*
2 linear-programming.cc -- implement
4 source file of the GNU LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@cs.ruu.nl>
8 */
10 #if 0
11 #include "linear-programming.hh"
13 Linear_programming::Linear_programming (int n)
14 : cost_vec_ (n)
17 int
18 Linear_programming::dim () const
20 return cost_vec_.dim ();
23 void
24 Linear_programming::add_constraint (Vector c, double r)
26 assert (c.dim () == cost_vec_);
27 constraints_.push (c);
28 constraint_rhss_.push (r);
31 void
32 Linear_programming::set_cost (Vector c)
34 cost_vec_ = c;
37 void
38 Linear_programming::print () const
40 DOUT << "cost: " << cost_vec_;
41 for (int i=0; constraints_.size (); i++)
43 DOUT << constraints_[i] << ". x = " << constraint_rhss_[i];
47 void
48 Linear_programming::OK () const
50 assert (constraint_rhss_.size () == constraints_.size ());
51 for (int i=0; constraints_.size (); i++)
52 constraints_[i].dim () == cost_vec_.dim ();
56 bool
57 Linear_programming::check_constraints (Vector v) const
59 bool is_cool = true;
60 for (int i=0; is_cool && i < v.dim (); i++)
61 is_cool = is_cool && v[i] >= 0;
62 for (int i=0; is_cool && i < constraints_.size (); i++)
63 is_cool = is_cool && (constraints_[i] * v <= constraint_rhss_[i]);
67 return is_cool;
70 Vector
71 Linear_programming::solve (Vector initial) const
73 Array<int> binding, nonbinding;
75 assert (check_constraints (initial));
76 OK ();
78 Vector x (initial);
79 Real value (x * cost_vec_):
81 for (int i=0; i < constraints_.size ())
82 nonbinding.push (i);
84 while ()
86 get_negative_index (
90 #endif