// NagCFunctionsAPI: Wrapper for NAG C Lib functions // using System; using System.Text; using System.Runtime.InteropServices; namespace NagCFunctionsAPI { public enum Nag_PrintType { Nag_PrintNotSet=1124 , Nag_NoPrint, Nag_Soln_Root, Nag_Soln, Nag_Iter, Nag_Iter_Long, Nag_Soln_Root_Iter, Nag_Soln_Iter, Nag_Soln_Iter_Long, Nag_Soln_Iter_Const, Nag_Soln_Iter_Diag, Nag_Soln_Iter_Full } ; // Nag Options structure [StructLayout(LayoutKind.Sequential)] public struct Nag_E04_Opt { public IntPtr f_name; // const char* public IntPtr f_longname; // const char* public int init1; // Integer public int init2; // Integer public int minlin; // Nag_LinFun public int grade; // Integer public int nf; // Integer public int iter; // Integer public int major_iter; // Integer public int max_iter; // Integer public int minor_max_iter; // Integer public int min_infeas; // Boolean public double f_est; // double public double step_max; // double public double step_limit; // double public double max_line_step; // double public double f_prec; // double public double linesearch_tol; // double public double optim_tol; // double public IntPtr conf; // double * public int nag_conf; // Integer public IntPtr conjac; // double * public int nag_conjac; // Integer /*IntPtr r; e04ucc */ /* int nag_r; */ public IntPtr h; // double * public int nag_h; //Integer public int h_unit_init; // Boolean public int h_reset_freq; // Integer public IntPtr s; // double * public int nag_s; // Integer public IntPtr v; // double * public int nag_v; // Integer public int tdv; // Integer public IntPtr delta; // double * public int nag_delta; // Integer public IntPtr hesl; // double * public int nag_hesl; // Integer public IntPtr hesd; // double * public int nag_hesd; // Integer public IntPtr state; // Integer * public int nag_state; // Integer public int init_state; // Nag_InitType public int obj_deriv; // Boolean public int con_deriv; // Boolean public double f_diff_int; // double public double c_diff_int; // double public int obj_check_start;// Integer public int obj_check_stop; // Integer public int con_check_start;// Integer public int con_check_stop; // Integer public int verify_grad; // Nag_GradChk public int hessian; // Boolean public int local_search; // Boolean public int deriv_check; // Boolean public int list; // Boolean public int print_gcheck; // Boolean public int print_deriv; // Nag_DPrintType public Nag_PrintType /*int*/ print_level; // Nag_PrintType public int minor_print_level; // Nag_PrintType public int print_iter; // Integer [MarshalAs (UnmanagedType.ByValArray, SizeConst=512)] public char [] outfile; // char [] public IntPtr print_fun; // NAG_E04_PRINTFUN public IntPtr ax; // double * public int nag_ax; // Integer public IntPtr lambda; // double * public int nag_lambda; // Integer public int fcheck; // Integer public double crash_tol; // double public int reset_ftol; // Integer public int fmax_iter; // Integer public double ftol; // double public double lin_feas_tol; // double public double nonlin_feas_tol; // double public int hrows; // Integer public double inf_bound; // double public double inf_step; // double public int max_df; // Integer public int prob; // Nag_ProblemType public double rank_tol; // double public int form_hessian; // Boolean public int start; // Nag_Start public int debug_iter; // Integer public int minor_debug_iter; // Integer public int debug; // Boolean public int used; // Boolean public int unitq; // Boolean public int nfree; // Integer public int nactiv; // Integer /* These are used in the e04ucc stringent */ public int nprob; // Integer public int n; // Integer public int nclin; // Integer public int ncnlin; // Integer public double bndlow; // double public double bndupp; // double /* New e04nkc members */ public int minimize; // Boolean public int factor_freq; // Integer public int partial_price; // Integer public int max_sb; // Integer public double lu_factor_tol; // double public double lu_sing_tol; // double public double lu_update_tol; // double public double pivot_tol; // double public double scale_tol; // double public int crash; // Nag_CrashType public int scale; // Nag_ScaleType [MarshalAs (UnmanagedType.ByValArray, SizeConst=9)] public char [] prob_name; // char [] [MarshalAs (UnmanagedType.ByValArray, SizeConst=9)] public char [] obj_name; // char [] [MarshalAs (UnmanagedType.ByValArray, SizeConst=9)] public char [] bnd_name; // char [] [MarshalAs (UnmanagedType.ByValArray, SizeConst=9)] public char [] rhs_name; // char [] [MarshalAs (UnmanagedType.ByValArray, SizeConst=9)] public char [] range_name; // char [] public IntPtr crnames; // char ** public int nag_crnames; // Integer public int nsb; // Integer /* e04nkc undocumented options */ public int max_restart; // Integer public int max_basis_len; // Integer public int max_compress; // Integer public int max_basis_nfactor; // Integer /* e04mzc options (MPS Reading) */ public double col_lo_default; // double public double col_up_default; // double public double infinity; // double public int ncol_approx; // Integer public int nrow_approx; // Integer public double est_density; // double public int output_level; // Nag_OutputType /* e04xac options */ public int deriv_want; // Nag_DWantType public int use_hfwd_init; // Boolean public double f_prec_used; // double /* e04ugc new members */ public int print_80ch; // Boolean public int feas_exit; // Boolean public int hess_freq; // Integer public double elastic_wt; // double public double lu_den_tol; // double public int part_price; // Integer public int scale_opt; // Integer public int expand_freq; // Integer public int hess_update; // Integer public int iter_lim; // Integer public double major_opt_tol; // double public double minor_opt_tol; // double public double unbounded_obj; // double public double major_step_lim; // double public int major_iter_lim; // Integer public double major_feas_tol; // double public int minor_iter_lim; // Integer public double minor_feas_tol; // double public double violation_limit; // double public double nz_coef; // double public int deriv_linesearch; // Boolean public int hess_storage; // Nag_HessianType public int direction; // Nag_DirectionType public int ncon; // Integer } [StructLayout(LayoutKind.Sequential)] public struct Nag_E04State { [MarshalAs (UnmanagedType.ByValArray, SizeConst=600*8)] public char [] cw; //char cw[600*8] [MarshalAs (UnmanagedType.ByValArray, SizeConst=600)] public int [] iw; // Integer iw[600] [MarshalAs (UnmanagedType.ByValArray, SizeConst=600)] public double [] rw; // double rw[600] } // Nag Communications structure public struct CommStruct //Nag_Comm { public int flag; // Integer public int first; // Boolean public int last; // Boolean public int nf; // Integer public int it_prt; // Boolean public int it_maj_prt; // Boolean public int sol_sqp_prt; // Boolean public int sol_prt; // Boolean public int rootnode_sol_prt; // Boolean public int node_prt; // Boolean public int rootnode_prt; // Boolean public int g_prt; // Boolean public int new_lm; // Boolean public int needf; // Integer public int p; // Pointer public IntPtr iuser; // Integer * public IntPtr user; // Integer * public IntPtr nag_w; // double * public IntPtr nag_iw; // Integer * public int nag_p; // Pointer public IntPtr nag_print_w; // double * public IntPtr nag_print_iw; // Integer * public int nrealloc; // Integer }; public struct Nag_Comm //CommStruct also { public int flag; // Integer public int first; // Boolean public int last; // Boolean public int nf; // Integer public int it_prt; // Boolean public int it_maj_prt; // Boolean public int sol_sqp_prt; // Boolean public int sol_prt; // Boolean public int rootnode_sol_prt; // Boolean public int node_prt; // Boolean public int rootnode_prt; // Boolean public int g_prt; // Boolean public int new_lm; // Boolean public int needf; // Integer public int p; // Pointer public IntPtr iuser; // Integer * public IntPtr user; // Integer * public IntPtr nag_w; // double * public IntPtr nag_iw; // Integer * public int nag_p; // Pointer public IntPtr nag_print_w; // double * public IntPtr nag_print_iw; // Integer * public int nrealloc; // Integer }; // NagError structure [StructLayout(LayoutKind.Sequential)] public struct NagError { public int code; // int public int print; // Boolean [MarshalAs (UnmanagedType.ByValArray, SizeConst=512)] public char [] char_array; // char [NAG_ERROR_BUF_LEN] public IntPtr handler; // NAG_ERRHAN public int errnum; // Integer public int iflag; // Integer public int ival; // Integer } // Nag Complex type [StructLayout(LayoutKind.Sequential)] public struct Complex { public double re; public double im; }; // Nag_QuadProgress, used by d01 quadrature routines [StructLayout(LayoutKind.Sequential)] public struct Nag_QuadProgress { public int num_subint; public int fun_count; public IntPtr sub_int_beg_pts; public IntPtr sub_int_end_pts; public IntPtr sub_int_result; public IntPtr sub_int_error; }; // Nag_Spline structure used by curve fitting routines, e01, e02 [StructLayout(LayoutKind.Sequential)] public struct Nag_Spline { public int n; public IntPtr lamda; public IntPtr c; public int init1; public int init2; }; /* Following used by d01 d02 e02 and e04 functions */ public enum Nag_Start { Nag_StartNotSet=1106 , Nag_Cold, Nag_Warm, Nag_Hot, Nag_NewStart, Nag_ReStart, Nag_Continue, Nag_BasisFile=50001}; // d01ajc delegate public delegate double NAG_D01AJC_FUN (double x); // e04ccc delegate public delegate void NAG_E04CCC_FUN (int n, IntPtr xc_ptr, ref double fc, ref CommStruct comm); // e04nfc delegate public delegate void NAG_E04NFC_QPHESS (int n, int jthcol, IntPtr h_ptr, int tdh, IntPtr x_ptr, [In, Out] IntPtr hx, ref CommStruct comm); // e04ucc delegates public delegate void NAG_E04UCC_OBJFUN (int n, IntPtr x_ptr, ref double objf, [In, Out] IntPtr g_ptr, ref CommStruct comm); public delegate void NAG_E04UCC_CONFUN (int n, int ncnlin, IntPtr needc_ptr, IntPtr x_ptr, [In, Out] IntPtr conf_ptr, [In, Out] IntPtr conjac_ptr, ref CommStruct comm); // e04unc delegates public delegate void NAG_E04UNC_OBJFUN (int m, int n, IntPtr x_ptr, [In, Out] IntPtr f_ptr, [In, Out] IntPtr fjac_ptr, int tdfjac, ref CommStruct comm); public delegate void NAG_E04UNC_CONFUN (int n, int ncnlin, IntPtr needc_ptr, IntPtr x_ptr, [In, Out] IntPtr conf_ptr, [In, Out] IntPtr conjac_ptr, ref CommStruct comm); // e04wdc delegates public delegate void NAG_E04WDC_OBJFUN (ref int mode, int n, IntPtr x_ptr, ref double objf, [In, Out] IntPtr g_ptr, int nstate, ref Nag_Comm comm); public delegate void NAG_E04WDC_CONFUN (ref int mode, int ncnln, int n, int pdcj, IntPtr needc_ptr, IntPtr x_ptr, [In, Out] IntPtr conf_ptr, [In, Out] IntPtr conjac_ptr, int nstate, ref Nag_Comm comm); // e04vhc delegates public delegate void NAG_E04VHC_USRFUN (ref int status, int n, IntPtr x_ptr, int needf, int nf, [In, Out] IntPtr f_ptr, int needg, int leng, [In, Out] IntPtr g_ptr, ref Nag_Comm comm); // M chapter public delegate int NAG_M01_FUN ([In] IntPtr a, [In] IntPtr b); // public class Nag_Types public enum MatrixTranspose { NoTranspose = 1001, Transpose, ConjugateTranspose }; public enum Nag_OrderType { Nag_RowMajor = 101, Nag_ColMajor = 102 }; public enum Nag_JobType { Nag_DoBoth=1044, Nag_EigVals, Nag_DoNothing, Nag_Permute, Nag_Schur, Nag_Scale, Nag_Subspace, Nag_EigVecs } ; public enum Nag_UploType { Nag_Upper = 121, Nag_Lower = 122 }; public enum Nag_SortOrder { Nag_Ascending = 1597, Nag_Descending = 1598 }; public enum Nag_ProblemType { Nag_ProbTypeNotSet = 1187, Nag_FP, Nag_LP, Nag_QP1, Nag_QP2, Nag_QP3, Nag_QP4, Nag_LS1, Nag_LS2, Nag_LS3, Nag_LS4, Nag_SparseFP, Nag_SparseLP, Nag_SparseQP, Nag_SparseFPE, Nag_SparseFPL, Nag_SparseFPS, Nag_SparseQPP, Nag_SparseQPS }; public class NagFunctions { [DllImport("CLW3209DA_nag")] public static extern void d01ajc(NAG_D01AJC_FUN f , double a, double b, double epsabs, double epsrel, int max_num_subint, ref double result, ref double abserr, ref Nag_QuadProgress qp, ref NagError fail); [DllImport("CLW3209DA_nag")] public static extern void e01bac(int m, double [] x, double [] y, ref Nag_Spline spline, ref NagError fail); [DllImport("CLW3209DA_nag")] public static extern void e01bec(int n, double[] x, double[] f, double[] d, ref NagError fail); [DllImport("CLW3209DA_nag")] public static extern void e01bfc(int n, double[] x, double[] f, double[] d, int m, double[] px, double[] pf, ref NagError fail); [DllImport("CLW3209DA_nag")] public static extern void e02adc(int m, int kplus1, int tda, double[] x, double[] y, double[] w, double[,] a, double[] s, ref NagError fail); [DllImport("CLW3209DA_nag")] public static extern void e02aec(int nplus1, double[] a, double xcap, ref double p, ref NagError fail); [DllImport("CLW3209DA_nag")] public static extern void e02bac(int m, double[] x, double[] y, double[] w, ref double ss, ref Nag_Spline spline, ref NagError fail); // [DllImport("CLW3209DA_nag")] // public static extern void e02bbc(double x, ref double s, ref Nag_Spline spline, ref NagError fail); [DllImport("CLW3209DA_nag")] public static extern void e02bbc(double x, ref double s, ref Nag_Spline spline, ref NagError fail); [DllImport("CLW3209DA_nag")] public static extern void e04ccc(int n, NAG_E04CCC_FUN funct, double [] x, ref double fmin, ref Nag_E04_Opt options, ref CommStruct user_comm, ref NagError fail); [DllImport("CLW3209DA_nag")] public static extern void e04nfc(int n, int nclin, double[,] a, int tda, double[] bl, double[] bu, double[] cvec, double[,] h, int tdh, NAG_E04NFC_QPHESS qphess, double[] x, ref double objf, ref Nag_E04_Opt options, ref CommStruct user_comm, ref NagError fail); [DllImport("CLW3209DA_nag")] public static extern void e04ucc(int n, int nclin, int ncnlin, double [,] a, int tda, double [] bl, double [] bu, NAG_E04UCC_OBJFUN objfun, NAG_E04UCC_CONFUN confun, double [] x, ref double objf, double [] g, ref Nag_E04_Opt options, ref CommStruct user_comm, ref NagError fail); [DllImport("CLW3209DA_nag")] public static extern void e04unc(int m, int n, int nclin, int ncnlin, double [,] a, int tda, double [] bl, double [] bu, double [] y, NAG_E04UNC_OBJFUN objfun, NAG_E04UNC_CONFUN confun, double [] x, ref double objf, double [] f, double [,] fjac, int tdfjac, ref Nag_E04_Opt options, ref CommStruct user_comm, ref NagError fail); [DllImport("CLW3209DA_nag")] public static extern void e04wcc(ref Nag_E04State state, ref NagError fail); [DllImport("CLW3209DA_nag")] public static extern void e04wdc(int n, int nclin, int ncnln, int pda, int pdcj, int pdh, double [,] a, double [] bl, double [] bu, NAG_E04WDC_CONFUN confun, NAG_E04WDC_OBJFUN objfun, ref int majits, int [] istate, double [] ccon, double [,] cjac, double [] clamda, ref double objf, double [] grad, double [,] hess, double [] x, ref Nag_E04State state, ref Nag_Comm comm, ref NagError fail); [DllImport("CLW3209DA_nag")] public static extern void e04vhc(Nag_Start start, int nf, int n, int nxname, int nfname, double objadd, int objrow, string prob, NAG_E04VHC_USRFUN usrfun, int [] iafun, int [] javar, double [] a, int lena, int nea, int [] igfun, int [] jgvar, int leng, int neg, double [] xlow, double [] xupp, //String xnames, String [] xnames, double [] flow, double [] fupp, String [] fnames, // String fnames, double [] x, int [] xstate, double [] xmul, double [] f, int [] fstate, double [] fmul, ref int ns, ref int ninf, ref double sinf, ref Nag_E04State state, ref Nag_Comm comm, ref NagError fail); [DllImport("CLW3209DA_nag")] public static extern void e04vgc(ref Nag_E04State state, ref NagError fail); [DllImport("CLW3209DA_nag")] public static extern void e04vmc( string opt_string, int ivalue, ref Nag_E04State state, ref NagError fail); [DllImport("CLW3209DA_nag")] public static extern void e04wec(int /* Nag_FileID */ fileid, ref Nag_E04State state, ref NagError fail); [DllImport("CLW3209DA_nag")] public static extern void e04wfc( string opt_string, ref Nag_E04State state, ref NagError fail); [DllImport("CLW3209DA_nag")] public static extern void e04wgc( string opt_string, int ivalue, ref Nag_E04State state, ref NagError fail); [DllImport("CLW3209DA_nag")] public static extern void e04whc( string opt_string, double rvalue, ref Nag_E04State state, ref NagError fail); [DllImport("CLW3209DA_nag")] public static extern void e04wkc( string opt_string, ref int ivalue, ref Nag_E04State state, ref NagError fail); [DllImport("CLW3209DA_nag")] public static extern void e04wlc( string opt_string, ref double rvalue, ref Nag_E04State state, ref NagError fail); [DllImport("CLW3209DA_nag")] public static extern void e04xxc(ref Nag_E04_Opt options); [DllImport("CLW3209DA_nag")] public static extern void f02aac (int n, double [,] a, int tda, double [] r, ref NagError fail); [DllImport("CLW3209DA_nag")] public static extern void f03afc (int n, double [,] a, int tda, int [] pivot, ref double detf, ref int dete, ref NagError fail); [DllImport("CLW3209DA_nag")] public static extern void f04ajc (int n, int nrhs, double [,] a, int tda, int [] pivot, double [,] b, int tdb, ref NagError fail); [DllImport("CLW3209DA_nag")] public static extern void f06pac( MatrixTranspose trans, int m, int n, double alpha, IntPtr a, int tda, IntPtr x, int incx, double beta, [In, Out] IntPtr y, int incy); [DllImport("CLW3209DA_nag")] public static extern void f08fqc( Nag_OrderType order, Nag_JobType job, Nag_UploType uplo, int n, [In, Out] Complex [,] a, int pda, double [] w, ref NagError fail); [DllImport("CLW3209DA_nag")] public static extern void g02dac(/* Nag_IncludeMean */ int mean, int n, double [,] x, int tdx, int m, int [] sx, int ip, double [] y, double [] wt, ref double rss, ref double df, double [] b, double [] se, double [] cov, double [] res, double [] h, double [,] q, int tdq, ref int svd, ref int rank, double [] p, double tol, double [] comm_ar, ref NagError fail); [DllImport("CLW3209DA_nag")] public static extern void g02jac(int n, int ncol, double[,] dat, int tddat, int[] levels, int yvid, int cwid, int nfv, int[] fvid, int fint, int nrv, int[] rvid, int nvpr, int[] vpr, int rint, int svid, double[] gamma, ref int nff, ref int nrf, ref int df, ref double reml, int lb, double[] b, double[] se, int maxit, double tol, ref int warn, ref NagError fail); [DllImport("CLW3209DA_nag")] public static extern void g03aac(int /*Nag_PrinCompMat*/ pcmatrix, int /*Nag_PrinCompScores*/ scores, int n, int m, double [,] x, int tdx, int [] isx, double [] s, double [] wt, int nvar, double [,] e, int tde, double [,] p, int tdp, double [,] v, int tdv, ref NagError fail); [DllImport("CLW3209DA_nag")] public static extern void g03eac(/*Nag_MatUpdate */ int update, /* Nag_DistanceType */ int dist, /* Nag_VarScaleType*/ int scale, int n, int m, double [,] x, int tdx, int [] isx, double [] s, double [] d, ref NagError fail); [DllImport("CLW3209DA_nag")] public static extern void g03ecc(/* Nag_ClusterMethod */ int method, int n, double [] d, int [] ilc, int [] iuc, double [] cd, int [] iord, double [] dord, ref NagError fail); [DllImport("CLW3209DA_nag")] public static extern void g03efc(int n, int m, double [,] x, int tdx, int [] isx, int nvar, int k, double [,] cmeans, int tdc, double [] wt, int [] inc, int [] nic, double [] css, double [] csw, int maxit, ref NagError fail); // [DllImport("CLW3209DA_nag")] // public unsafe static extern void g03ehc(/*Nag_DendOrient*/int orient, int n, // double [] dord, double dmin, // double dstep, int nsym, /*ref IntPtr c*/ // out IntPtr c, ref NagError fail); [DllImport("CLW3209DA_nag")] public static extern void g03xzc( ref IntPtr c /* char ***c */); [DllImport("CLW3209DA_nag")] public static extern void g05cbc(int seed); [DllImport("CLW3209DA_nag")] public static extern int g05eyc(IntPtr r); [DllImport("CLW3209DA_nag")] public static extern void g05ecc(double t, ref IntPtr r, ref NagError fail); [DllImport("CLW3209DA_nag")] /* Free memory allocated within NAG routines */ public static extern void x04bdc(ref IntPtr ptr); [DllImport("CLW3209DA_nag")] public static extern string x04mcc(int enum_int, string enum_string); // [DllImport("CLW3209DA_nag")] // unsafe public static extern void m01csc(double ** vec, uint n, uint size, uint stride, // NAG_M01_FUN compare, Nag_SortOrder order, ref NagError fail); [DllImport("CLW3209DA_nag")] public static extern double s07aac(double x, ref NagError fail); [DllImport("CLW3209DA_nag")] public static extern void x04acc( string filename, int mode, ref int /*Nag_FileID */fileid, ref NagError fail); } }