Skip to content

Commit 280978f

Browse files
committed
fix to new api
1 parent d357b49 commit 280978f

File tree

4 files changed

+19
-26
lines changed

4 files changed

+19
-26
lines changed

docs/source/reference/ramplcpp.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,12 @@ AMPL
203203

204204
Returns ``TRUE`` if the underlying engine is running.
205205

206-
.. method:: AMPL.solve("", "")
206+
.. method:: AMPL.solve(problem, solver)
207207

208208
Solve the current model.
209209

210+
:param string problem: The problem that will be solved.
211+
:param string solver: The solver that will be used to solve the problem.
210212
:raises Error: If the underlying interpreter is not running.
211213

212214
.. method:: AMPL.getData(statements)

src/rampl.cpp

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -471,12 +471,11 @@ RParameterEntity RAMPL::getParameter(std::string name) const {
471471
*/
472472
Rcpp::List RAMPL::getVariables() const {
473473
Rcpp::List list;
474-
//const ampl::EntityMap<ampl::Variable> map = _impl.getVariables();
475-
ampl::EntityMap<ampl::Variable> map = _impl.getVariables();
474+
const ampl::EntityMap<ampl::Variable> map = _impl.getVariables();
476475
ampl::EntityMap<ampl::Variable>::iterator begin = map.begin();
477476
ampl::EntityMap<ampl::Variable>::iterator end = map.end();
478477
for(ampl::EntityMap<ampl::Variable>::iterator itr = begin; itr != end; itr++){
479-
list[itr->first] = RVariableEntity(itr->second);
478+
list[itr->name()] = RVariableEntity(*itr);
480479
}
481480
return list;
482481
}
@@ -489,12 +488,11 @@ Rcpp::List RAMPL::getVariables() const {
489488
*/
490489
Rcpp::List RAMPL::getConstraints() const {
491490
Rcpp::List list;
492-
//const ampl::EntityMap<ampl::Constraint> map = _impl.getConstraints();
493-
ampl::EntityMap<ampl::Constraint> map = _impl.getConstraints();
491+
const ampl::EntityMap<ampl::Constraint> map = _impl.getConstraints();
494492
ampl::EntityMap<ampl::Constraint>::iterator begin = map.begin();
495493
ampl::EntityMap<ampl::Constraint>::iterator end = map.end();
496494
for(ampl::EntityMap<ampl::Constraint>::iterator itr = begin; itr != end; itr++){
497-
list[itr->first] = RConstraintEntity(itr->second);
495+
list[itr->name()] = RConstraintEntity(*itr);
498496
}
499497
return list;
500498
}
@@ -507,12 +505,11 @@ Rcpp::List RAMPL::getConstraints() const {
507505
*/
508506
Rcpp::List RAMPL::getObjectives() const {
509507
Rcpp::List list;
510-
//const ampl::EntityMap<ampl::Objective> map = _impl.getObjectives();
511-
ampl::EntityMap<ampl::Objective> map = _impl.getObjectives();
508+
const ampl::EntityMap<ampl::Objective> map = _impl.getObjectives();
512509
ampl::EntityMap<ampl::Objective>::iterator begin = map.begin();
513510
ampl::EntityMap<ampl::Objective>::iterator end = map.end();
514511
for(ampl::EntityMap<ampl::Objective>::iterator itr = begin; itr != end; itr++){
515-
list[itr->first] = RObjectiveEntity(itr->second);
512+
list[itr->name()] = RObjectiveEntity(*itr);
516513
}
517514
return list;
518515
}
@@ -525,12 +522,11 @@ Rcpp::List RAMPL::getObjectives() const {
525522
*/
526523
Rcpp::List RAMPL::getSets() const {
527524
Rcpp::List list;
528-
//const ampl::EntityMap<ampl::Set> map = _impl.getSets();
529-
ampl::EntityMap<ampl::Set> map = _impl.getSets();
525+
const ampl::EntityMap<ampl::Set> map = _impl.getSets();
530526
ampl::EntityMap<ampl::Set>::iterator begin = map.begin();
531527
ampl::EntityMap<ampl::Set>::iterator end = map.end();
532528
for(ampl::EntityMap<ampl::Set>::iterator itr = begin; itr != end; itr++){
533-
list[itr->first] = RSetEntity(itr->second);
529+
list[itr->name()] = RSetEntity(*itr);
534530
}
535531
return list;
536532
}
@@ -543,12 +539,11 @@ Rcpp::List RAMPL::getSets() const {
543539
*/
544540
Rcpp::List RAMPL::getParameters() const {
545541
Rcpp::List list;
546-
//const ampl::EntityMap<ampl::Parameter> map = _impl.getParameters();
547-
ampl::EntityMap<ampl::Parameter> map = _impl.getParameters();
542+
const ampl::EntityMap<ampl::Parameter> map = _impl.getParameters();
548543
ampl::EntityMap<ampl::Parameter>::iterator begin = map.begin();
549544
ampl::EntityMap<ampl::Parameter>::iterator end = map.end();
550545
for(ampl::EntityMap<ampl::Parameter>::iterator itr = begin; itr != end; itr++){
551-
list[itr->first] = RParameterEntity(itr->second);
546+
list[itr->name()] = RParameterEntity(*itr);
552547
}
553548
return list;
554549
}

src/rbasicentity.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,8 @@ SEXP RBasicEntity<T, TW>::getScalar() const {
228228
*/
229229
template <class T, class TW>
230230
SEXP RBasicEntity<T, TW>::find(Rcpp::List index) const {
231-
std::map<ampl::Tuple, T> instances = _impl.getInstances();
232-
typename std::map<ampl::Tuple, T>::iterator it = instances.find(list2tuple(index));
233-
if(it != instances.end()) {
231+
typename ampl::BasicEntity<T>::iterator it = _impl.find(list2tuple(index));
232+
if(it != _impl.end()) {
234233
return Rcpp::wrap(TW(it->second));
235234
} else {
236235
return R_NilValue;
@@ -246,8 +245,7 @@ SEXP RBasicEntity<T, TW>::find(Rcpp::List index) const {
246245
template <class T, class TW>
247246
Rcpp::List RBasicEntity<T, TW>::getInstances() const {
248247
Rcpp::List list;
249-
std::map<ampl::Tuple, T> instances = _impl.getInstances();
250-
for(typename std::map<ampl::Tuple, T>::iterator it = instances.begin(); it != instances.end(); it++) {
248+
for(typename ampl::BasicEntity<T>::iterator it = _impl.begin(); it != _impl.end(); it++) {
251249
list[it->second.name()] = TW(it->second);
252250
}
253251
return list;

src/rparam_entity.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,8 @@ SEXP RParameterEntity::getScalar() const {
165165
}
166166

167167
SEXP RParameterEntity::find(Rcpp::List index) const {
168-
std::map<ampl::Tuple, ampl::Variant> instances = _impl.getInstances();
169-
typename std::map<ampl::Tuple, ampl::Variant>::iterator it = instances.find(list2tuple(index));
170-
if(it != instances.end()) {
168+
ampl::BasicEntity<ampl::Variant>::iterator it = _impl.find(list2tuple(index));
169+
if(it != _impl.end()) {
171170
return variant2sexp(it->second);
172171
} else {
173172
return R_NilValue;
@@ -176,8 +175,7 @@ SEXP RParameterEntity::find(Rcpp::List index) const {
176175

177176
Rcpp::List RParameterEntity::getInstances() const {
178177
Rcpp::List list;
179-
std::map<ampl::Tuple, ampl::Variant> instances = _impl.getInstances();
180-
for(typename std::map<ampl::Tuple, ampl::Variant>::iterator it = instances.begin(); it != instances.end(); it++) {
178+
for(ampl::BasicEntity<ampl::Variant>::iterator it = _impl.begin(); it != _impl.end(); it++) {
181179
Rcpp::List row = tuple2list(it->first);
182180
row.push_back(variant2sexp(it->second));
183181
list.push_back(row);

0 commit comments

Comments
 (0)