Esempio n. 1
0
 //----------------------------------------SIMPLEX METODAI-------------------------------------------
 private SimplexLentele MakeLentelesCopy(SimplexLentele Lent)
 {
     SimplexLentele nauja = new SimplexLentele();
     eilute eil = new eilute();
     nauja.BVS.AddRange(Lent.BVS);
     for (int i = 0; i < Lent.eilutes.Count; i++)
     {
         eil = new eilute();
         eil.eilutesReiksmes.AddRange(Lent.eilutes[i].eilutesReiksmes);
         nauja.eilutes.Add(eil);
     }
     nauja.RHS.AddRange(Lent.RHS);
     return nauja;
 }
Esempio n. 2
0
 private Boolean ParuostiSpausdinimui(SimplexLentele Lent, List<int> Likutis, ref RandomElements rnd)
 {
     RandomiserClass Randomiser = new RandomiserClass();
     Randomiser.sablonas = subsabl;
     for (int i = 0; i < Randomiser.sablonas.SablonoSubNr.Count; i++)
     {
         Randomiser.kiekis.Add(0);
     }
     int dabartinis = 0;
     Boolean blogas = false;
     for (int i = 0; i < Lent.RHS.Count; i++)
     {
         if (Lent.BVS[i] >= 0)
         {
             if (Lent.RHS[i] < 0)
             {
                 blogas = true;
                 return true;
             }
             dabartinis += Lent.RHS[i];
             Randomiser.kiekis[Lent.BVS[i]] = Lent.RHS[i];
         }
     }
     if (blogas == false)
     {
         Randomiser.suma.AddRange(Likutis);
         for (int i = 0; i < Likutis.Count; i++)
         {
             if (Likutis[i] < 0)
             {
                 blogas = true;
                 return true;
             }
             Randomiser.liekana += Likutis[i];
         }
         if (blogas == false)
         {
             Randomiser.ilgis.AddRange(problem.ilgis);
             Randomiser.tipas.AddRange(problem.tipai);
             Randomiser.pagamintaDetaliu = dabartinis;
             if (rnd.random.Count > 0)
             {
                 if (rnd.random[0].pagamintaDetaliu < dabartinis)
                 {
                     rnd.random.Clear();
                     rnd.random.Add(Randomiser);
                 }
                 if (rnd.random[0].pagamintaDetaliu == dabartinis)
                 {
                     rnd.random.Add(Randomiser);
                 }
                 if (rnd.random[0].pagamintaDetaliu > dabartinis)
                 {
                     return true;
                 }
             }
             else
             {
                 rnd.random.Add(Randomiser);
             }
         }
     }
     return false;
 }
Esempio n. 3
0
 private Boolean CheckArGalimaTestiSprendima(SimplexLentele Lent)
 {
     for (int i = 0; i < Lent.RHS.Count; i++)
     {
         if (Lent.RHS[i] < 0)
         {
             return false;
         }
     }
     for (int i = 0; i < Lent.eilutes[Lent.eilutes.Count - 1].eilutesReiksmes.Count; i++)
     {
         double tikrinimui = Lent.eilutes[Lent.eilutes.Count - 1].eilutesReiksmes[i];
         if (Math.Round(tikrinimui, 2, MidpointRounding.ToEven) > 0)
         {
             return true;
         }
     }
     return false;
 }
Esempio n. 4
0
 //-------------------------------------------SIMPLEX------------------------------------------------
 private void LygciuSudarimas()
 {
     Lygtys = new LygciuSistema();
     Lygtis LG = new Lygtis();
     for (int i = 0; i < problem.kiekis.Count; i++)
     {
         LG = new Lygtis();
         LG.LygtiesSprendinys = problem.kiekis[i];
         LG.LygtiesLiekana = problem.kiekis[i];
         for (int j = 0; j < subsabl.SablonoElem.Count; j++)
         {
             for (int h = 0; h < subsabl.SablonoElem[j].JuostIlgis.Count; h++)
             {
                 if (subsabl.SablonoElem[j].JuostIlgis[h] == problem.ilgis[i] && subsabl.SablonoElem[j].JuostTipas[h] == problem.tipai[i])
                 {
                     LG.kiekis.Add(subsabl.SablonoElem[j].Kiekis[h]);
                     LG.variantas.Add(subsabl.SablonoSubNr[j] - 1);
                 }
             }
         }
         Lygtys.Lygtis.Add(LG);
     }
     Lentele = new SimplexLentele();
     LenteleBack = new SimplexLentele();
     eilute eil = new eilute();
     eilute eil2 = new eilute();
     for (int i = 0; i < problem.kiekis.Count; i++)
     {
         Lentele.BVS.Add(-1);
         LenteleBack.BVS.Add(-1);
         Lentele.RHS.Add(problem.kiekis[i]);
         LenteleBack.RHS.Add(problem.kiekis[i]);
         eil = new eilute();
         eil2 = new eilute();
         for (int j = 0; j < subsabl.SablonoElem.Count; j++)
         {
             eil.eilutesReiksmes.Add(0);
             eil2.eilutesReiksmes.Add(0);
         }
         for (int j = 0; j < Lygtys.Lygtis[i].variantas.Count; j++)
         {
             eil.eilutesReiksmes[Lygtys.Lygtis[i].variantas[j]] = Lygtys.Lygtis[i].kiekis[j];
             eil2.eilutesReiksmes[Lygtys.Lygtis[i].variantas[j]] = Lygtys.Lygtis[i].kiekis[j];
         }
         Lentele.eilutes.Add(eil);
         LenteleBack.eilutes.Add(eil2);
     }
     eil = new eilute();
     eil2 = new eilute();
     for (int j = 0; j < subsabl.SablonoElem.Count; j++)
     {
         eil.eilutesReiksmes.Add(1);
         eil2.eilutesReiksmes.Add(1);
     }
     Lentele.eilutes.Add(eil);
     LenteleBack.eilutes.Add(eil2);
 }
