Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public IEnumerable<IEnumerable<List<double>>> grupuj(List<List<double>> probki)
- {
- //główna funkcja do napisania,
- /// przykładowa zawartość funkcji, początek
- List<List<List<double>>> grupy = new List<List<List<double>>>();
- for (int i = 0; i < probki.Count; i++)
- {
- grupy.Add(new List<List<double>> { probki[i] });
- }
- int tmp = 0;
- while (tmp < 30)
- {
- Dictionary<List<int>, double> odleglosci = new Dictionary<List<int>, double>();
- foreach (var grupa in grupy)
- {
- if (grupa.Count > tmp)
- {
- tmp = grupa.Count;
- }
- }
- for (int a = 0; a < grupy.Count; a++)
- {
- for (int b = 0; b < grupy.Count; b++)
- {
- if (a != b)
- {
- var srodek1 = GetSrodekGrupy(grupy[a]);
- var srodek2 = GetSrodekGrupy(grupy[b]);
- var odleglosc = Math.Sqrt(Math.Pow(srodek1[0] * srodek2[0], 2) + Math.Pow(srodek1[1] * srodek2[1], 2));
- odleglosci.Add(new List<int> { a, b }, odleglosc);
- }
- }
- }
- var ktoreOut = odleglosci.OrderBy(t => t.Value).First().Key;
- var n = ktoreOut[0];
- var m = ktoreOut[1];
- var grupa1 = grupy[n];
- var grupa2 = grupy[m];
- var nowaGrupa = grupa1.Concat(grupa2).ToList();
- grupy.RemoveAt(n);
- grupy.RemoveAt(m-1);
- grupy.Add(nowaGrupa);
- }
- wypisz_grupy(grupy);
- return grupy;
- }
- public List<double> GetSrodekGrupy(List<List<double>> grupa)
- {
- var sumaX = 0.0;
- var sumaY = 0.0;
- for (int i = 0; i < grupa.Count; i++)
- {
- sumaX += grupa[i][0];
- sumaY += grupa[i][1];
- }
- return new List<double> { sumaX / grupa.Count, sumaY / grupa.Count };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement