assignment_optimization-2Dgrasp
solver.h
1 // -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2 //
3 // Author: Ugo Pattacini - <ugo.pattacini@iit.it>
4 
5 #ifndef SOLVER_H
6 #define SOLVER_H
7 
8 #include <vector>
9 #include <IpTNLP.hpp>
10 #include "problem.h"
11 
12 namespace problem_ns {
13 
17 class Grasp : public Ipopt::TNLP
18 {
19 protected:
20  const Problem &problem;
21  std::vector<Force> result;
22 
23  /***************************************************/
24  bool get_nlp_info(Ipopt::Index &n, Ipopt::Index &m,
25  Ipopt::Index &nnz_jac_g,
26  Ipopt::Index &nnz_h_lag,
27  IndexStyleEnum &index_style) override;
28 
29  /***************************************************/
30  bool get_bounds_info(Ipopt::Index n, Ipopt::Number *x_l,
31  Ipopt::Number *x_u, Ipopt::Index m,
32  Ipopt::Number *g_l, Ipopt::Number *g_u) override;
33 
34  /***************************************************/
35  bool get_starting_point(Ipopt::Index n, bool init_x,
36  Ipopt::Number *x, bool init_z,
37  Ipopt::Number *z_L, Ipopt::Number *z_U,
38  Ipopt::Index m, bool init_lambda,
39  Ipopt::Number *lambda) override;
40 
41  /***************************************************/
42  bool eval_f(Ipopt::Index n, const Ipopt::Number *x,
43  bool new_x, Ipopt::Number &obj_value) override;
44 
45  /***************************************************/
46  bool eval_grad_f(Ipopt::Index n, const Ipopt::Number *x,
47  bool new_x, Ipopt::Number *grad_f) override;
48 
49  /***************************************************/
50  bool eval_g(Ipopt::Index n, const Ipopt::Number *x,
51  bool new_x, Ipopt::Index m, Ipopt::Number *g) override;
52 
53  /***************************************************/
54  bool eval_jac_g(Ipopt::Index n, const Ipopt::Number *x,
55  bool new_x, Ipopt::Index m, Ipopt::Index nele_jac,
56  Ipopt::Index *iRow, Ipopt::Index *jCol,
57  Ipopt::Number *values) override;
58 
59  /***************************************************/
60  bool eval_h(Ipopt::Index n, const Ipopt::Number *x, bool new_x,
61  Ipopt::Number obj_factor, Ipopt::Index m, const Ipopt::Number *lambda,
62  bool new_lambda, Ipopt::Index nele_hess, Ipopt::Index *iRow,
63  Ipopt::Index *jCol, Ipopt::Number *values) override
64  {
65  return true;
66  }
67 
68  /***************************************************/
69  void finalize_solution(Ipopt::SolverReturn status,
70  Ipopt::Index n, const Ipopt::Number *x,
71  const Ipopt::Number *z_L,
72  const Ipopt::Number *z_U, Ipopt::Index m,
73  const Ipopt::Number *g, const Ipopt::Number *lambda,
74  Ipopt::Number obj_value, const Ipopt::IpoptData *ip_data,
75  Ipopt::IpoptCalculatedQuantities *ip_cq) override;
76 
77 public:
78  /***************************************************/
79  Grasp(const Problem &problem_) : problem(problem_), result(2) { }
80 
81  /***************************************************/
82  const std::vector<Force>& get_result() const
83  {
84  return result;
85  }
86 };
87 
91 class Solver
92 {
93 public:
100  static std::vector<Force> solve(const Problem& problem,
101  const bool verbose=true);
102 };
103 
104 }
105 
106 #endif
Definition: solver.h:18
Definition: problem.h:42
Definition: solver.h:92
static std::vector< Force > solve(const Problem &problem, const bool verbose=true)
Definition: solver.cpp:118