GLPK/IAJAAR.H project

This page describes a C++ class that wraps the C-style GLPK vectors ia, ja, and ar. The class can be used directly with C++ or via language bindings for Java and R created with SWIG.

IAJAAR.H project
IAJAAR.H is a small project that provides the specialized triple container class IAJAAR. The purpose of this C++ class is to offer more convenient problem build calls than those available using straight C code. The author is Nigel Galloway.

C++ class IAJAAR definition
The C++ IAJAAR class definition is:

The member function  adds 3-tuples (triples) in the form (row, col, value). The respective arrays can be later retrieved using the member functions,  , and. The member function returns the current number of entries.

IAJAAR is designed to work with the following GLPK routine:

It would be possible to reformulate class IAJAAR using s internally. That would omit the need to pre-specify the maximum size s in advance, although an optional hint could be given.

C++ usage
Usage with C++ is straightforward &mdash; no special language bindings are required. A description of the underlying problem is can be found on the project website.

Python usage
IAJAAR can be used with Python. This February 2011 posting explains more.

Java usage
Java usage requires dedicated language bindings. Unlike the C++ example, Q and N are hardcoded.

R usage
R usage requires dedicated language bindings. Unlike the C++ example, Q and N are hard-coded.


 * 1)  File: 'gist10yo.R'
 * 2)  Nigel Galloway / July 2009

dyn.load(paste("GLPK_R", .Platform$dynlib.ext, sep="")) source("GLPKconstants.R") source("GLPK_R.R") cacheMetaData(1) Q <- 22 N <- 7 t <- IAJAAR(6) lp <- glp_create_prob glp_add_rows(lp,3) glp_add_cols(lp,3) glp_set_col_bnds(lp,1,GLP_FR,0,0) glp_set_col_bnds(lp,2,GLP_FR,0,0) glp_set_col_bnds(lp,3,GLP_FR,0,0) IAJAAR_Add(t,1,1,1) IAJAAR_Add(t,1,2,1) IAJAAR_Add(t,2,1,1) IAJAAR_Add(t,2,3,1) IAJAAR_Add(t,3,2,1) IAJAAR_Add(t,3,3,N-1) glp_set_row_bnds(lp,1,GLP_FX,Q,Q) glp_set_row_bnds(lp,2,GLP_FX,0,0) glp_set_row_bnds(lp,3,GLP_FX,0,0) loadMatrix(t,lp); delete(t) if (glp_simplex(lp,t)==0) { R <- glp_get_col_prim(lp,1) print(sprintf("The arithmetic mean of a sample of %f numbers which sum to %f is %f",N,Q,R)) } else { print("No solution") }
 * 1)  col 1 is M
 * 2)  col 2 is v1
 * 3)  col 3 is v2

Further information is available from the project website. In particular, the source code for iajaar.cpp is worth reviewing.