Skip to content

Commit 92edf10

Browse files
committed
fix r api
1 parent 56aec94 commit 92edf10

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

src/rampl.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -491,11 +491,11 @@ RParameterEntity RAMPL::getParameter(std::string name) const {
491491
*/
492492
Rcpp::List RAMPL::getVariables() const {
493493
Rcpp::List list;
494-
ampl::EntityMap<ampl::Variable> map = _impl.getVariables();
494+
const ampl::EntityMap<ampl::Variable> map = _impl.getVariables();
495495
ampl::EntityMap<ampl::Variable>::iterator begin = map.begin();
496496
ampl::EntityMap<ampl::Variable>::iterator end = map.end();
497497
for(ampl::EntityMap<ampl::Variable>::iterator itr = begin; itr != end; itr++){
498-
list[itr->first] = RVariableEntity(itr->second);
498+
list[itr->name()] = RVariableEntity(*itr);
499499
}
500500
return list;
501501
}
@@ -508,11 +508,11 @@ Rcpp::List RAMPL::getVariables() const {
508508
*/
509509
Rcpp::List RAMPL::getConstraints() const {
510510
Rcpp::List list;
511-
ampl::EntityMap<ampl::Constraint> map = _impl.getConstraints();
511+
const ampl::EntityMap<ampl::Constraint> map = _impl.getConstraints();
512512
ampl::EntityMap<ampl::Constraint>::iterator begin = map.begin();
513513
ampl::EntityMap<ampl::Constraint>::iterator end = map.end();
514514
for(ampl::EntityMap<ampl::Constraint>::iterator itr = begin; itr != end; itr++){
515-
list[itr->first] = RConstraintEntity(itr->second);
515+
list[itr->name()] = RConstraintEntity(*itr);
516516
}
517517
return list;
518518
}
@@ -525,11 +525,11 @@ Rcpp::List RAMPL::getConstraints() const {
525525
*/
526526
Rcpp::List RAMPL::getObjectives() const {
527527
Rcpp::List list;
528-
ampl::EntityMap<ampl::Objective> map = _impl.getObjectives();
528+
const ampl::EntityMap<ampl::Objective> map = _impl.getObjectives();
529529
ampl::EntityMap<ampl::Objective>::iterator begin = map.begin();
530530
ampl::EntityMap<ampl::Objective>::iterator end = map.end();
531531
for(ampl::EntityMap<ampl::Objective>::iterator itr = begin; itr != end; itr++){
532-
list[itr->first] = RObjectiveEntity(itr->second);
532+
list[itr->name()] = RObjectiveEntity(*itr);
533533
}
534534
return list;
535535
}
@@ -542,11 +542,11 @@ Rcpp::List RAMPL::getObjectives() const {
542542
*/
543543
Rcpp::List RAMPL::getSets() const {
544544
Rcpp::List list;
545-
ampl::EntityMap<ampl::Set> map = _impl.getSets();
545+
const ampl::EntityMap<ampl::Set> map = _impl.getSets();
546546
ampl::EntityMap<ampl::Set>::iterator begin = map.begin();
547547
ampl::EntityMap<ampl::Set>::iterator end = map.end();
548548
for(ampl::EntityMap<ampl::Set>::iterator itr = begin; itr != end; itr++){
549-
list[itr->first] = RSetEntity(itr->second);
549+
list[itr->name()] = RSetEntity(*itr);
550550
}
551551
return list;
552552
}
@@ -559,11 +559,11 @@ Rcpp::List RAMPL::getSets() const {
559559
*/
560560
Rcpp::List RAMPL::getParameters() const {
561561
Rcpp::List list;
562-
ampl::EntityMap<ampl::Parameter> map = _impl.getParameters();
562+
const ampl::EntityMap<ampl::Parameter> map = _impl.getParameters();
563563
ampl::EntityMap<ampl::Parameter>::iterator begin = map.begin();
564564
ampl::EntityMap<ampl::Parameter>::iterator end = map.end();
565565
for(ampl::EntityMap<ampl::Parameter>::iterator itr = begin; itr != end; itr++){
566-
list[itr->first] = RParameterEntity(itr->second);
566+
list[itr->name()] = RParameterEntity(*itr);
567567
}
568568
return list;
569569
}

src/rbasicentity.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,9 @@ SEXP RBasicEntity<T, TW>::getScalar() const {
228228
*/
229229
template <class T, class TW>
230230
SEXP RBasicEntity<T, TW>::find(Rcpp::List index) const {
231+
typename ampl::BasicEntity<T>::iterator end = _impl.end();
231232
auto it = _impl.find(list2tuple(index));
232-
if(it != _impl.end()) {
233+
if(it != end) {
233234
return Rcpp::wrap(TW(it->second));
234235
} else {
235236
return R_NilValue;
@@ -245,7 +246,9 @@ SEXP RBasicEntity<T, TW>::find(Rcpp::List index) const {
245246
template <class T, class TW>
246247
Rcpp::List RBasicEntity<T, TW>::getInstances() const {
247248
Rcpp::List list;
248-
for(auto it = _impl.begin(); it != _impl.end(); it++) {
249+
typename ampl::BasicEntity<T>::iterator begin = _impl.begin();
250+
typename ampl::BasicEntity<T>::iterator end = _impl.end();
251+
for(auto it = begin; it != end; it++) {
249252
list[it->second.name()] = TW(it->second);
250253
}
251254
return list;

0 commit comments

Comments
 (0)