{"id":343291,"date":"2022-12-28T21:01:20","date_gmt":"2022-12-28T21:01:20","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=343291"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=343291","title":{"rendered":"<span>\u041e\u0431\u0437\u043e\u0440 \u043f\u0430\u043a\u0435\u0442\u043e\u0432 SciPy, Pyomo \u0438 CVXPY \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447 \u0443\u0441\u043b\u043e\u0432\u043d\u043e\u0439 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, Habr! \u041d\u0430 \u0441\u0432\u044f\u0437\u0438\u00a0<a href=\"https:\/\/habr.com\/ru\/users\/muxeu\/\"><u>\u041c\u0438\u0445\u0430\u0438\u043b \u0411\u0443\u0434\u044b\u043b\u0438\u043d<\/u><\/a>\u00a0\u0438\u00a0<a href=\"https:\/\/habr.com\/ru\/users\/6redik\/\"><u>\u0410\u043d\u0442\u043e\u043d \u0414\u0435\u043d\u0438\u0441\u043e\u0432<\/u><\/a>, \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0432 \u043e\u0442\u0434\u0435\u043b\u0435 \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 X5 Tech.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043f\u0440\u043e \u043f\u0440\u0438\u043a\u043b\u0430\u0434\u043d\u043e\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0442\u0435\u043e\u0440\u0438\u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438. \u0412 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u043a\u0440\u0430\u0442\u043a\u0438\u0439 \u043e\u0431\u0437\u043e\u0440 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 open-source \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0432 Python, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043c\u044b \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u043b\u0438\u0441\u044c \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435. \u0417\u0430\u0442\u0440\u043e\u043d\u0435\u043c \u0438\u0445 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f \u0438 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438, \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0437\u0430\u0434\u0430\u0447, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0448\u0430\u0442\u044c \u0441 \u0438\u0445 \u043f\u043e\u043c\u043e\u0449\u044c\u044e.<\/p>\n<p>\u0412 \u043d\u0430\u0448\u0435\u0439\u00a0<a href=\"https:\/\/habr.com\/ru\/company\/X5Tech\/blog\/685590\/\"><u>\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/u><\/a>\u00a0\u043c\u044b \u043e\u043f\u0438\u0441\u0430\u043b\u0438 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447, \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0438\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0437\u0430\u0434\u0430\u0447 \u0438\u0437 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0440\u0438\u0442\u0435\u0439\u043b\u0430, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441\u0440\u0430\u0432\u043d\u0438\u043b\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0434\u0432\u0443\u0445 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440\u043e\u0432 \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u0446\u0435\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 Python.<\/p>\n<h2>\u041e\u0431\u0437\u043e\u0440 \u043f\u0430\u043a\u0435\u0442\u043e\u0432 Python<\/h2>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u043f\u043e\u043c\u043d\u0438\u043c \u043e\u0441\u043d\u043e\u0432\u0443 \u2014 \u043f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0443 \u0437\u0430\u0434\u0430\u0447\u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438:<\/p>\n<p>\u041f\u0443\u0441\u0442\u044c\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"x\" alt=\"x\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/745\/d2a\/9b4\/745d2a9b4b25c245d7c559607faec50a.svg\" width=\"11\" height=\"12\"\/>&#8212; \u0432\u0435\u043a\u0442\u043e\u0440 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"n\" alt=\"n\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8ec\/5a2\/e71\/8ec5a2e71b4e7eafc750038967c50a1b.svg\" width=\"12\" height=\"12\"\/>, <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"x \\in X\" alt=\"x \\in X\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d1d\/b10\/aff\/d1db10affe515aa07bda9b9833133966.svg\" width=\"52\" height=\"17\"\/>&#8212; \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u044d\u0442\u0438\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445.<br \/><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"f(x) \\to \\min(\\max), f(\\cdot) \" alt=\"f(x) \\to \\min(\\max), f(\\cdot) \" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/83c\/5dd\/0d3\/83c5dd0d3b317b119cc8e007b4c002ed.svg\" width=\"192\" height=\"22\"\/>&#8212; \u0446\u0435\u043b\u0435\u0432\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"g_i(x) \\leqslant 0, \\ i=1..m\" alt=\"g_i(x) \\leqslant 0, \\ i=1..m\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/433\/dc2\/8b8\/433dc28b8100e4f865126206319797c9.svg\" width=\"163\" height=\"22\"\/>&#8212; \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0432\u0438\u0434\u0430 \u043d\u0435\u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"h_i(x) = 0, \\ j=1..k\" alt=\"h_i(x) = 0, \\ j=1..k\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/fd7\/688\/ed0\/fd7688ed00c8fab37595718ed7309795.svg\" width=\"159\" height=\"22\"\/>&#8212; \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0432\u0438\u0434\u0430 \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432.<\/p>\n<p>\u0410 \u0442\u0430\u043a \u0436\u0435, \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447, \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u0443\u044e \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435:<\/p>\n<ul>\n<li>\n<p><strong>\u0411\u0435\u0437\u0443\u0441\u043b\u043e\u0432\u043d\u0430\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f<\/strong> <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"g_i(x), h_j(x)\" alt=\"g_i(x), h_j(x)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/106\/7be\/b52\/1067beb5221053c78ee68fb92ac278eb.svg\" width=\"97\" height=\"23\"\/> \u2014 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442, <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"X = \\mathbb{R}^n\" alt=\"X = \\mathbb{R}^n\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/aea\/1b2\/8c9\/aea1b28c9e2257d19b97d5fc633d4b56.svg\" width=\"67\" height=\"18\"\/>;<\/p>\n<\/li>\n<li>\n<p><strong>LP<\/strong> (linear programming) \u2014 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435. <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"f(x), g_i(x), h_j(x)\" alt=\"f(x), g_i(x), h_j(x)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/da0\/b9d\/ea7\/da0b9dea749eeec8f4699fa19a766c96.svg\" width=\"143\" height=\"23\"\/> &#8212; \u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"X = \\mathbb{R}_+^n\" alt=\"X = \\mathbb{R}_+^n\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4a6\/307\/68c\/4a630768c1d69d8516afaa26942cc301.svg\" width=\"70\" height=\"23\"\/>;<\/p>\n<\/li>\n<li>\n<p><strong>MILP<\/strong> (mixed integer linear programming) \u2014 \u0441\u043c\u0435\u0448\u0430\u043d\u043d\u043e\u0435 \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u0435 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u044d\u0442\u043e \u0437\u0430\u0434\u0430\u0447\u0430 LP \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0447\u0430\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u043c\u0438;<\/p>\n<\/li>\n<li>\n<p><strong>NLP<\/strong> (nonlinear programming) \u2014 \u043d\u0435\u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043a\u043e\u0433\u0434\u0430 \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u043d\u0430 \u0438\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"f(x),\\ g_i(x),\\ h_j(x)\" alt=\"f(x),\\ g_i(x),\\ h_j(x)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d41\/519\/e78\/d41519e78795fdf343fdb05197afc210.svg\" width=\"152\" height=\"23\"\/>\u043d\u0435\u043b\u0438\u043d\u0435\u0439\u043d\u0430;<\/p>\n<\/li>\n<li>\n<p><strong>MINLP<\/strong> (mixed integer nonlinear programming) \u2014 \u0441\u043c\u0435\u0448\u0430\u043d\u043d\u043e\u0435 \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u0435 \u043d\u0435\u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043a\u0430\u043a \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 MILP, \u043a\u043e\u0433\u0434\u0430 \u0447\u0430\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f;<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u0443\u044e \u043a\u0430\u0440\u0442\u0438\u043d\u0443 \u0441\u043e\u043b\u0432\u0435\u0440\u044b \u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u043c \u0432 \u0432\u0438\u0434\u0435 \u0441\u0445\u0435\u043c\u044b:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/f01\/1e4\/4d3\/f011e44d385ab345d31d214b6f2c2a77.jpg\" alt=\"\u041f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0435\u043c\u044b\u0445 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u0441\u043e\u043b\u0432\u0435\u0440\u043e\u0432\" title=\"\u041f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0435\u043c\u044b\u0445 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u0441\u043e\u043b\u0432\u0435\u0440\u043e\u0432\" width=\"4105\" height=\"3897\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f01\/1e4\/4d3\/f011e44d385ab345d31d214b6f2c2a77.jpg\" data-blurred=\"true\"\/><figcaption>\u041f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0435\u043c\u044b\u0445 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u0441\u043e\u043b\u0432\u0435\u0440\u043e\u0432<\/figcaption><\/figure>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0432 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u044d\u0442\u0438 \u043f\u0430\u043a\u0435\u0442\u044b \u0438 \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043e \u0432\u0430\u0436\u043d\u044b\u0445, \u043d\u0430 \u043d\u0430\u0448 \u0432\u0437\u0433\u043b\u044f\u0434, \u0434\u0435\u0442\u0430\u043b\u044f\u0445 \u0438\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u0438 \u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u0437\u0430\u0434\u0430\u0447 \u0443\u0441\u043b\u043e\u0432\u043d\u043e\u0439 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438. \u0414\u043b\u044f \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0440\u0430\u0441\u0447\u0451\u0442\u043e\u0432 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043f\u0430\u043a\u0435\u0442\u044b \u0438\u0437 <a href=\"https:\/\/github.com\/mbudylin\/optimizers_review#readme\">Readme<\/a>, \u0442\u0430\u043a\u0436\u0435 \u0435\u0441\u0442\u044c <a href=\"https:\/\/github.com\/mbudylin\/optimizers_review\/blob\/master\/Dockerfile\">\u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f<\/a> \u043f\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0443 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u0441 jupyter \u0432 \u0434\u043e\u043a\u0435\u0440\u0435.<\/p>\n<h3>SciPy. \u041e\u0431\u0437\u043e\u0440.<\/h3>\n<p><a href=\"https:\/\/scipy.org\/\"><strong>SciPy<\/strong><\/a> \u2014 \u043e\u0434\u043d\u0430 \u0438\u0437 \u043f\u0435\u0440\u0432\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0432 Python, \u0437\u043d\u0430\u043a\u043e\u043c\u0441\u0442\u0432\u043e \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0443 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0441\u0442\u043e\u0432 \u0432 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 Data Science: \u043e\u043d\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043d\u0430\u0431\u043e\u0440 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0434\u043b\u044f \u043d\u0430\u0443\u0447\u043d\u044b\u0445 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0438\u043c\u0435\u0435\u0442 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447, \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0438\u0445\u0441\u044f \u0432 \u043c\u043e\u0434\u0443\u043b\u0435 <strong>scipy.optimize<\/strong>. \u0412 \u044d\u0442\u043e\u043c \u043c\u043e\u0434\u0443\u043b\u0435 \u0438\u043c\u0435\u044e\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447 \u043a\u0430\u043a \u043d\u0435\u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f (<strong>NLP<\/strong>), \u0442\u0430\u043a \u0438 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f (<strong>LP<\/strong>), \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0437\u0430\u0434\u0430\u0447 \u0441\u043c\u0435\u0448\u0430\u043d\u043d\u043e\u0433\u043e \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f (<strong>MILP<\/strong>).<\/p>\n<p>\u0421\u0440\u0435\u0434\u0438 \u0441\u043e\u043b\u0432\u0435\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447 \u0443\u0441\u043b\u043e\u0432\u043d\u043e\u0439 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 (NLP) \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c <strong>COBYLA<\/strong>, <strong>SLSQP<\/strong>, <strong>trust-constr<\/strong>. \u0412\u0441\u0435 \u0442\u0440\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u044b \u0432 \u043f\u0430\u043a\u0435\u0442\u0435<br \/> <code>scipy.optimize.minimize<\/code> \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c <code>method<\/code> (<code>'cobyla'<\/code>,<code>'slsqp'<\/code> \u0438 <code>'trust-constr',<\/code> \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e).<\/p>\n<p><strong>COBYLA<\/strong> \u2014 \u044d\u0442\u043e \u043c\u0435\u0442\u043e\u0434, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u0435\u043d, \u0442.\u0435., \u043f\u043e \u0441\u0443\u0442\u0438, \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c\u0441\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u00ab\u0447\u0435\u0440\u043d\u043e\u0433\u043e \u044f\u0449\u0438\u043a\u0430\u00bb.<br \/>\u0414\u043b\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432\u0430\u0436\u043d\u043e, \u0447\u0442\u043e \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434:<\/p>\n<ul>\n<li>\n<p><strong>\u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442<\/strong> \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u0430 \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u0430: <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"a(x) = b\" alt=\"a(x) = b\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9e5\/d82\/771\/9e5d82771a00fbbe9ee7c9695c2eae56.svg\" width=\"71\" height=\"22\"\/>. \u0421\u0432\u044f\u0437\u0430\u043d\u043e \u044d\u0442\u043e \u0441 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u043e\u043b\u0432\u0435\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u0435\u0431\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 SciPy. \u042d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u043e\u0439\u0442\u0438, \u0437\u0430\u043c\u0435\u043d\u0438\u0432 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 \u0434\u0432\u0430 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0432\u0438\u0434\u0430 \u043d\u0435\u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u0430: <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"a(x) \\leq b\" alt=\"a(x) \\leq b\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/2e0\/01d\/e10\/2e001de10733b52ee0d782caa151072d.svg\" width=\"71\" height=\"22\"\/> \u0438 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"a(x) \\geq b\" alt=\"a(x) \\geq b\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e07\/232\/aa0\/e07232aa0d9d5546b18f7abf043a1411.svg\" width=\"71\" height=\"22\"\/>, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0440\u0430\u0432\u043d\u043e\u0441\u0438\u043b\u044c\u043d\u043e \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u0443.<\/p>\n<\/li>\n<li>\n<p><strong>\u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442<\/strong> \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"x,\" alt=\"x,\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/cae\/74e\/a97\/cae74ea9705dbde29341aa23d833cd6b.svg\" width=\"17\" height=\"15\"\/>\u0437\u0430\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0445 \u0447\u0435\u0440\u0435\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 bounds \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <strong>minimize<\/strong> (\u0438\u0437 \u043c\u043e\u0434\u0443\u043b\u044f scipy.optimize) \u2014 \u0438\u0445 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e LinearConstraint.<\/p>\n<\/li>\n<\/ul>\n<p><strong>SLSQP<\/strong> \u0438 <strong>trust-constr<\/strong> \u2014 \u044d\u0442\u043e \u043c\u0435\u0442\u043e\u0434\u044b \u0443\u0436\u0435 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0430, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0434\u043b\u044f \u043d\u0438\u0445 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u043d\u0435\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u043e\u0441\u0442\u044c 1-\u043e\u0439 \u0438 2-\u043e\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u044b\u0445.<\/p>\n<p>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u0439 \u043e\u0431\u0437\u043e\u0440 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043b\u0438\u0442\u0435\u0440\u0430\u0442\u0443\u0440\u044b \u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0441\u043e\u043b\u0432\u0435\u0440\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/ods\/blog\/448054\/\">\u0442\u0443\u0442<\/a>.<\/p>\n<h4>SciPy. \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 NLP.<\/h4>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 <strong>scipy<\/strong> \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u0446\u0435\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u0437 <a href=\"https:\/\/habr.com\/ru\/company\/X5Tech\/blog\/685590\/\">\u0441\u0442\u0430\u0442\u044c\u0438 1<\/a>. \u0417\u0430\u0434\u0430\u0447\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u043b\u0430\u0441\u044c \u0432 \u043c\u0430\u043a\u0441\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u044b\u0440\u0443\u0447\u043a\u0438 \u0441 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435\u043c \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u043c\u0430\u0440\u0436\u0438 \u0441 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u044b\u043c \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u043e\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0446\u0435\u043d\u044b \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u00b110% \u043e\u0442 \u0442\u0435\u043a\u0443\u0449\u0435\u0439.<\/p>\n<p>\u041f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0431\u044b\u043b\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"n\" alt=\"n\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/60c\/a34\/9dc\/60ca349dc619968d89a935b0b255792b.svg\" width=\"12\" height=\"12\"\/> \u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0442\u043e\u0432\u0430\u0440\u043e\u0432,<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"P_{0, i}\" alt=\"P_{0, i}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b8c\/b92\/569\/b8cb9256919a7532aa3eedf73cf64f54.svg\" width=\"30\" height=\"22\"\/> \u2014 \u0442\u0435\u043a\u0443\u0449\u0430\u044f \u0446\u0435\u043d\u0430 \u0442\u043e\u0432\u0430\u0440\u0430 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"i\" alt=\"i\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d9c\/a26\/f4d\/d9ca26f4d687ecb1034f1358a52f1790.svg\" width=\"7\" height=\"16\"\/>,<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"Q_{0, i}\" alt=\"Q_{0, i}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a30\/a90\/7de\/a30a907de3eb2cdb12360abec32e613b.svg\" width=\"33\" height=\"22\"\/> \u2014 \u0442\u0435\u043a\u0443\u0449\u0438\u0435 \u043f\u0440\u043e\u0434\u0430\u0436\u0438 \u0442\u043e\u0432\u0430\u0440\u0430 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"i\" alt=\"i\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/944\/7f1\/c67\/9447f1c67f515743095b99697359f3ff.svg\" width=\"7\" height=\"16\"\/>,<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"x_{i} = P_{i} \/ P_{0, i}\" alt=\"x_{i} = P_{i} \/ P_{0, i}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/01d\/aaf\/5bb\/01daaf5bb788d83a538e95a10796202e.svg\" width=\"103\" height=\"23\"\/> \u2014 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0439 \u0446\u0435\u043d\u044b <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"P_{i}\" alt=\"P_{i}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c5f\/3a4\/e94\/c5f3a4e947a19b251253ac2229a435eb.svg\" width=\"19\" height=\"20\"\/> \u043a \u0442\u0435\u043a\u0443\u0449\u0435\u0439 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"P_{0, i}\" alt=\"P_{0, i}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/370\/650\/3bf\/3706503bfa88755611a419181e6d8da6.svg\" width=\"30\" height=\"22\"\/>,<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"E_{i}\" alt=\"E_{i}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/687\/c6c\/6b4\/687c6c6b4053b0151fd791b87f5e75b8.svg\" width=\"21\" height=\"20\"\/> \u2014 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0441\u0447\u0451\u0442\u0430 \u0441\u043f\u0440\u043e\u0441\u0430 \u043d\u0430 \u0442\u043e\u0432\u0430\u0440 \u043f\u043e \u0444\u043e\u0440\u043c\u0443\u043b\u0435 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"Q_{i}(x) = Q_{0, i} \\cdot \\exp(E_{i} \\cdot (x_{i} - 1))\" alt=\"Q_{i}(x) = Q_{0, i} \\cdot \\exp(E_{i} \\cdot (x_{i} - 1))\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/47d\/cac\/566\/47dcac5666c9b4129775c80c0ee889bc.svg\" width=\"269\" height=\"23\"\/>,<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"R_{i}(x_{i}) = \\sum_{i=1}^{n} P_{0, i} \\cdot x_{i} \\cdot Q_{i}(x_i)\" alt=\"R_{i}(x_{i}) = \\sum_{i=1}^{n} P_{0, i} \\cdot x_{i} \\cdot Q_{i}(x_i)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7fd\/03b\/477\/7fd03b477cc68387db030d10d4e233b6.svg\" width=\"244\" height=\"57\"\/>\u2014 \u0432\u044b\u0440\u0443\u0447\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u043e\u0432\u0430\u0440\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0435\u0433\u043e \u0446\u0435\u043d\u044b \u043d\u0430 \u043f\u0440\u043e\u0434\u0430\u0436\u0438, <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M_{i}(x_{i}) = \\sum_{i=1}^{n} (P_{0, i} \\cdot x_{i} - C_{i})\\cdot Q_{0, i} \\cdot Q_{i}(x_i)\" alt=\"M_{i}(x_{i}) = \\sum_{i=1}^{n} (P_{0, i} \\cdot x_{i} - C_{i})\\cdot Q_{0, i} \\cdot Q_{i}(x_i)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/469\/da6\/179\/469da61796160198bd09e93610c3d5e4.svg\" width=\"352\" height=\"57\"\/>\u2014 \u043c\u0430\u0440\u0436\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0440\u0430\u0437\u043d\u043e\u0441\u0442\u044c \u043c\u0435\u0436\u0434\u0443 \u0446\u0435\u043d\u043e\u0439 \u043f\u0440\u043e\u0434\u0430\u0436\u0438 \u0438 \u0441\u0435\u0431\u0435\u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c\u044e, \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u043d\u043e\u0439 \u043d\u0430 \u043f\u0440\u043e\u0434\u0430\u0436\u0438,<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M_{0} = \\sum_{i=1}^{n} M_{i}(x_{i}=1)\" alt=\"M_{0} = \\sum_{i=1}^{n} M_{i}(x_{i}=1)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8d5\/92c\/82a\/8d592c82a689ff43e4fe4204186ca809.svg\" width=\"180\" height=\"57\"\/> \u2014 \u0442\u0435\u043a\u0443\u0449\u0430\u044f \u043c\u0430\u0440\u0436\u0430, \u0442.\u0435. \u0435\u0451 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u0438 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0446\u0435\u043d\u0435,<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\begin{cases} \\tag{1} \\sum_{i=1}^{n} R_{i}(x_{i}) \\to \\max, \\\\ \\sum_{i=1}^{n} M_{i}(x_{i}) \\geqslant M_{0}, \\\\ x_i \\in [0.9, 1.1], \\ i=1..n\\\\ \\end{cases}\" alt=\"\\begin{cases} \\tag{1} \\sum_{i=1}^{n} R_{i}(x_{i}) \\to \\max, \\\\ \\sum_{i=1}^{n} M_{i}(x_{i}) \\geqslant M_{0}, \\\\ x_i \\in [0.9, 1.1], \\ i=1..n\\\\ \\end{cases}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/2f0\/8db\/be3\/2f08dbbe34043b5483257bd882ca4a2c.svg\" width=\"697\" height=\"74\"\/><\/p>\n<p>\u041e\u0444\u043e\u0440\u043c\u0438\u043c \u0432\u0441\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u0432 \u0432\u0438\u0434\u0435 \u043a\u043e\u0434\u0430 \u0438 \u0437\u0430\u0434\u0430\u0434\u0438\u043c \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f:<\/p>\n<pre><code class=\"python\"># \u043c\u0438\u043d\u0438 \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0437 \u043f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 import scipy.optimize as scopt import numpy as np  # \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0442\u043e\u0432\u0430\u0440\u043e\u0432 N = 3 # \u0437\u0430\u0434\u0430\u0435\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b E, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0432 \u0444\u043e\u0440\u043c\u0443\u043b\u0435 Q = Q0 * exp(E * (x - 1)) E = np.array([-3., -1., -0.5]) # \u0442\u0435\u043a\u0443\u0449\u0438\u0435 \u0446\u0435\u043d\u044b P0 = np.array([100., 100., 100.]) # \u0442\u0435\u043a\u0443\u0449\u0438\u0435 \u043f\u0440\u043e\u0434\u0430\u0436\u0438 Q0 = np.array([50000., 200000., 30000.0]) # \u0441\u0435\u0431\u0435\u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c C = np.array([90.0, 80.0, 70.0]) # \u0442\u0435\u043a\u0443\u0449\u0430\u044f \u0432\u044b\u0440\u0443\u0447\u043a\u0430 R0 = np.sum(P0 * Q0) # \u0442\u0435\u043a\u0443\u0449\u0430\u044f \u043c\u0430\u0440\u0436\u0430 M0 = np.sum((P0 - C) * Q0)  # \u0432\u044b\u0440\u0443\u0447\u043a\u0430 - \u0446\u0435\u043b\u0435\u0432\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0437\u0430\u0434\u0430\u0435\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \"\u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c\" \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u043e\u043c \u0447\u0435\u0440\u0435\u0437 'scale' def f_obj(x, args):     f = - args['scale'] * np.sum(Q0 * P0 * x * np.exp(E * (x - 1.)))     return f obj = f_obj  # \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u043c\u0430\u0440\u0436\u0435, \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043d\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043d\u0430 \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u0432\u044b\u0440\u0443\u0447\u043a\u0443 def f_cons(x):     f = np.sum(Q0 * (P0 * x - C) * np.exp(E * (x - 1.0))) \/ R0     return f  con_mrg = scopt.NonlinearConstraint(f_cons, lb=M0 \/ R0, ub=np.inf) # \u043f\u043e\u0438\u0441\u043a \u043d\u043e\u0432\u043e\u0439 \u0446\u0435\u043d\u044b \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u043c \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 90% - 110% \u043e\u0442 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0446\u0435\u043d\u044b x_bounds = [(0.9, 1.1)] * 3 # \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0432 cobyla con_bnd = scopt.LinearConstraint(np.eye(3), lb=[0.9] * 3, ub=[1.1] * 3) # \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u0430\u044f \u0442\u043e\u0447\u043a\u0430 \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 x0 = [1.0] * 3  def print_results(model, solver_name, M0, R0):     print(f\"\u0420\u0435\u0448\u0435\u043d\u0438\u0435 {solver_name}: {list(np.round(model['x'], 4))}; model message: {model['message']}\")     print(f\"\u0412\u044b\u0440\u0443\u0447\u043a\u0430: {round(-f_obj(model['x'], {'scale': 1}), 0)}\")     print(f\"\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 \u043c\u0430\u0440\u0436\u0443 M >= {M0}; \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u0430\u0440\u0436\u0438: {round(R0 * con_mrg.fun(model['x']), 0)}\")<\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 SciPy:<\/p>\n<pre><code class=\"python\"># \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0441\u043e\u043b\u0432\u0435\u0440\u0430 cobyla res_cobyla = scopt.minimize(obj, x0, constraints=[con_bnd, con_mrg], method='cobyla', args={'scale': 1}) print_results(res_cobyla, 'cobyla', M0, R0)  # output: # \u0420\u0435\u0448\u0435\u043d\u0438\u0435 cobyla: [0.9, 1.0165, 1.1]; model message: Optimization terminated successfully. # \u0412\u044b\u0440\u0443\u0447\u043a\u0430: 29210742.0 # \u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 \u043c\u0430\u0440\u0436\u0443 M >= 5400000.0; \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u0430\u0440\u0436\u0438: 5399998.0<\/code><\/pre>\n<pre><code class=\"python\"># \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0441\u043e\u043b\u0432\u0435\u0440\u0430 trust-constr res_trust_const = scopt.minimize(obj, x0, bounds=x_bounds, constraints=[con_mrg], method='trust-constr', args={'scale': 1}) print_results(res_trust_const, 'trust-constr', M0, R0)  # output: # \u0420\u0435\u0448\u0435\u043d\u0438\u0435 trust-constr: [0.9, 1.0165, 1.1]; model message: `gtol` termination condition is satisfied. # \u0412\u044b\u0440\u0443\u0447\u043a\u0430: 29210742.0 # \u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 \u043c\u0430\u0440\u0436\u0443 M >= 5400000.0; \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u0430\u0440\u0436\u0438: 5400005.0<\/code><\/pre>\n<pre><code class=\"python\"># \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0441\u043e\u043b\u0432\u0435\u0440\u0430 slsqp res_slsqp = scopt.minimize(obj, x0, bounds=x_bounds, constraints=[con_mrg], method='slsqp', args={'scale': 1}) print_results(res_slsqp, 'slsqp', M0, R0)  # output # \u0420\u0435\u0448\u0435\u043d\u0438\u0435 slsqp: [1.0, 1.0, 1.0]; model message: Optimization terminated successfully # \u0412\u044b\u0440\u0443\u0447\u043a\u0430: 28000000.0 # \u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 \u043c\u0430\u0440\u0436\u0443 M >= 5400000.0; \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u0430\u0440\u0436\u0438: 5400000.0<\/code><\/pre>\n<p>\u041f\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c 2 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u043c\u043e\u043c\u0435\u043d\u0442\u0430:<\/p>\n<ul>\n<li>\n<p>\u043c\u0435\u0442\u043e\u0434\u044b <strong>COBYLA<\/strong> \u0438 <strong>trust-constr<\/strong> \u0441\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u043a \u043e\u0434\u043d\u043e\u043c\u0443 \u0438 \u0442\u043e\u043c\u0443 \u0436\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044e. \u0422\u0430\u043a\u0436\u0435 \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0432\u0441\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f (\u043f\u043e \u0433\u0440\u0430\u043d\u0438\u0446\u0430\u043c \u0438 \u043f\u043e \u043c\u0430\u0440\u0436\u0435 &#8212; \u0441 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c\u044e \u0431\u043e\u043b\u0435\u0435 7-8 \u0437\u043d\u0430\u043a\u043e\u0432),<\/p>\n<\/li>\n<li>\n<p><strong>SLSQP<\/strong> \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u00ab\u043e\u0441\u0442\u0430\u043b\u0441\u044f\u00bb \u0432 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0435 \u2014 \u044d\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u0435\u043c \u043d\u0430 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0443 \u043f\u0440\u0438 \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0435\u0433\u0443\u043b\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b ftol \u0438 eps \u0432 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0435 options.<\/p>\n<\/li>\n<\/ul>\n<p>\u0412\u043e\u043e\u0431\u0449\u0435 \u0433\u043e\u0432\u043e\u0440\u044f, \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439 \u0441\u043e\u043b\u0432\u0435\u0440\u043e\u0432 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043a \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e \u043f\u043e\u0440\u044f\u0434\u043a\u0430 1, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u0432\u044b\u0441\u0438\u0442\u044c \u0443\u0441\u0442\u043e\u0439\u0447\u0438\u0432\u043e\u0441\u0442\u044c \u0438 \u0441\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u043e\u0432. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 \u0437\u0430\u0434\u0430\u0447\u0435 \u043f\u0443\u0442\u0451\u043c \u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 (\u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0432\u044b\u0440\u0443\u0447\u043a\u0438) \u043d\u0430 \u0432\u044b\u0440\u0443\u0447\u043a\u0443 \u043f\u0440\u0438 \u0442\u0435\u043a\u0443\u0449\u0438\u0445 \u0446\u0435\u043d\u0430\u0445 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"R_{0}\" alt=\"R_{0}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d04\/a6b\/8ac\/d04a6b8ac804be7ea5910f6ca428d114.svg\" width=\"24\" height=\"20\"\/>.<\/p>\n<pre><code class=\"python\"># \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0441\u043e\u043b\u0432\u0435\u0440\u0430 slsqp res_slsqp = scopt.minimize(obj, x0, bounds=x_bounds, constraints=[con_mrg], method='slsqp', args={'scale': 1. \/ R0}) print_results(res_slsqp, 'slsqp', M0, R0)  # output # \u0420\u0435\u0448\u0435\u043d\u0438\u0435 slsqp: [0.9, 1.0165, 1.1]; model message: Optimization terminated successfully # \u0412\u044b\u0440\u0443\u0447\u043a\u0430: 29210742.0 # \u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 \u043c\u0430\u0440\u0436\u0443 M >= 5400000.0; \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u0430\u0440\u0436\u0438: 5399999.0<\/code><\/pre>\n<h4>SciPy. \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 MILP.<\/h4>\n<p>\u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u043f\u043e\u0434\u043c\u043e\u0434\u0443\u043b\u0435 <strong>optimize<\/strong> \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <a href=\"https:\/\/docs.scipy.org\/doc\/scipy\/reference\/generated\/scipy.optimize.linprog.html#scipy.optimize.linprog\"><strong>linprog<\/strong><\/a>, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0432\u0435\u0440\u0441\u0438\u0438 <a href=\"https:\/\/docs.scipy.org\/doc\/scipy\/release.1.9.0.html\">SciPy==1.9.0<\/a> \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0433\u043e \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <a href=\"https:\/\/scipy.github.io\/devdocs\/reference\/generated\/scipy.optimize.milp.html\"><strong>milp<\/strong><\/a> \u0438 <strong>linprog<\/strong>.<br \/>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0441\u043e\u043b\u0432\u0435\u0440\u0430 \u0434\u043b\u044f LP(MILP) \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <a href=\"https:\/\/www.maths.ed.ac.uk\/hall\/HiGHS\/\">HiGHS<\/a> \u2014 \u0432 \u043d\u0451\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u044b \u0441\u0438\u043c\u043f\u043b\u0435\u043a\u0441 \u043c\u0435\u0442\u043e\u0434 (highs-ds) \u0438 \u043c\u0435\u0442\u043e\u0434 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0439 \u0442\u043e\u0447\u043a\u0438 (highs-ipm). \u041f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u043e\u0434\u0438\u043d \u0438\u0437 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 \u043f\u0440\u0438\u043d\u0443\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442.<\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u043a\u0443 \u0441\u043c\u0435\u0448\u0430\u043d\u043d\u043e\u0433\u043e \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0440\u044e\u043a\u0437\u0430\u043a\u0430, \u0433\u0434\u0435 \u0434\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430 <strong>linprog<\/strong> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\begin{cases} \\tag{2} x = (x_{1}, x_{2}, x_{3}, x_{4}) \\\\ \\\\ F(x) = 1 \\cdot x_{1} + 2 \\cdot x_{2} + 3 \\cdot x_{3} + 1 \\cdot x_{4} \\to \\max \\\\ \\\\ 3 \\cdot x_1 + 1 \\cdot x_2 + 2 \\cdot x_3 + 2 \\cdot x_4 \\leqslant 7.0 \\\\ \\\\ x_{1} \\in \\{0, 1, 2\\}, x_{2}, x_{3} \\in \\{0, 1\\}, x_{4} \\in [0.0; 0.5] \\end{cases}\" alt=\"\\begin{cases} \\tag{2} x = (x_{1}, x_{2}, x_{3}, x_{4}) \\\\ \\\\ F(x) = 1 \\cdot x_{1} + 2 \\cdot x_{2} + 3 \\cdot x_{3} + 1 \\cdot x_{4} \\to \\max \\\\ \\\\ 3 \\cdot x_1 + 1 \\cdot x_2 + 2 \\cdot x_3 + 2 \\cdot x_4 \\leqslant 7.0 \\\\ \\\\ x_{1} \\in \\{0, 1, 2\\}, x_{2}, x_{3} \\in \\{0, 1\\}, x_{4} \\in [0.0; 0.5] \\end{cases}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/35f\/556\/a2d\/35f556a2d7c42be44252b737a0bcd656.svg\" width=\"697\" height=\"166\"\/><\/p>\n<pre><code class=\"python\"># \u043f\u0440\u0438\u043c\u0435\u0440 \u0441 \"\u0440\u044e\u043a\u0437\u0430\u043a\u043e\u043c\", \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0442\u0438\u043f\u044b \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u0430\u0437\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f # \u0442\u0430\u043a \u043a\u0430\u043a scipy \u0440\u0435\u0448\u0435\u0442 \u0437\u0430\u0434\u0430\u0447\u0443 \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438, \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043c\u0438\u043d\u0443\u0441 \u0434\u043b\u044f \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u043e\u0432 \u0432 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u043c\u0430\u043a\u0441\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 c = -np.array([1., 2., 3., 1.]) A_ub = np.array([[3., 1., 2., 2.]]) b_ub = np.array([7.0]) # \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u0434\u043b\u044f \u0442\u0438\u043f\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445, 0 - \u043d\u0435\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u043e\u0435, 1 - \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e var_types = [1, 1, 1, 0] # \u0442\u0430\u043a\u0436\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0433\u0440\u0430\u043d\u0438\u0446\u044b, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0438 \u0434\u043b\u044f \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 bounds = [(0, 2), (0, 1), (0, 1), (0, 0.5)] res_milp = scopt.linprog(c=c, A_ub=A_ub, b_ub=b_ub, bounds=bounds, integrality=var_types, method='highs') print(f\"\u0420\u0435\u0448\u0435\u043d\u0438\u0435: x = {list(np.round(res_milp['x'], 2))}, f = {-res_milp['fun']}, {res_milp['message']}\")  # output # \u0420\u0435\u0448\u0435\u043d\u0438\u0435: x = [1.0, 1.0, 1.0, 0.5], f = 6.5, Optimization terminated successfully. (HiGHS Status 7: Optimal)<\/code><\/pre>\n<p>\u041a\u0430\u043a \u043c\u044b \u0432\u0438\u0434\u0438\u043c, \u0437\u0430\u0434\u0430\u0447\u0430 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0440\u0435\u0448\u0435\u043d\u0430. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u043f\u043e\u0434\u043e\u0431\u0440\u0430\u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u0431\u043e\u0440\u043e\u043c, \u0442\u0430\u043a \u043a\u0430\u043a \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u043d\u0435 \u0442\u0430\u043a \u043c\u043d\u043e\u0433\u043e: \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 3, \u0432\u0442\u043e\u0440\u043e\u0439 \u0438 \u0442\u0440\u0435\u0442\u044c\u0435\u0439 \u2014 2, \u0438\u0442\u043e\u0433\u043e 3 * 2 * 2 = 12 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432. \u0418, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443, \u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u043c\u0430\u043a\u0441\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0441 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u0430\u043c\u0438 \u0432 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0442\u043e \u043d\u0435\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u043d\u0443\u0436\u043d\u043e \u0431\u0440\u0430\u0442\u044c \u00ab\u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439\u00bb, \u043f\u043e\u043a\u0430 \u043d\u0435 \u0443\u043f\u0440\u0451\u043c\u0441\u044f \u043b\u0438\u0431\u043e \u0432 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435, \u043b\u0438\u0431\u043e \u0432 \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b\u0435 \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439. \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043f\u0435\u0440\u0435\u0431\u043e\u0440\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u0441\u0435\u0447\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0440\u0443\u0448\u0430\u044e\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 \u0441\u0443\u043c\u043c\u0443, \u043e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 \u043e\u0442\u043c\u0435\u0447\u0435\u043d\u044b \u043c\u0435\u0442\u043a\u043e\u0439 is_valid=False:<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0438\u0439 \u043f\u0435\u0440\u0435\u0431\u043e\u0440<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\"># \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043f\u043e\u043b\u043d\u044b\u0439 \u043f\u0435\u0440\u0435\u0431\u043e\u0440 import dataframe_image as dfi import itertools import pandas as pd  # \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0434\u043b\u044f \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 sols = pd.DataFrame(list(itertools.product([0., 1., 2.], [0., 1.], [0., 1.])), columns=['x1', 'x2', 'x3']) # \u0447\u0430\u0441\u0442\u044c \u0441\u0443\u043c\u043c\u044b \u0438\u0437 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u0430\u044f \u0441 \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438 sols['a'] = sols[['x1', 'x2', 'x3']].multiply(np.array([3., 1., 2.]), axis=1).sum(axis=1) # \u043d\u0435\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043f\u043e \u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e\u043c\u0443 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0443 \u043f\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044e \u0434\u043b\u044f \u043c\u0430\u043a\u0441\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 # \u0437\u0434\u0435\u0441\u044c \u0436\u0435 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c, \u0447\u0442\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0440\u0430\u0432\u043d\u043e 0.5 sols['x4'] = np.clip((7.0 - sols['a']) \/ 2.0, 0.0, 0.5) # \u043f\u043e\u0434\u0441\u0447\u0435\u0442 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u043f\u043e\u0438\u0441\u043a \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0441 \u0432\u044b\u0432\u043e\u0434\u043e\u043c \u0432\u0441\u0435\u0445 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 # \u0433\u0434\u0435 \u0447\u0435\u0440\u0435\u0437 is_valid \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u044b \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f sols['f'] = sols[['x1', 'x2', 'x3', 'x4']].multiply(np.array([1., 2., 3., 1.]), axis=1).sum(axis=1) sols['a'] = sols['a'] + 2 * sols['x4'] sols['is_valid'] = sols['a'] &lt;= 7.0 i_max = sols[sols['is_valid']]['f'].idxmax() sols = sols[['x1', 'x2', 'x3', 'x4', 'a', 'is_valid', 'f']].transpose() res = sols.style.set_properties(**{'background-color': '#5eae76'}, subset=[i_max]).format(precision=2) dfi.export(res, '.\/images\/milp_brute_force.png')<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<figure class=\"bordered full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/37d\/f31\/46f\/37df3146f5928b6369e9f20cce6cd853.png\" alt=\"\u0417\u0434\u0435\u0441\u044c \u043f\u043e \u0432\u0435\u0440\u0442\u0438\u043a\u0430\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445, a -\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f, \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0441\u0442\u0440\u043e\u0447\u043a\u043e\u0439 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u041f\u043e \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u0438 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u043f\u0435\u0440\u0435\u0431\u043e\u0440\u0430\" title=\"\u0417\u0434\u0435\u0441\u044c \u043f\u043e \u0432\u0435\u0440\u0442\u0438\u043a\u0430\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445, a -\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f, \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0441\u0442\u0440\u043e\u0447\u043a\u043e\u0439 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u041f\u043e \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u0438 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u043f\u0435\u0440\u0435\u0431\u043e\u0440\u0430\" width=\"572\" height=\"241\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/37d\/f31\/46f\/37df3146f5928b6369e9f20cce6cd853.png\"\/><figcaption>\u0417\u0434\u0435\u0441\u044c \u043f\u043e \u0432\u0435\u0440\u0442\u0438\u043a\u0430\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445, a -\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f, \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0441\u0442\u0440\u043e\u0447\u043a\u043e\u0439 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u041f\u043e \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u0438 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u043f\u0435\u0440\u0435\u0431\u043e\u0440\u0430<\/figcaption><\/figure>\n<p>\u041a\u0430\u043a \u043c\u044b \u0432\u0438\u0434\u0438\u043c \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u0437\u0430\u0434\u0430\u0447\u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f, \u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043e\u043b\u0432\u0435\u0440\u0430.<\/p>\n<h3>Pyomo. \u041e\u0431\u0437\u043e\u0440.<\/h3>\n<p><a href=\"http:\/\/www.pyomo.org\/\"><strong>Pyomo<\/strong><\/a> \u2014 \u043f\u0430\u043a\u0435\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0440\u044f\u0434 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0438 \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439. \u0413\u043b\u0430\u0432\u043d\u0430\u044f \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u2014 \u044d\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u043b\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0441\u043e\u043b\u0432\u0435\u0440\u043e\u0432, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u043a\u043e\u043c\u043c\u0435\u0440\u0447\u0435\u0441\u043a\u0438\u0445. Pyomo \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u0435\u0431\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0441\u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u0432 \u0444\u043e\u0440\u043c\u0430\u0442, \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0439 \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c\u043e\u0433\u043e \u0441\u043e\u043b\u0432\u0435\u0440\u0430.<\/p>\n<p>Pyomo \u0432\u0445\u043e\u0434\u0438\u0442 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442 <a href=\"https:\/\/www.coin-or.org\/\">COIN-OR<\/a>, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0440\u044f\u0434 \u0441\u043e\u043b\u0432\u0435\u0440\u043e\u0432, \u0441\u0440\u0435\u0434\u0438 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432\u044b\u0434\u0435\u043b\u0438\u043c \u0434\u0432\u0430:<\/p>\n<p><a href=\"https:\/\/github.com\/coin-or\/Ipopt\"><strong>Ipopt<\/strong><\/a> &#8212; \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u043e\u043f\u0442\u0438\u043c\u0443\u043c\u044b \u0432 \u0437\u0430\u0434\u0430\u0447\u0435 NLP \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0440\u044f\u043c\u043e-\u0434\u0432\u043e\u0439\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0439 \u0442\u043e\u0447\u043a\u0438 (\u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0432 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0439 <a href=\"http:\/\/www.optimization-online.org\/DB_HTML\/2004\/03\/836.html\">\u0441\u0442\u0430\u0442\u044c\u0435<\/a>).<\/p>\n<p><a href=\"https:\/\/github.com\/coin-or\/Cbc\"><strong>Cbc<\/strong><\/a> &#8212; \u0440\u0435\u0448\u0430\u0435\u0442 \u0437\u0430\u0434\u0430\u0447\u0438 MILP, \u043d\u0430 \u0431\u0430\u0437\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430, \u0441\u043e\u0447\u0435\u0442\u0430\u044e\u0449\u0435\u043c \u0432 \u0441\u0435\u0431\u0435 \u043c\u0435\u0442\u043e\u0434 \u0432\u0435\u0442\u0432\u0435\u0439 \u0438 \u0433\u0440\u0430\u043d\u0438\u0446 \u0438 \u0441\u0435\u043a\u0443\u0449\u0438\u0445 \u043f\u043b\u043e\u0441\u043a\u043e\u0441\u0442\u0435\u0439 (\u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043d\u0430 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Branch_and_cut\">wiki<\/a>).<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447 LP\/MILP \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u043f\u0430\u043a\u0435\u0442\u0430 <a href=\"https:\/\/en.wikipedia.org\/wiki\/GNU_Linear_Programming_Kit\">GLPK<\/a>.<br \/> \u041e\u0442\u043c\u0435\u0442\u0438\u043c \u0435\u0449\u0451 \u043e\u0434\u0438\u043d \u0441\u043e\u043b\u0432\u0435\u0440 <a href=\"https:\/\/github.com\/coin-or\/Bonmin\">bonmin<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d \u043d\u0430 \u0431\u0430\u0437\u0435 \u0441\u043e\u043b\u0432\u0435\u0440\u043e\u0432 <strong>Cbc<\/strong> \u0438 <strong>Ipopt<\/strong>, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0437\u0430 \u0437\u0430\u0434\u0430\u0447\u0438 <strong>MINLP<\/strong>.<\/p>\n<p>\u041f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0432 <strong>Pyomo<\/strong> \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u044d\u0442\u0430\u043f\u043e\u0432:<\/p>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438,<\/p>\n<\/li>\n<li>\n<p>\u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0432 \u044d\u0442\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0441 \u0433\u0440\u0430\u043d\u0438\u0446\u0430\u043c\u0438,<\/p>\n<\/li>\n<li>\n<p>\u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438,<\/p>\n<\/li>\n<li>\n<p>\u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439,<\/p>\n<\/li>\n<li>\n<p>\u0437\u0430\u043f\u0443\u0441\u043a \u0441\u043e\u043b\u0432\u0435\u0440\u0430, \u0440\u0435\u0448\u0430\u044e\u0449\u0435\u0433\u043e \u0437\u0430\u0434\u0430\u0447\u0443.<\/p>\n<\/li>\n<\/ul>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0448\u0430\u0433\u0438 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0437\u0430\u0434\u0430\u0447 (1) \u0438 (2).<\/p>\n<h4>Pyomo. \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 NLP.<\/h4>\n<pre><code class=\"python\"># \u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447\u0438 (1) import pyomo.environ as pyo  # \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 - \u043c\u043e\u0434\u0435\u043b\u0438  model = pyo.ConcreteModel('model')  # \u0437\u0430\u0434\u0430\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u043d\u0438 \u0432\u0441\u0435 \u043d\u0435\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u044b\u0435, \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c 1.0 model.x = pyo.Var(range(N), domain=pyo.Reals, bounds=x_bounds, initialize=1)  # \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0432 \u043c\u043e\u0434\u0435\u043b\u044c obj_expr = sum(P0[i] * model.x[i] * Q0[i] * pyo.exp(E[i] * (model.x[i] - 1)) for i in model.x) model.obj = pyo.Objective(expr=obj_expr, sense=pyo.maximize)  # \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0432 \u043c\u043e\u0434\u0435\u043b\u044c con_expr = sum((P0[i] * model.x[i] - C[i]) * Q0[i] * pyo.exp(E[i] * (model.x[i] - 1)) for i in model.x) >= M0 model.con = pyo.Constraint(expr=con_expr)  # \u0437\u0430\u043f\u0443\u0441\u043a \u0441\u043e\u043b\u0432\u0435\u0440\u0430 ipopt \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 solver = pyo.SolverFactory('ipopt') res = solver.solve(model)  # \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043e\u0442\u0432\u0435\u0442\u0430 - \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 x_opt = [round(model.x[i].value, 3) for i in model.x]  print(f\"\u0420\u0435\u0448\u0435\u043d\u0438\u0435 ipopt: {list(x_opt)} {res.solver.termination_condition}\") print(f\"\u0412\u044b\u0440\u0443\u0447\u043a\u0430: {round(model.obj(), 0)}\") print(f\"\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 \u043c\u0430\u0440\u0436\u0443 M >= {M0}; \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u0430\u0440\u0436\u0438: {round(model.con(), 0)}\")  # output # \u0420\u0435\u0448\u0435\u043d\u0438\u0435 ipopt: [0.9, 1.016, 1.1] optimal # \u0412\u044b\u0440\u0443\u0447\u043a\u0430: 29210742.0 # \u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 \u043c\u0430\u0440\u0436\u0443 M >= 5400000.0; \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u0430\u0440\u0436\u0438: 5400000.0<\/code><\/pre>\n<h4>Pyomo. \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 NLP.<\/h4>\n<pre><code class=\"python\">''' MILP \u043f\u0440\u0438\u043c\u0435\u0440 \u0441 \u0440\u044e\u043a\u0437\u0430\u043a\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u0441 \"\u0440\u044e\u043a\u0437\u0430\u043a\u043e\u043c\", \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0442\u0438\u043f\u044b \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u0430\u0437\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u0442\u0430\u043a \u043a\u0430\u043a \u0432 pyomo \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0432 \u043e\u0434\u043d\u043e\u043c \u0432\u0435\u043a\u0442\u043e\u0440\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0445 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0438 \u0434\u0430\u043d\u043d\u044b\u0435, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0442\u043e\u0436\u0435 ''' c_i, c_c = np.array([1., 2., 3.]), np.array([1.]) A_i, A_c = np.array([3., 1., 2.]), np.array([2.]) b = 7.0 # \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 - \u043c\u043e\u0434\u0435\u043b\u0438  model = pyo.ConcreteModel('model')  # \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 - \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0435 \u0438 \u043d\u0435\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u044b\u0435 bounds_i = [(0.0, 2.0), (0.0, 1.0), (0.0, 1.0)] bounds_c = [(0.0, 0.5)] model.x_i = pyo.Var(range(3), domain=pyo.Integers, bounds=bounds_i) model.x_c = pyo.Var(range(1), domain=pyo.Reals, bounds=bounds_c)  # \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0432 \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u043b\u044f \u043c\u0430\u043a\u0441\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 obj_expr = sum(c_i[i] * model.x_i[i] for i in model.x_i) +\\            sum(c_c[i] * model.x_c[i] for i in model.x_c) model.obj = pyo.Objective(expr=obj_expr, sense=pyo.maximize)  # \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 con_expr = sum(A_i[i] * model.x_i[i] for i in model.x_i) +\\            sum(A_c[i] * model.x_c[i] for i in model.x_c) &lt;= b model.con = pyo.Constraint(expr=con_expr)  solver = pyo.SolverFactory('glpk') res = solver.solve(model) x_opt = [model.x_i[i].value for i in model.x_i] + [model.x_c[i].value for i in model.x_c]  print(f\"\u0420\u0435\u0448\u0435\u043d\u0438\u0435: x = {x_opt}, f = {model.obj()}, {res.solver.termination_condition}\")  # output # \u0420\u0435\u0448\u0435\u043d\u0438\u0435: x = [1.0, 1.0, 1.0, 0.5], f = 6.5, optimal<\/code><\/pre>\n<p>\u0412\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u0441\u043e\u043b\u0432\u0435\u0440\u044b \u0441\u043f\u0440\u0430\u0432\u0438\u043b\u0438\u0441\u044c \u0441 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u044b\u043c\u0438 \u0437\u0430\u0434\u0430\u0447\u0430\u043c\u0438 \u0438 \u0432\u044b\u0434\u0430\u043b\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b, \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0435 \u043f\u0430\u043a\u0435\u0442\u0430\u043c <strong>SciPy<\/strong>. <\/p>\n<h4>Pyomo. \u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438.<\/h4>\n<p>\u0418\u0437 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e Pyomo \u0438\u043c\u0435\u0435\u0442 \u043f\u043e\u0434\u043c\u043e\u0434\u0443\u043b\u044c <strong>GDP<\/strong> <a href=\"https:\/\/pyomo.readthedocs.io\/en\/stable\/modeling_extensions\/gdp\/index.html\">(Generalized Disjunctive Programming)<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0438 \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u043d\u0451\u043d, \u043a\u043e\u0433\u0434\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043e\u0434\u043d\u043e \u0438\u0437 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439, \u043a\u0430\u0436\u0434\u043e\u0435 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u0432\u043e\u0435\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439. \u0420\u0430\u0437\u0431\u0435\u0440\u0451\u043c, \u0447\u0435\u043c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u0435\u043d \u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0438:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\begin{cases} \\tag{3} f_1(x_1) = x_1^2 \\\\ f_2(x_2) = (x_2 - 1) ^ 2 \\\\ f_3(x_3) = (x_3 + 2) ^ 2 \\\\ F(x_1, x_2, x_3) = f_1(x_1) + f_2(x_2) + f_3(x_3) \\\\ x_i \\in [-3; -1.5 ] \\cup \\{0\\} \\cup [ 1.5; 3] , \\ i = 1..3 \\end{cases}\" alt=\"\\begin{cases} \\tag{3} f_1(x_1) = x_1^2 \\\\ f_2(x_2) = (x_2 - 1) ^ 2 \\\\ f_3(x_3) = (x_3 + 2) ^ 2 \\\\ F(x_1, x_2, x_3) = f_1(x_1) + f_2(x_2) + f_3(x_3) \\\\ x_i \\in [-3; -1.5 ] \\cup \\{0\\} \\cup [ 1.5; 3] , \\ i = 1..3 \\end{cases}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7ce\/fc3\/f37\/7cefc3f37d03f7bae21e1c5228c0191a.svg\" width=\"697\" height=\"124\"\/><\/p>\n<p>\u041a\u0430\u043a \u043d\u0435\u0441\u043b\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0437\u0434\u0435\u0441\u044c \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0435\u0441\u0442\u044c \u00ab\u0440\u0430\u0437\u0440\u044b\u0432\u00bb, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u0432\u043e\u0434\u0438\u0442\u044c \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u043d\u0430 \u0442\u043e, \u0432 \u043a\u0430\u043a\u043e\u0439 \u0438\u0437 \u0442\u0440\u0451\u0445 \u043e\u0431\u043b\u0430\u0441\u0442\u0435\u0439 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"[-3; -1.5 ], \\{0\\}, [ 1.5; 3]\" alt=\"[-3; -1.5 ], \\{0\\}, [ 1.5; 3]\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/401\/745\/a9f\/401745a9f130fcc6a86b704a891672de.svg\" width=\"186\" height=\"22\"\/> \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c \u043f\u043e\u0438\u0441\u043a \u0440\u0435\u0448\u0435\u043d\u0438\u044f. \u0422\u0430\u043a \u043a\u0430\u043a \u0438\u0441\u0445\u043e\u0434\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"F\" alt=\"F\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e74\/826\/da0\/e74826da072874b088948ef6cfa31f37.svg\" width=\"15\" height=\"17\"\/> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0443\u043c\u043c\u043e\u0439 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0445 \u0434\u0440\u0443\u0433 \u043e\u0442 \u0434\u0440\u0443\u0433\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0442\u043e \u043c\u0438\u043d\u0438\u043c\u0443\u043c <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"F\" alt=\"F\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/bf8\/659\/80e\/bf865980e8b10f4f8e27c2c2e89d42f0.svg\" width=\"15\" height=\"17\"\/> \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u0435\u0442\u0441\u044f \u0432 \u043c\u0438\u043d\u0438\u043c\u0443\u043c\u0435 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"f_i\" alt=\"f_i\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/173\/7dd\/16f\/1737dd16f106fafa9af332310a1bf1fb.svg\" width=\"16\" height=\"21\"\/>. \u041e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u043c \u0433\u0440\u0430\u0444\u0438\u043a\u0438 \u0441 \u0443\u0447\u0451\u0442\u043e\u043c \u0443\u0441\u043b\u043e\u0432\u0438\u0439 \u043d\u0430 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"x\" alt=\"x\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8c9\/f0a\/1e2\/8c9f0a1e28faaad66019907eddd69801.svg\" width=\"11\" height=\"12\"\/> \u043d\u0438\u0436\u0435: \u043d\u0430 \u043d\u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u0432\u0438\u0434\u0435\u0442\u044c, \u0447\u0442\u043e <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"f_1\" alt=\"f_1\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/07b\/e93\/8be\/07be938bed703e4dfb920d4d481220ef.svg\" width=\"18\" height=\"21\"\/> \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u0435\u0442 \u0441\u0432\u043e\u0435\u0433\u043e \u043c\u0438\u043d\u0438\u043c\u0443\u043c\u0430 \u0432 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"x_1 = 0.0\" alt=\"x_1 = 0.0\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/845\/d6c\/13c\/845d6c13c1303531b77744e67aed67e5.svg\" width=\"71\" height=\"19\"\/>, <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"f_2\" alt=\"f_2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/2cf\/01f\/8a4\/2cf01f8a4369b5a0c5d44d964710b794.svg\" width=\"18\" height=\"21\"\/> \u0432 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"x_2=1.5\" alt=\"x_2=1.5\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/41a\/4b8\/16c\/41a4b816c0f4f5f7ff7be912a3dd4a94.svg\" width=\"71\" height=\"19\"\/>, <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"f_3\" alt=\"f_3\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c8f\/13a\/ca7\/c8f13aca7abffa61a6aaf55620a804be.svg\" width=\"18\" height=\"21\"\/> \u0432 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"x_3=-2.0\" alt=\"x_3=-2.0\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c41\/095\/fcb\/c41095fcbd53beb37cbcc0d559ac9293.svg\" width=\"86\" height=\"20\"\/>.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/9a6\/2f1\/8bf\/9a62f18bfa4b85d7df86729a5d83e819.png\" alt=\"\u0418\u043b\u043b\u044e\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u043a \u0437\u0430\u0434\u0430\u0447\u0435 (3)\" title=\"\u0418\u043b\u043b\u044e\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u043a \u0437\u0430\u0434\u0430\u0447\u0435 (3)\" width=\"800\" height=\"500\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9a6\/2f1\/8bf\/9a62f18bfa4b85d7df86729a5d83e819.png\"\/><figcaption>\u0418\u043b\u043b\u044e\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u043a \u0437\u0430\u0434\u0430\u0447\u0435 (3)<\/figcaption><\/figure>\n<p>\u041f\u0440\u043e\u0446\u0435\u0441\u0441 \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447\u0438 (3) \u043a\u043e\u043d\u0446\u0435\u043f\u0442\u0443\u0430\u043b\u044c\u043d\u043e \u043f\u043e\u0445\u043e\u0436 \u043d\u0430 \u0442\u043e\u0442, \u0447\u0442\u043e \u0431\u044b\u043b \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447 (1) \u0438 (2).<br \/>\u041e\u043f\u0438\u0448\u0435\u043c \u0435\u0433\u043e \u043a\u043e\u0434\u043e\u043c \u043d\u0438\u0436\u0435, \u0441\u043d\u0430\u0431\u0434\u0438\u0432 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c\u0438 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u043c\u0438:<\/p>\n<pre><code class=\"python\"># \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u043e \u0440\u044e\u043a\u0437\u0430\u043a\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e pyomo import pyomo.environ as pyo from pyomo.gdp import Disjunction  # \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 pyomo model = pyo.ConcreteModel('gdp_sample') # \u043e\u0431\u0449\u0438\u0439 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 [-3.0, 3.0] model.x = pyo.Var(range(0, 3), domain=pyo.Reals, bounds=(-3., 3.))  # \u0437\u0430\u0434\u0430\u043d\u0438\u0435 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 a = [0.0, 1.0, -2.0] obj_expr = sum((model.x[i] - a[i]) ** 2 for i in model.x) model.obj = pyo.Objective(expr=obj_expr, sense=pyo.minimize)  # \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u0430\u0432\u0438\u043b \u0434\u043b\u044f \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u043e\u0432 \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 Disjunction. # \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0435 Disjunction \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0432 \u0432\u0438\u0434\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 # \u0432\u0441\u0435\u0433\u043e \u0443 \u043d\u0430\u0441 \u0442\u0440\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0437\u0430\u0434\u0430\u0435\u043c \u0442\u0440\u0438 \u0433\u0440\u0443\u043f\u043f\u044b \u0443\u0441\u043b\u043e\u0432\u0438\u0439, \u0432 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u043e model.djn = Disjunction(range(3))  # \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0437\u0430\u0434\u0430\u043d\u0438\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0439 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 for i in range(3):     model.djn[i] = [model.x[i] &lt;= -1.5, model.x[i] == 0, model.x[i] >= 1.5]  ''' \u041f\u0435\u0440\u0435\u0434 \u043d\u0430\u0447\u0430\u043b\u043e\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0439 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0432 \u0441\u043e\u043b\u0432\u0435\u0440. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043c \u0442.\u043d. \u043c\u0435\u0442\u043e\u0434\u043e\u043c big-M, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0435\u0440\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0432 \u0430\u043b\u0433\u0435\u0431\u0440\u0430\u0438\u0447\u0435\u0441\u043a\u0438\u0435, \u0441\u0432\u043e\u0434\u044f \u0437\u0430\u0434\u0430\u0447\u0443 \u043a MINLP. \u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e, \u043a\u0430\u043a \u0443\u0441\u0442\u0440\u043e\u0435\u043d \u043c\u0435\u0442\u043e\u0434 \u0438 \u043f\u0440\u0438\u043c\u0435\u0440 \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0443\u0441\u043b\u043e\u0432\u0438\u0439 \u0440\u0443\u043a\u0430\u043c\u0438 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435. \u0417\u0434\u0435\u0441\u044c \u043d\u0438\u0436\u0435 \u043e\u0441\u0442\u0430\u0432\u0438\u043c \u0441\u0441\u044b\u043b\u043a\u0443 \u0434\u043b\u044f \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u043c. ''' pyo.TransformationFactory('gdp.bigm').apply_to(model) solver = pyo.SolverFactory('bonmin') res = solver.solve(model) x_opt = [round(model.x[i].value, 3) for i in model.x] print('\u0420\u0435\u0448\u0435\u043d\u0438\u0435:', x_opt, ', f =', round(model.obj(), 2))  # output # \u0420\u0435\u0448\u0435\u043d\u0438\u0435: [-0.0, 1.5, -2.0] , f = 0.25<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u043c, \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0434\u043b\u044f <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"x\" alt=\"x\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5c8\/0bf\/228\/5c80bf2289cc035448d9d148dcbb5b94.svg\" width=\"11\" height=\"12\"\/> \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u043c. \u0410 \u0432\u043e\u0442 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Big_M_method\">\u0441\u0441\u044b\u043b\u043a\u0430<\/a> \u043d\u0430 \u043c\u0435\u0442\u043e\u0434 big-M.<\/p>\n<h3>CVXPY. \u041e\u0431\u0437\u043e\u0440.<\/h3>\n<p><a href=\"https:\/\/www.cvxpy.org\/index.html\"><strong>CVXPY<\/strong><\/a> &#8212; \u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u0430\u043a\u0435\u0442 \u0431\u044b\u043b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Convex_optimization\">\u0432\u044b\u043f\u0443\u043a\u043b\u043e\u0439 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438<\/a>.<\/p>\n<p>\u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438, \u043f\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0438 \u0441 <strong>Pyomo<\/strong>, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0448\u0430\u0433\u043e\u0432: \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u0437\u0430\u0434\u0430\u0442\u044c \u0446\u0435\u043b\u0435\u0432\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438. \u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0437\u0430\u0434\u0430\u0447\u0430 \u0441\u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0430, \u043f\u0435\u0440\u0435\u0434 \u0437\u0430\u043f\u0443\u0441\u043a\u043e\u043c \u0441\u043e\u043b\u0432\u0435\u0440\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u0432\u044b\u043f\u0443\u043a\u043b\u043e\u0441\u0442\u044c \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0440\u0430\u0432\u0438\u043b <a href=\"https:\/\/www.cvxpy.org\/tutorial\/dcp\/index.html\">DCP<\/a> (Disciplined Convex Programming). \u041f\u043e \u0441\u0443\u0442\u0438, \u044d\u0442\u043e \u043d\u0430\u0431\u043e\u0440 \u043f\u0440\u0430\u0432\u0438\u043b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u044e\u0442 \u0432\u044b\u043f\u0443\u043a\u043b\u043e\u0441\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0437\u0434\u0435\u0441\u044c \u0441\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 &#8212; \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f, \u043d\u043e \u043d\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u044b\u0435, \u043f\u043e\u0447\u0435\u043c\u0443 \u044d\u0442\u043e \u0442\u0430\u043a \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043d\u0438\u0436\u0435. \u041f\u043e\u0441\u043b\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0437\u0430\u0434\u0430\u0447\u0430 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0441\u043e\u043b\u0432\u0435\u0440\u0443 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0449\u0438\u0439 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447 \u0432\u044b\u043f\u0443\u043a\u043b\u043e\u0439 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 <strong>CVXPY<\/strong> \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043a\u043e\u043c\u043c\u0435\u0440\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u043e\u043b\u0432\u0435\u0440\u044b. \u041f\u043e\u043b\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u043e\u043b\u0432\u0435\u0440\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u044d\u0442\u043e\u0439 <a href=\"https:\/\/www.cvxpy.org\/tutorial\/advanced\/index.html\">\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435<\/a>, \u0442\u0430\u043c \u0436\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u044b \u0432\u0441\u0435 \u0442\u0438\u043f\u044b \u0437\u0430\u0434\u0430\u0447, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0435\u0448\u0430\u0442\u044c <strong>CVXPY<\/strong>. \u041e\u0431\u0440\u0430\u0442\u0438\u043c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0430\u043a\u0435\u0442\u0430 \u043d\u0435 \u0442\u0430\u043a \u0432\u0430\u0436\u043d\u043e \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043d\u0435\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u043e\u0441\u0442\u0438 \u043f\u0435\u0440\u0432\u043e\u0439 \u0438 \u0432\u0442\u043e\u0440\u043e\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u043e\u0439, \u0432\u0430\u0436\u043d\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u043f\u0443\u043a\u043b\u043e\u0441\u0442\u044c.<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043f\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0438 \u0441 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u043c\u0438 \u043f\u0430\u043a\u0435\u0442\u0430\u043c\u0438 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 <strong>CVXPY<\/strong> \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445.<\/p>\n<h4>CVXPY. \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 NLP.<\/h4>\n<p>\u0417\u0430\u0434\u0430\u0447\u0443 (1) \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <strong>CVXPY<\/strong> \u0440\u0435\u0448\u0438\u0442\u044c \u043d\u0435 \u0443\u0434\u0430\u0441\u0442\u0441\u044f, \u0442\u0430\u043a \u043a\u0430\u043a \u0446\u0435\u043b\u0435\u0432\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0432 \u043e\u0431\u0449\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432\u044b\u043f\u0443\u043a\u043b\u044b\u043c\u0438 \u0438, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043d\u0435 \u043f\u043e\u0434\u0447\u0438\u043d\u044f\u044e\u0442\u0441\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c DCP. \u0426\u0435\u043b\u0435\u0432\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0441\u0443\u043c\u043c\u044b \u0441\u043b\u0430\u0433\u0430\u0435\u043c\u044b\u0445 \u0432\u0438\u0434\u0430 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"f(x) = x e^{E(x-1)}\" alt=\"f(x) = x e^{E(x-1)}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9ad\/c3f\/4ec\/9adc3f4ecc07073c738d2a17d70131da.svg\" width=\"133\" height=\"26\"\/>, \u0432\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u0430\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0440\u0430\u0432\u043d\u0430:<\/p>\n<p> <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"f''(x) = E x e^{E(x-1)}(Ex + 2)\" alt=\"f''(x) = E x e^{E(x-1)}(Ex + 2)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/819\/507\/254\/81950725463e43a1df28da5abe91acd5.svg\" width=\"233\" height=\"26\"\/> \u0438 \u043c\u0435\u043d\u044f\u0435\u0442 \u0441\u0432\u043e\u0439 \u0437\u043d\u0430\u043a \u0432 \u0442\u043e\u0447\u043a\u0435 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"x_{0} = \\frac{-2}{E} = \\frac{2}{|E|} \\geqslant 0\" alt=\"x_{0} = \\frac{-2}{E} = \\frac{2}{|E|} \\geqslant 0\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/850\/530\/b5c\/850530b5ca63912bd3f6d83ed425e155.svg\" width=\"173\" height=\"48\"\/><\/p>\n<p>(\u0441 \u0443\u0447\u0451\u0442\u043e\u043c \u0442\u043e\u0433\u043e, \u0447\u0442\u043e <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"E \\leqslant 0\" alt=\"E \\leqslant 0\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/eec\/2f2\/872\/eec2f287245dc381a873e9a33b19efad.svg\" width=\"51\" height=\"19\"\/>) \u2014 \u0442\u043e \u0435\u0441\u0442\u044c \u0432 \u043e\u0431\u0449\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u044b\u043f\u0443\u043a\u043b\u043e\u0439.<\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0442\u043e\u0433\u0434\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440: \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0438\u0437 \u0442\u043e\u0447\u043a\u0438 \u0441 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430\u043c\u0438 (0, 0) \u0432 \u0442\u043e\u0447\u043a\u0443 (1, 2), \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0430 \u043d\u0430 \u0434\u0432\u0435 \u0447\u0430\u0441\u0442\u0438 \u0432\u0434\u043e\u043b\u044c \u043b\u0438\u043d\u0438\u0438 y = 1; \u0434\u043e y = 1 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0440\u0430\u0432\u043d\u0430 1, \u0430 \u043f\u043e\u0441\u043b\u0435 \u0432 k (\u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 k=1.5) \u0440\u0430\u0437 \u043c\u0435\u043d\u044c\u0448\u0435.<br \/>\u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0441\u0430\u043c\u044b\u0439 \u0431\u044b\u0441\u0442\u0440\u044b\u0439 \u043f\u0443\u0442\u044c \u2014 \u044d\u0442\u043e \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u0435 \u043f\u043e \u043f\u0440\u044f\u043c\u043e\u0439 \u043b\u0438\u043d\u0438\u0438 \u0441 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c\u044e \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0438\u0437 \u0443\u0447\u0430\u0441\u0442\u043a\u043e\u0432, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0430 \u0433\u0440\u0430\u043d\u0438\u0446\u0435 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u00ab\u0440\u0430\u0437\u0440\u044b\u0432\u043e\u0432\u00bb \u0442\u0440\u0430\u0435\u043a\u0442\u043e\u0440\u0438\u0438. \u0412 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u043e\u043d\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443 \u043c\u043e\u0436\u043d\u043e \u0441\u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\begin{cases} \\tag{4} T = \\sqrt{(x-x_{1})^2 + (y-y_{1})^2} + k \\cdot \\sqrt{(x-x_{2})^2 + (y-y_{2})^2} \\to min, \\\\ x_{1} = 0,\\ y_{1} = 0,\\ x_{2} = 1,\\ y_{2} = 2, \\\\ y = 1 \\\\ x \\in [0; 2] \\end{cases}\" alt=\"\\begin{cases} \\tag{4} T = \\sqrt{(x-x_{1})^2 + (y-y_{1})^2} + k \\cdot \\sqrt{(x-x_{2})^2 + (y-y_{2})^2} \\to min, \\\\ x_{1} = 0,\\ y_{1} = 0,\\ x_{2} = 1,\\ y_{2} = 2, \\\\ y = 1 \\\\ x \\in [0; 2] \\end{cases}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ea9\/f08\/68a\/ea9f0868afbe9cd9cac6e7c6c5b7f938.svg\" width=\"697\" height=\"100\"\/><\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u0432 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"T\" alt=\"T\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/44c\/54b\/30d\/44c54b30d1c06221f992db5abc90f950.svg\" width=\"14\" height=\"17\"\/> \u2014 \u043f\u0435\u0440\u0432\u043e\u0435 \u0438 \u0432\u0442\u043e\u0440\u043e\u0435 \u0441\u043b\u0430\u0433\u0430\u0435\u043c\u044b\u0435 \u2014 \u044d\u0442\u043e \u043f\u0443\u0442\u044c \u043f\u043e \u043f\u0440\u044f\u043c\u043e\u0439 \u043e\u0442 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0439\/\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u0434\u043e \u0442\u043e\u0447\u043a\u0438 \u043d\u0430 \u0433\u0440\u0430\u043d\u0438\u0446\u0435, \u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0439 \u043d\u0430 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c, \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438 \u2014 \u0432\u0440\u0435\u043c\u044f, \u0437\u0430\u0442\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c\u043e\u0435 \u043f\u0440\u043e\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u043f\u0443\u0442\u0438 \u043d\u0430 1-\u043e\u043c \u0438 2-\u043e\u043c \u0443\u0447\u0430\u0441\u0442\u043a\u0430\u0445. \u041a\u0430\u0436\u0434\u043e\u0435 \u0438\u0437 \u0441\u043b\u0430\u0433\u0430\u0435\u043c\u044b\u0445 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u044b\u043f\u0443\u043a\u043b\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439, \u0430 \u0437\u043d\u0430\u0447\u0438\u0442 \u0438 \u0438\u0445 \u0441\u0443\u043c\u043c\u0430 \u0442\u043e\u0436\u0435.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/9cb\/85e\/d11\/9cb85ed11f79232e7c7b6320fdef4647.png\" alt=\"\u0418\u043b\u043b\u044e\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u043a \u0437\u0430\u0434\u0430\u0447\u0435 (4)\" title=\"\u0418\u043b\u043b\u044e\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u043a \u0437\u0430\u0434\u0430\u0447\u0435 (4)\" width=\"1200\" height=\"600\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9cb\/85e\/d11\/9cb85ed11f79232e7c7b6320fdef4647.png\"\/><figcaption>\u0418\u043b\u043b\u044e\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u043a \u0437\u0430\u0434\u0430\u0447\u0435 (4)<\/figcaption><\/figure>\n<pre><code class=\"python\"># \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0441 \u0440\u0430\u0437\u0440\u044b\u0432\u043e\u043c \u0432 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e cvxpy import cvxpy as cp  X1, Y1 = 0.0, 0.0 X2, Y2 = 1.0, 2.0 K = 1.5  # \u0437\u0430\u0434\u0430\u0435\u043c \u043e\u0434\u043d\u0443 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e x X = cp.Variable(1) Y_ = 1.0  # \u0446\u0435\u043b\u0435\u0432\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f - \u043a\u043e\u0440\u043d\u0438 \u0438\u0437 \u0441\u0443\u043c\u043c\u044b \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043e\u0432 - \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432\u044b\u043f\u0443\u043a\u043b\u044b\u043c\u0438 objective = cp.sqrt(cp.square(X - X1) + cp.square(Y_ - Y1) ** 2) +\\             cp.sqrt(cp.square(X2 - X) + cp.square(Y2 - Y_) ** 2)  # \u0437\u0434\u0435\u0441\u044c \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 - \u044d\u0442\u043e \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d \u0434\u043b\u044f x constraints = [] constraints.extend([X >= 0.0, X &lt;= X2])  # \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u043c \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u043e\u043d\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443, \u0437\u0434\u0435\u0441\u044c \u0431\u0435\u0440\u0435\u043c \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044e \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 problem = cp.Problem(cp.Minimize(objective), constraints)  # \u0441\u043e\u0432\u0435\u0440\u0448\u0430\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u0437\u0430\u0434\u0430\u0447\u0438 \u043d\u0430 \u0432\u044b\u043f\u0443\u043a\u043b\u043e\u0441\u0442\u044c \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c DCP print(f\"is dcp: {problem.is_dcp()}\")  # output # is dcp: False<\/code><\/pre>\n<p>\u041a\u0430\u043a \u043c\u044b \u0432\u0438\u0434\u0438\u043c, \u0437\u0430\u0434\u0430\u0447\u0430 \u043d\u0435 \u043f\u0440\u043e\u0448\u043b\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043d\u0430 \u0432\u044b\u043f\u0443\u043a\u043b\u043e\u0441\u0442\u044c \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c DCP, \u0442\u0430\u043a \u043a\u0430\u043a \u0431\u0435\u0440\u0451\u0442\u0441\u044f \u0432\u043e\u0433\u043d\u0443\u0442\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f(\u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043d\u044b\u0439 \u043a\u043e\u0440\u0435\u043d\u044c) \u043e\u0442 \u0432\u044b\u043f\u0443\u043a\u043b\u043e\u0439 (\u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0438\u0447\u043d\u043e\u0439), \u043d\u043e \u0434\u0430\u043d\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0437\u043e\u0432\u043e\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 norm \u0434\u043b\u044f \u0440\u0430\u0441\u0447\u0451\u0442\u0430 \u0434\u043b\u0438\u043d\u044b \u0432\u0435\u043a\u0442\u043e\u0440\u0430 (\u0432 \u043d\u0430\u0448\u0435\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435), \u043f\u0440\u043e \u043a\u043e\u0442\u043e\u0440\u0443\u044e <strong>CVXPY<\/strong> \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u0447\u0442\u043e \u043e\u043d\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u044b\u043f\u0443\u043a\u043b\u043e\u0439. <br \/> \u0412 \u043c\u043e\u0434\u0443\u043b\u0435 \u0435\u0441\u0442\u044c \u0442\u0430\u043a\u0436\u0435 \u0435\u0449\u0451 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043f\u043e\u0434\u0447\u0438\u043d\u044f\u044e\u0442\u0441\u044f DCP, \u043d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0432\u044b\u043f\u0443\u043a\u043b\u044b\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, log_sum_exp &#8212; \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c \u043e\u0442 \u0441\u0443\u043c\u043c\u044b \u044d\u043a\u0441\u043f\u043e\u043d\u0435\u043d\u0442. \u0422\u0430\u043a\u0438\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u0438 \u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u043a\u0435 \u0437\u0430\u0434\u0430\u0447 \u0432 CVXPY.<\/p>\n<pre><code class=\"python\"># \u0441\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u0438\u0440\u0443\u0435\u043c \u0446\u0435\u043b\u0435\u0432\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0447\u0435\u0440\u0435\u0437 \u0432\u044b\u0437\u043e\u0432 norm objective = cp.norm(cp.hstack([X - X1, Y_ - Y1]), 2) + K * cp.norm(cp.hstack([X2 - X, Y2 - Y_]), 2)  # \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0438 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0437\u0430\u0434\u0430\u0447\u0443 constraints = [] constraints.extend([X >= 0.0, X &lt;= X2]) problem = cp.Problem(cp.Minimize(objective), constraints)  # \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0430 \u0432\u044b\u043f\u0443\u043a\u043b\u043e\u0441\u0442\u044c print(f\"is dcp: {problem.is_dcp()}\")  # \u0440\u0435\u0448\u0430\u0435\u043c \u0437\u0430\u0434\u0430\u0447\u0443 \u043f\u0443\u0442\u0435\u043c \u0432\u044b\u0437\u043e\u0432\u0430 \u0441\u043e\u043b\u0432\u0435\u0440\u0430 ECOS sol = problem.solve('ECOS')  # \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435 x_opt = X.value[0] print(f\"\u0420\u0435\u0448\u0435\u043d\u0438\u0435: x = {round(x_opt, 3)}, f = {round(sol, 2)}\")  # output # is dcp: True # \u0420\u0435\u0448\u0435\u043d\u0438\u0435: x = 0.623, f = 2.78 <\/code><\/pre>\n<h4>CVXPY. \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 MILP<\/h4>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c, \u043a\u0430\u043a \u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u0437\u0430\u0434\u0430\u0447\u0430 <a href=\"#example_2\">(2)<\/a> \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <strong>CVXPY<\/strong>, \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u0430\u043a\u0435\u0442 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0435\u0448\u0430\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0438 LP (MILP):<\/p>\n<pre><code class=\"python\"># \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445, \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0445 \u0438 \u043d\u0435\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u044b\u0445 x_i = cp.Variable(3, integer=True) x_c = cp.Variable(1, nonneg=True)  # \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 c = np.array([1., 2., 3., 1.]) A = np.array([3., 1., 2., 2.]) b = 7.0  # \u043c\u0430\u043a\u0441\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 - \u0441\u0443\u043c\u043c\u0430 \u043f\u043e \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u0439 \u0438 \u043d\u0435\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 obj = cp.Maximize(cp.sum(c[:3] @ x_i) + cp.sum(c[3:4] @ x_c))  # \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043d\u0430 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d \u0438 \u043d\u0430 \u043e\u0431\u0449\u0443\u044e \u0441\u0443\u043c\u043c\u0443 cons = [     x_i[0] &lt;= 2, x_i[1] &lt;= 1, x_i[2] &lt;= 1,     x_c &lt;= 1,     ((A[:3] @ x_i) + (A[3:4] @ x_c)) &lt;= b ]  # \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0438 \u0435\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 prb = cp.Problem(obj, cons) sol = prb.solve(verbose=False, solver='GLPK_MI') x_opt = np.concatenate([x_i.value, x_c.value])  print(f\"\u0420\u0435\u0448\u0435\u043d\u0438\u0435: x = {list(np.round(x_opt, 2))}, f = {sol}, {prb.status}\")  # output # \u0420\u0435\u0448\u0435\u043d\u0438\u0435: x = [1.0, 1.0, 1.0, 0.5], f = 6.5, optimal<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0442\u0430\u043a\u0436\u0435 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c \u043f\u043e\u043b\u043d\u043e\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0441 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u043c\u0438 \u043f\u0430\u043a\u0435\u0442\u0430\u043c\u0438.<\/p>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\u041c\u044b \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u043b\u0438\u0441\u044c \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 open-source \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u043c\u0438 \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447. <\/p>\n<p>\u041f\u043e\u0434\u0432\u043e\u0434\u044f \u0438\u0442\u043e\u0433, \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0438 \u0441 \u0447\u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0447\u0430\u0442\u044c, \u0438\u0441\u0445\u043e\u0434\u044f \u0438\u0437 \u043d\u0430\u0448\u0435\u0433\u043e \u043e\u043f\u044b\u0442\u0430. \u0415\u0441\u043b\u0438 \u0432 \u0437\u0430\u0434\u0430\u0447\u0435 NLP \u043f\u0435\u0440\u0432\u044b\u0435 \u0438 \u0432\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u044b\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0433\u043b\u0430\u0434\u043a\u0438\u043c\u0438, \u0442\u043e \u0437\u0434\u0435\u0441\u044c \u0445\u043e\u0440\u043e\u0448\u043e \u0441\u0435\u0431\u044f \u0437\u0430\u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u043e\u0432\u0430\u043b \u0441\u0435\u0431\u044f Ipopt \u0432 \u043f\u0430\u043a\u0435\u0442\u0435 Pyomo. \u0415\u0441\u043b\u0438 \u0432 NLP \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0435 \u0433\u043b\u0430\u0434\u043a\u0438\u0435, \u043d\u043e \u0432\u044b\u043f\u0443\u043a\u043b\u044b\u0435, \u0442\u043e \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u043f\u043e\u0434\u043e\u0439\u0434\u0435\u0442 CVXPY.<br \/>Scipy \u0445\u043e\u0440\u043e\u0448\u043e \u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u043c\u0438 \u0437\u0430\u0434\u0430\u0447\u0430\u043c\u0438, \u0430 COBYLA \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447 \u0431\u0435\u0437 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u0430 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u0414\u043b\u044f \u0437\u0430\u0434\u0430\u0447\u0438 MILP \u043a\u043e\u043d\u043a\u0443\u0440\u0438\u0440\u0443\u044e\u0449\u0438\u043c\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0441\u043e\u043b\u0432\u0435\u0440\u044b GLPK, Cbc, HiGHS \u2014 \u0437\u0434\u0435\u0441\u044c \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043a\u0430\u043a\u043e\u0439 \u0438\u0437 \u043d\u0438\u0445 \u0431\u0443\u0434\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u043d\u0435\u043f\u0440\u043e\u0441\u0442\u043e, \u043d\u0430\u0434\u043e \u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c, \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0442\u044c. Scipy \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u0435\u043d, \u0435\u0441\u043b\u0438 \u0438\u043c\u0435\u044e\u0442\u0441\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0421\u043e\u0441\u0442\u0430\u0432\u0438\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043d\u044b\u0445 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u0430\u043a\u0435\u0442\u043e\u0432 \u0438 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a\u0438\u0435 \u0442\u0438\u043f\u044b \u0437\u0430\u0434\u0430\u0447 \u043e\u043d\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0440\u0435\u0448\u0430\u0442\u044c:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th data-colwidth=\"117\" width=\"117\">\n<p>\u041f\u0430\u043a\u0435\u0442\u044b \u0432 Python<\/p>\n<\/th>\n<th>\n<p>\u0421\u043e\u043b\u0432\u0435\u0440(\u043c\u0435\u0442\u043e\u0434)<\/p>\n<\/th>\n<th>\n<p>NLP<\/p>\n<\/th>\n<th>\n<p>LP<\/p>\n<\/th>\n<th>\n<p>MILP<\/p>\n<\/th>\n<th>\n<p>MINLP<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td data-colwidth=\"117\" width=\"117\">\n<p align=\"left\">SciPy<\/p>\n<\/td>\n<td>\n<p align=\"left\">COBYLA<\/p>\n<\/td>\n<td>\n<p align=\"left\">+<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"117\" width=\"117\">\n<p align=\"left\">SciPy<\/p>\n<\/td>\n<td>\n<p align=\"left\">SLSQP<\/p>\n<\/td>\n<td>\n<p align=\"left\">+<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"117\" width=\"117\">\n<p align=\"left\">SciPy<\/p>\n<\/td>\n<td>\n<p align=\"left\">trust-constr<\/p>\n<\/td>\n<td>\n<p align=\"left\">+<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"117\" width=\"117\">\n<p align=\"left\">SciPy<\/p>\n<\/td>\n<td>\n<p align=\"left\">HiGHS<\/p>\n<\/td>\n<td>\n<p align=\"left\">+<\/p>\n<\/td>\n<td>\n<p align=\"left\">+<\/p>\n<\/td>\n<td>\n<p align=\"left\">+<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"117\" width=\"117\">\n<p align=\"left\">Pyomo<\/p>\n<\/td>\n<td>\n<p align=\"left\">Ipopt<\/p>\n<\/td>\n<td>\n<p align=\"left\">+<\/p>\n<\/td>\n<td>\n<p align=\"left\">+<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"117\" width=\"117\">\n<p align=\"left\">Pyomo, CVXPY<\/p>\n<\/td>\n<td>\n<p align=\"left\">GLPK<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">+<\/p>\n<\/td>\n<td>\n<p align=\"left\">+<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"117\" width=\"117\">\n<p align=\"left\">Pyomo, CVXPY<\/p>\n<\/td>\n<td>\n<p align=\"left\">Cbc<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">+<\/p>\n<\/td>\n<td>\n<p align=\"left\">+<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"117\" width=\"117\">\n<p align=\"left\">CVXPY<\/p>\n<\/td>\n<td>\n<p align=\"left\">Ecos<\/p>\n<\/td>\n<td>\n<p align=\"left\">+-<\/p>\n<\/td>\n<td>\n<p align=\"left\">+<\/p>\n<\/td>\n<td>\n<p align=\"left\">+<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"117\" width=\"117\">\n<p align=\"left\">Pyomo<\/p>\n<\/td>\n<td>\n<p align=\"left\">Bonmin<\/p>\n<\/td>\n<td>\n<p align=\"left\">+<\/p>\n<\/td>\n<td>\n<p align=\"left\">+<\/p>\n<\/td>\n<td>\n<p align=\"left\">+<\/p>\n<\/td>\n<td>\n<p align=\"left\">+<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0430\u043a\u0446\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043d\u043e \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435 \u043a\u0430\u0441\u0430\u043b\u0438\u0441\u044c \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u041e\u0431 \u044d\u0442\u043e\u043c \u0438 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u044b \u043f\u043b\u0430\u043d\u0438\u0440\u0443\u0435\u043c \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/X5Tech\/blog\/708294\/\"> https:\/\/habr.com\/ru\/company\/X5Tech\/blog\/708294\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, Habr! \u041d\u0430 \u0441\u0432\u044f\u0437\u0438\u00a0<a href=\"https:\/\/habr.com\/ru\/users\/muxeu\/\"><u>\u041c\u0438\u0445\u0430\u0438\u043b \u0411\u0443\u0434\u044b\u043b\u0438\u043d<\/u><\/a>\u00a0\u0438\u00a0<a href=\"https:\/\/habr.com\/ru\/users\/6redik\/\"><u>\u0410\u043d\u0442\u043e\u043d \u0414\u0435\u043d\u0438\u0441\u043e\u0432<\/u><\/a>, \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0432 \u043e\u0442\u0434\u0435\u043b\u0435 \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 X5 Tech.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043f\u0440\u043e \u043f\u0440\u0438\u043a\u043b\u0430\u0434\u043d\u043e\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0442\u0435\u043e\u0440\u0438\u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438. \u0412 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u043a\u0440\u0430\u0442\u043a\u0438\u0439 \u043e\u0431\u0437\u043e\u0440 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 open-source \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0432 Python, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043c\u044b \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u043b\u0438\u0441\u044c \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435. \u0417\u0430\u0442\u0440\u043e\u043d\u0435\u043c \u0438\u0445 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f \u0438 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438, \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0437\u0430\u0434\u0430\u0447, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0448\u0430\u0442\u044c \u0441 \u0438\u0445 \u043f\u043e\u043c\u043e\u0449\u044c\u044e.<\/p>\n<p>\u0412 \u043d\u0430\u0448\u0435\u0439\u00a0<a href=\"https:\/\/habr.com\/ru\/company\/X5Tech\/blog\/685590\/\"><u>\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/u><\/a>\u00a0\u043c\u044b \u043e\u043f\u0438\u0441\u0430\u043b\u0438 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447, \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0438\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0437\u0430\u0434\u0430\u0447 \u0438\u0437 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0440\u0438\u0442\u0435\u0439\u043b\u0430, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441\u0440\u0430\u0432\u043d\u0438\u043b\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0434\u0432\u0443\u0445 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440\u043e\u0432 \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u0446\u0435\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 Python.<\/p>\n<h2>\u041e\u0431\u0437\u043e\u0440 \u043f\u0430\u043a\u0435\u0442\u043e\u0432 Python<\/h2>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u043f\u043e\u043c\u043d\u0438\u043c \u043e\u0441\u043d\u043e\u0432\u0443 \u2014 \u043f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0443 \u0437\u0430\u0434\u0430\u0447\u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438:<\/p>\n<p>\u041f\u0443\u0441\u0442\u044c\u00a0&#8212; \u0432\u0435\u043a\u0442\u043e\u0440 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438\u00a0, &#8212; \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u044d\u0442\u0438\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445.<br \/>&#8212; \u0446\u0435\u043b\u0435\u0432\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f.<\/p>\n<p>&#8212; \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0432\u0438\u0434\u0430 \u043d\u0435\u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432.<\/p>\n<p>&#8212; \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0432\u0438\u0434\u0430 \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432.<\/p>\n<p>\u0410 \u0442\u0430\u043a \u0436\u0435, \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447, \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u0443\u044e \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435:<\/p>\n<ul>\n<li>\n<p><strong>\u0411\u0435\u0437\u0443\u0441\u043b\u043e\u0432\u043d\u0430\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f<\/strong>  \u2014 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442, ;<\/p>\n<\/li>\n<li>\n<p><strong>LP<\/strong> (linear programming) \u2014 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435.  &#8212; \u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, ;<\/p>\n<\/li>\n<li>\n<p><strong>MILP<\/strong> (mixed integer linear programming) \u2014 \u0441\u043c\u0435\u0448\u0430\u043d\u043d\u043e\u0435 \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u0435 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u044d\u0442\u043e \u0437\u0430\u0434\u0430\u0447\u0430 LP \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0447\u0430\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u043c\u0438;<\/p>\n<\/li>\n<li>\n<p><strong>NLP<\/strong> (nonlinear programming) \u2014 \u043d\u0435\u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043a\u043e\u0433\u0434\u0430 \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u043d\u0430 \u0438\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043d\u0435\u043b\u0438\u043d\u0435\u0439\u043d\u0430;<\/p>\n<\/li>\n<li>\n<p><strong>MINLP<\/strong> (mixed integer nonlinear programming) \u2014 \u0441\u043c\u0435\u0448\u0430\u043d\u043d\u043e\u0435 \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u0435 \u043d\u0435\u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043a\u0430\u043a \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 MILP, \u043a\u043e\u0433\u0434\u0430 \u0447\u0430\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f;<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u0443\u044e \u043a\u0430\u0440\u0442\u0438\u043d\u0443 \u0441\u043e\u043b\u0432\u0435\u0440\u044b \u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u043c \u0432 \u0432\u0438\u0434\u0435 \u0441\u0445\u0435\u043c\u044b:<\/p>\n<figure class=\"full-width\"><figcaption>\u041f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0435\u043c\u044b\u0445 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u0441\u043e\u043b\u0432\u0435\u0440\u043e\u0432<\/figcaption><\/figure>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0432 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u044d\u0442\u0438 \u043f\u0430\u043a\u0435\u0442\u044b \u0438 \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043e \u0432\u0430\u0436\u043d\u044b\u0445, \u043d\u0430 \u043d\u0430\u0448 \u0432\u0437\u0433\u043b\u044f\u0434, \u0434\u0435\u0442\u0430\u043b\u044f\u0445 \u0438\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u0438 \u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u0437\u0430\u0434\u0430\u0447 \u0443\u0441\u043b\u043e\u0432\u043d\u043e\u0439 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438. \u0414\u043b\u044f \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0440\u0430\u0441\u0447\u0451\u0442\u043e\u0432 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043f\u0430\u043a\u0435\u0442\u044b \u0438\u0437 <a href=\"https:\/\/github.com\/mbudylin\/optimizers_review#readme\">Readme<\/a>, \u0442\u0430\u043a\u0436\u0435 \u0435\u0441\u0442\u044c <a href=\"https:\/\/github.com\/mbudylin\/optimizers_review\/blob\/master\/Dockerfile\">\u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f<\/a> \u043f\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0443 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u0441 jupyter \u0432 \u0434\u043e\u043a\u0435\u0440\u0435.<\/p>\n<h3>SciPy. \u041e\u0431\u0437\u043e\u0440.<\/h3>\n<p><a href=\"https:\/\/scipy.org\/\"><strong>SciPy<\/strong><\/a> \u2014 \u043e\u0434\u043d\u0430 \u0438\u0437 \u043f\u0435\u0440\u0432\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0432 Python, \u0437\u043d\u0430\u043a\u043e\u043c\u0441\u0442\u0432\u043e \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0443 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0441\u0442\u043e\u0432 \u0432 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 Data Science: \u043e\u043d\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043d\u0430\u0431\u043e\u0440 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0434\u043b\u044f \u043d\u0430\u0443\u0447\u043d\u044b\u0445 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0438\u043c\u0435\u0435\u0442 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447, \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0438\u0445\u0441\u044f \u0432 \u043c\u043e\u0434\u0443\u043b\u0435 <strong>scipy.optimize<\/strong>. \u0412 \u044d\u0442\u043e\u043c \u043c\u043e\u0434\u0443\u043b\u0435 \u0438\u043c\u0435\u044e\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447 \u043a\u0430\u043a \u043d\u0435\u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f (<strong>NLP<\/strong>), \u0442\u0430\u043a \u0438 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f (<strong>LP<\/strong>), \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0437\u0430\u0434\u0430\u0447 \u0441\u043c\u0435\u0448\u0430\u043d\u043d\u043e\u0433\u043e \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f (<strong>MILP<\/strong>).<\/p>\n<p>\u0421\u0440\u0435\u0434\u0438 \u0441\u043e\u043b\u0432\u0435\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447 \u0443\u0441\u043b\u043e\u0432\u043d\u043e\u0439 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 (NLP) \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c <strong>COBYLA<\/strong>, <strong>SLSQP<\/strong>, <strong>trust-constr<\/strong>. \u0412\u0441\u0435 \u0442\u0440\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u044b \u0432 \u043f\u0430\u043a\u0435\u0442\u0435<br \/> <code>scipy.optimize.minimize<\/code> \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c <code>method<\/code> (<code>'cobyla'<\/code>,<code>'slsqp'<\/code> \u0438 <code>'trust-constr',<\/code> \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e).<\/p>\n<p><strong>COBYLA<\/strong> \u2014 \u044d\u0442\u043e \u043c\u0435\u0442\u043e\u0434, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u0435\u043d, \u0442.\u0435., \u043f\u043e \u0441\u0443\u0442\u0438, \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c\u0441\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u00ab\u0447\u0435\u0440\u043d\u043e\u0433\u043e \u044f\u0449\u0438\u043a\u0430\u00bb.<br \/>\u0414\u043b\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432\u0430\u0436\u043d\u043e, \u0447\u0442\u043e \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434:<\/p>\n<ul>\n<li>\n<p><strong>\u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442<\/strong> \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u0430 \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u0430: . \u0421\u0432\u044f\u0437\u0430\u043d\u043e \u044d\u0442\u043e \u0441 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u043e\u043b\u0432\u0435\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u0435\u0431\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 SciPy. \u042d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u043e\u0439\u0442\u0438, \u0437\u0430\u043c\u0435\u043d\u0438\u0432 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 \u0434\u0432\u0430 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0432\u0438\u0434\u0430 \u043d\u0435\u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u0430:  \u0438 , \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0440\u0430\u0432\u043d\u043e\u0441\u0438\u043b\u044c\u043d\u043e \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u0443.<\/p>\n<\/li>\n<li>\n<p><strong>\u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442<\/strong> \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0445 \u0447\u0435\u0440\u0435\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 bounds \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <strong>minimize<\/strong> (\u0438\u0437 \u043c\u043e\u0434\u0443\u043b\u044f scipy.optimize) \u2014 \u0438\u0445 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e LinearConstraint.<\/p>\n<\/li>\n<\/ul>\n<p><strong>SLSQP<\/strong> \u0438 <strong>trust-constr<\/strong> \u2014 \u044d\u0442\u043e \u043c\u0435\u0442\u043e\u0434\u044b \u0443\u0436\u0435 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0430, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0434\u043b\u044f \u043d\u0438\u0445 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u043d\u0435\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u043e\u0441\u0442\u044c 1-\u043e\u0439 \u0438 2-\u043e\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u044b\u0445.<\/p>\n<p>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u0439 \u043e\u0431\u0437\u043e\u0440 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043b\u0438\u0442\u0435\u0440\u0430\u0442\u0443\u0440\u044b \u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0441\u043e\u043b\u0432\u0435\u0440\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/ods\/blog\/448054\/\">\u0442\u0443\u0442<\/a>.<\/p>\n<h4>SciPy. \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 NLP.<\/h4>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 <strong>scipy<\/strong> \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u0446\u0435\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u0437 <a href=\"https:\/\/habr.com\/ru\/company\/X5Tech\/blog\/685590\/\">\u0441\u0442\u0430\u0442\u044c\u0438 1<\/a>. \u0417\u0430\u0434\u0430\u0447\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u043b\u0430\u0441\u044c \u0432 \u043c\u0430\u043a\u0441\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u044b\u0440\u0443\u0447\u043a\u0438 \u0441 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435\u043c \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u043c\u0430\u0440\u0436\u0438 \u0441 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u044b\u043c \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u043e\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0446\u0435\u043d\u044b \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u00b110% \u043e\u0442 \u0442\u0435\u043a\u0443\u0449\u0435\u0439.<\/p>\n<p>\u041f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0431\u044b\u043b\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439:<\/p>\n<p> \u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0442\u043e\u0432\u0430\u0440\u043e\u0432,<\/p>\n<p> \u2014 \u0442\u0435\u043a\u0443\u0449\u0430\u044f \u0446\u0435\u043d\u0430 \u0442\u043e\u0432\u0430\u0440\u0430 ,<\/p>\n<p> \u2014 \u0442\u0435\u043a\u0443\u0449\u0438\u0435 \u043f\u0440\u043e\u0434\u0430\u0436\u0438 \u0442\u043e\u0432\u0430\u0440\u0430 ,<\/p>\n<p> \u2014 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0439 \u0446\u0435\u043d\u044b  \u043a \u0442\u0435\u043a\u0443\u0449\u0435\u0439 ,<\/p>\n<p> \u2014 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0441\u0447\u0451\u0442\u0430 \u0441\u043f\u0440\u043e\u0441\u0430 \u043d\u0430 \u0442\u043e\u0432\u0430\u0440 \u043f\u043e \u0444\u043e\u0440\u043c\u0443\u043b\u0435 ,<\/p>\n<p>\u2014 \u0432\u044b\u0440\u0443\u0447\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u043e\u0432\u0430\u0440\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0435\u0433\u043e \u0446\u0435\u043d\u044b \u043d\u0430 \u043f\u0440\u043e\u0434\u0430\u0436\u0438, <\/p>\n<p>\u2014 \u043c\u0430\u0440\u0436\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0440\u0430\u0437\u043d\u043e\u0441\u0442\u044c \u043c\u0435\u0436\u0434\u0443 \u0446\u0435\u043d\u043e\u0439 \u043f\u0440\u043e\u0434\u0430\u0436\u0438 \u0438 \u0441\u0435\u0431\u0435\u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c\u044e, \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u043d\u043e\u0439 \u043d\u0430 \u043f\u0440\u043e\u0434\u0430\u0436\u0438,<\/p>\n<p> \u2014 \u0442\u0435\u043a\u0443\u0449\u0430\u044f \u043c\u0430\u0440\u0436\u0430, \u0442.\u0435. \u0435\u0451 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u0438 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0446\u0435\u043d\u0435,<\/p>\n<p>\u041e\u0444\u043e\u0440\u043c\u0438\u043c \u0432\u0441\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u0432 \u0432\u0438\u0434\u0435 \u043a\u043e\u0434\u0430 \u0438 \u0437\u0430\u0434\u0430\u0434\u0438\u043c \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f:<\/p>\n<pre><code class=\"python\"># \u043c\u0438\u043d\u0438 \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0437 \u043f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 import scipy.optimize as scopt import numpy as np  # \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0442\u043e\u0432\u0430\u0440\u043e\u0432 N = 3 # \u0437\u0430\u0434\u0430\u0435\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b E, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0432 \u0444\u043e\u0440\u043c\u0443\u043b\u0435 Q = Q0 * exp(E * (x - 1)) E = np.array([-3., -1., -0.5]) # \u0442\u0435\u043a\u0443\u0449\u0438\u0435 \u0446\u0435\u043d\u044b P0 = np.array([100., 100., 100.]) # \u0442\u0435\u043a\u0443\u0449\u0438\u0435 \u043f\u0440\u043e\u0434\u0430\u0436\u0438 Q0 = np.array([50000., 200000., 30000.0]) # \u0441\u0435\u0431\u0435\u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c C = np.array([90.0, 80.0, 70.0]) # \u0442\u0435\u043a\u0443\u0449\u0430\u044f \u0432\u044b\u0440\u0443\u0447\u043a\u0430 R0 = np.sum(P0 * Q0) # \u0442\u0435\u043a\u0443\u0449\u0430\u044f \u043c\u0430\u0440\u0436\u0430 M0 = np.sum((P0 - C) * Q0)  # \u0432\u044b\u0440\u0443\u0447\u043a\u0430 - \u0446\u0435\u043b\u0435\u0432\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0437\u0430\u0434\u0430\u0435\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \"\u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c\" \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u043e\u043c \u0447\u0435\u0440\u0435\u0437 'scale' def f_obj(x, args):     f = - args['scale'] * np.sum(Q0 * P0 * x * np.exp(E * (x - 1.)))     return f obj = f_obj  # \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u043c\u0430\u0440\u0436\u0435, \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043d\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043d\u0430 \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u0432\u044b\u0440\u0443\u0447\u043a\u0443 def f_cons(x):     f = np.sum(Q0 * (P0 * x - C) * np.exp(E * (x - 1.0))) \/ R0     return f  con_mrg = scopt.NonlinearConstraint(f_cons, lb=M0 \/ R0, ub=np.inf) # \u043f\u043e\u0438\u0441\u043a \u043d\u043e\u0432\u043e\u0439 \u0446\u0435\u043d\u044b \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u043c \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 90% - 110% \u043e\u0442 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0446\u0435\u043d\u044b x_bounds = [(0.9, 1.1)] * 3 # \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0432 cobyla con_bnd = scopt.LinearConstraint(np.eye(3), lb=[0.9] * 3, ub=[1.1] * 3) # \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u0430\u044f \u0442\u043e\u0447\u043a\u0430 \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 x0 = [1.0] * 3  def print_results(model, solver_name, M0, R0):     print(f\"\u0420\u0435\u0448\u0435\u043d\u0438\u0435 {solver_name}: {list(np.round(model['x'], 4))}; model message: {model['message']}\")     print(f\"\u0412\u044b\u0440\u0443\u0447\u043a\u0430: {round(-f_obj(model['x'], {'scale': 1}), 0)}\")     print(f\"\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 \u043c\u0430\u0440\u0436\u0443 M >= {M0}; \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u0430\u0440\u0436\u0438: {round(R0 * con_mrg.fun(model['x']), 0)}\")<\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 SciPy:<\/p>\n<pre><code class=\"python\"># \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0441\u043e\u043b\u0432\u0435\u0440\u0430 cobyla res_cobyla = scopt.minimize(obj, x0, constraints=[con_bnd, con_mrg], method='cobyla', args={'scale': 1}) print_results(res_cobyla, 'cobyla', M0, R0)  # output: # \u0420\u0435\u0448\u0435\u043d\u0438\u0435 cobyla: [0.9, 1.0165, 1.1]; model message: Optimization terminated successfully. # \u0412\u044b\u0440\u0443\u0447\u043a\u0430: 29210742.0 # \u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 \u043c\u0430\u0440\u0436\u0443 M >= 5400000.0; \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u0430\u0440\u0436\u0438: 5399998.0<\/code><\/pre>\n<pre><code class=\"python\"># \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0441\u043e\u043b\u0432\u0435\u0440\u0430 trust-constr res_trust_const = scopt.minimize(obj, x0, bounds=x_bounds, constraints=[con_mrg], method='trust-constr', args={'scale': 1}) print_results(res_trust_const, 'trust-constr', M0, R0)  # output: # \u0420\u0435\u0448\u0435\u043d\u0438\u0435 trust-constr: [0.9, 1.0165, 1.1]; model message: `gtol` termination condition is satisfied. # \u0412\u044b\u0440\u0443\u0447\u043a\u0430: 29210742.0 # \u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 \u043c\u0430\u0440\u0436\u0443 M >= 5400000.0; \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u0430\u0440\u0436\u0438: 5400005.0<\/code><\/pre>\n<pre><code class=\"python\"># \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0441\u043e\u043b\u0432\u0435\u0440\u0430 slsqp res_slsqp = scopt.minimize(obj, x0, bounds=x_bounds, constraints=[con_mrg], method='slsqp', args={'scale': 1}) print_results(res_slsqp, 'slsqp', M0, R0)  # output # \u0420\u0435\u0448\u0435\u043d\u0438\u0435 slsqp: [1.0, 1.0, 1.0]; model message: Optimization terminated successfully # \u0412\u044b\u0440\u0443\u0447\u043a\u0430: 28000000.0 # \u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 \u043c\u0430\u0440\u0436\u0443 M >= 5400000.0; \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u0430\u0440\u0436\u0438: 5400000.0<\/code><\/pre>\n<p>\u041f\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c 2 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u043c\u043e\u043c\u0435\u043d\u0442\u0430:<\/p>\n<ul>\n<li>\n<p>\u043c\u0435\u0442\u043e\u0434\u044b <strong>COBYLA<\/strong> \u0438 <strong>trust-constr<\/strong> \u0441\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u043a \u043e\u0434\u043d\u043e\u043c\u0443 \u0438 \u0442\u043e\u043c\u0443 \u0436\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044e. \u0422\u0430\u043a\u0436\u0435 \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0432\u0441\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f (\u043f\u043e \u0433\u0440\u0430\u043d\u0438\u0446\u0430\u043c \u0438 \u043f\u043e \u043c\u0430\u0440\u0436\u0435 &#8212; \u0441 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c\u044e \u0431\u043e\u043b\u0435\u0435 7-8 \u0437\u043d\u0430\u043a\u043e\u0432),<\/p>\n<\/li>\n<li>\n<p><strong>SLSQP<\/strong> \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u00ab\u043e\u0441\u0442\u0430\u043b\u0441\u044f\u00bb \u0432 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0435 \u2014 \u044d\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u0435\u043c \u043d\u0430 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0443 \u043f\u0440\u0438 \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0435\u0433\u0443\u043b\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b ftol \u0438 eps \u0432 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0435 options.<\/p>\n<\/li>\n<\/ul>\n<p>\u0412\u043e\u043e\u0431\u0449\u0435 \u0433\u043e\u0432\u043e\u0440\u044f, \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439 \u0441\u043e\u043b\u0432\u0435\u0440\u043e\u0432 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043a \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e \u043f\u043e\u0440\u044f\u0434\u043a\u0430 1, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u0432\u044b\u0441\u0438\u0442\u044c \u0443\u0441\u0442\u043e\u0439\u0447\u0438\u0432\u043e\u0441\u0442\u044c \u0438 \u0441\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u043e\u0432. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 \u0437\u0430\u0434\u0430\u0447\u0435 \u043f\u0443\u0442\u0451\u043c \u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 (\u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0432\u044b\u0440\u0443\u0447\u043a\u0438) \u043d\u0430 \u0432\u044b\u0440\u0443\u0447\u043a\u0443 \u043f\u0440\u0438 \u0442\u0435\u043a\u0443\u0449\u0438\u0445 \u0446\u0435\u043d\u0430\u0445 .<\/p>\n<pre><code class=\"python\"># \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0441\u043e\u043b\u0432\u0435\u0440\u0430 slsqp res_slsqp = scopt.minimize(obj, x0, bounds=x_bounds, constraints=[con_mrg], method='slsqp', args={'scale': 1. \/ R0}) print_results(res_slsqp, 'slsqp', M0, R0)  # output # \u0420\u0435\u0448\u0435\u043d\u0438\u0435 slsqp: [0.9, 1.0165, 1.1]; model message: Optimization terminated successfully # \u0412\u044b\u0440\u0443\u0447\u043a\u0430: 29210742.0 # \u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 \u043c\u0430\u0440\u0436\u0443 M >= 5400000.0; \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u0430\u0440\u0436\u0438: 5399999.0<\/code><\/pre>\n<h4>SciPy. \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 MILP.<\/h4>\n<p>\u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u043f\u043e\u0434\u043c\u043e\u0434\u0443\u043b\u0435 <strong>optimize<\/strong> \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <a href=\"https:\/\/docs.scipy.org\/doc\/scipy\/reference\/generated\/scipy.optimize.linprog.html#scipy.optimize.linprog\"><strong>linprog<\/strong><\/a>, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0432\u0435\u0440\u0441\u0438\u0438 <a href=\"https:\/\/docs.scipy.org\/doc\/scipy\/release.1.9.0.html\">SciPy==1.9.0<\/a> \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0433\u043e \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <a href=\"https:\/\/scipy.github.io\/devdocs\/reference\/generated\/scipy.optimize.milp.html\"><strong>milp<\/strong><\/a> \u0438 <strong>linprog<\/strong>.<br \/>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0441\u043e\u043b\u0432\u0435\u0440\u0430 \u0434\u043b\u044f LP(MILP) \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <a href=\"https:\/\/www.maths.ed.ac.uk\/hall\/HiGHS\/\">HiGHS<\/a> \u2014 \u0432 \u043d\u0451\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u044b \u0441\u0438\u043c\u043f\u043b\u0435\u043a\u0441 \u043c\u0435\u0442\u043e\u0434 (highs-ds) \u0438 \u043c\u0435\u0442\u043e\u0434 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0439 \u0442\u043e\u0447\u043a\u0438 (highs-ipm). \u041f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u043e\u0434\u0438\u043d \u0438\u0437 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 \u043f\u0440\u0438\u043d\u0443\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442.<\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u043a\u0443 \u0441\u043c\u0435\u0448\u0430\u043d\u043d\u043e\u0433\u043e \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0440\u044e\u043a\u0437\u0430\u043a\u0430, \u0433\u0434\u0435 \u0434\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430 <strong>linprog<\/strong> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432:<\/p>\n<pre><code class=\"python\"># \u043f\u0440\u0438\u043c\u0435\u0440 \u0441 \"\u0440\u044e\u043a\u0437\u0430\u043a\u043e\u043c\", \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0442\u0438\u043f\u044b \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u0430\u0437\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f # \u0442\u0430\u043a \u043a\u0430\u043a scipy \u0440\u0435\u0448\u0435\u0442 \u0437\u0430\u0434\u0430\u0447\u0443 \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438, \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043c\u0438\u043d\u0443\u0441 \u0434\u043b\u044f \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u043e\u0432 \u0432 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u043c\u0430\u043a\u0441\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 c = -np.array([1., 2., 3., 1.]) A_ub = np.array([[3., 1., 2., 2.]]) b_ub = np.array([7.0]) # \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u0434\u043b\u044f \u0442\u0438\u043f\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445, 0 - \u043d\u0435\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u043e\u0435, 1 - \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e var_types = [1, 1, 1, 0] # \u0442\u0430\u043a\u0436\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0433\u0440\u0430\u043d\u0438\u0446\u044b, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0438 \u0434\u043b\u044f \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 bounds = [(0, 2), (0, 1), (0, 1), (0, 0.5)] res_milp = scopt.linprog(c=c, A_ub=A_ub, b_ub=b_ub, bounds=bounds, integrality=var_types, method='highs') print(f\"\u0420\u0435\u0448\u0435\u043d\u0438\u0435: x = {list(np.round(res_milp['x'], 2))}, f = {-res_milp['fun']}, {res_milp['message']}\")  # output # \u0420\u0435\u0448\u0435\u043d\u0438\u0435: x = [1.0, 1.0, 1.0, 0.5], f = 6.5, Optimization terminated successfully. (HiGHS Status 7: Optimal)<\/code><\/pre>\n<p>\u041a\u0430\u043a \u043c\u044b \u0432\u0438\u0434\u0438\u043c, \u0437\u0430\u0434\u0430\u0447\u0430 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0440\u0435\u0448\u0435\u043d\u0430. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u043f\u043e\u0434\u043e\u0431\u0440\u0430\u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u0431\u043e\u0440\u043e\u043c, \u0442\u0430\u043a \u043a\u0430\u043a \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u043d\u0435 \u0442\u0430\u043a \u043c\u043d\u043e\u0433\u043e: \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 3, \u0432\u0442\u043e\u0440\u043e\u0439 \u0438 \u0442\u0440\u0435\u0442\u044c\u0435\u0439 \u2014 2, \u0438\u0442\u043e\u0433\u043e 3 * 2 * 2 = 12<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-343291","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/343291","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=343291"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/343291\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=343291"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=343291"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=343291"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}