Browse Source

v1.0

master
parent
commit
aab392f6c2
  1. 37
      predprs/Program.cs

37
predprs/Program.cs

@ -14,7 +14,7 @@ namespace predprs
{ {
static void Main(string[] args) static void Main(string[] args)
{ {
double[,] matrix = new double[,] double[,] matrix = new double[,] //матрица прибылей
{ {
{ 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 },
{ 0.5, 0.1, 0.6, 0.3, 1.0 }, { 0.5, 0.1, 0.6, 0.3, 1.0 },
@ -29,25 +29,15 @@ namespace predprs
{ 3, 3.5, 1.8, 1.5, 1.3 } { 3, 3.5, 1.8, 1.5, 1.3 }
}; };
for(int i = 0; i < matrix.GetLength(0); i++) for(int i = 0; i < matrix.GetLength(0); i++)//её вывод
{ {
for (int j = 0; j < matrix.GetLength(1); j++) Write("{0:0.0} ", matrix[i, j]); for (int j = 0; j < matrix.GetLength(1); j++) Write("{0:0.0} ", matrix[i, j]);
WriteLine(); WriteLine();
} }
WriteLine("\n\n"); WriteLine("\n\n");
int[] data = new int[11];
for (int i = 0; i < 11; i++) data[i] = i;
//foreach (int i in data) Write(i + " ");
WriteLine("\n");
int[] data2 = { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 7, 8, 9, 10 }; int[] data2 = { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 7, 8, 9, 10 };
Variations<int> variations = new Variations<int>(data2, 5);//всевозможные чила в комбинациях
//Variations<int> variations = new Variations<int>(data, 5);
Variations<int> variations = new Variations<int>(data2, 5);
//Permutations<int> variations = new Permutations<int>(data, GenerateOption.WithRepetition);
double result = 0, best = 0; double result = 0, best = 0;
string bestStr = string.Empty; string bestStr = string.Empty;
@ -55,27 +45,32 @@ namespace predprs
sw.Start(); sw.Start();
List<string> resus = new List<string>(); List<string> resus = new List<string>();
bool tr = true;
foreach (IList<int> v in variations) foreach (IList<int> v in variations)
{ {
if (v[0] + v[1] + v[2] + v[3] + v[4] == 10) if (v[0] + v[1] + v[2] + v[3] + v[4] == 10) //проверка, если сумма в комбинации равна 10
{ {
result = matrix[v[0], 0] + matrix[v[1], 1] + matrix[v[2], 2] + matrix[v[3], 3] + matrix[v[4], 4]; result = matrix[v[0], 0] + matrix[v[1], 1] + matrix[v[2], 2] + matrix[v[3], 3] + matrix[v[4], 4];
//сопоставление количества мешков и прибыли
if (result > best) if (result > best)
{ {
best = result; best = result;
bestStr = string.Format("[{0} {1} {2} {3} {4}]", v[0], v[1], v[2], v[3], v[4]); bestStr = string.Format("[{0} {1} {2} {3} {4}]", v[0], v[1], v[2], v[3], v[4]);
} }
bool tr = false;
string r = string.Format("[{0} {1} {2} {3} {4}]", v[0], v[1], v[2], v[3], v[4]); string r = string.Format("[{0} {1} {2} {3} {4}]", v[0], v[1], v[2], v[3], v[4]);
foreach (var vr in resus) if (r != vr) tr = true; //заполнения листа с наилучшими вариантами
if (result == 5.4 && tr) if (result == 5.6)
{ {
resus.Add(r); tr = true;
tr = false; foreach (string st in resus) if (r == st) tr = false;
}
if (tr)
{
resus.Add(r);
tr = false;
}
}
//WriteLine("[{0} {1} {2} {3} {4}] {5}", v[0], v[1], v[2], v[3], v[4], result); //WriteLine("[{0} {1} {2} {3} {4}] {5}", v[0], v[1], v[2], v[3], v[4], result);
//Thread.Sleep(100); //Thread.Sleep(100);
} }

Loading…
Cancel
Save