Exemplo n.º 1
0
        public static double[] linkernTour(int numNodes)
        {
            double[] result = new double[numNodes];

            try
            {
                IList<string> command = new List<string>();

                    command.Add("linkern.exe");

                command.Add("-o");
                command.Add("linkern_output");
                command.Add("linkern_input");

                CommandLineBuilder builder = new CommandLineBuilder(command);
                builder.redirectErrorStream(true);
                //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
                //ORIGINAL LINE: final Process process = builder.start();
                Process process = builder.start();
                //main thread wait for this process to end and exit, then continue.
                process.waitFor();
                //InputStream is = process.getInputStream();
                //InputStreamReader isr = new InputStreamReader(is);
                //BufferedReader br = new BufferedReader(isr);
                string line;

                //br.close();

                StreamReader scanner = new StreamReader("linkern_output");
                // discard the first line
                scanner.ReadLine();
                line = null;
                for (int i = 0; i < result.Length; i++)
                {
                    line = scanner.ReadLine();

                    double number = Convert.ToDouble(line.Split("\\s+", true)[2]);
                    result[i] = number;
                }

                scanner.Close();

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                Console.Write(ex.StackTrace);
            }

            return result;
        }