lp_generator.h 1.96 KB
Newer Older
Jonas Seidel's avatar
Jonas Seidel committed
1
2
3
4
5
6
7
8
#ifndef LP_GENERATOR_H
#define LP_GENERATOR_H

#include <string>
#include <sstream>
#include <tuple>
#include <vector>
#include <map>
jonasseidel's avatar
jonasseidel committed
9
#include <unordered_map>
Jonas Seidel's avatar
Jonas Seidel committed
10
11
12
13
14
#include <functional>

#include "../Linear_Programming/Linear_Program.h"
#include "../Graphtheory/Graph.h"

Jonas Seidel's avatar
Jonas Seidel committed
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using lhs_constraint_data =
std::pair<
  std::vector<
    std::pair<
      std::pair<Node*,std::string>,
      double
    >
  >,
  std::vector<
    std::pair<
      std::pair<Edge*,std::string>,
      double
    >
  >
>;
Jonas Seidel's avatar
Jonas Seidel committed
30

Jonas Seidel's avatar
Jonas Seidel committed
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using constraint_data =
std::tuple<
  std::string,
  relation,
  lhs_constraint_data,
  double
>;


using node_constraint_data_generator =
std::function<
  std::vector<constraint_data>(Node*)
>;

using edge_constraint_data_generator =
std::function<
  std::vector<constraint_data>(Edge*)
>;
Jonas Seidel's avatar
Jonas Seidel committed
49
50

class lp_generator{
jonasseidel's avatar
jonasseidel committed
51
  static std::unordered_map<Variable*, Coefficient> lhs_from_data(
Jonas Seidel's avatar
Jonas Seidel committed
52
53
54
55
56
57
58
59
60
61
62
    lhs_constraint_data& data,

    const std::map<
      std::pair<Edge*,std::string>,
      std::pair<Variable*, size_t>
    >& edge_variable_lookup,

    const std::map<
      std::pair<Node*,std::string>,
      std::pair<Variable*, size_t>
    >& node_variable_lookup
63
  );
Jonas Seidel's avatar
Jonas Seidel committed
64

Jonas Seidel's avatar
Jonas Seidel committed
65
public:
Jonas Seidel's avatar
Jonas Seidel committed
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108

  static
  std::pair<
    std::map<
      std::pair<Node*, std::string>,
      std::pair<Variable*, size_t>
    >,
    std::map<
      std::pair<Edge*, std::string>,
      std::pair<Variable*, size_t>
    >
  >
  grow_from_graph(
    Linear_Program& lp,

    Graph& g,

    edge_constraint_data_generator edge_generator,

    node_constraint_data_generator node_generator,

    const std::vector<
      std::pair<
        std::string,
        std::tuple<
          integrality,
          std::pair<bool, double>,
          std::pair<bool, double>
        >
      >
    > edge_var_data,

    const std::vector<
      std::pair<
        std::string,
        std::tuple<
          integrality,
          std::pair<bool, double>,
          std::pair<bool, double>
        >
      >
    > node_var_data,

109
    std::string name_appendix
110
  );
Jonas Seidel's avatar
Jonas Seidel committed
111

Jonas Seidel's avatar
Jonas Seidel committed
112
};
Jonas Seidel's avatar
Jonas Seidel committed
113
114

#endif