Beispiel #1
0
 public Form1()
 {
     InitializeComponent();
     SetUp();
     Knapsack_Class MaybeIsABigestOne  = ToDo(0, items, new Knapsack_Class(10), false);
     Knapsack_Class MaybeIsABigestOne2 = Answers.Find(x => x.Cost_Total == Answers.Max(z => z.Cost_Total));
 }
Beispiel #2
0
 public Knapsack_Class(Knapsack_Class In)
 {
     items = new List <ItemTable_Class>();
     foreach (var temp in In.items)
     {
         items.Add(temp);
     }
     Cost_Total     = In.Cost_Total;
     Weight_Total   = In.Weight_Total;
     Quantity_Total = In.Quantity_Total;
     Load           = In.Load;
 }
Beispiel #3
0
        Knapsack_Class ToDo(int n, List <Items_Class> items_L, Knapsack_Class pack, bool Take)
        {
            if (pack.Weight_Total == pack.Load)
            {
                return(pack);
            }
            if (Take && items_L.ElementAt(n).Weight + pack.Weight_Total <= pack.Load)
            {
                pack.Add(items_L.ElementAt(n));
            }
            if (n == (items_L.Count - 1))
            {
                Answers.Add(new Knapsack_Class(pack));
                return(pack);
            }
            Knapsack_Class A = ToDo(n + 1, items_L, (new Knapsack_Class(pack)), false);
            Knapsack_Class B = ToDo(n + 1, items_L, (new Knapsack_Class(pack)), true);

            return(A.Cost_Total > B.Cost_Total ? A : B);
        }