blob: a15b9e0ac2bf80f1dc60b9d98c4081d80ae50ae8 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
#ifndef LINPROG_SOLVER_H
#define LINPROG_SOLVER_H
#include "linprog/model.h"
class Solution
{
public:
virtual ~Solution() {};
virtual double get_value(unsigned int variable_index) const = 0;
virtual double evaluate(const LinearExpression &exp) const
{
double sum = 0;
foreach(exp.get_terms(), term)
{
double coeff = term->first;
double var = term->second;
sum += coeff * get_value(var);
}
return sum;
}
};
#if defined(CONFIG_HAVE_CPLEX)
#include "linprog/cplex.h"
#elif defined(CONFIG_HAVE_GLPK)
#include "linprog/glpk.h"
#else
#warning No LP solver available.
#endif
static inline Solution *linprog_solve(
const LinearProgram& lp,
unsigned int max_num_vars)
{
#if defined(CONFIG_HAVE_CPLEX)
return cpx_solve(lp, max_num_vars);
#elif defined(CONFIG_HAVE_GLPK)
return glpk_solve(lp, max_num_vars);
#else
assert(0);
return NULL;
#endif
}
#endif
|