Skip to content

Commit

Permalink
no way tp specify default arguments for methods, use method overloading
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgen-lentz committed Feb 15, 2025
1 parent 6121e07 commit cb61454
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
20 changes: 14 additions & 6 deletions src/rampl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,16 @@ bool RAMPL::isRunning() const {
return _impl.isRunning();
}

/*.. method:: AMPL.solve(problem, solver)
Solve the current model.
:raises Error: If the underlying interpreter is not running.
*/
void RAMPL::solve() {
_impl.solve("", "");
}

/*.. method:: AMPL.solve(problem, solver)
Solve the current model.
Expand All @@ -318,11 +328,8 @@ bool RAMPL::isRunning() const {
:param string solver: The solver that will be used to solve the problem.
:raises Error: If the underlying interpreter is not running.
*/
void RAMPL::solve(Rcpp::Nullable<std::string> problem, Rcpp::Nullable<std::string> solver) {
std::string cpp_problem = problem.isNotNull() ? Rcpp::as<std::string>(problem) : "";
std::string cpp_solver = solver.isNotNull() ? Rcpp::as<std::string>(solver) : "";

_impl.solve(cpp_problem, cpp_solver);
void RAMPL::solve(std::string problem, std::string solver) {
_impl.solve(problem, solver);
}


Expand Down Expand Up @@ -658,7 +665,8 @@ RCPP_MODULE(rampl){
.method("reset", &RAMPL::reset)
.method("close", &RAMPL::close)
.method("isRunning", &RAMPL::isRunning)
.method("solve", &RAMPL::solve, List::create( _["problem"], _["solver"] = "" ))
.method("solve", ( void (RAMPL::*)() )(&RAMPL::solve))
.method("solve", ( void (RAMPL::*)(std:string, std:string) )(&RAMPL::solve))

.method("getData", &RAMPL::getData)
.method("getValue", &RAMPL::getValue)
Expand Down
4 changes: 2 additions & 2 deletions src/rampl.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ class RAMPL {
void reset();
void close();
bool isRunning() const;
void solve(Rcpp::Nullable<std::string> problem = Rcpp::Nullable<std::string>(), Rcpp::Nullable<std::string> solver = Rcpp::Nullable<std::string>());

void solve();
void solve(std::string problem, std::string solver);
Rcpp::DataFrame getData(Rcpp::List statements) const;
SEXP getValue(std::string scalarExpression) const;
Rcpp::String getOutput(std::string amplstatements);
Expand Down

0 comments on commit cb61454

Please sign in to comment.