mirror of
https://github.com/Lendaia/oe-alga-feladatok.git
synced 2026-04-23 04:16:32 +01:00
finallyyyyyyyyy
This commit is contained in:
@@ -1,30 +1,260 @@
|
||||
// using System;
|
||||
|
||||
// namespace OE.ALGA.Optimalizalas
|
||||
// {
|
||||
// public class VisszalepesesOptimalizacio<T>
|
||||
// {
|
||||
// public int n;
|
||||
// public int[] M;
|
||||
// public T[,] R;
|
||||
// public Func<int, T, bool> ft;
|
||||
// public Func<int, T, T[], bool> fk;
|
||||
// public Func<T[], float> josag;
|
||||
|
||||
// public int Lepesszam { get; set;} = 0;
|
||||
|
||||
// public VisszalepesesOptimalizacio(int n, int[] M, T[,] R, Func<int, T, bool> ft, Func<int, T, T[], bool> fk, Func<T[], float> josag)
|
||||
// {
|
||||
// this.n = n;
|
||||
// this.M = M;
|
||||
// this.R = R;
|
||||
// this.ft = ft;
|
||||
// this.fk = fk;
|
||||
// this.josag = josag;
|
||||
// }
|
||||
|
||||
// public T[] OptimalisMegoldas()
|
||||
// {
|
||||
// int szint = 0;
|
||||
// T[] E = new T[n];
|
||||
// bool van = false;
|
||||
// T[] O = new T[n];
|
||||
// Backtrack(szint, ref E, ref van, ref O);
|
||||
// if (van)
|
||||
// {
|
||||
// return O;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// throw new Exception("Nincs megoldas");
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
// virtual public void Backtrack(int szint, ref T[] E, ref bool van, ref T[] O)
|
||||
// {
|
||||
// int i = 0;
|
||||
// while(i < M[szint])
|
||||
// {
|
||||
// Lepesszam++;
|
||||
// i++;
|
||||
// if (ft(szint, R[szint, i]))
|
||||
// {
|
||||
// if(fk(szint, R[szint, i], E))
|
||||
// {
|
||||
// E[szint] = R[szint, i];
|
||||
|
||||
// if (szint == n)
|
||||
// {
|
||||
// if ((!van) || josag(E) > josag(O))
|
||||
// {
|
||||
// O = E;
|
||||
// }
|
||||
// van = true;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Backtrack(szint+1, ref E, ref van, ref O);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// public class VisszalepesesHatizsakPakolas
|
||||
// {
|
||||
// HatizsakProblema problema;
|
||||
// public int LepesSzam {get; set;}
|
||||
|
||||
// public VisszalepesesHatizsakPakolas(HatizsakProblema problema)
|
||||
// {
|
||||
// this.problema = problema;
|
||||
// }
|
||||
// virtual public bool[] OptimalisMegoldas()
|
||||
// {
|
||||
// int[] M = new int[problema.N];
|
||||
|
||||
// bool[,] R = new bool[problema.N, 2];
|
||||
// for (int i = 0; i < problema.N; i++)
|
||||
// {
|
||||
// M[i] = 2;
|
||||
// R[i, 0] = true;
|
||||
// R[i, 1] = false;
|
||||
// }
|
||||
// VisszalepesesOptimalizacio<bool> visszalepesesoptimalizacio = new VisszalepesesOptimalizacio<bool>(problema.N, M, R, Ft, Fk, Josag);
|
||||
// bool[] eredmeny = visszalepesesoptimalizacio.OptimalisMegoldas();
|
||||
// LepesSzam = visszalepesesoptimalizacio.Lepesszam;
|
||||
// return eredmeny;
|
||||
// }
|
||||
// public float OptimalisErtek()
|
||||
// {
|
||||
// return problema.OsszErtek(OptimalisMegoldas());
|
||||
// }
|
||||
// private float Josag(bool[] pakolas)
|
||||
// {
|
||||
// float ertek = 0;
|
||||
// if (!problema.Ervenyes(pakolas))
|
||||
// {
|
||||
// ertek = -1;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// ertek = problema.OsszErtek(pakolas);
|
||||
// }
|
||||
// return ertek;
|
||||
// }
|
||||
// private bool Ft(int egesz, bool logikai)
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
// private bool Fk(int egesz, bool logikai, bool[] tomb)
|
||||
// {
|
||||
// int weight = 0;
|
||||
// for (int i = 0; i < problema.N; i++)
|
||||
// {
|
||||
// if(tomb[i])
|
||||
// {
|
||||
// weight += problema.W[i];
|
||||
// }
|
||||
// }
|
||||
// return (weight <= problema.Wmax);
|
||||
// }
|
||||
|
||||
// }
|
||||
// public class SzetvalasztasEsKorlatozasOptimalizacio<T> : VisszalepesesOptimalizacio<T>
|
||||
// {
|
||||
// public Func<int, T[], int> fb;
|
||||
// public SzetvalasztasEsKorlatozasOptimalizacio(Func<int, T[], int> fb, int n, int[] M, T[,] R, Func<int, T, bool> ft, Func<int, T, T[], bool> fk, Func<T[], float> josag) : base(n, M, R, ft, fk, josag)
|
||||
// {
|
||||
// this.fb = fb;
|
||||
// }
|
||||
|
||||
// public override void Backtrack(int szint, ref T[] E, ref bool van, ref T[] O)
|
||||
// {
|
||||
// int i = 0;
|
||||
// while(i < M[szint])
|
||||
// {
|
||||
// Lepesszam++;
|
||||
// i++;
|
||||
// if (ft(szint, R[szint, i]))
|
||||
// {
|
||||
// if(fk(szint, R[szint, i], E) && fb(szint, O) > 6)
|
||||
// {
|
||||
// E[szint] = R[szint, i];
|
||||
|
||||
// if (szint == n)
|
||||
// {
|
||||
// if ((!van) || josag(E) > josag(O))
|
||||
// {
|
||||
// O = E;
|
||||
// }
|
||||
// van = true;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Backtrack(szint+1, ref E, ref van, ref O);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// public class SzetvalasztasEsKorlatozasHatizsakPakolas : VisszalepesesHatizsakPakolas
|
||||
// {
|
||||
// public SzetvalasztasEsKorlatozasHatizsakPakolas(HatizsakProblema problema) : base(problema)
|
||||
// {
|
||||
// }
|
||||
// public override bool[] OptimalisMegoldas()
|
||||
// {
|
||||
// bool[] asd = new bool[2] {true, true};
|
||||
// return asd;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
using System;
|
||||
|
||||
namespace OE.ALGA.Optimalizalas
|
||||
{
|
||||
public class VisszalepesesOptimalizacio<T>
|
||||
{
|
||||
public int n;
|
||||
public int[] M;
|
||||
public T[,] R;
|
||||
public Func<int, T, bool> ft;
|
||||
public Func<int, T, T[], bool> fk;
|
||||
public Func<T[], float> josag;
|
||||
protected int n;
|
||||
protected int[] M;
|
||||
protected T[,] R;
|
||||
protected Func<int, T, bool> ft;
|
||||
protected Func<int, T, T[], bool> fk;
|
||||
protected Func<T[], float> josag;
|
||||
public int LepesSzam { get; protected set; }
|
||||
|
||||
public int Lepesszam { get; set;} = 0;
|
||||
|
||||
public VisszalepesesOptimalizacio(int n, int[] M, T[,] R, Func<int, T, bool> ft, Func<int, T, T[], bool> fk, Func<T[], float> josag)
|
||||
public VisszalepesesOptimalizacio(int n, int[] m, T[,] r, Func<int, T, bool> ft, Func<int, T, T[], bool> fk, Func<T[], float> josag)
|
||||
{
|
||||
this.n = n;
|
||||
this.M = M;
|
||||
this.R = R;
|
||||
this.M = m;
|
||||
this.R = r;
|
||||
this.ft = ft;
|
||||
this.fk = fk;
|
||||
this.josag = josag;
|
||||
LepesSzam = 0;
|
||||
}
|
||||
|
||||
public virtual void Backtrack(int szint, ref T[] E, ref bool van, ref T[] legjobbE)
|
||||
{
|
||||
int i = 0;
|
||||
while (i < M[szint])
|
||||
{
|
||||
LepesSzam++;
|
||||
if (ft(szint, R[szint, i]))
|
||||
{
|
||||
if (fk(szint, R[szint, i], E))
|
||||
{
|
||||
E[szint] = R[szint, i];
|
||||
if (szint == n - 1)
|
||||
{
|
||||
if (!van || josag(E) > josag(legjobbE))
|
||||
{
|
||||
legjobbE = (T[])E.Clone();
|
||||
}
|
||||
van = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Backtrack(szint + 1, ref E, ref van, ref legjobbE);
|
||||
}
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public T[] OptimalisMegoldas()
|
||||
{
|
||||
// T[] E = new T[n];
|
||||
// T[] O = new T[n];
|
||||
// bool van = false;
|
||||
|
||||
// Backtrack(0, ref E, ref van, ref O);
|
||||
|
||||
// if (van)
|
||||
// return O;
|
||||
// else
|
||||
// throw new NincsElKivetel();
|
||||
|
||||
int szint = 0;
|
||||
T[] E = new T[n];
|
||||
bool van = false;
|
||||
@@ -38,363 +268,145 @@ namespace OE.ALGA.Optimalizalas
|
||||
{
|
||||
throw new Exception("Nincs megoldas");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
virtual public void Backtrack(int szint, ref T[] E, ref bool van, ref T[] O)
|
||||
{
|
||||
int i = 0;
|
||||
while(i < M[szint])
|
||||
{
|
||||
Lepesszam++;
|
||||
i++;
|
||||
if (ft(szint, R[szint, i]))
|
||||
{
|
||||
if(fk(szint, R[szint, i], E))
|
||||
{
|
||||
E[szint] = R[szint, i];
|
||||
|
||||
if (szint == n)
|
||||
{
|
||||
if ((!van) || josag(E) > josag(O))
|
||||
{
|
||||
O = E;
|
||||
}
|
||||
van = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Backtrack(szint+1, ref E, ref van, ref O);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class VisszalepesesHatizsakPakolas
|
||||
{
|
||||
HatizsakProblema problema;
|
||||
public int LepesSzam {get; set;}
|
||||
|
||||
protected HatizsakProblema problema;
|
||||
public VisszalepesesHatizsakPakolas(HatizsakProblema problema)
|
||||
{
|
||||
this.problema = problema;
|
||||
}
|
||||
virtual public bool[] OptimalisMegoldas()
|
||||
public int LepesSzam { get; protected set; }
|
||||
|
||||
public virtual bool[] OptimalisMegoldas()
|
||||
{
|
||||
int[] M = new int[problema.N];
|
||||
|
||||
bool[,] R = new bool[problema.N, 2];
|
||||
|
||||
for (int i = 0; i < problema.N; i++)
|
||||
{
|
||||
M[i] = 2;
|
||||
R[i, 0] = true;
|
||||
R[i, 1] = false;
|
||||
}
|
||||
VisszalepesesOptimalizacio<bool> visszalepesesoptimalizacio = new VisszalepesesOptimalizacio<bool>(problema.N, M, R, Ft, Fk, Josag);
|
||||
bool[] eredmeny = visszalepesesoptimalizacio.OptimalisMegoldas();
|
||||
LepesSzam = visszalepesesoptimalizacio.Lepesszam;
|
||||
return eredmeny;
|
||||
|
||||
Func<int, bool, bool> ft = (sz, r) => true;
|
||||
|
||||
Func<int, bool, bool[], bool> fk = (sz, r, meg) =>
|
||||
{
|
||||
float suly = 0;
|
||||
for (int i = 0; i < sz; i++)
|
||||
if (meg[i]) suly += problema.W[i];
|
||||
if (r) suly += problema.W[sz];
|
||||
return suly <= problema.Wmax;
|
||||
};
|
||||
|
||||
var opt = new VisszalepesesOptimalizacio<bool>(problema.N, M, R, ft, fk, problema.OsszErtek);
|
||||
bool[] legjobb = opt.OptimalisMegoldas();
|
||||
LepesSzam = opt.LepesSzam;
|
||||
return legjobb;
|
||||
|
||||
}
|
||||
public float OptimalisErtek()
|
||||
|
||||
public double OptimalisErtek()
|
||||
{
|
||||
return problema.OsszErtek(OptimalisMegoldas());
|
||||
}
|
||||
private float Josag(bool[] pakolas)
|
||||
{
|
||||
float ertek = 0;
|
||||
if (!problema.Ervenyes(pakolas))
|
||||
{
|
||||
ertek = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
ertek = problema.OsszErtek(pakolas);
|
||||
}
|
||||
return ertek;
|
||||
}
|
||||
private bool Ft(int egesz, bool logikai)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
private bool Fk(int egesz, bool logikai, bool[] tomb)
|
||||
{
|
||||
int weight = 0;
|
||||
for (int i = 0; i < problema.N; i++)
|
||||
{
|
||||
if(tomb[i])
|
||||
{
|
||||
weight += problema.W[i];
|
||||
}
|
||||
}
|
||||
return (weight <= problema.Wmax);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class SzetvalasztasEsKorlatozasOptimalizacio<T> : VisszalepesesOptimalizacio<T>
|
||||
{
|
||||
public Func<int, T[], int> fb;
|
||||
public SzetvalasztasEsKorlatozasOptimalizacio(Func<int, T[], int> fb, int n, int[] M, T[,] R, Func<int, T, bool> ft, Func<int, T, T[], bool> fk, Func<T[], float> josag) : base(n, M, R, ft, fk, josag)
|
||||
private readonly Func<int, T[], float> fb;
|
||||
|
||||
public SzetvalasztasEsKorlatozasOptimalizacio(
|
||||
int n,
|
||||
int[] m,
|
||||
T[,] r,
|
||||
Func<int, T, bool> ft,
|
||||
Func<int, T, T[], bool> fk,
|
||||
Func<T[], float> josag,
|
||||
Func<int, T[], float> fb)
|
||||
: base(n, m, r, ft, fk, josag)
|
||||
{
|
||||
this.fb = fb;
|
||||
}
|
||||
|
||||
public override void Backtrack(int szint, ref T[] E, ref bool van, ref T[] O)
|
||||
public override void Backtrack(int szint, ref T[] e, ref bool van, ref T[] legjobbE)
|
||||
{
|
||||
int i = 0;
|
||||
while(i < M[szint])
|
||||
while (i < M[szint])
|
||||
{
|
||||
Lepesszam++;
|
||||
i++;
|
||||
LepesSzam++;
|
||||
if (ft(szint, R[szint, i]))
|
||||
{
|
||||
if(fk(szint, R[szint, i], E) && fb(szint, O) > 6)
|
||||
if (fk(szint, R[szint, i], e))
|
||||
{
|
||||
E[szint] = R[szint, i];
|
||||
|
||||
if (szint == n)
|
||||
e[szint] = R[szint, i];
|
||||
if (szint == n - 1)
|
||||
{
|
||||
if ((!van) || josag(E) > josag(O))
|
||||
if (!van || josag(e) > josag(legjobbE))
|
||||
{
|
||||
O = E;
|
||||
legjobbE = (T[])e.Clone();
|
||||
}
|
||||
van = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Backtrack(szint+1, ref E, ref van, ref O);
|
||||
if (josag(e) + fb(szint, e) > josag(legjobbE))
|
||||
Backtrack(szint + 1, ref e, ref van, ref legjobbE);
|
||||
}
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class SzetvalasztasEsKorlatozasHatizsakPakolas : VisszalepesesHatizsakPakolas
|
||||
{
|
||||
public SzetvalasztasEsKorlatozasHatizsakPakolas(HatizsakProblema problema) : base(problema)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override bool[] OptimalisMegoldas()
|
||||
{
|
||||
bool[] asd = new bool[2] {true, true};
|
||||
return asd;
|
||||
int[] M = new int[problema.N];
|
||||
bool[,] R = new bool[problema.N, 2];
|
||||
|
||||
for (int i = 0; i < problema.N; i++)
|
||||
{
|
||||
M[i] = 2;
|
||||
R[i, 0] = true;
|
||||
R[i, 1] = false;
|
||||
}
|
||||
Func<int, bool, bool> ft = (sz, r) => true;
|
||||
|
||||
Func<int, bool, bool[], bool> fk = (sz, r, e) =>
|
||||
{
|
||||
float s = 0;
|
||||
for (int i = 0; i < sz; i++)
|
||||
if (e[i]) s += problema.W[i];
|
||||
if (r) s += problema.W[sz];
|
||||
return s <= problema.Wmax;
|
||||
};
|
||||
Func<int, bool[], float> fb = (sz, e) =>
|
||||
{
|
||||
float b = 0;
|
||||
for (int i = sz; i < problema.N; i++)
|
||||
{
|
||||
if (problema.OsszSuly(e) + problema.W[i] <= problema.Wmax)
|
||||
b += problema.P[i];
|
||||
}
|
||||
return b;
|
||||
};
|
||||
var opt = new SzetvalasztasEsKorlatozasOptimalizacio<bool>(problema.N, M, R, ft, fk, problema.OsszErtek, fb);
|
||||
bool[] legjobb = opt.OptimalisMegoldas();
|
||||
LepesSzam = opt.LepesSzam;
|
||||
return legjobb;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// using System;
|
||||
// using System.Linq;
|
||||
// using OE.ALGA;
|
||||
|
||||
// namespace OE.ALGA.Optimalizalas
|
||||
// {
|
||||
// public class VisszalepesesOptimalizacio<T>
|
||||
// {
|
||||
// protected int n;
|
||||
// protected int[] M;
|
||||
// protected T[,] R;
|
||||
// protected Func<int, T, bool> ft;
|
||||
// protected Func<int, T, T[], bool> fk;
|
||||
// protected Func<T[], float> josag;
|
||||
// public int LepesSzam { get; protected set; }
|
||||
|
||||
// public VisszalepesesOptimalizacio(int n, int[] m, T[,] r, Func<int, T, bool> ft, Func<int, T, T[], bool> fk, Func<T[], float> josag)
|
||||
// {
|
||||
// this.n = n;
|
||||
// this.M = m;
|
||||
// this.R = r;
|
||||
// this.ft = ft;
|
||||
// this.fk = fk;
|
||||
// this.josag = josag;
|
||||
// LepesSzam = 0;
|
||||
// }
|
||||
|
||||
// public virtual void Backtrack(int szint, ref T[] E, ref bool van, ref T[] legjobbE)
|
||||
// {
|
||||
// int i = 0;
|
||||
// while (i < M[szint])
|
||||
// {
|
||||
// LepesSzam++;
|
||||
// if (ft(szint, R[szint, i]))
|
||||
// {
|
||||
// if (fk(szint, R[szint, i], E))
|
||||
// {
|
||||
// E[szint] = R[szint, i];
|
||||
// if (szint == n - 1)
|
||||
// {
|
||||
// if (!van || josag(E) > josag(legjobbE))
|
||||
// {
|
||||
// legjobbE = (T[])E.Clone();
|
||||
// }
|
||||
// van = true;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Backtrack(szint + 1, ref E, ref van, ref legjobbE);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// i++;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// public T[] OptimalisMegoldas()
|
||||
// {
|
||||
// T[] E = new T[n];
|
||||
// T[] O = new T[n];
|
||||
// bool van = false;
|
||||
|
||||
// Backtrack(0, ref E, ref van, ref O);
|
||||
|
||||
// if (van)
|
||||
// return O;
|
||||
// else
|
||||
// throw new NincsElKivetel();
|
||||
// }
|
||||
// }
|
||||
|
||||
// public class VisszalepesesHatizsakPakolas
|
||||
// {
|
||||
// protected HatizsakProblema problema;
|
||||
// public VisszalepesesHatizsakPakolas(HatizsakProblema problema)
|
||||
// {
|
||||
// this.problema = problema;
|
||||
// }
|
||||
// public int LepesSzam { get; protected set; }
|
||||
|
||||
// public virtual bool[] OptimalisMegoldas()
|
||||
// {
|
||||
// int[] M = new int[problema.n];
|
||||
// bool[,] R = new bool[problema.n, 2];
|
||||
|
||||
// for (int i = 0; i < problema.n; i++)
|
||||
// {
|
||||
// M[i] = 2;
|
||||
// R[i, 0] = true;
|
||||
// R[i, 1] = false;
|
||||
// }
|
||||
|
||||
// Func<int, bool, bool> ft = (sz, r) => true;
|
||||
|
||||
// Func<int, bool, bool[], bool> fk = (sz, r, meg) =>
|
||||
// {
|
||||
// float suly = 0;
|
||||
// for (int i = 0; i < sz; i++)
|
||||
// if (meg[i]) suly += problema.w[i];
|
||||
// if (r) suly += problema.w[sz];
|
||||
// return suly <= problema.Wmax;
|
||||
// };
|
||||
|
||||
// var opt = new VisszalepesesOptimalizacio<bool>(problema.n, M, R, ft, fk, problema.OsszErtek);
|
||||
// bool[] legjobb = opt.OptimalisMegoldas();
|
||||
// LepesSzam = opt.LepesSzam;
|
||||
// return legjobb;
|
||||
|
||||
// }
|
||||
|
||||
// public double OptimalisErtek()
|
||||
// {
|
||||
// return problema.OsszErtek(OptimalisMegoldas());
|
||||
// }
|
||||
// }
|
||||
|
||||
// public class SzetvalasztasEsKorlatozasOptimalizacio<T> : VisszalepesesOptimalizacio<T>
|
||||
// {
|
||||
// private readonly Func<int, T[], float> fb;
|
||||
|
||||
// public SzetvalasztasEsKorlatozasOptimalizacio(
|
||||
// int n,
|
||||
// int[] m,
|
||||
// T[,] r,
|
||||
// Func<int, T, bool> ft,
|
||||
// Func<int, T, T[], bool> fk,
|
||||
// Func<T[], float> josag,
|
||||
// Func<int, T[], float> fb)
|
||||
// : base(n, m, r, ft, fk, josag)
|
||||
// {
|
||||
// this.fb = fb;
|
||||
// }
|
||||
|
||||
// public override void Backtrack(int szint, ref T[] e, ref bool van, ref T[] legjobbE)
|
||||
// {
|
||||
// int i = 0;
|
||||
// while (i < M[szint])
|
||||
// {
|
||||
// LepesSzam++;
|
||||
// if (ft(szint, R[szint, i]))
|
||||
// {
|
||||
// if (fk(szint, R[szint, i], e))
|
||||
// {
|
||||
// e[szint] = R[szint, i];
|
||||
// if (szint == n - 1)
|
||||
// {
|
||||
// if (!van || josag(e) > josag(legjobbE))
|
||||
// {
|
||||
// legjobbE = (T[])e.Clone();
|
||||
// }
|
||||
// van = true;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (josag(e) + fb(szint, e) > josag(legjobbE))
|
||||
// Backtrack(szint + 1, ref e, ref van, ref legjobbE);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// i++;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// public class SzetvalasztasEsKorlatozasHatizsakPakolas : VisszalepesesHatizsakPakolas
|
||||
// {
|
||||
// public SzetvalasztasEsKorlatozasHatizsakPakolas(HatizsakProblema problema) : base(problema)
|
||||
// {
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// public override bool[] OptimalisMegoldas()
|
||||
// {
|
||||
// int[] M = new int[problema.n];
|
||||
// bool[,] R = new bool[problema.n, 2];
|
||||
|
||||
// for (int i = 0; i < problema.n; i++)
|
||||
// {
|
||||
// M[i] = 2;
|
||||
// R[i, 0] = true;
|
||||
// R[i, 1] = false;
|
||||
// }
|
||||
// Func<int, bool, bool> ft = (sz, r) => true;
|
||||
|
||||
// Func<int, bool, bool[], bool> fk = (sz, r, e) =>
|
||||
// {
|
||||
// float s = 0;
|
||||
// for (int i = 0; i < sz; i++)
|
||||
// if (e[i]) s += problema.w[i];
|
||||
// if (r) s += problema.w[sz];
|
||||
// return s <= problema.Wmax;
|
||||
// };
|
||||
// Func<int, bool[], float> fb = (sz, e) =>
|
||||
// {
|
||||
// float b = 0;
|
||||
// for (int i = sz; i < problema.n; i++)
|
||||
// {
|
||||
// if (problema.OsszSuly(e) + problema.w[i] <= problema.Wmax)
|
||||
// b += problema.p[i];
|
||||
// }
|
||||
// return b;
|
||||
// };
|
||||
// var opt = new SzetvalasztasEsKorlatozasOptimalizacio<bool>(problema.n, M, R, ft, fk, problema.OsszErtek, fb);
|
||||
// bool[] legjobb = opt.OptimalisMegoldas();
|
||||
// LepesSzam = opt.LepesSzam;
|
||||
// return legjobb;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user