From 12fb4b8c910524d853d18320d6039373216d422a Mon Sep 17 00:00:00 2001 From: suntsev Date: Wed, 31 Oct 2018 22:36:48 +0300 Subject: [PATCH] =?UTF-8?q?Release=201.0=20(=D0=BF=D0=BE=D0=BB=D0=BD=D1=8B?= =?UTF-8?q?=D0=B9=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B1=D0=BE=D1=80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- predprs/App.config | 18 ++++++++++- predprs/Program.cs | 66 ++++++++++++++++++++--------------------- predprs/packages.config | 51 +++++++++++++++++++++++++++++++ predprs/predprs.csproj | 57 +++++++++++++++++++++++++++++++++-- 4 files changed, 154 insertions(+), 38 deletions(-) create mode 100644 predprs/packages.config diff --git a/predprs/App.config b/predprs/App.config index 731f6de..daf6772 100644 --- a/predprs/App.config +++ b/predprs/App.config @@ -1,6 +1,22 @@ - + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/predprs/Program.cs b/predprs/Program.cs index 9184ac0..9038ed0 100644 --- a/predprs/Program.cs +++ b/predprs/Program.cs @@ -1,10 +1,5 @@ -using System; -using System.Collections.Generic; +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; @@ -36,49 +31,52 @@ namespace predprs } WriteLine("\n\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 variations = new Variations(data2, 5);//всевозможные чила в комбинациях - double result = 0, best = 0; - string bestStr = string.Empty; + int[] data = { 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 variations = new Variations(data, 5);//всевозможные чиcла в комбинациях Stopwatch sw = new Stopwatch(); sw.Start(); - List resus = new List(); - bool tr = true; + List bestResult = new List(); + bestResult.Add(new Routes { Inc = 0, Route = "" }); foreach (IList v in variations) { - if (v[0] + v[1] + v[2] + v[3] + v[4] == 10) //проверка, если сумма в комбинации равна 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]; - //сопоставление количества мешков и прибыли - if (result > best) + double result = matrix[v[0], 0] + matrix[v[1], 1] + matrix[v[2], 2] + matrix[v[3], 3] + matrix[v[4], 4]; + if (result > bestResult[0].Inc) //если найдено значение с бОльшей прибылью { - best = result; - bestStr = string.Format("[{0} {1} {2} {3} {4}]", v[0], v[1], v[2], v[3], v[4]); - } + bestResult.Clear(); // отчистка листа при нахождении большего результата - string r = string.Format("[{0} {1} {2} {3} {4}]", v[0], v[1], v[2], v[3], v[4]); - //заполнения листа с наилучшими вариантами - if (result == 5.6) + string bestStr = string.Format("[{0} {1} {2} {3} {4}]", v[0], v[1], v[2], v[3], v[4]); + bestResult.Add(new Routes { Inc = result, Route = bestStr }); //добавление объекта в лист + } + else if (result == bestResult[0].Inc)// если количество прибыли одинаково { - tr = true; - foreach (string st in resus) if (r == st) tr = false; - - if (tr) - { - resus.Add(r); - tr = false; - } + bool check = true; + string temp = string.Format("[{0} {1} {2} {3} {4}]", v[0], v[1], v[2], v[3], v[4]); + foreach (var vr in bestResult) if (temp == vr.Route) check = false; //проверка на совпацение по маршруту + + if (check) + bestResult.Add(new Routes { Inc = result, Route = temp }); } - //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); + + string answer = string.Empty; + foreach (var route in bestResult) + answer += route.Route + "\n"; + sw.Stop(); - WriteLine("Наибольшая прибыль при {0} со значением {1}\n{2} ms", bestStr, best, sw.ElapsedMilliseconds); + WriteLine("Наибольшая прибыль при: \n{0}Cо значением {1}\n{2} ms", answer, bestResult[0].Inc, sw.ElapsedMilliseconds); ReadKey(); } + + class Routes + { + public double Inc { get; set; } + public string Route { get; set; } + } } } + diff --git a/predprs/packages.config b/predprs/packages.config new file mode 100644 index 0000000..40d60f8 --- /dev/null +++ b/predprs/packages.config @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/predprs/predprs.csproj b/predprs/predprs.csproj index f72e3b1..d2e8ee8 100644 --- a/predprs/predprs.csproj +++ b/predprs/predprs.csproj @@ -33,16 +33,66 @@ 4 - - ..\..\..\vs\pacs\Combinatorics.1.1.0.19\lib\netstandard1.2\Combinatorics.dll + + ..\packages\Combinatorics.1.1.0.19\lib\netstandard1.2\Combinatorics.dll + + + ..\packages\Microsoft.Win32.Primitives.4.0.1\lib\net46\Microsoft.Win32.Primitives.dll + + ..\packages\System.AppContext.4.1.0\lib\net46\System.AppContext.dll + + + + ..\packages\System.Console.4.0.0\lib\net46\System.Console.dll + + + ..\packages\System.Diagnostics.DiagnosticSource.4.0.0\lib\net46\System.Diagnostics.DiagnosticSource.dll + + + ..\packages\System.Globalization.Calendars.4.0.1\lib\net46\System.Globalization.Calendars.dll + + + ..\packages\System.IO.Compression.4.1.0\lib\net46\System.IO.Compression.dll + + + + ..\packages\System.IO.Compression.ZipFile.4.0.1\lib\net46\System.IO.Compression.ZipFile.dll + + + ..\packages\System.IO.FileSystem.4.0.1\lib\net46\System.IO.FileSystem.dll + + + ..\packages\System.IO.FileSystem.Primitives.4.0.1\lib\net46\System.IO.FileSystem.Primitives.dll + + + ..\packages\System.Net.Http.4.1.0\lib\net46\System.Net.Http.dll + + + ..\packages\System.Net.Sockets.4.1.0\lib\net46\System.Net.Sockets.dll + + + + ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.0.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + + + ..\packages\System.Security.Cryptography.Algorithms.4.2.0\lib\net461\System.Security.Cryptography.Algorithms.dll + + + ..\packages\System.Security.Cryptography.Encoding.4.0.0\lib\net46\System.Security.Cryptography.Encoding.dll + + + ..\packages\System.Security.Cryptography.Primitives.4.0.0\lib\net46\System.Security.Cryptography.Primitives.dll + + + ..\packages\System.Security.Cryptography.X509Certificates.4.1.0\lib\net461\System.Security.Cryptography.X509Certificates.dll + - @@ -51,6 +101,7 @@ + \ No newline at end of file