Skip to content

Commit bc764d7

Browse files
committed
use default empty parameters in solve function
1 parent 3f4c693 commit bc764d7

File tree

7 files changed

+28
-19
lines changed

7 files changed

+28
-19
lines changed

docs/source/class-structure.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ The currently defined entities are obtained from the various get methods of the
258258
(see section :ref:`secAMPLClass`). Once a reference to an entity is created, the entity is automatically kept up-to-date
259259
with the corresponding entity in the AMPL interpreter. That is, if a reference to a newly created AMPL variable
260260
is obtained by means of :meth:`.AMPL.getVariable()`, and the model the variable is part of is then solved
261-
by means of :meth:`.AMPL.solve("", "")`, the values of the instances of the variable will automatically be updated.
261+
by means of :meth:`.AMPL.solve()`, the values of the instances of the variable will automatically be updated.
262262
The following code snippet should demonstrate the concept.
263263

264264
.. code-block:: R
@@ -271,7 +271,7 @@ The following code snippet should demonstrate the concept.
271271
# At this point x$value() evaluates to 0
272272
print(x$value()) # prints 0
273273
274-
ampl$solve("", "")
274+
ampl$solve()
275275
276276
# At this point x$value() evaluates to 10
277277
print(x$value()) # prints 10

docs/source/quick-start.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ This is the complete listing of the example. Please note that, for clarity of pr
3030
ampl$readData("models/diet.dat")
3131
3232
# Solve
33-
ampl$solve("", "")
33+
ampl$solve()
3434
3535
# Get objective entity by AMPL name
3636
totalcost <- ampl$getObjective("Total_Cost")
@@ -43,7 +43,7 @@ This is the complete listing of the example. Please note that, for clarity of pr
4343
cat("Increased costs of beef and ham.\n")
4444
4545
# Resolve and display objective
46-
ampl$solve("", "")
46+
ampl$solve()
4747
cat(sprintf("New objective value: %g\n", totalcost$value()))
4848
4949
# Reassign data - all instances
@@ -52,7 +52,7 @@ This is the complete listing of the example. Please note that, for clarity of pr
5252
cat("Updated all costs.\n")
5353
5454
# Resolve and display objective
55-
ampl$solve("", "")
55+
ampl$solve()
5656
cat(sprintf("New objective value: %g\n", totalcost$value()))
5757
5858
# Get the values of the variable Buy in a dataframe object
@@ -123,7 +123,7 @@ To solve the currently loaded problem instance, it is sufficient to issue the co
123123

124124
.. code-block:: R
125125
126-
ampl$solve("", "")
126+
ampl$solve()
127127
128128
129129
Get an AMPL entity in the programming environment (get objective value)
@@ -175,7 +175,7 @@ values is overloaded, and is in both cases :meth:`Parameter.setValues()`.
175175
cost <- ampl$getParameter("cost")
176176
cost$setValues(data.frame(index=c("BEEF", "HAM"), value=c(5.01, 4.55)))
177177
cat("Increased costs of beef and ham.\n")
178-
ampl$solve("", "")
178+
ampl$solve()
179179
cat(sprintf("New objective value: %g\n", totalcost$value()))
180180
181181
The code above assigns the values 5.01 and 4.55 to the parameter cost for the objects beef and ham respectively.
@@ -186,7 +186,7 @@ both the index and the value. A collection of values is assigned to each of the
186186
187187
cost$setValues(c(3, 5, 5, 6, 1, 2, 5.01, 4.55))
188188
cat("Updated all costs.\n")
189-
ampl$solve("", "")
189+
ampl$solve()
190190
cat(sprintf("New objective value: %g\n", totalcost$value()))
191191
192192
The statements above produce the following output::

