-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathrcon_instance.cpp
301 lines (222 loc) · 8.84 KB
/
rcon_instance.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
#include "rcon_entity.h"
#include "utils.h"
#include <Rcpp.h>
/*.. _secRrefConInstance:
.. highlight:: r
ConstraintInstance
==================
*/
/*.. class:: ConstraintInstance
This class represent an instance of a constraint.
In general, all AMPL suffixes for a constraint are available through methods
with the same name in this class. See http://www.ampl.com/NEW/suffbuiltin.html
for a list of the available suffixes.
Note that, since this class represents instances of both algebraic and logical
constraints, some suffixes might not be available for every instance.
If a wrong suffix for the specific class
of constraint is accessed, an error is thrown.
All the accessors in this class throw an error if the instance
has been deleted in the underlying AMPL interpreter.
*/
RConstraintInstance::RConstraintInstance(ampl::ConstraintInstance impl): _impl(impl) { }
/*.. method:: ConstraintInstance.name()
Returns the name of this instance.
:return: Name of the instance.
*/
std::string RConstraintInstance::name() const {
return _impl.name();
}
/*.. method:: ConstraintInstance.toString()
Returns a string representation of this instance.
:return: String representation of this instance.
*/
std::string RConstraintInstance::toString() const {
return _impl.toString();
}
/*.. method:: ConstraintInstance.drop()
Drop this constraint instance, corresponding to the AMPL
code: `drop constraintname;`
*/
void RConstraintInstance::drop() {
return _impl.drop();
}
/*.. method:: ConstraintInstance.restore()
Restore this constraint instance, corresponding to the
AMPL code: `restore constraintname;`
*/
void RConstraintInstance::restore() {
return _impl.restore();
}
/*.. method:: ConstraintInstance.body()
Get the current value of the constraint's body.
:return: The current value of the constraint's body.
*/
double RConstraintInstance::body() const {
return _impl.body();
}
/*.. method:: ConstraintInstance.astatus()
Get the current AMPL status (dropped, presolved, or substituted out).
:return: The current AMPL status.
*/
std::string RConstraintInstance::astatus() const {
return _impl.astatus();
}
/*.. method:: ConstraintInstance.defvar()
Get the index in `_var` of "defined variable" substituted out by the constraint.
:return: The index of the variable substituted out by the constraint.
*/
int RConstraintInstance::defvar() const {
return _impl.defvar();
}
/*.. method:: ConstraintInstance.dinit()
Get the current initial guess for the constraint's dual variable.
:return: The current initial guess for the constraint's dual variable.
*/
double RConstraintInstance::dinit() const {
return _impl.dinit();
}
/*.. method:: ConstraintInstance.dinit0()
Get the original initial guess for the constraint's dual variable.
:return: The original initial guess for the constraint's dual variable.
*/
double RConstraintInstance::dinit0() const {
return _impl.dinit0();
}
/*.. method:: ConstraintInstance.dual()
Get the current value of the constraint's dual variable.
Note that dual values are often reset by the underlying AMPL interpreter by
the presolve functionalities triggered by some methods.
A possible workaround is to set the option `presolve;` to `false`
(see :meth:`~.AMPL.setOption`).
:return: The current value of the constraint's dual variable.
*/
double RConstraintInstance::dual() const {
return _impl.dual();
}
/*.. method:: ConstraintInstance.lb()
Get the current value of the constraint's lower bound.
:return: The current value of the constraint's lower bound.
*/
double RConstraintInstance::lb() const {
return _impl.lb();
}
/*.. method:: ConstraintInstance.ub()
Get the current value of the constraint's upper bound.
:return: The current value of the constraint's upper bound.
*/
double RConstraintInstance::ub() const {
return _impl.ub();
}
/*.. method:: ConstraintInstance.lbs()
Get the constraint lower bound sent to the solver (reflecting adjustment
for fixed variables).
:return: The constraint lower bound sent to the solver.
*/
double RConstraintInstance::lbs() const {
return _impl.lbs();
}
/*.. method:: ConstraintInstance.ubs()
Get the constraint upper bound sent to the solver (reflecting adjustment
for fixed variables).
:return: The constraint upper bound sent to the solver.
*/
double RConstraintInstance::ubs() const {
return _impl.ubs();
}
/*.. method:: ConstraintInstance.ldual()
Get the current dual value associated with the lower bound.
:return: The current dual value associated with the lower bound.
*/
double RConstraintInstance::ldual() const {
return _impl.ldual();
}
/*.. method:: ConstraintInstance.udual()
Get the current dual value associated with the upper bounds
:return: The current dual value associated with the upper bound.
*/
double RConstraintInstance::udual() const {
return _impl.udual();
}
/*.. method:: ConstraintInstance.lslack()
Get the slack at lower bound `body - lb`.
:return: The slack at lower bound.
*/
double RConstraintInstance::lslack() const {
return _impl.lslack();
}
/*.. method:: ConstraintInstance.uslack()
Get the slack at upper bound `ub - body`
:return: The slack at upper bound.
*/
double RConstraintInstance::uslack() const {
return _impl.uslack();
}
/*.. method:: ConstraintInstance.slack()
Constraint slack (the lesser of lslack and uslack).
:return: The constraint slack.
*/
double RConstraintInstance::slack() const {
return _impl.slack();
}
/*.. method:: ConstraintInstance.sstatus()
Get the solver status (basis status of constraint's slack or artificial variable)
:return: The solver status.
*/
std::string RConstraintInstance::sstatus() const {
return _impl.sstatus();
}
/*.. method:: ConstraintInstance.status()
Get the AMPL status if not `in`, otherwise solver status.
:return: The AMPL status.
*/
std::string RConstraintInstance::status() const {
return _impl.status();
}
/*.. method:: ConstraintInstance.setDual(dual)
Set the value of the dual variable associated to this constraint (valid
only if the constraint is scalar). Equivalent to the AMPL statement:
`let c := dual;`
Note that dual values are often reset by the underlying AMPL interpreter by
the presolve functionalities triggered by some methods.
A possible workaround is to set the option `presolve` to `false`
(see :meth:`~.AMPL.setOption`).
:param float dual: The value to be assigned to the dual variable.
*/
void RConstraintInstance::setDual(double dual) {
return _impl.setDual(dual);
}
/*.. method:: ConstraintInstance.val()
Get the AMPL val suffix. Valid only for logical constraints.
:return: The val suffix.
*/
double RConstraintInstance::val() const {
return _impl.val();
}
// *** RCPP_MODULE ***
RCPP_MODULE(rcon_instance){
Rcpp::class_<RConstraintInstance>( "ConstraintInstance" )
.method("name", &RConstraintInstance::name)
.method("toString", &RConstraintInstance::toString)
.method("drop", &RConstraintInstance::drop, "Drop this constraint instance")
.method("restore", &RConstraintInstance::restore, "Restore this constraint instance")
.method("body", &RConstraintInstance::body, "Get the current value of the constraint's body")
.method("astatus", &RConstraintInstance::astatus, "Get the current AMPL status")
.method("defvar", &RConstraintInstance::defvar, "Get the index of variable substituted out by the constraint")
.method("dinit", &RConstraintInstance::dinit, "Get the current initial guess for the constraint's dual variable")
.method("dinit0", &RConstraintInstance::dinit0, "Get the original initial guess for the constraint's dual variable")
.method("dual", &RConstraintInstance::dual, "Get the current value of the constraint's dual variable.")
.method("lb", &RConstraintInstance::lb, "Get the current value of the constraint's lower bound")
.method("ub", &RConstraintInstance::ub, "Get the current value of the constraint's upper bound")
.method("lbs", &RConstraintInstance::lbs, "Get the constraint lower bound sent to the solver")
.method("ubs", &RConstraintInstance::ubs, "Get the constraint upper bound sent to the solver")
.method("ldual", &RConstraintInstance::ldual, "Get the current dual value associated with the lower bound")
.method("udual", &RConstraintInstance::udual, "Get the current dual value associated with the upper bounds")
.method("lslack", &RConstraintInstance::lslack, "Get the slack at lower bound")
.method("uslack", &RConstraintInstance::uslack, "Get the slack at upper bound")
.method("slack", &RConstraintInstance::slack, "Constraint slack")
.method("sstatus", &RConstraintInstance::sstatus, "Get the solver status")
.method("status", &RConstraintInstance::status, "Get the AMPL status")
.method("setDual", &RConstraintInstance::setDual, "Set the value of the dual variable associated to this constraint")
.method("val", &RConstraintInstance::val, "Get the AMPL val suffix.")
;
}