public int[,] GetMatriceDistances(Corpus corpus, Graphe g, int t)
        {
            int[,] matrice = new int[corpus.concepts.Count, corpus.concepts.Count];

            for (int i = 0; i < corpus.concepts.Count; i++)
            {
                for (int j = 0; j < corpus.concepts.Count; j++)
                {
                    matrice[i, j] = (i == j) ? 0 : int.MaxValue;
                }
            }

            for (int i = 0; i < corpus.concepts.Count; i++)
            {
                HashSet <string> servicesOld = new HashSet <string>();
                HashSet <string> servicesNew = new HashSet <string>();
                HashSet <string> conceptsOld = new HashSet <string>();
                HashSet <string> conceptsNew = new HashSet <string>();

                conceptsNew.Add(corpus.concepts[i].id);
                conceptsOld.Add(corpus.concepts[i].id);

                for (int currentLevel = 0; currentLevel < t; currentLevel++)
                {
                    servicesNew.Clear();

                    foreach (string c in conceptsNew)
                    {
                        foreach (string s in g.inputServices[c])
                        {
                            if (servicesOld.Contains(s) == false)
                            {
                                servicesNew.Add(s);
                                servicesOld.Add(s);
                            }
                        }
                    }

                    conceptsNew.Clear();

                    foreach (string s in servicesNew)
                    {
                        foreach (string c in g.serviceOutputs[s])
                        {
                            if (conceptsOld.Contains(c) == false)
                            {
                                conceptsNew.Add(c);
                                conceptsOld.Add(c);
                                matrice[i, corpus.conceptIndex[c]] = currentLevel + 1;
                            }
                        }
                    }
                }
            }

            return(matrice);
        }
        private void initEspaceRecherche(int t)
        {
            start = DateTime.Now;

            g = new Graphe();

            foreach (Concept c in corpus.concepts)
            {
                g.outputServices.Add(c.id, new HashSet <string>());
                g.inputServices.Add(c.id, new HashSet <string>());
            }

            foreach (Service s in corpus.services)
            {
                g.serviceInputs.Add(s.id, new HashSet <string>());
                g.serviceOutputs.Add(s.id, new HashSet <string>());

                foreach (string i in s.input)
                {
                    g.serviceInputs[s.id].Add(i);
                    g.inputServices[i].Add(s.id);
                }
                foreach (string o in s.output)
                {
                    g.serviceOutputs[s.id].Add(o);
                    g.outputServices[o].Add(s.id);
                }
            }

            results.timeGeneration = (DateTime.Now - start).TotalSeconds;


            start = DateTime.Now;

            HashSet <string>[] servicesPertinantsOutputs = new HashSet <string> [t];
            HashSet <string>[] servicesPertinantsInputs  = new HashSet <string> [t];

            HashSet <string> currentConceptsOutputs = new HashSet <string>();
            HashSet <string> currentConceptsInputs  = new HashSet <string>();
            List <string>    currentPrameters       = new List <string>();

            servicesPertinants = new HashSet <string> [t];

            foreach (string e in requete.output)
            {
                currentConceptsOutputs.Add(e);
            }
            foreach (string e in requete.input)
            {
                currentConceptsInputs.Add(e);
                currentPrameters.Add(e);
            }

            for (int currentLevel = 0; currentLevel < t; currentLevel++)
            {
                servicesPertinantsOutputs[t - 1 - currentLevel] = new HashSet <string>();
                servicesPertinantsInputs[currentLevel]          = new HashSet <string>();

                // Inputs to Services

                foreach (Service s in corpus.services)
                {
                    if (ContainsAllItems(currentPrameters, s.input))
                    {
                        servicesPertinantsInputs[currentLevel].Add(s.id);
                    }
                }

                foreach (string s in servicesPertinantsInputs[currentLevel])
                {
                    foreach (string c in g.serviceOutputs[s])
                    {
                        if (currentPrameters.Contains(c) == false)
                        {
                            currentPrameters.Add(c);
                        }
                    }
                }

                currentConceptsInputs.Clear();

                foreach (string s in servicesPertinantsInputs[currentLevel])
                {
                    foreach (string c in g.serviceOutputs[s])
                    {
                        currentConceptsInputs.Add(c);
                    }
                }

                // Services To Outputs

                if (currentLevel > 0)
                {
                    foreach (string s in servicesPertinantsOutputs[t - currentLevel])
                    {
                        servicesPertinantsOutputs[t - 1 - currentLevel].Add(s);
                    }
                }

                foreach (string c in currentConceptsOutputs)
                {
                    foreach (string s in g.outputServices[c])
                    {
                        servicesPertinantsOutputs[t - 1 - currentLevel].Add(s);
                    }
                }

                currentConceptsOutputs.Clear();

                foreach (string s in servicesPertinantsOutputs[t - 1 - currentLevel])
                {
                    foreach (string c in g.serviceInputs[s])
                    {
                        currentConceptsOutputs.Add(c);
                    }
                }
            }

            double d = 100;

            for (int currentLevel = 0; currentLevel < t; currentLevel++)
            {
                servicesPertinants[currentLevel] = new HashSet <string>();

                foreach (string s in servicesPertinantsInputs[currentLevel])
                {
                    if (servicesPertinantsOutputs[currentLevel].Contains(s))
                    {
                        servicesPertinants[currentLevel].Add(s);
                    }
                }

                results.optimisations += servicesPertinants[currentLevel].Count + "-";

                d = d * servicesPertinants[currentLevel].Count / corpus.services.Count;
            }

            results.optimisations = d + "****" + results.optimisations;

            results.timeOptimisation = (DateTime.Now - start).TotalSeconds;

            return;
        }