Browse Source

v0.5

andreyTree
parent
commit
6ca3f39ce3
  1. 47
      predprs/Program.cs

47
predprs/Program.cs

@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Combinatorics.Collections;
using static System.Console;
@ -14,6 +16,7 @@ namespace predprs
{
double[,] matrix = new double[,]
{
{ 0, 0, 0, 0, 0 },
{ 0.5, 0.1, 0.6, 0.3, 1.0 },
{ 1.0, 0.5, 1.1, 0.6, 1.2 },
{ 1.4, 1.2, 1.2, 1.3, 1.3 },
@ -26,30 +29,60 @@ namespace predprs
{ 3, 3.5, 1.8, 1.5, 1.3 }
};
for(int i = 0; i < 10; i++)
for(int i = 0; i < matrix.GetLength(0); i++)
{
for (int j = 0; j < 5; 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("\n\n");
int[] data = new int[11];
for (int i = 0; i < 11; i++) data[i] = i;
foreach (int i in data) Write(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 };
//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;
string bestStr = string.Empty;
Stopwatch sw = new Stopwatch();
sw.Start();
List<string> resus = new List<string>();
Variations<int> variations = new Variations<int>(data, 5);
string vformat = "Variations of {{A B C D}} choose 2: size = {0}";
WriteLine(string.Format(vformat, variations.Count));
foreach (IList<int> v in variations)
{
if (v[0] + v[1] + v[2] + v[3] + v[4] == 10)
{
WriteLine(string.Format("[{0} {1} {2} {3} {4}]", v[0], v[1], v[2], v[3], v[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)
{
best = result;
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]);
foreach (var vr in resus) if (r != vr) tr = true;
if (result == 5.4 && tr)
{
resus.Add(r);
tr = false;
}
//WriteLine("[{0} {1} {2} {3} {4}] {5}", v[0], v[1], v[2], v[3], v[4], result);
//Thread.Sleep(100);
}
}
foreach (string s in resus) WriteLine(s);
sw.Stop();
WriteLine("Наибольшая прибыль при {0} со значением {1}\n{2} ms", bestStr, best, sw.ElapsedMilliseconds);
ReadKey();
}
}

Loading…
Cancel
Save