Esempio n. 1
0
    /**
     * Reads data from file.
     *
     * @param fname file name
     */
    private void read_data(String fname)
    {
        System.IO.StreamReader fr = null;
        String comment;
        int    i, j;

        try {
            fr = new System.IO.StreamReader(fname);
        } catch (Exception ex) {
            GLPK.glp_cli_error(ex.Message);
        }

        Console.WriteLine("Reading LOP instance data from '"
                          + fname
                          + "'...");

        comment = fr.ReadLine().Trim();
        Console.WriteLine(comment);

        n = nextInt(fr);
        if (n < 1)
        {
            Console.WriteLine("invalid number of nodes");
            Environment.Exit(1);
        }
        if (n > N_MAX)
        {
            Console.WriteLine("too many nodes");
            Environment.Exit(1);
        }
        Console.WriteLine("Digraph has " + n + " nodes");
        w = new int[1 + n, 1 + n];
        for (i = 1; i <= n; i++)
        {
            for (j = 1; j <= n; j++)
            {
                w [i, j] = nextInt(fr);
            }
        }
        try {
            fr.Close();
        } catch (Exception ex) {
            GLPK.glp_cli_error(ex.Message);
        }
    }
Esempio n. 2
0
 private int nextInt(System.IO.StreamReader fr)
 {
     for (;;)
     {
         if (line.Count == 0)
         {
             string buf = fr.ReadLine();
             if (buf == null)
             {
                 GLPK.glp_cli_error("End of file reached");
             }
             line.AddRange(buf.Split(' '));
         }
         string token = (string)line [0];
         token = token.Trim();
         line.RemoveAt(0);
         if (token.Length > 0)
         {
             return(Convert.ToInt32(token));
         }
     }
 }