Esempio n. 5
0
 private void SimplexCiklas(SimplexLentele Lentele, int kiek)
 {
     //int kiek = Lentele.eilutes[Lentele.eilutes.Count - 1].eilutesReiksmes.Count;
     for (int i = 0; i < kiek; i++) // kiek
     {
         worker.ReportProgress(Convert.ToInt32(Math.Round(Convert.ToDouble(i) / Convert.ToDouble(kiek) * 100)));
         SymplexCikloNR(Lentele, i);
         if (uzbaigti == true)
         {
             i = kiek;
         }
     }
     if (RandomList.random.Count > 10)
     {
         TestingForSimplex(1, 10);
     }
 }
Esempio n. 6
0
 private void SymplexCikloNR(SimplexLentele Lentele, int cikloNr)
 {
     SimplexLentele Lent = new SimplexLentele();
     Lent = MakeLentelesCopy(Lentele);
     Boolean stop = false;
     RandomElements LocalList = new RandomElements();
     while (CheckArGalimaTestiSprendima(Lent) == true && stop == false)
     {
         List<int> Likutis = new List<int> { };
         int MaxCj = RastiMaxCjCikle(Lent, cikloNr);
         Tuple<int, double> back = RastiMinRHS(MaxCj, Lent);
         int MinRHS = back.Item1;
         int MinRHSReiksme = Convert.ToInt32(Math.Floor(back.Item2));
         Lent.BVS[MinRHS] = MaxCj;
         PertvarkytiPagrindineEilute(MinRHS, MaxCj, ref Lent);
         PertvarkytiLikusesEilutes(MinRHS, MaxCj, ref Lent);
         PertvarkytiPagrindiniStulpeli(MinRHS, MaxCj, ref Lent);
         PerskaiciuotiRHS(MinRHS, MaxCj, MinRHSReiksme, ref Lent, ref Likutis);
         stop = ParuostiSpausdinimui(Lent, Likutis, ref LocalList);
         if (LocalList.random.Count > 100)
         {
             stop = true;
         }
     }
     RandomList.random.AddRange(LocalList.random);
 }
Esempio n. 7
0
 private Tuple<int, double> RastiMinRHS(int MaxCj, SimplexLentele Lent)
 {
     double min = Lent.RHS[0];
     int mn = 0;
     double tikrinti = 0;
     for (int i = 0; i < Lent.eilutes.Count - 1; i++)
     {
         if (Lent.eilutes[i].eilutesReiksmes[MaxCj] > 0)
         {
             tikrinti = Lent.RHS[i] / Lent.eilutes[i].eilutesReiksmes[MaxCj];
             if (tikrinti < min && tikrinti > 0) // FIXED?
             {
                 min = tikrinti;
                 mn = i;
             }
         }
     }
     return Tuple.Create(mn, min);
 }
Esempio n. 8
0
 //-------------------------------------------SU CIKLU-----------------------------------------------
 private void SimplexBeCiklo(SimplexLentele Lentele, int nr)
 {
     SymplexCikloNR(Lentele, nr);
     TestingForSimplex(1, 0);
 }
Esempio n. 9
0
 private void PertvarkytiPagrindiniStulpeli(int MinRHS, int MaxCj, ref SimplexLentele Lent)
 {
     for (int i = 0; i < Lent.eilutes.Count; i++)
     {
         if (i != MinRHS)
         {
             Lent.eilutes[i].eilutesReiksmes[MaxCj] = 0;
         }
     }
 }
