lilypond-1.3.12
[lilypond.git] / lily / linear-programming.cc
blob727d3fc46df37f61b071eca41b964a1fafbb232a
1 /*
2 linear-programming.cc -- implement
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
10 #if 0
11 #include "linear-programming.hh"
13 Linear_programming::Linear_programming (int n)
14 : cost_vec_ (n)
16 dim_ = n;
18 int
19 Linear_programming::dim () const
21 return dim_;
25 void
26 Linear_programming::add_constraint (Vector c, double r)
28 assert (c.dim () == cost_vec_);
29 constraints_.push (c);
30 constraint_rhss_.push (r);
33 void
34 Linear_programming::set_cost (Vector c)
36 assert (dim_ == c.dim ());
37 cost_vec_ = c;
40 void
41 Linear_programming::print () const
43 DOUT << "cost: " << cost_vec_;
44 for (int i=0; constraints_.size (); i++)
46 DOUT << constraints_[i] << ". x = " << constraint_rhss_[i];
50 void
51 Linear_programming::OK () const
53 assert (constraint_rhss_.size () == constraints_.size ());
54 for (int i=0; constraints_.size (); i++)
55 constraints_[i].dim () == cost_vec_.dim ();
59 bool
60 Linear_programming::check_constraints (Vector v) const
62 bool is_cool = true;
63 assert (v.dim () == dim_);
65 for (int i=0; is_cool && i < v.dim (); i++)
66 is_cool = is_cool && v[i] >= 0;
67 for (int i=0; is_cool && i < constraints_.size (); i++)
68 is_cool = is_cool && (constraints_[i] * v <= constraint_rhss_[i]);
72 return is_cool;
75 Vector
76 Linear_programming::solve (Vector initial_basic_solution) const
78 assert (check_constraints (initial_basic_solution));
80 Array<bool> basis;
81 for (int i=0; i < dim_; i++)
82 basis.push (bool(initial_basic_solution[i]));
84 Vector x = initial_basic_solution;
85 Real current_cost = x * cost_vec_;
86 while (iter < MAXITER)
88 // select pivot
91 iter ++;
98 Array<int> binding, nonbinding;
100 assert (check_constraints (initial));
101 OK ();
103 Vector x (initial);
104 Real value (x * cost_vec_):
106 for (int i=0; i < constraints_.size ())
107 nonbinding.push (i);
109 while ()
111 get_negative_index (
115 #endif