Skip to content

Commit

Permalink
fix solve mthod
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgen-lentz committed Oct 12, 2024
1 parent d1a6f8a commit fc49694
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 20 deletions.
6 changes: 3 additions & 3 deletions docs/source/class-structure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Commands and options
~~~~~~~~~~~~~~~~~~~~

Some AMPL commands are encapsulated by functions in the :class:`AMPL` class for ease of access.
These comprise :meth:`.AMPL.solve()` and others.
These comprise :meth:`.AMPL.solve("", "")` and others.
To access and set options in AMPL, the functions :meth:`.AMPL.getOption()` and :meth:`.AMPL.setOption()` are provided.
These functions provide an easier programmatic access to the AMPL options.
In general, when an encapsulation is available for an AMPL command, the programmatic access to it is to be preferred to calling the same command using
Expand Down Expand Up @@ -258,7 +258,7 @@ The currently defined entities are obtained from the various get methods of the
(see section :ref:`secAMPLClass`). Once a reference to an entity is created, the entity is automatically kept up-to-date
with the corresponding entity in the AMPL interpreter. That is, if a reference to a newly created AMPL variable
is obtained by means of :meth:`.AMPL.getVariable()`, and the model the variable is part of is then solved
by means of :meth:`.AMPL.solve()`, the values of the instances of the variable will automatically be updated.
by means of :meth:`.AMPL.solve("", "")`, the values of the instances of the variable will automatically be updated.
The following code snippet should demonstrate the concept.

.. code-block:: R
Expand All @@ -271,7 +271,7 @@ The following code snippet should demonstrate the concept.
# At this point x$value() evaluates to 0
print(x$value()) # prints 0
ampl$solve()
ampl$solve("", "")
# At this point x$value() evaluates to 10
print(x$value()) # prints 10
Expand Down
12 changes: 6 additions & 6 deletions docs/source/quick-start.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ This is the complete listing of the example. Please note that, for clarity of pr
ampl$readData("models/diet.dat")
# Solve
ampl$solve()
ampl$solve("", "")
# Get objective entity by AMPL name
totalcost <- ampl$getObjective("Total_Cost")
Expand All @@ -43,7 +43,7 @@ This is the complete listing of the example. Please note that, for clarity of pr
cat("Increased costs of beef and ham.\n")
# Resolve and display objective
ampl$solve()
ampl$solve("", "")
cat(sprintf("New objective value: %g\n", totalcost$value()))
# Reassign data - all instances
Expand All @@ -52,7 +52,7 @@ This is the complete listing of the example. Please note that, for clarity of pr
cat("Updated all costs.\n")
# Resolve and display objective
ampl$solve()
ampl$solve("", "")
cat(sprintf("New objective value: %g\n", totalcost$value()))
# Get the values of the variable Buy in a dataframe object
Expand Down Expand Up @@ -123,7 +123,7 @@ To solve the currently loaded problem instance, it is sufficient to issue the co

.. code-block:: R
ampl$solve()
ampl$solve("", "")
Get an AMPL entity in the programming environment (get objective value)
Expand Down Expand Up @@ -175,7 +175,7 @@ values is overloaded, and is in both cases :meth:`Parameter.setValues()`.
cost <- ampl$getParameter("cost")
cost$setValues(data.frame(index=c("BEEF", "HAM"), value=c(5.01, 4.55)))
cat("Increased costs of beef and ham.\n")
ampl$solve()
ampl$solve("", "")
cat(sprintf("New objective value: %g\n", totalcost$value()))
The code above assigns the values 5.01 and 4.55 to the parameter cost for the objects beef and ham respectively.
Expand All @@ -186,7 +186,7 @@ both the index and the value. A collection of values is assigned to each of the
cost$setValues(c(3, 5, 5, 6, 1, 2, 5.01, 4.55))
cat("Updated all costs.\n")
ampl$solve()
ampl$solve("", "")
cat(sprintf("New objective value: %g\n", totalcost$value()))
The statements above produce the following output::
Expand Down
2 changes: 1 addition & 1 deletion docs/source/reference/ramplcpp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ AMPL

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