Esempio n. 10
0
 private int RastiMaxCjCikle(SimplexLentele Lent, int cikloNr)
 {
     double pradineReiksme = Lent.eilutes[Lent.eilutes.Count - 1].eilutesReiksmes[0];
     Boolean VisiVienodi = true;
     for (int i = 0; i < Lent.eilutes[Lent.eilutes.Count - 1].eilutesReiksmes.Count; i++)
     {
         if (Lent.eilutes[Lent.eilutes.Count - 1].eilutesReiksmes[i] != pradineReiksme)
         {
             VisiVienodi = false;
             i = Lent.eilutes[Lent.eilutes.Count - 1].eilutesReiksmes.Count;
         }
     }
     if (VisiVienodi == true)
     {
         return cikloNr;
     }
     else
     {
         double max = 0;
         int mx = 0;
         for (int i = 0; i < Lent.eilutes[Lent.eilutes.Count - 1].eilutesReiksmes.Count; i++)
         {
             if (max < Lent.eilutes[Lent.eilutes.Count - 1].eilutesReiksmes[i])
             {
                 max = Lent.eilutes[Lent.eilutes.Count - 1].eilutesReiksmes[i];
                 mx = i;
             }
         }
         return mx;
     }
 }
Esempio n. 11
0
 private void PertvarkytiPagrindineEilute(int MinRHS, int MaxCj, ref SimplexLentele Lent)
 {
     double IsKoDalinti = Lent.eilutes[MinRHS].eilutesReiksmes[MaxCj];
     for (int i = 0; i < Lent.eilutes[MinRHS].eilutesReiksmes.Count; i++)
     {
         double beta = Lent.eilutes[MinRHS].eilutesReiksmes[i] / IsKoDalinti;
         Lent.eilutes[MinRHS].eilutesReiksmes[i] = Math.Round(beta, 10); // ?
     }
 }
Esempio n. 12
0
 private void PertvarkytiLikusesEilutes(int MinRHS, int MaxCj, ref SimplexLentele Lent)
 {
     for (int i = 0; i < Lent.eilutes.Count; i++)
     {
         if (i != MinRHS)
         {
             for (int j = 0; j < Lent.eilutes[i].eilutesReiksmes.Count; j++)
             {
                 if (j != MaxCj)
                 {
                     double beta = Lent.eilutes[i].eilutesReiksmes[j] - Lent.eilutes[i].eilutesReiksmes[MaxCj] * Lent.eilutes[MinRHS].eilutesReiksmes[j];
                     //if (beta < 0)
                     //{
                     //    beta = 0;
                     //}
                     Lent.eilutes[i].eilutesReiksmes[j] = Math.Round(beta, 10);
                 }
             }
         }
     }
 }
Esempio n. 13
0
 private void PerskaiciuotiRHS(int MinRHS, int MaxCj, int MinRHSReiksme, ref SimplexLentele Lent, ref List<int> Likuciai)
 {
     Lent.RHS[MinRHS] = MinRHSReiksme;
     for (int i = 0; i < LenteleBack.eilutes.Count - 1; i++)
     {
         int likutis = LenteleBack.RHS[i] - MinRHSReiksme * Convert.ToInt32(LenteleBack.eilutes[i].eilutesReiksmes[MaxCj]);
         Likuciai.Add(likutis);
     }
     for (int i = 0; i < Likuciai.Count; i++)
     {
         if (i != MinRHS)
         {
             if (Lent.BVS[i] >= 0)
             {
                 // rasti minimuma is kiek galima dalinti.
                 double min = Convert.ToDouble(Likuciai[i]);
                 for (int j = 0; j < LenteleBack.eilutes.Count - 1; j++)
                 {
                     if (LenteleBack.eilutes[j].eilutesReiksmes[Lent.BVS[i]] > 0)
                     {
                         double kiekdalinti = Convert.ToDouble(Likuciai[j]) / LenteleBack.eilutes[j].eilutesReiksmes[Lent.BVS[i]]; // ????????????????????
                         if (kiekdalinti < min)
                         {
                             min = kiekdalinti;
                         }
                     }
                 }
                 Lent.RHS[i] = Convert.ToInt32(Math.Floor(min));
                 // atimti is likuciu
                 for (int j = 0; j < Likuciai.Count; j++)
                 {
                     Likuciai[j] -= Lent.RHS[i] * Convert.ToInt32(LenteleBack.eilutes[j].eilutesReiksmes[Lent.BVS[i]]); //?
                 }
             }
         }
     }
     // liekanos
     for (int i = 0; i < Likuciai.Count; i++)
     {
         if (i != MinRHS)
         {
             if (Lent.BVS[i] < 0)
             {
                 Lent.RHS[i] = Likuciai[i];
             }
         }
     }
 }
Esempio n. 14
0
 //-------------------------------------------SU CIKLU-------------------------------------------
 private void SimplexCiklas(SimplexLentele Lentele)
 {
     SimplexLentele Lent = new SimplexLentele();
     List<int> Likutis = new List<int> { };
     int kiek = Lentele.eilutes[Lentele.eilutes.Count - 1].eilutesReiksmes.Count;
     int i;
     for (i = 0; i < kiek; i++) // kiek
     {
         SymplexCikloNR(Lentele, i);
         TestingForSimplex(1);
     }
 }
Esempio n. 15
0
 private void Reset()
 {
     problem = new Uzklausa();
     visoP = new Uzklausa();
     RandomList = new RandomElements();
     problemOld = new Uzklausa();
     Lygtys = new LygciuSistema();
     Lentele = new SimplexLentele();
 }