QUBO++ Library with QUBO Solver APIs
Author: Koji Nakano, License: Non-commercial research and evaluation purposes without any guarantees.
abs2.hpp
Go to the documentation of this file.
1 
19 #ifndef ABS2_HPP
20 #define ABS2_HPP
21 #include <iostream>
22 #include <memory>
23 #include <string>
24 
26 namespace abs2 {
27 //===========================
28 // Class forward declarations
29 //===========================
30 class Solver;
31 class Model;
32 class Param;
33 class Sol;
34 class Callback;
35 
36 //====================
37 // Class declarations
38 //====================
39 
43 class Solver {
44  public:
47  Solver(bool verbose = true);
48 
51 
55  std::string get(const std::string &key);
56 
60  void print(const std::string &option = "",
61  std::ostream &output_stream = std::cout) const;
62 
66  void print(std::ostream &output_stream, const std::string &option = "") const;
67 
73  Sol operator()(const Model &model, const Param &param) const;
74 
81  Sol operator()(const Model &model, const Param &param,
82  const Sol &start) const;
83 
84 private:
85  class Impl;
86  // std::unique_ptr<Impl> pimpl;
87  Impl *pimpl;
88 };
89 
91 class Model {
92  public:
98  Model(int size, int bits);
99 
105  Model(int size, int64_t min_coeff, int64_t max_coeff);
106 
109  Model(const std::string &filename);
110 
113 
116  Model(const Model &model);
117 
121  Model &operator=(const Model &model);
122 
127  void set(int i, int j, int64_t val);
128 
133  int64_t get(int i, int j) const;
134 
138  void set(const std::string &key, const std::string &val);
139 
143  std::string get(const std::string &key) const;
144 
148  void print(const std::string &option = "",
149  std::ostream &output_stream = std::cout) const;
150 
154  void print(std::ostream &output_stream, const std::string &option = "") const;
155 
156 private:
157  class Impl;
158  std::unique_ptr<Impl> pimpl;
159 };
160 
162 class Param {
163  public:
165  Param();
170  Param(const Param &param);
174  Param &operator=(const Param &param);
178  void set(const std::string &key, const std::string &val);
182  std::string get(const std::string &key) const;
188  void set(Callback &callback);
192  void print(const std::string &option = "",
193  std::ostream &output_stream = std::cout) const;
197  void print(std::ostream &output_stream, const std::string &option = "") const;
198 
199 private:
200  class Impl;
201  std::unique_ptr<Impl> pimpl;
202 };
205 class Sol {
206  public:
209  Sol(int size);
211  Sol();
213  ~Sol();
216  Sol(const Sol &sol);
219  Sol(Sol &&sol);
222  Sol &operator=(const Sol &sol);
225  Sol &operator=(Sol &&sol);
229  void set(int i, bool val);
233  bool get(int i) const;
237  void set(const std::string &key, const std::string &val);
241  const std::string get(const std::string &key) const;
245  void print(const std::string &option = "",
246  std::ostream &output_stream = std::cout) const;
250  void print(std::ostream &output_stream, const std::string &option = "") const;
251 
252 private:
253  class Impl;
254  std::unique_ptr<Impl> pimpl;
255 };
256 
258 class Callback {
259  public:
264  virtual ~Callback() = default;
268  virtual void callback(const std::string &event) = 0;
272  void set(const std::string &operation);
277  void set(const std::string &operation, const std::string &operand);
282  void set(const Sol &hint);
284  const Sol &get() const;
285 
286 private:
287  class Impl;
288  std::shared_ptr<Impl> pimpl;
289 };
290 
291 } // namespace abs2
292 
293 #endif // ABS2_HPP_
Class to manage callback function for ABS2 QUBO solver.
Definition: abs2.hpp:258
void set(const std::string &operation, const std::string &operand)
Set the operation and operand to the ABS2 Callback.
void set(const std::string &operation)
Set the operation to the ABS2 Callback.
virtual ~Callback()=default
Destructor for deleting a callback object.
void set(const Sol &hint)
Provide a hint solution to the ABS2 solver.
virtual void callback(const std::string &event)=0
Callback function must be defined by user.
const Sol & get() const
Get the current solution.
Callback()
Constructor for creating a callback object.
std::shared_ptr< Impl > pimpl
Definition: abs2.hpp:287
Class to store and manipulate a QUBO model.
Definition: abs2.hpp:91
Model & operator=(const Model &model)
Assignment operator for copying the QUBO model.
Model(const Model &model)
Copy constructor for the QUBO model.
Model(const std::string &filename)
Constructor for loading a QUBO model from a file.
void print(std::ostream &output_stream, const std::string &option="") const
Outputs the model to the specified output stream.
int64_t get(int i, int j) const
Gets the value of W_{i,j} if i<=j, and W_{j,i} if j<i.
void set(int i, int j, int64_t val)
Sets the value of W_{i,j} if i<=j, and W_{j,i} if j<i.
std::unique_ptr< Impl > pimpl
Definition: abs2.hpp:157
Model(int size, int bits)
Constructor for an empty QUBO model.
void set(const std::string &key, const std::string &val)
Sets a value for a given key.
std::string get(const std::string &key) const
Gets the value associated with a given key.
void print(const std::string &option="", std::ostream &output_stream=std::cout) const
Outputs the model to the specified output stream.
~Model()
Destructor for the QUBO model.
Model(int size, int64_t min_coeff, int64_t max_coeff)
Constructor for an empty QUBO model with specified variable size and coefficient range.
Class to store parameters for ABS2 QUBO solver.
Definition: abs2.hpp:162
std::unique_ptr< Impl > pimpl
Definition: abs2.hpp:200
~Param()
Destructor.
Param & operator=(const Param &param)
Assignment overload with copying "param".
void set(const std::string &key, const std::string &val)
Set "val" to "key".
void print(const std::string &option="", std::ostream &output_stream=std::cout) const
Output parameters in stream "output_stream".
void print(std::ostream &output_stream, const std::string &option="") const
Output parameters in stream "output_stream".
Param()
Constructor for creating param object with empty parameters.
Param(const Param &param)
Copy Constructor with copying "param".
void set(Callback &callback)
Set Callback function to ABS2.
std::string get(const std::string &key) const
Get the value of "key".
Class to store a solution computed by ABS2 QUBO solver.
Definition: abs2.hpp:205
Sol(int size)
Constructor for a solution with "size" bits.
void print(const std::string &option="", std::ostream &output_stream=std::cout) const
Output solution in stream "output_stream".
Sol(Sol &&sol)
Move constructor. Create a new Sol object from "sol".
Sol & operator=(const Sol &sol)
Copy assignment of "sol".
void print(std::ostream &output_stream, const std::string &option="") const
Output solution in stream "output_stream".
Sol()
Construct a new Sol object.
Sol(const Sol &sol)
Copy constructor. Create a new Sol object from "sol".
~Sol()
Destructor.
bool get(int i) const
Get the value of x_i.
Sol & operator=(Sol &&sol)
Move assignment of "sol".
void set(const std::string &key, const std::string &val)
Set "val" to key.
std::unique_ptr< Impl > pimpl
Definition: abs2.hpp:253
void set(int i, bool val)
Set "val" to x_i.
const std::string get(const std::string &key) const
Get the value of key.
Class to configure the ABS2 QUBO solver.
Definition: abs2.hpp:43
Solver(bool verbose=true)
Constructor for the ABS2 QUBO solver.
Sol operator()(const Model &model, const Param &param, const Sol &start) const
Executes the ABS2 solver for the given model, parameters, and initial solution, returning the solutio...
void print(std::ostream &output_stream, const std::string &option="") const
Outputs the solver attribute value in the specified format.
~Solver()
Destructor for the ABS2 QUBO solver.
void print(const std::string &option="", std::ostream &output_stream=std::cout) const
Outputs the solver attribute value in the specified format.
Impl * pimpl
Definition: abs2.hpp:85
std::string get(const std::string &key)
Retrieves the solver attribute value associated with the given key.
Sol operator()(const Model &model, const Param &param) const
Executes the ABS2 solver for the given model and parameters, returning the solution.
Namespace to call ABS2 GPU QUBO solver.
Definition: abs2.hpp:26