graph_analysis
Problem.hpp
Go to the documentation of this file.
1 #ifndef GRAPH_ANALYSIS_ALGORITHMS_LP_PROBLEM_HPP
2 #define GRAPH_ANALYSIS_ALGORITHMS_LP_PROBLEM_HPP
3 
4 #include <string>
5 #include <limits>
6 #include <vector>
7 #include <map>
8 #include "../LPSolver.hpp"
9 
10 namespace graph_analysis {
11 namespace algorithms {
12 namespace lp {
13 
14 typedef std::string Variable;
15 typedef std::vector<Variable> Variables;
16 typedef std::map<Variable, double> ObjectiveFunction;
20 
21 struct Bounds
22 {
23  Bounds();
24  Bounds(double min, double max, BoundType type = LowerUpper);
25 
26  double min;
27  double max;
28 
30 
31  static std::string minBound(double min);
32  static std::string maxBound(double max);
33 
34  std::string toLowerUpperString(const std::string& variable) const;
35 };
36 
38 {
39  MatrixEntry();
40  MatrixEntry(const std::string& columName,
41  double coefficient);
42 
43  std::string name;
44  double coefficient;
45 };
46 
48 {
49  Column();
50  Column(const std::string& name,
51  const Bounds& bounds,
52  double coefficient = 1.0);
53 
56 };
57 
58 struct Row
59 {
60  Row();
61  Row(const std::string& name,
62  const Bounds& bounds);
63 
64  std::string name;
66  std::vector<MatrixEntry> entries;
67 };
68 
69 
70 class Problem
71 {
72 public:
73 
79  Problem(const std::string& name,
80  OptimizationDirection optimizationDirection = OPTIMIZE_MIN);
81 
82  void setRowBounds(const std::string& row, double min, double max);
83  void setRowBoundsExact(const std::string& row, double exact) { setRowBounds(row, exact, exact); }
84  void addRow(const Row& row);
85  Row& rowByName(const std::string& name);
89  Row& rowByIdx(size_t idx, size_t offset = -1);
90 
91 
92  void setColumnBounds(const std::string& col, double min, double max);
93  void setColumnBoundsExact(const std::string& col, double exact) { setColumnBounds(col, exact, exact); }
94  void addColumn(const Column& column, bool doThrow = false);
98  Column& columnByIdx(size_t idx, size_t offset = -1);
99 
101  std::string toString(size_t indent = 0) const;
102 
103 private:
104  std::string mName;
105  std::vector<Column> mColumns;
106  std::vector<Row> mRows;
107 
108  OptimizationDirection mOptimizationDirection;
109 
110 };
111 } // end namespace lp
112 } // end namespace algorithms
113 } // end namespace graph_analysis
114 #endif // GRAPH_ANALYSIS_ALGORITHMS_LP_PROBLEM_HPP
graph_analysis::algorithms::lp::Bounds::maxBound
static std::string maxBound(double max)
Definition: Problem.cpp:44
graph_analysis::algorithms::lp::Problem::setRowBounds
void setRowBounds(const std::string &row, double min, double max)
Definition: Problem.cpp:97
graph_analysis::algorithms::lp::Row::bounds
Bounds bounds
Definition: Problem.hpp:65
graph_analysis::algorithms::lp::LowerUpper
@ LowerUpper
Definition: Problem.hpp:18
graph_analysis::algorithms::lp::Bounds::toLowerUpperString
std::string toLowerUpperString(const std::string &variable) const
Definition: Problem.cpp:25
graph_analysis::algorithms::lp::Bounds::minBound
static std::string minBound(double min)
Definition: Problem.cpp:30
graph_analysis::algorithms::lp::Row::Row
Row()
Definition: Problem.cpp:70
graph_analysis::algorithms::lp::Problem::setColumnBoundsExact
void setColumnBoundsExact(const std::string &col, double exact)
Definition: Problem.hpp:93
graph_analysis::algorithms::lp::Column::type
ValueType type
Definition: Problem.hpp:55
graph_analysis::algorithms::lp::Row
Definition: Problem.hpp:58
graph_analysis::algorithms::lp::Problem::addRow
void addRow(const Row &row)
Definition: Problem.cpp:125
graph_analysis::algorithms::lp::Problem::rowByName
Row & rowByName(const std::string &name)
Definition: Problem.cpp:105
graph_analysis::algorithms::lp::Upper
@ Upper
Definition: Problem.hpp:18
graph_analysis::algorithms::lp::Bounds::type
BoundType type
Definition: Problem.hpp:29
graph_analysis::algorithms::lp::Problem::Problem
Problem(const std::string &name, OptimizationDirection optimizationDirection=OPTIMIZE_MIN)
Definition: Problem.cpp:58
graph_analysis::algorithms::lp::ValueType
ValueType
Definition: Problem.hpp:17
graph_analysis::algorithms::lp::Variable
std::string Variable
Definition: Problem.hpp:14
graph_analysis
Main namespace of the graph analysis library.
Definition: BFS.cpp:3
graph_analysis::algorithms::lp::MatrixEntry::name
std::string name
Definition: Problem.hpp:43
graph_analysis::algorithms::lp::Problem::saveProblemToTempfile
std::string saveProblemToTempfile(LPSolver::ProblemFormat format=LPSolver::CPLEX)
Definition: Problem.cpp:302
graph_analysis::algorithms::lp::Problem::toString
std::string toString(size_t indent=0) const
Definition: Problem.cpp:167
graph_analysis::algorithms::lp::Integer
@ Integer
Definition: Problem.hpp:17
graph_analysis::algorithms::lp::Problem::setRowBoundsExact
void setRowBoundsExact(const std::string &row, double exact)
Definition: Problem.hpp:83
graph_analysis::algorithms::lp::Bounds::max
double max
Definition: Problem.hpp:27
graph_analysis::algorithms::lp::Bounds
Definition: Problem.hpp:21
graph_analysis::algorithms::lp::Binary
@ Binary
Definition: Problem.hpp:17
graph_analysis::algorithms::LPSolver::ProblemFormat
ProblemFormat
Definition: LPSolver.hpp:41
graph_analysis::algorithms::lp::Row::entries
std::vector< MatrixEntry > entries
Definition: Problem.hpp:66
graph_analysis::algorithms::lp::BoundType
BoundType
Definition: Problem.hpp:18
graph_analysis::algorithms::lp::ObjectiveFunction
std::map< Variable, double > ObjectiveFunction
Definition: Problem.hpp:16
graph_analysis::algorithms::lp::Bounds::min
double min
Definition: Problem.hpp:26
graph_analysis::algorithms::lp::MatrixEntry
Definition: Problem.hpp:37
graph_analysis::algorithms::lp::Lower
@ Lower
Definition: Problem.hpp:18
graph_analysis::algorithms::lp::OPTIMIZE_MIN
@ OPTIMIZE_MIN
Definition: Problem.hpp:19
graph_analysis::algorithms::lp::Problem::setColumnBounds
void setColumnBounds(const std::string &col, double min, double max)
graph_analysis::algorithms::lp::MatrixEntry::MatrixEntry
MatrixEntry()
Definition: Problem.cpp:79
graph_analysis::algorithms::lp::Continuous
@ Continuous
Definition: Problem.hpp:17
graph_analysis::algorithms::lp::OptimizationDirection
OptimizationDirection
Definition: Problem.hpp:19
graph_analysis::algorithms::lp::Problem
Definition: Problem.hpp:70
graph_analysis::algorithms::lp::Column::bounds
Bounds bounds
Definition: Problem.hpp:54
graph_analysis::algorithms::lp::Problem::columnByIdx
Column & columnByIdx(size_t idx, size_t offset=-1)
Definition: Problem.cpp:162
graph_analysis::algorithms::lp::Free
@ Free
Definition: Problem.hpp:18
graph_analysis::algorithms::LPSolver::CPLEX
@ CPLEX
Definition: LPSolver.hpp:41
graph_analysis::algorithms::lp::Problem::rowByIdx
Row & rowByIdx(size_t idx, size_t offset=-1)
Definition: Problem.cpp:120
graph_analysis::algorithms::lp::Row::name
std::string name
Definition: Problem.hpp:64
graph_analysis::algorithms::lp::Variables
std::vector< Variable > Variables
Definition: Problem.hpp:15
graph_analysis::algorithms::lp::Column
Definition: Problem.hpp:47
graph_analysis::algorithms::lp::MatrixEntry::coefficient
double coefficient
Definition: Problem.hpp:44
graph_analysis::algorithms::lp::Exact
@ Exact
Definition: Problem.hpp:18
graph_analysis::algorithms::lp::Problem::addColumn
void addColumn(const Column &column, bool doThrow=false)
Definition: Problem.cpp:144
graph_analysis::algorithms::lp::Column::Column
Column()
Definition: Problem.cpp:83
graph_analysis::algorithms::lp::Bounds::Bounds
Bounds()
Definition: Problem.cpp:13
graph_analysis::algorithms::lp::OPTIMIZE_MAX
@ OPTIMIZE_MAX
Definition: Problem.hpp:19