Limbo
3.5.4
Toggle main menu visibility
Loading...
Searching...
No Matches
test
solvers
test_solvers.cpp
Go to the documentation of this file.
1
7
#include <iostream>
8
#include <
limbo/solvers/Solvers.h
>
9
11
void
test1
()
12
{
13
typedef
limbo::solvers::LinearModel<float, float>
model_type;
14
model_type optModel;
15
model_type::expression_type expr;
16
// create variables
17
std::vector<model_type::variable_type> vVar;
18
for
(
int
i = 0; i < 5; ++i)
19
vVar.push_back(optModel.addVariable(0, 5,
limbo::solvers::INTEGER
,
""
));
20
// create constraints
21
limboAssertMsg
(optModel.addConstraint(vVar[0]+1+2*vVar[1]-vVar[2]*10 <= 10),
"fail to add constraint"
);
22
limboAssertMsg
(optModel.addConstraint(-3*vVar[0]-1.5-vVar[1]+1.5+vVar[3] >= 5),
"fail to add constraint"
);
23
limboAssertMsg
(optModel.addConstraint(1-vVar[0]-2*(vVar[1]+vVar[3]) == 5),
"fail to add constraint"
);
24
expr = (vVar[4]*4-vVar[2]*3)/2;
25
expr = vVar[1]*2 + expr;
26
expr /= 2;
27
expr *= 4;
28
limboAssertMsg
(optModel.addConstraint(expr >= 1),
"fail to add constraint"
);
29
limboAssertMsg
(optModel.addConstraint(vVar[1]-vVar[0]-(1-vVar[1]) <= -1),
"fail to add constraint"
);
30
// create objective
31
expr.clear();
32
expr = vVar[0]*4 + vVar[1]*2 + vVar[2]/2 + (vVar[3]/4 - (-vVar[4])*5);
33
expr -= vVar[0] + -vVar[2]/4;
34
optModel.setObjective(expr);
35
optModel.setOptimizeType(
limbo::solvers::MAX
);
36
37
std::cout <<
"////////////////////// "
<< __func__ <<
"//////////////////////\n"
;
38
optModel.print(std::cout);
39
}
40
43
void
test2
(std::string
const
& filename)
44
{
45
typedef
limbo::solvers::LinearModel<float, float>
model_type;
46
model_type optModel;
47
optModel.
read
(filename);
48
49
std::cout <<
"////////////////////// "
<< __func__ <<
"//////////////////////\n"
;
50
optModel.print(std::cout);
51
}
52
56
int
main
(
int
argc,
char
** argv)
57
{
58
// test function API
59
test1
();
60
if
(argc > 1)
61
{
62
// test file API
63
test2
(argv[1]);
64
}
65
else
std::cout <<
"at least one argument is required to test file API\n"
;
66
67
return
0;
68
}
limboAssertMsg
#define limboAssertMsg(condition, args...)
custom assertion with message
Definition
AssertMsg.h:24
Solvers.h
Basic utilities such as variables and linear expressions in solvers.
limbo::solvers::LinearModel
model to describe an optimization problem
Definition
Solvers.h:1161
limbo::solvers::LinearModel::read
void read(std::string const &filename)
read lp format
Definition
Solvers.h:1464
limbo::solvers::MAX
@ MAX
maximize objective
Definition
Solvers.h:32
limbo::solvers::INTEGER
@ INTEGER
integer number
Definition
Solvers.h:34
main
int main()
Definition
test_ChromaticNumber.cpp:78
test1
void test1()
test function API
Definition
test_solvers.cpp:11
test2
void test2(std::string const &filename)
test file API
Definition
test_solvers.cpp:43
Generated on
for Limbo by
1.17.0