]> git.donarmstrong.com Git - lilypond.git/commitdiff
lilypond-0.1.50
authorfred <fred>
Thu, 19 Mar 1998 00:58:59 +0000 (00:58 +0000)
committerfred <fred>
Thu, 19 Mar 1998 00:58:59 +0000 (00:58 +0000)
lily/include/linear-programming.hh [new file with mode: 0644]
lily/linear-programming.cc [new file with mode: 0644]

diff --git a/lily/include/linear-programming.hh b/lily/include/linear-programming.hh
new file mode 100644 (file)
index 0000000..1490edf
--- /dev/null
@@ -0,0 +1,42 @@
+/*   
+  linear-programming.hh -- declare 
+  
+  source file of the GNU LilyPond music typesetter
+  
+  (c) 1997 Han-Wen Nienhuys <hanwen@cs.ruu.nl>
+  
+ */
+
+#ifndef LINEAR_PROGRAMMING_HH
+#define LINEAR_PROGRAMMING_HH
+
+#include "linear-programming.hh"
+
+/**
+
+   min c* x
+
+   constraints_[i] * x = constraint_rhss_ [i]
+   
+   x[j] >= 0
+*/
+
+class Linear_programming
+{
+  Array<Vector> constraints_;
+  Array<Real> constraint_rhss_;
+  Vector cost_vec_;
+
+public:
+  Vector constraint_solve (Vector initial) const;
+  int dim () const;
+  Vector solve (Vector) const;
+  void add_constraint (Vector c, double r);
+  Linear_programming (int n);
+  void set_cost (Vector);
+  void print () const;
+  void OK () const;
+}
+
+#endif /* LINEAR_PROGRAMMING_HH */
+
diff --git a/lily/linear-programming.cc b/lily/linear-programming.cc
new file mode 100644 (file)
index 0000000..83c4823
--- /dev/null
@@ -0,0 +1,90 @@
+/*   
+  linear-programming.cc --  implement 
+  
+  source file of the GNU LilyPond music typesetter
+  
+  (c) 1997 Han-Wen Nienhuys <hanwen@cs.ruu.nl>
+  
+ */
+
+#if 0
+#include "linear-programming.hh"
+
+Linear_programming::Linear_programming (int n)
+  : cost_vec_ (n)
+{
+}
+int
+Linear_programming::dim () const
+{
+  return cost_vec_.dim ();
+}
+
+void
+Linear_programming::add_constraint (Vector c, double r)
+{
+  assert (c.dim () == cost_vec_);
+  constraints_.push (c);
+  constraint_rhss_.push (r);
+}
+
+void
+Linear_programming::set_cost (Vector c)
+{
+  cost_vec_ = c;
+}
+
+void
+Linear_programming::print () const
+{
+  DOUT << "cost: " << cost_vec_;
+  for (int i=0; constraints_.size (); i++)
+    {
+      DOUT << constraints_[i] << ". x = " << constraint_rhss_[i];
+    }
+}
+
+void
+Linear_programming::OK () const
+{
+  assert (constraint_rhss_.size () == constraints_.size ());
+  for (int i=0; constraints_.size (); i++)
+    constraints_[i].dim () == cost_vec_.dim ();
+}
+
+
+bool
+Linear_programming::check_constraints (Vector v) const
+{
+  bool is_cool = true;
+  for (int i=0; is_cool && i < v.dim (); i++)
+    is_cool = is_cool && v[i] >= 0;
+  for (int i=0; is_cool && i < constraints_.size (); i++)  
+    is_cool = is_cool && (constraints_[i] * v <= constraint_rhss_[i]);
+
+
+
+  return is_cool;
+}
+
+Vector
+Linear_programming::solve (Vector initial) const
+{
+  Array<int> binding, nonbinding;
+  
+  assert (check_constraints (initial));
+  OK ();
+
+  Vector x (initial);
+  Real value (x * cost_vec_):
+  
+  for (int i=0; i < constraints_.size ())
+    nonbinding.push (i);
+
+  while  ()
+    {
+      get_negative_index (
+    }
+  
+}
+#endif