Scippy

SCIP

Solving Constraint Integer Programs

queens.hpp
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the examples to */
4 /* An introduction to SCIP */
5 /* */
6 /* Copyright (C) 2007 Cornelius Schwarz */
7 /* */
8 /* 2007 University of Bayreuth */
9 /* */
10 /* */
11 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12 
13 /**@file queens.hpp
14  * @brief n-queens example
15  * @author Cornelius Schwarz
16  */
17 
18 #ifndef QUEENS_H
19 #define QUEENS_H
20 
21 #include <vector>
22 #include <iostream>
23 
24 #include <scip/scip.h>
25 #include <scip/scipdefplugins.h>
26 
27 namespace scipexamples
28 {
29  /**@class QueensSolver
30  * @brief solver class for the n-queens problem
31  *
32  * this class implements a solver for the n-queens problem as an mip model, which will be solved using SCIP
33  */
35  {
36  private:
37 
38  /** @brief pointer to scip structure
39  *
40  * SCIP organizes all the problem informations by itself, we can access them by the SCIP * pointer
41  */
42  SCIP * _scip;
43 
44  /** @brief number of queens */
45  size_t _n;
46 
47  /** @brief one binary variable for each field (i,j) on the chess bord
48  *
49  * To access variable information (objective value, bounds,
50  * etc.) use the SCIP_VAR * pointer. Since we want to know the
51  * value of each variable in the solution, we have to store
52  * these pointers.
53  */
54  std::vector<std::vector<SCIP_VAR *> > _vars;
55 
56  /** @brief constraints for rows, cols and diags of the chess board
57  *
58  * To access constraint information (right hand side, left hand
59  * side, dual values, etc.) use the SCIP_CONS * pointer. For the
60  * n-queens problem we do not really need to store them but we
61  * do for illustration.
62  */
63  std::vector<SCIP_CONS *> _cons;
64 
65  public:
66  /** @brief constructs the BP model for the n-queens problem
67  *
68  * the constructor builds a BP model in scip for the n-queens problem
69  * @param[in] n the number of queens
70  */
71  QueensSolver(size_t n = 8);
72 
73  /** @brief destructor this is the place to release the SCIP_VAR
74  * and SCIP_CONS pointers and to free the SCIP pointer
75  * afterwards
76  */
77  ~QueensSolver();
78 
79  void solve(void); ///< solves the queens problem using SCIPsolve
80 
81  /** @brief display the solution
82  *
83  * a simplex ASCII output function to display the solution of the n - queens problem
84  * @param[in,out] out ostream class for output(default cout)
85  */
86  void disp(std::ostream & out = std::cout);
87  };
88 }
89 #endif
QueensSolver(size_t n=8)
constructs the BP model for the n-queens problem
Definition: queens.cpp:28
void solve(void)
solves the queens problem using SCIPsolve
Definition: queens.cpp:244
void disp(std::ostream &out=std::cout)
display the solution
Definition: queens.cpp:173
~QueensSolver()
destructor this is the place to release the SCIP_VAR and SCIP_CONS pointers and to free the SCIP poin...
Definition: queens.cpp:210
default SCIP plugins
SCIP callable library.
solver class for the n-queens problem
Definition: queens.hpp:34