Limbo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_solvers.cpp
Go to the documentation of this file.
1 
7 #include <iostream>
9 
11 void test1()
12 {
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 {
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 }
void test2(std::string const &filename)
test file API
maximize objective
Definition: Solvers.h:32
Basic utilities such as variables and linear expressions in solvers.
void test1()
test function API
int main(int argc, char **argv)
main function
void read(std::string const &filename)
read lp format
Definition: Solvers.h:1464
integer number
Definition: Solvers.h:34
model to describe an optimization problem
Definition: Solvers.h:80
#define limboAssertMsg(condition, args...)
custom assertion with message
Definition: AssertMsg.h:52