this repo has no description
1/**** , [ QCSPPlusUnblockable.hh ],
2Copyright (c) 2009 Universite d'Orleans - Jeremie Vautard
3
4Permission is hereby granted, free of charge, to any person obtaining a copy
5of this software and associated documentation files (the "Software"), to deal
6in the Software without restriction, including without limitation the rights
7to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8copies of the Software, and to permit persons to whom the Software is
9furnished to do so, subject to the following conditions:
10
11The above copyright notice and this permission notice shall be included in
12all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20THE SOFTWARE.
21 *************************************************************************/
22
23#ifndef __QECODE_UNBLOCKABLE__
24#define __QECODE_UNBLOCKABLE__
25
26#include <iostream>
27#include<vector>
28#include "qecode.hh"
29#include "vartype.hh"
30#include "UnblockableBranching.hh"
31#include "myspace.hh"
32
33
34using namespace std;
35using namespace Gecode;
36
37class QECODE_VTABLE_EXPORT QcspUnblockable {
38private :
39
40 int n;
41 int nbSpaces;
42 void** v;
43 VarType* type_of_v;
44 int* whichSpaceOwns;
45 unsigned int currentDeclareSpace;
46 bool* Quantifiers;
47 MySpace* goal;
48 int* nbVarBySpace;
49 bool* varInitialised;
50 UnblockableBranching* br;
51 vector<int>* vars;
52 vector<int>* bvars;
53 MySpace* arul;
54
55public:
56 QECODE_EXPORT int nv() {return n;}
57
58 /** \brief Default constructor for a restricted-quantified space
59 *
60 * This is the first step for building a QCSP+/QCOP+ problem. The prefix is defined here.
61 * @param ns The number of scopes in the prefix.
62 * @param quant Array of booleans which contains the quantifier of every scope (true for universal, false for existential).
63 * @param nv Array of integer which contains the number of variables by scope.
64 */
65 QECODE_EXPORT QcspUnblockable(int ns, bool* quant,int* nv);
66 QECODE_EXPORT ~QcspUnblockable();
67
68 /** \brief Defines an integer variable in the quantified space
69 *
70 * Defines an integer variable in the quantifies space using a fully declared domain.
71 * @param var Number of the variable to be defined.
72 * @param dom The initial domain of the variable.
73 */
74 QECODE_EXPORT void QIntVar(int var,int min,int max);
75
76 /** \brief Defines an integer variable in the quantified space
77 *
78 * Defines an integer variable in the quantifies space using a fully declared domain.
79 * @param var Number of the variable to be defined.
80 * @param dom The initial domain of the variable.
81 */
82 QECODE_EXPORT void QIntVar(int var,IntSet dom);
83
84 /** \brief Defines a boolean variable in the quantified space
85 *
86 * Defines a boolean variable with a full initial domain in the quantified space.
87 * @param var Number of the variable to be defined.
88 */
89 QECODE_EXPORT void QBoolVar(int var);
90
91 /** \brief Returns the current declarating space
92 *
93 * Return the space we are currently declarating constraints in. nextScope() is used to set the nextspace as the current one.
94 */
95 QECODE_EXPORT MySpace* space();
96
97 /** \brief Returns an integer variable from the space we are currently declaring
98 *
99 * Returns an integer variable from the cpace we are currently declaring. Will abort if the variable is not integer.
100 * @param n The number of the variable to return.
101 */
102 QECODE_EXPORT IntVar var(int n);
103
104 /** \brief Returns a boolean variable from the space we are currently declaring
105 *
106 * Returns a boolean variable from the space we are currently declaring. Will abort if the variable is not boolean.
107 * @param n The number of the variable to return.
108 */
109 QECODE_EXPORT BoolVar bvar(int n);
110
111 /** \brief Switch to the next space for constraint declaration
112 *
113 * Switches to the next space for constraint declaration. var, bvar and space methods will now refer to the next rule space (or to the goal space if the current space was the last rule one).
114 * Returns the new space number, or -1 if it was called while there was no next space to declare constraints in.
115 */
116 QECODE_EXPORT int nextScope();
117
118 /** \brief Finalizes the object construction
119 *
120 * Finalizes the restricted-quantified space construction. Must be invoked once all the variable and all the constraints have been declared, and before the search is performed on this space.
121 * calling this method is not mandatory, although it is recommanded to besure that the problem have been well built.
122 * For the existential scopes on which an optimization condition have not been defined yet, this method will post a "Any" optimization condition (i.e. do not optimize).
123 */
124 QECODE_EXPORT void makeStructure();
125
126 QECODE_EXPORT bool qt_of_var(int v); ///< returns uantifier of variable 'v'
127 QECODE_EXPORT bool quantification(int scope) {return Quantifiers[scope];} ///< returns quantifier of scope 'scope'
128 QECODE_EXPORT int spaces(); ///< returns the number of scopes of the problem
129 QECODE_EXPORT int nbVarInScope(int scope) {return nbVarBySpace[scope];}///< returns the number of variables present in scope 'scope'
130 QECODE_EXPORT MySpace* getSpace(int scope);///< returns a copy of the Gecode::Space corresponding to the scope-th restricted quantifier of the problem
131 QECODE_EXPORT MySpace* getGoal();
132
133 /** \brief sets the branching heuristic
134 *
135 * Declares the branching heuristic that will be used to solve this problem.
136 */
137 QECODE_EXPORT void branch(UnblockableBranching* b);
138};
139
140#endif