]> git.donarmstrong.com Git - lilypond.git/blob - lily/linear-programming.cc
eed55a9b3726cf61fbb205a394972d046ac1a9b3
[lilypond.git] / lily / linear-programming.cc
1 /*   
2   linear-programming.cc --  implement 
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c)  1997--1998 Han-Wen Nienhuys <hanwen@cs.ruu.nl>
7   
8  */
9
10 #if 0
11 #include "linear-programming.hh"
12
13 Linear_programming::Linear_programming (int n)
14   : cost_vec_ (n)
15 {
16 }
17 int
18 Linear_programming::dim () const
19 {
20   return cost_vec_.dim ();
21 }
22
23 void
24 Linear_programming::add_constraint (Vector c, double r)
25 {
26   assert (c.dim () == cost_vec_);
27   constraints_.push (c);
28   constraint_rhss_.push (r);
29 }
30
31 void
32 Linear_programming::set_cost (Vector c)
33 {
34   cost_vec_ = c;
35 }
36
37 void
38 Linear_programming::print () const
39 {
40   DOUT << "cost: " << cost_vec_;
41   for (int i=0; constraints_.size (); i++)
42     {
43       DOUT << constraints_[i] << ". x = " << constraint_rhss_[i];
44     }
45 }
46
47 void
48 Linear_programming::OK () const
49 {
50   assert (constraint_rhss_.size () == constraints_.size ());
51   for (int i=0; constraints_.size (); i++)
52     constraints_[i].dim () == cost_vec_.dim ();
53 }
54
55
56 bool
57 Linear_programming::check_constraints (Vector v) const
58 {
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]);
64
65
66
67   return is_cool;
68 }
69
70 Vector
71 Linear_programming::solve (Vector initial) const
72 {
73   Array<int> binding, nonbinding;
74   
75   assert (check_constraints (initial));
76   OK ();
77
78   Vector x (initial);
79   Real value (x * cost_vec_):
80   
81   for (int i=0; i < constraints_.size ())
82     nonbinding.push (i);
83
84   while  ()
85     {
86       get_negative_index (
87     }
88   
89 }
90 #endif