src/work/marci/lp/lp_solver_wrapper_3.h
changeset 1106 0a7d604a9763
parent 1100 299d1127a846
child 1110 ba28dfbea5f2
equal deleted inserted replaced
4:b723d4c19f64 5:a297d19dd7eb
     8 
     8 
     9 // #include <stdio.h>
     9 // #include <stdio.h>
    10 #include <stdlib.h>
    10 #include <stdlib.h>
    11 #include <iostream>
    11 #include <iostream>
    12 #include <map>
    12 #include <map>
       
    13 #include <limits>
    13 // #include <stdio>
    14 // #include <stdio>
    14 //#include <stdlib>
    15 //#include <stdlib>
    15 extern "C" {
    16 extern "C" {
    16 #include "glpk.h"
    17 #include "glpk.h"
    17 }
    18 }
   194     IterablePartition<int> col_iter_map;
   195     IterablePartition<int> col_iter_map;
   195     /// \e
   196     /// \e
   196     const int VALID_CLASS;
   197     const int VALID_CLASS;
   197     /// \e
   198     /// \e
   198     const int INVALID_CLASS;
   199     const int INVALID_CLASS;
       
   200     /// \e 
       
   201     static const _Value INF;
   199   public:
   202   public:
   200     /// \e
   203     /// \e
   201     LPSolverBase() : row_iter_map(2), 
   204     LPSolverBase() : row_iter_map(2), 
   202 		     col_iter_map(2), 
   205 		     col_iter_map(2), 
   203 		     VALID_CLASS(0), INVALID_CLASS(1) { }
   206 		     VALID_CLASS(0), INVALID_CLASS(1) { }
   219     virtual int _addRow() = 0;
   222     virtual int _addRow() = 0;
   220     /// \e
   223     /// \e
   221     virtual int _addCol() = 0;
   224     virtual int _addCol() = 0;
   222     /// \e
   225     /// \e
   223     virtual void _setRowCoeffs(int i, 
   226     virtual void _setRowCoeffs(int i, 
   224 			       std::vector<std::pair<int, double> > coeffs) = 0;
   227 			       const std::vector<std::pair<int, _Value> >& coeffs) = 0;
   225     /// \e
   228     /// \e
   226     virtual void _setColCoeffs(int i, 
   229     virtual void _setColCoeffs(int i, 
   227 			       std::vector<std::pair<int, double> > coeffs) = 0;
   230 			       const std::vector<std::pair<int, _Value> >& coeffs) = 0;
   228     /// \e
   231     /// \e
   229     virtual void _eraseCol(int i) = 0;
   232     virtual void _eraseCol(int i) = 0;
   230     /// \e
   233     /// \e
   231     virtual void _eraseRow(int i) = 0;
   234     virtual void _eraseRow(int i) = 0;
   232   public:
   235   public:
   421     virtual int getColStat(const ColIt& col_it) = 0;
   424     virtual int getColStat(const ColIt& col_it) = 0;
   422     /// \e
   425     /// \e
   423     virtual void printColStatus(int i) = 0;
   426     virtual void printColStatus(int i) = 0;
   424   };
   427   };
   425   
   428   
       
   429   template <typename _Value>
       
   430   const _Value LPSolverBase<_Value>::INF=std::numeric_limits<_Value>::infinity();
       
   431 
   426 
   432 
   427   /// \brief Wrappers for LP solvers
   433   /// \brief Wrappers for LP solvers
   428   /// 
   434   /// 
   429   /// This class implements a lemon wrapper for glpk.
   435   /// This class implements a lemon wrapper for glpk.
   430   /// Later other LP-solvers will be wrapped into lemon.
   436   /// Later other LP-solvers will be wrapped into lemon.
   472     int _addRow() { 
   478     int _addRow() { 
   473       return lpx_add_rows(lp, 1);
   479       return lpx_add_rows(lp, 1);
   474     }
   480     }
   475     /// \e
   481     /// \e
   476     virtual void _setRowCoeffs(int i, 
   482     virtual void _setRowCoeffs(int i, 
   477 			       std::vector<std::pair<int, double> > coeffs) {
   483 			       const std::vector<std::pair<int, double> >& coeffs) {
   478       int mem_length=1+colNum();
   484       int mem_length=1+colNum();
   479       int* indices = new int[mem_length];
   485       int* indices = new int[mem_length];
   480       double* doubles = new double[mem_length];
   486       double* doubles = new double[mem_length];
   481       int length=0;
   487       int length=0;
   482       for (std::vector<std::pair<int, double> >::
   488       for (std::vector<std::pair<int, double> >::
   492       delete [] indices;
   498       delete [] indices;
   493       delete [] doubles;
   499       delete [] doubles;
   494     }
   500     }
   495     /// \e
   501     /// \e
   496     virtual void _setColCoeffs(int i, 
   502     virtual void _setColCoeffs(int i, 
   497 			       std::vector<std::pair<int, double> > coeffs) {
   503 			       const std::vector<std::pair<int, double> >& coeffs) {
   498       int mem_length=1+rowNum();
   504       int mem_length=1+rowNum();
   499       int* indices = new int[mem_length];
   505       int* indices = new int[mem_length];
   500       double* doubles = new double[mem_length];
   506       double* doubles = new double[mem_length];
   501       int length=0;
   507       int length=0;
   502       for (std::vector<std::pair<int, double> >::
   508       for (std::vector<std::pair<int, double> >::