examples/dietmodel.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ dietmodel <- function(solver=NULL, modelDirectory=NULL) {
4747
ampl$setData(df, 2, "")
4848

4949
# Solve the model
50-
ampl$solve("", "")
50+
ampl$solve()
5151

5252
# Print out the result
5353
cat(sprintf("Objective: %f\n", ampl$getObjective("Total_Cost")$value()))

examples/efficientfrontier.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ efficientfrontier <- function(solver=NULL, modelDirectory=NULL) {
4343
# Relax the integrality
4444
ampl$setOption("relax_integrality", TRUE)
4545
# Solve the problem
46-
ampl$solve("", "")
46+
ampl$solve()
4747
# Calibrate the efficient frontier range
4848
minret <- portfolioReturn$value()
4949
values <- averageReturn$getValues()
@@ -60,14 +60,14 @@ efficientfrontier <- function(solver=NULL, modelDirectory=NULL) {
6060
ampl$eval("let stockopall:={};let stockrun:=stockall;")
6161
# Relax integrality
6262
ampl$setOption("relax_integrality", TRUE)
63-
ampl$solve("", "")
63+
ampl$solve()
6464
cat(sprintf("QP result = %g\n", variance$value()))
6565
# Adjust included stocks
6666
ampl$eval("let stockrun:={i in stockrun:weights[i]>0};")
6767
ampl$eval("let stockopall:={i in stockrun:weights[i]>0.5};")
6868
# Set integrality back
6969
ampl$setOption("relax_integrality", FALSE)
70-
ampl$solve("", "")
70+
ampl$solve()
7171
cat(sprintf("QMIP result = %g\n", variance$value()))
7272
# Store data of corrent frontier point
7373
returns <- c(returns, maxret - (i - 1) * stepsize)

examples/firstexample.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ firstexample <- function(solver=NULL, modelDirectory=NULL) {
1919
ampl$readData(paste(modelDirectory, "/diet/diet.dat", sep=""))
2020

2121
# Solve
22-
ampl$solve("", "")
22+
ampl$solve()
2323

2424
# Get objective entity by AMPL name
2525
totalcost <- ampl$getObjective("Total_Cost")
@@ -34,7 +34,7 @@ firstexample <- function(solver=NULL, modelDirectory=NULL) {
3434
cat(sprintf("Increased costs of beef and ham.\n"))
3535

3636
# Resolve and display objective
37-
ampl$solve("", "")
37+
ampl$solve()
3838
cat(sprintf("New objective value: %f\n", totalcost$value()))
3939

4040
# Reassign data - all instances
@@ -43,7 +43,7 @@ firstexample <- function(solver=NULL, modelDirectory=NULL) {
4343
cat(sprintf("Updated all costs.\n"))
4444

4545
# Resolve and display objective
46-
ampl$solve("", "")
46+
ampl$solve()
4747
cat(sprintf("New objective value: %f\n", totalcost$value()))
4848

4949
# Get the values of the variable Buy in a dataframe object

examples/trackingmodel.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ trackingmodel <- function(solver=NULL, modelDirectory=NULL) {
3636
# Relax the integrality
3737
ampl$setOption("relax_integrality", TRUE)
3838
# Solve the problem
39-
ampl$solve("", "")
39+
ampl$solve()
4040
cat(sprintf("QP objective value ", ampl$getObjectives()[[1]]$value()))
4141

4242
lowcutoff <- 0.04
@@ -62,6 +62,6 @@ trackingmodel <- function(solver=NULL, modelDirectory=NULL) {
6262
# Get back to the integer problem
6363
ampl$setOption("relax_integrality", FALSE)
6464
# Solve the (integer) problem
65-
ampl$solve("", "")
65+
ampl$solve()
6666
cat(sprintf("QMIP objective value %g\n", ampl$getObjectives()[[1]]$value()))
6767
}

src/rampl.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,17 @@ bool RAMPL::isRunning() const {
318318
:param string solver: The solver that will be used to solve the problem.
319319
:raises Error: If the underlying interpreter is not running.
320320
*/
321-
void RAMPL::solve(std::string problem, std::string solver) {
322-
_impl.solve(problem, solver);
321+
void RAMPL::solve(Rcpp::Nullable<std::string> problem = R_NilValue, Rcpp::Nullable<std::string> solver = R_NilValue) {
322+
if (problem.isNotNull() && solver.isNotNull())
323+
_impl.solve(problem, solver);
324+
else if (problem.isNotNull())
325+
_impl.solve(problem, "");
326+
else if (solver.isNotNull())
327+
_impl.solve("", solver);
328+
else
329+
_impl.solve("", "")
330+
331+
323332
//return _impl.solve("", ""); // FIXME: does not print to stdout with R IDE on Windows
324333
}
325334

0 commit comments

Comments
 (0)