Search code examples
r-forge

Optimist R-Forge project


I´m studing the bin packing problem begining with the knapsack code of Martello algorithm. It wrote in Old Fortran IV or 66 code. I found a very interesting project at R-Forge calling Optimist (Administrator Hans W. Borchers) that by R console you can call the subroutine that it was written in Fortran 66 and run it to check the results. This is util if you want write the code in a more modern lenguage and check if arrives to the same results. I downloaded R x64 3.3.1 and the Optimist packages. I don´t know how to run this packages from R. I´m saying: invoke the subroutine in Fortran, input data and view the results from the R IDE.

Any suggestions?

Thank in advance. Eduardo


Solution

  • The original Martello and Toth Fortran routines are available in the 'knapsack' package of the Optimist R-Forge project (and not in the 'adagio' package). Unfortunately, these Fortran codes cannot be distributed through CRAN. The reason being that they are published under the ACM license, not compatible with GPL. I asked Prof. Silvano Martello whether he would be willing to change the license, but he could not or did not want to do so (as he explicitly told me).

    To give you a start: I guess you have installed R or, even better, R and RStudio. When you have started R, first you have to install the package once and to load it everytime you start R anew with: (You will need to have a Fortran compiler available, but I guess you have that.)

    > install.packages("knapsack", repos="http://R-Forge.R-project.org")
    > library(knapsack)
    

    Then you can call help or example on, e.g., the knapsack function. The functions implemented at the moment are knapsack and subsetsum. The help pages will show you how to apply these routines. p and w (the profits and weights) must be vectors of integer values of equal length, with p[i]/w[i] a strictly decreasing sequence:

    > p = c(15, 100, 90, 60, 40, 15, 10,  1)
    > w = c( 2,  20, 20, 30, 40, 30, 60, 10)
    > cap = 102
    

    Now you can call the knapsack function and display the result:

    > res = knapsack(p, w, cap)
    > res
    # [1]  1 2 3 4 6
    

    There is also the subsetsum routine. Other codes from the book of Martello and Toth have not yet been wrapped in the 'knapsack' package. But it could easily been done if you are interested. These additional routines are solving the bin packing, assignment, and change making problems.