// h02cb Example Program Text // Mark 20 Revised. NAG Copyright 2001. // C# version, NAG Copyright 2008 using System; using NagLibrary; using System.Globalization; namespace NagDotNetExamples { public class H02CBE { // Specify data file as a command line argument. // It defaults to the named file specified below otherwise. static string datafile = "ExampleData/h02cbe.d"; const int nin = 5; const int lintvr = 1; const int nmax = 10; const int ncmax = 10; const int lda = ncmax; const int ldh = nmax; const int liwrk = 1000; const int lwrk = 10000; const int mdepth = 30; static void Main(String[] args) { if (args.Length == 1) { datafile = args[0]; } StartExample(); } public static void StartExample() { H.H02CB_QPHESS e04nfuH02CBF = new H.H02CB_QPHESS(H.h02cbv); H.H02CB_MONIT h02cbuH02CBF = new H.H02CB_MONIT(H.h02cbu); DataReader sr = new DataReader(datafile); double obj = 0.0; int i = 0, j = 0, n = 0, nclin = 0, strtgy = 0; double[,] a = new double[lda, nmax]; double[] ax = new double[10]; double[] bl = new double[20]; double[] bu = new double[20]; double[] clamda = new double[20]; double[] cvec = new double[10]; double[,] h = new double[ldh, nmax]; double[] wrk = new double[10000]; double[] xs = new double[20]; int[] intvar = new int[1]; int[] istate = new int[20]; int[] iwrk = new int[1000]; int ifail; Console.WriteLine("h02cb Example Program Results"); // Skip heading in data file sr.Reset(); sr.Reset(); n = int.Parse(sr.Next()); nclin = int.Parse(sr.Next()); if ((n <= nmax) && (nclin <= ncmax)) { // // Read CVEC, A, BL, BU, XS and H from data file // sr.Reset(); for (i = 1; i <= n; i++) { cvec[i - 1] = double.Parse(sr.Next(), CultureInfo.InvariantCulture); } sr.Reset(); for (i = 1; i <= nclin; i++) { for (j = 1; j <= n; j++) { a[i - 1, j - 1] = double.Parse(sr.Next(), CultureInfo.InvariantCulture); } } sr.Reset(); for (i = 1; i <= n + nclin; i++) { bl[i - 1] = double.Parse(sr.Next(), CultureInfo.InvariantCulture); } sr.Reset(); for (i = 1; i <= n + nclin; i++) { bu[i - 1] = double.Parse(sr.Next(), CultureInfo.InvariantCulture); } sr.Reset(); for (i = 1; i <= n; i++) { xs[i - 1] = double.Parse(sr.Next(), CultureInfo.InvariantCulture); } sr.Reset(); for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { h[i - 1, j - 1] = double.Parse(sr.Next(), CultureInfo.InvariantCulture); } } // strtgy = 2; intvar[0] = 4; // Solve the problem // // H.h02cbOptions options = new H.h02cbOptions(); options.Set("Print Level = 0"); H.h02cb(n, nclin, a, bl, bu, cvec, h, e04nfuH02CBF, intvar, mdepth, istate, xs, out obj, ax, clamda, strtgy, h02cbuH02CBF, options, out ifail); // // Print out the best integer solution found // Console.Write(" Optimal Integer Value is = "); Console.Write(" {0}", obj); Console.WriteLine(); Console.WriteLine(" Components are "); for (i = 1; i <= n; i++) { // nested do in write Console.Write("X({0})=", i); Console.Write(xs[i - 1]); Console.WriteLine(); } Console.WriteLine(); // } // } } }