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>
11 #include "linear-programming.hh"
13 Linear_programming::Linear_programming (int n)
18 Linear_programming::dim () const
20 return cost_vec_.dim ();
24 Linear_programming::add_constraint (Vector c, double r)
26 assert (c.dim () == cost_vec_);
27 constraints_.push (c);
28 constraint_rhss_.push (r);
32 Linear_programming::set_cost (Vector c)
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];
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 ();
57 Linear_programming::check_constraints (Vector v) const
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]);
71 Linear_programming::solve (Vector initial) const
73 Array<int> binding, nonbinding;
75 assert (check_constraints (initial));
79 Real value (x * cost_vec_):
81 for (int i=0; i < constraints_.size ())