/*****************************************************************
        * TESTING
        *****************************************************************/

        /// <summary>
        /// Test all available initial mapping algorithms.
        /// </summary>
        private static void TestAvailableInitialMappings()
        {
            int nbRep = -1;

            while (nbRep <= 0)
            {
                try
                {
                    ConsoleLayout.Header("Initial mapping test");
                    Console.Write("The number of times to repeat each algorithm: ");
                    nbRep = Convert.ToInt32(Console.ReadLine());
                    if (nbRep <= 0)
                    {
                        throw new FormatException();
                    }
                } catch (FormatException)
                {
                    ConsoleLayout.Error();
                    Console.WriteLine("PRESS ENTER TO CONTINUE ...");
                    Console.ReadLine();
                }
            }


            string path = @"C:\Users\User\Documents\GitHub\QuantumCircuitTransformation\QuantumCircuitTransformation\Results";

            Console.Write("The name for the excel file: ");
            string       fileName     = Console.ReadLine();
            Architecture architecture = QuantumDevices.IBM_Q20;

            using (ExcelPackage e = new ExcelPackage())
            {
                Mapping         mapping;
                LogicalCircuit  lCircuit;
                PhysicalCircuit pCircuit;
                ExcelWorksheet  ws;
                double          timeInitialMapping, timeTransforamtion;
                int             nbGatesPhysical;

                foreach (InitialMapping im in AlgorithmParameters.AvailableInitialMappings)
                {
                    e.Workbook.Worksheets.Add(im.GetFullShort());
                    ws = e.Workbook.Worksheets[im.GetFullShort()];
                    ws.Cells["A1"].Value = "Benchmark";
                    ws.Cells["B1"].Value = "Initial nb gates";
                    ws.Cells["C1"].Value = "Initial mapping time";
                    ws.Cells["D1"].Value = "Total Transformation time";
                    ws.Cells["E1"].Value = "Extra nb gates";


                    for (int i = 0; i < Benchmarks.LoadedBenchmarks.Count; i++)
                    {
                        lCircuit = CircuitGenerator.ReadFromFile(Benchmarks.LoadedBenchmarks[i].Name);
                        ws.Cells["A" + (i + 2)].Value = Benchmarks.LoadedBenchmarks[i].Name;
                        ws.Cells["B" + (i + 2)].Value = lCircuit.NbGates;

                        Console.WriteLine(Benchmarks.LoadedBenchmarks[i].Name);

                        timeInitialMapping = 0;
                        timeTransforamtion = 0;
                        nbGatesPhysical    = 0;

                        foreach (Transformation tr in AlgorithmParameters.AvailableTransformationAlgorithms)
                        {
                            for (int j = 0; j < nbRep; j++)
                            {
                                Globals.Timer.Restart();
                                (mapping, _) = im.Execute(architecture, lCircuit);
                                Globals.Timer.Stop();
                                timeInitialMapping += Globals.Timer.Elapsed.TotalMilliseconds;

                                Globals.Timer.Restart();
                                pCircuit = tr.Execute(lCircuit, architecture, mapping);
                                Globals.Timer.Stop();
                                timeTransforamtion += Globals.Timer.Elapsed.TotalMilliseconds;
                                nbGatesPhysical    += pCircuit.NbGates;
                            }
                        }
                        ws.Cells["C" + (i + 2)].Value = timeInitialMapping / nbRep;
                        ws.Cells["D" + (i + 2)].Value = timeTransforamtion / nbRep;
                        ws.Cells["E" + (i + 2)].Value = nbGatesPhysical / nbRep - lCircuit.NbGates;
                    }
                }

                e.SaveAs(new FileInfo(@path + @"\" + fileName + ".xlsx")); // Save excel
            }

            ConsoleLayout.Footer();
        }
        private static void Test()
        {
            ConsoleLayout.Header("Test environment");



            //LoadAllAvailableBenchmarks();


            CircuitGenerator.ReadFromFile("test.qasm");


            //List<int> x = new List<int> { 1, 2, 3, 4, 5, 6 };
            //List<int> y = new List<int>(x);


            //y[2] = 100000;



            //foreach (var i in x)
            //    Console.WriteLine(i);
            //foreach (var i in y)
            //    Console.WriteLine(i);


            //string fileName = "hwb7_59";

            //Globals.Timer.Restart();
            //LogicalCircuit circuit = CircuitGenerator.ReadFromFile(fileName + ".qasm");
            //Globals.Timer.Stop();
            //Console.WriteLine("Gate imported with {0} gates in {1} milliseconds.",
            //    circuit.NbGates, Globals.Timer.Elapsed.TotalMilliseconds);

            //Globals.Timer.Restart();
            //DependencyGraph g = DependencyGraphGenerator.Generate(circuit);
            //Globals.Timer.Stop();
            //Console.WriteLine("Dependency graph generated in {0} milliseconds.",
            //    Globals.Timer.Elapsed.TotalMilliseconds);

            //int nbDependencies = 0;
            //for (int i = 0; i < g.ExecuteBefore.Count(); i++)
            //{
            //    nbDependencies += g.ExecuteBefore[i].Count();
            //    try
            //    {
            //        Console.Write(i + ": ");
            //        Console.Write(g.ExecuteBefore[i][0]);
            //        for (int j = 1; j < g.ExecuteBefore[i].Count; j++)
            //        {
            //            Console.Write(", " + g.ExecuteBefore[i][j]);
            //        }
            //    }
            //    catch { }
            //    Console.Write('\n');
            //}
            //Console.WriteLine("Dependency graph with {0} dependencies is genereated in {1} milliseconds",
            //    nbDependencies, Globals.Timer.Elapsed.TotalMilliseconds);



            ConsoleLayout.Footer();
        }