.. method:: AMPL.solve()
.. method:: AMPL.solve("", "")

Solve the current model.

Expand Down
2 changes: 1 addition & 1 deletion examples/dietmodel.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ dietmodel <- function(solver=NULL, modelDirectory=NULL) {
ampl$setData(df, 2, "")

# Solve the model
ampl$solve()
ampl$solve("", "")

# Print out the result
cat(sprintf("Objective: %f\n", ampl$getObjective("Total_Cost")$value()))
Expand Down
6 changes: 3 additions & 3 deletions examples/efficientfrontier.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ efficientfrontier <- function(solver=NULL, modelDirectory=NULL) {
# Relax the integrality
ampl$setOption("relax_integrality", TRUE)
# Solve the problem
ampl$solve()
ampl$solve("", "")
# Calibrate the efficient frontier range
minret <- portfolioReturn$value()
values <- averageReturn$getValues()
Expand All @@ -60,14 +60,14 @@ efficientfrontier <- function(solver=NULL, modelDirectory=NULL) {
ampl$eval("let stockopall:={};let stockrun:=stockall;")
# Relax integrality
ampl$setOption("relax_integrality", TRUE)
ampl$solve()
ampl$solve("", "")
cat(sprintf("QP result = %g\n", variance$value()))
# Adjust included stocks
ampl$eval("let stockrun:={i in stockrun:weights[i]>0};")
ampl$eval("let stockopall:={i in stockrun:weights[i]>0.5};")
# Set integrality back
ampl$setOption("relax_integrality", FALSE)
ampl$solve()
ampl$solve("", "")
cat(sprintf("QMIP result = %g\n", variance$value()))
# Store data of corrent frontier point
returns <- c(returns, maxret - (i - 1) * stepsize)
Expand Down
6 changes: 3 additions & 3 deletions examples/firstexample.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ firstexample <- function(solver=NULL, modelDirectory=NULL) {
ampl$readData(paste(modelDirectory, "/diet/diet.dat", sep=""))

# Solve
ampl$solve()
ampl$solve("", "")

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

# Resolve and display objective
ampl$solve()
ampl$solve("", "")
cat(sprintf("New objective value: %f\n", totalcost$value()))

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

# Resolve and display objective
ampl$solve()
ampl$solve("", "")
cat(sprintf("New objective value: %f\n", totalcost$value()))

# Get the values of the variable Buy in a dataframe object
Expand Down
4 changes: 2 additions & 2 deletions examples/trackingmodel.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ trackingmodel <- function(solver=NULL, modelDirectory=NULL) {
# Relax the integrality
ampl$setOption("relax_integrality", TRUE)
# Solve the problem
ampl$solve()
ampl$solve("", "")
cat(sprintf("QP objective value ", ampl$getObjectives()[[1]]$value()))

lowcutoff <- 0.04
Expand All @@ -62,6 +62,6 @@ trackingmodel <- function(solver=NULL, modelDirectory=NULL) {
# Get back to the integer problem
ampl$setOption("relax_integrality", FALSE)
# Solve the (integer) problem
ampl$solve()
ampl$solve("", "")
cat(sprintf("QMIP objective value %g\n", ampl$getObjectives()[[1]]$value()))
}
2 changes: 1 addition & 1 deletion src/rampl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ bool RAMPL::isRunning() const {
*/
void RAMPL::solve(std::string problem, std::string solver) {
_impl.solve(problem, solver);
//return _impl.solve(); // FIXME: does not print to stdout with R IDE on Windows
//return _impl.solve("", ""); // FIXME: does not print to stdout with R IDE on Windows
}


Expand Down

0 comments on commit fc49694

Please sign in to comment.