line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------- |
2
|
|
|
|
|
|
|
| Copyright (c) 2013-2017, Nucleic Development Team. |
3
|
|
|
|
|
|
|
| |
4
|
|
|
|
|
|
|
| Distributed under the terms of the Modified BSD License. |
5
|
|
|
|
|
|
|
| |
6
|
|
|
|
|
|
|
| The full license is in the file LICENSE, distributed with this software. |
7
|
|
|
|
|
|
|
|----------------------------------------------------------------------------*/ |
8
|
|
|
|
|
|
|
#pragma once |
9
|
|
|
|
|
|
|
#include "constraint.h" |
10
|
|
|
|
|
|
|
#include "debug.h" |
11
|
|
|
|
|
|
|
#include "solverimpl.h" |
12
|
|
|
|
|
|
|
#include "strength.h" |
13
|
|
|
|
|
|
|
#include "variable.h" |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
namespace kiwi |
17
|
|
|
|
|
|
|
{ |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
class Solver |
20
|
|
|
|
|
|
|
{ |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
public: |
23
|
|
|
|
|
|
|
|
24
|
10
|
|
|
|
|
|
Solver() = default; |
25
|
|
|
|
|
|
|
|
26
|
10
|
|
|
|
|
|
~Solver() = default; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
/* Add a constraint to the solver. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Throws |
31
|
|
|
|
|
|
|
------ |
32
|
|
|
|
|
|
|
DuplicateConstraint |
33
|
|
|
|
|
|
|
The given constraint has already been added to the solver. |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
UnsatisfiableConstraint |
36
|
|
|
|
|
|
|
The given constraint is required and cannot be satisfied. |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
*/ |
39
|
2497
|
|
|
|
|
|
void addConstraint( const Constraint& constraint ) |
40
|
|
|
|
|
|
|
{ |
41
|
2497
|
|
|
|
|
|
m_impl.addConstraint( constraint ); |
42
|
2497
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
/* Remove a constraint from the solver. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Throws |
47
|
|
|
|
|
|
|
------ |
48
|
|
|
|
|
|
|
UnknownConstraint |
49
|
|
|
|
|
|
|
The given constraint has not been added to the solver. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
*/ |
52
|
0
|
|
|
|
|
|
void removeConstraint( const Constraint& constraint ) |
53
|
|
|
|
|
|
|
{ |
54
|
0
|
|
|
|
|
|
m_impl.removeConstraint( constraint ); |
55
|
0
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
/* Test whether a constraint has been added to the solver. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
*/ |
60
|
0
|
|
|
|
|
|
bool hasConstraint( const Constraint& constraint ) const |
61
|
|
|
|
|
|
|
{ |
62
|
0
|
|
|
|
|
|
return m_impl.hasConstraint( constraint ); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
/* Add an edit variable to the solver. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
This method should be called before the `suggestValue` method is |
68
|
|
|
|
|
|
|
used to supply a suggested value for the given edit variable. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Throws |
71
|
|
|
|
|
|
|
------ |
72
|
|
|
|
|
|
|
DuplicateEditVariable |
73
|
|
|
|
|
|
|
The given edit variable has already been added to the solver. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
BadRequiredStrength |
76
|
|
|
|
|
|
|
The given strength is >= required. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
*/ |
79
|
719
|
|
|
|
|
|
void addEditVariable( const Variable& variable, double strength ) |
80
|
|
|
|
|
|
|
{ |
81
|
719
|
|
|
|
|
|
m_impl.addEditVariable( variable, strength ); |
82
|
719
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
/* Remove an edit variable from the solver. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Throws |
87
|
|
|
|
|
|
|
------ |
88
|
|
|
|
|
|
|
UnknownEditVariable |
89
|
|
|
|
|
|
|
The given edit variable has not been added to the solver. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
*/ |
92
|
0
|
|
|
|
|
|
void removeEditVariable( const Variable& variable ) |
93
|
|
|
|
|
|
|
{ |
94
|
0
|
|
|
|
|
|
m_impl.removeEditVariable( variable ); |
95
|
0
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
/* Test whether an edit variable has been added to the solver. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
*/ |
100
|
0
|
|
|
|
|
|
bool hasEditVariable( const Variable& variable ) const |
101
|
|
|
|
|
|
|
{ |
102
|
0
|
|
|
|
|
|
return m_impl.hasEditVariable( variable ); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
/* Suggest a value for the given edit variable. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
This method should be used after an edit variable as been added to |
108
|
|
|
|
|
|
|
the solver in order to suggest the value for that variable. After |
109
|
|
|
|
|
|
|
all suggestions have been made, the `solve` method can be used to |
110
|
|
|
|
|
|
|
update the values of all variables. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Throws |
113
|
|
|
|
|
|
|
------ |
114
|
|
|
|
|
|
|
UnknownEditVariable |
115
|
|
|
|
|
|
|
The given edit variable has not been added to the solver. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
*/ |
118
|
619
|
|
|
|
|
|
void suggestValue( const Variable& variable, double value ) |
119
|
|
|
|
|
|
|
{ |
120
|
619
|
|
|
|
|
|
m_impl.suggestValue( variable, value ); |
121
|
619
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
/* Update the values of the external solver variables. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
*/ |
126
|
8
|
|
|
|
|
|
void updateVariables() |
127
|
|
|
|
|
|
|
{ |
128
|
8
|
|
|
|
|
|
m_impl.updateVariables(); |
129
|
8
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
/* Reset the solver to the empty starting condition. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
This method resets the internal solver state to the empty starting |
134
|
|
|
|
|
|
|
condition, as if no constraints or edit variables have been added. |
135
|
|
|
|
|
|
|
This can be faster than deleting the solver and creating a new one |
136
|
|
|
|
|
|
|
when the entire system must change, since it can avoid unecessary |
137
|
|
|
|
|
|
|
heap (de)allocations. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
*/ |
140
|
0
|
|
|
|
|
|
void reset() |
141
|
|
|
|
|
|
|
{ |
142
|
0
|
|
|
|
|
|
m_impl.reset(); |
143
|
0
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
/* Dump a representation of the solver internals to stdout. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
*/ |
148
|
0
|
|
|
|
|
|
void dump() |
149
|
|
|
|
|
|
|
{ |
150
|
0
|
|
|
|
|
|
debug::dump( m_impl ); |
151
|
0
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
/* Dump a representation of the solver internals to a stream. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
*/ |
156
|
|
|
|
|
|
|
void dump( std::ostream& out ) |
157
|
|
|
|
|
|
|
{ |
158
|
|
|
|
|
|
|
debug::dump( m_impl, out ); |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
/* Dump a representation of the solver internals to a string. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
*/ |
164
|
0
|
|
|
|
|
|
std::string dumps() |
165
|
|
|
|
|
|
|
{ |
166
|
0
|
|
|
|
|
|
return debug::dumps( m_impl ); |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
private: |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Solver( const Solver& ); |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Solver& operator=( const Solver& ); |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
impl::SolverImpl m_impl; |
176
|
|
|
|
|
|
|
}; |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
} // namespace kiwi |