Code:
/*
Begin NRldlmain.cpp
*/
#include "nr3.h"
#include "sparse.h"
#include "NRldl.h"
void init_Abc(const NRsparseMat &a, VecDoub_I &b, VecDoub_I &c, int M, int N, const int ptr_arr[], const int row_arr[], const double A_arr[])
{
NRsparseMatA;
A.nrows = M;
A.ncols = N;
A.nvals = M*N;
VecInt v, w;
VecDouby;
A.col_ptr(11,*ptr_arr); *Error:No match for call to '(VecInt) (int, const int&)'
A.row_ind = w(9,*row_arr); *Error:No match for call to '(VecInt) (int, const int&)'
A.val = y(9,*A_arr); *Error:No match for call to '(VecDoub) (int, const double&)'
}
int main() {
DoubX_act[3]= {0.000000,0.957167,0.000000};
Int my_Answer, N=3, M=3, k=1;
Doub my_A_arr[9] = {0.814724,0.905792,0.126987,0.913376,0.632359,
0.097540,0.278498,0.546882,0.957507}; // our A matrix in column-wise fashion
const Int my_A_ptr_arr[11] = {0,1,2,3,4,5,6,7,8,9,10}; // [0...N+1]
Int my_A_row_arr[9] = {0,1,2,0,1,2,0,1,2};
Doub my_b_arr[3] = {0.874253,0.605273,0.093362}; // our contraint vector
Doub my_c_arr[3] = {1.000000,1.000000,1.000000}; // our objective function coefficients
NRsparseMatA;
VecDoub_Ib, c;
VecDoub_O x;
init_Abc(A, b, c, M, N, my_A_ptr_arr, my_A_row_arr, my_A_arr);
return my_Answer;
}
/*
Begin sparse.h
*/
struct NRsparseMat //sparse matrix data structure for compressed column storage
{
Int nrows; //number of rows
Int ncols; //number of columns
Int nvals; //maximum number of nonzeros
VecInt col_ptr; //pointers to start of columns. length is ncols+1
VecInt row_ind; //row indices of nonzeros
VecDoub val; //array of nonzero values
NRsparseMat(); //default constructor
NRsparseMat(Int m,Int n,Int nnvals); //constructor. initializes vector to zero
VecDoub ax(const VecDoub &x) const; //multiply A by a vector x[0…ncols-1]
VecDoub atx(const VecDoub &x) const; //multiply A transpose by a vector x[0…nrows-1]
NRsparseMat transpose() const; //form A transpose
};
typedef const NRvector<Int> VecInt_I;
typedef NRvector<Int> VecInt, VecInt_O, VecInt_IO;
typedef const NRvector<Doub> VecDoub_I;
typedef NRvector<Doub> VecDoub, VecDoub_O, VecDoub_IO;
#ifdef _USESTDVECTOR_
#define NRvector vector
#else
template <class T>
class NRvector {
private:
int nn; // size of array. upper index is nn-1
T *v;
public:
NRvector();
explicit NRvector(int n); // Zero-based array
NRvector(int n, const T &a); //initialize to constant value
NRvector(int n, const T *a); // Initialize to array
NRvector(const NRvector &rhs); // Copy constructor
NRvector & operator=(const NRvector &rhs); //assignment
typedef T value_type; // make T available externally
inline T & operator[](const int i); //i'th element
inline const T & operator[](const int i) const;
inline int size() const;
void resize(int newn); // resize (contents not preserved)
void assign(int newn, const T &a); // resize and assign a constant value
~NRvector();
};
// NRvector definitions
template <class T>
NRvector<T>::NRvector() : nn(0), v(NULL) {}
template <class T>
NRvector<T>::NRvector(int n) : nn(n), v(n>0 ? new T[n] : NULL) {}
template <class T>
NRvector<T>::NRvector(int n, const T& a) : nn(n), v(n>0 ? new T[n] : NULL)
{
for(int i=0; i<n; i++) v[i] = a;
}
template <class T>
NRvector<T>::NRvector(int n, const T *a) : nn(n), v(n>0 ? new T[n] : NULL)
{
for(int i=0; i<n; i++) v[i] = *a++;
}