Esempio n. 1
0
 public int detect_sign(Book b, Plane p)
 {
     int sum = 0;
     for (int i = 0; i < N; i++ )
     {
         sum += b.mas[i] * p.lambdas[i];
     }
     if (sum - p.lambdas[N] > 0)
         return 1;
     else
         return 0;
 }
Esempio n. 2
0
 public void generate_lambdas(Book b1, Book b2)
 {
     int sum1 = 0;
     int sum2 = 0;
     int seed = 45;
     Random random = new Random(seed);
     int[] lambdas = new int[N+1];
     for (int i = 0; i < N; i++)
     {
         if (i == 0)
             lambdas[i] = GenerateRandomNumber(80, 400);
         else
             if (i == 1)
                 lambdas[i] = GenerateRandomNumber(20, 80);
             else
                 if (i == 2)
                     lambdas[i] = GenerateRandomNumber(0, 90);
                 else
                     if (i == 3)
                         lambdas[i] = GenerateRandomNumber(4, 9);
         sum1 += b1.mas[i] * lambdas[i];
         sum2 += b2.mas[i] * lambdas[i];
     }
     int lam = GenerateRandomNumber(0, B);
     while ((lam > Math.Max(sum1, sum2))&& (lam < Math.Min(sum1, sum2)))
     {
         lam = GenerateRandomNumber(0, B);
     }
     lambdas[N] = lam;
     Plane plane = new Plane(lambdas, planes.Count);
     planes.Add(plane);
     if (sum1 - lam > 0)
     {
         b1.addPlane(plane.number, 1);
         b2.addPlane(plane.number, 0);
     }
     else
     {
         b1.addPlane(plane.number, 0);
         b2.addPlane(plane.number, 1);
     }
     foreach (Book b in used_books)
     {
         foreach (Plane p in planes)
         {
             if (!b.signs.ContainsKey(p.number))
                 b.addPlane(p.number, detect_sign(b, p));
         }
     }
     if (!used_books.Contains(b1))
         used_books.Add(b1);
     if (!used_books.Contains(b2))
         used_books.Add(b2);
 }