diff --git a/ALGA/Optimalizalas/07_NyersEro.cs b/ALGA/Optimalizalas/07_NyersEro.cs index db5d73a..f04d994 100644 --- a/ALGA/Optimalizalas/07_NyersEro.cs +++ b/ALGA/Optimalizalas/07_NyersEro.cs @@ -1,6 +1,57 @@ using System; +using System.Runtime.InteropServices; namespace OE.ALGA.Optimalizalas { - // 7. heti labor feladat - Tesztek: 07_NyersEroTesztek.cs + public class HatizsakProblema + { + public int N { get; } + public int Wmax { get; } + public int[] W { get; } + public double[] P { get; } + public HatizsakProblema(int n, int wmax, int[] w, double[] p) + { + N = n; + Wmax = wmax; + if (w.Length == p.Length && p.Length == n) + { + W = w; + P = p; + } + } + public int OsszSuly(bool[] pakolas) + { + int osszsuly = 0; + if (pakolas.Length == N) + { + for (int i = 0; i < N; i++) + { + if (pakolas[i]) + { + osszsuly += W[i]; + } + } + } + return osszsuly; + } + public double OsszErtek(bool[] pakolas) + { + double osszertek = 0; + if (pakolas.Length == N) + { + for (int i = 0; i < N; i++) + { + if (pakolas[i]) + { + osszertek += P[i]; + } + } + } + return osszertek; + } + public bool Ervenyes(bool[] pakolas) + { + return (OsszSuly(pakolas) <= Wmax); + } + } }