Пример #1
0
        bool[] visited; // visited[x] = true when X is visited in path

        #endregion Fields

        #region Constructors

        public InitialPath(Input i, Random rnd)
        {
            cs = i.customers;
            visited = new bool[cs.Length];
            r = rnd;
        }
Пример #2
0
        private void InputTests()
        {
            // The files used in this example are created in the topic
              // How to: Write to a Text File. You can change the path and
              // file name to substitute text files of your own.

              // Example #2
              // Read each line of the file into a string array. Each element
              // of the array is one line of the file.
              OpenFileDialog sfd = new OpenFileDialog();
              string s = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory())));
              sfd.InitialDirectory = s;
              sfd.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";

              DialogResult dr = sfd.ShowDialog();
              string path = sfd.FileName;
              string name = Path.GetFileNameWithoutExtension(path);
              string[] lines = System.IO.File.ReadAllLines(path);
              nr_II = int.Parse(lines[0].Split(' ')[0]);
              nr_SA = int.Parse(lines[0].Split(' ')[1]);
              lines[0] = "";

              int i = 1;
              gemiddeld_costs = new long[lines.Length - 1];
              gemiddeld_tijd = new double[lines.Length - 1];
              initial_costs = new long[lines.Length - 1];
              N = new int[lines.Length - 1];
              M = new int[lines.Length - 1];
              cool = new double[nr_SA];
              tem = new int[nr_SA];

              foreach (string line in lines)
              {
            if (line != "")
            {
              // Use a tab to indent each line of the file.
              Test t = new Test(line);

              // create initial solutions
              if (!initsolutions.ContainsKey(new Tuple<string, string>(t.custom.ToString(), t.delivery.ToString())))
              {
            // blalj
            // if initial tests do not exist, create them
            int aantaltests = 30;
            Solution[] inits = new Solution[aantaltests];
            Random rnd = new Random();
            for (int a = 0; a < aantaltests; a++)
            {
              Input p = new Input(t.custom, rnd);
              InitialPath init = new InitialPath(p, rnd);
              inits[a] = init.getSolution(t.initial, t.delivery);
            }
            initsolutions.Add(new Tuple<string, string>(t.custom.ToString(), t.delivery.ToString()), inits);
              }

              // run test
              RunTest(t, path, name, i, lines.Length - 1);
              i++;
            }
              }
              Logger l = new Logger(7 * gemiddeld_tijd.Length + 16);
              l.AddLine("Initial-costs:");
              var x = 0;
              foreach (long d in initial_costs)
              {
            if (x == nr_II)
              l.AddLine("");
            l.AddLine(d.ToString());
            x++;
              }
              l.AddLine("");
              x = 0;
              l.AddLine("Gemiddelde costs:");
              foreach (long d in gemiddeld_costs)
              {
            if (x == nr_II)
              l.AddLine("");
            l.AddLine(d.ToString());
            x++;
              }
              l.AddLine("");
              x = 0;
              l.AddLine("Gemiddelde tijd: ");
              foreach (double d in gemiddeld_tijd)
              {
            if (x == nr_II)
              l.AddLine("");
            l.AddLine(d.ToString());
            x++;
              }

              l.AddLine("");
              l.AddLine("N: ");
              foreach (int n in N)
            l.AddLine(n.ToString());

              l.AddLine("");
              l.AddLine("M: ");
              foreach (int m in M)
            l.AddLine(m.ToString());

              l.AddLine("");
              l.AddLine("Cool-rate: ");
              foreach (double m in cool)
            l.AddLine(m.ToString());

              l.AddLine("");
              l.AddLine("Temperature: ");
              foreach (int m in tem)
            l.AddLine(m.ToString());

              l.Write(path, name);
        }