Limbo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LpDataBase.h
Go to the documentation of this file.
1 
8 #ifndef LPPARSER_DATABASE_H
9 #define LPPARSER_DATABASE_H
10 
11 #include <string>
12 #include <vector>
13 #include <iostream>
14 #include <fstream>
15 #include <sstream>
16 #include <cassert>
17 #include <limits>
18 #include <limbo/math/Math.h>
19 
21 namespace LpParser {
22 
24 using std::cout;
25 using std::endl;
26 using std::cerr;
27 using std::string;
28 using std::vector;
29 using std::pair;
30 using std::make_pair;
31 using std::ostringstream;
32 typedef int int32_t;
33 typedef unsigned int uint32_t;
34 typedef long int64_t;
36 
38 typedef std::vector<int64_t> IntegerArray;
40 typedef std::vector<std::string> StringArray;
41 
42 #if 0
43 class IntegerArray : public vector<int64_t>
46 {
47  public:
49  typedef vector<int64_t> base_type;
50  using base_type::size_type;
51  using base_type::value_type;
52  using base_type::allocator_type;
54 
57  IntegerArray(const allocator_type& alloc = allocator_type())
58  : base_type(alloc) {}
63  IntegerArray(size_type n, const value_type& val, const allocator_type& alloc = allocator_type())
64  : base_type(n, val, alloc) {}
65 };
66 
69 class StringArray : public vector<string>
70 {
71  public:
73  typedef vector<string> base_type;
74  using base_type::size_type;
75  using base_type::value_type;
76  using base_type::allocator_type;
78 
81  StringArray(const allocator_type& alloc = allocator_type())
82  : base_type(alloc) {}
87  StringArray(size_type n, const value_type& val, const allocator_type& alloc = allocator_type())
88  : base_type(n, val, alloc) {}
89 };
90 #endif
91 
93 struct Term
94 {
95  double coef;
96  string var;
97 
101  Term(double c, string const& v) : coef(c), var(v) {}
102 };
103 
105 typedef std::vector<Term> TermArray;
106 
107 // temporary data structures to hold parsed data
108 
109 // forward declaration
115 {
116  public:
121  virtual void add_variable(string const& vname,
122  double l = limbo::lowest<double>(),
123  double r = std::numeric_limits<double>::max()) = 0;
129  virtual void add_constraint(string const& cname, TermArray const& terms, char compare, double constant) = 0;
133  virtual void add_objective(bool minimize, TermArray const& terms) = 0;
137  virtual void set_integer(string const& vname, bool binary) = 0;
138 };
139 
140 } // namespace DefParser
141 
142 #endif
string var
variable
Definition: LpDataBase.h:96
virtual void add_constraint(string const &cname, TermArray const &terms, char compare, double constant)=0
add constraint that terms compare constant.
Base class for lp database. Only pure virtual functions are defined. User needs to inheritate this cl...
Definition: LpDataBase.h:114
std::vector< Term > TermArray
array of terms
Definition: LpDataBase.h:105
virtual void set_integer(string const &vname, bool binary)=0
set integer variables
std::vector< std::string > StringArray
string array
Definition: LpDataBase.h:40
virtual void add_objective(bool minimize, TermArray const &terms)=0
add object terms
mathematical utilities such as abs
double coef
coefficient
Definition: LpDataBase.h:95
Term(double c, string const &v)
constructor
Definition: LpDataBase.h:101
std::iterator_traits< Iterator >::value_type max(Iterator first, Iterator last)
get max of an array
Definition: Math.h:61
double lowest< double >()
specialization for floating point types
Definition: Math.h:163
virtual void add_variable(string const &vname, double l=limbo::lowest< double >(), double r=std::numeric_limits< double >::max())=0
add variable that l <= vname <= r.
a term denotes coefficient times a variable
Definition: LpDataBase.h:93
namespace for LpParser
Definition: LpDataBase.h:21
std::vector< int64_t > IntegerArray
integer array
Definition: LpDataBase.h:38