{"id":364243,"date":"2024-05-21T02:13:06","date_gmt":"2024-05-21T02:13:06","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=364243"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-05-21T02:13:06","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=364243","title":{"rendered":"<span>Ortools \u2014 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 VRP<\/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! \u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0418\u043b\u044c\u044f \u041d\u0430\u0431\u0430\u0442\u0447\u0438\u043a\u043e\u0432, \u044f MLE \u0432 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 Kamaz Digital. \u0422\u0430\u043a\u0436\u0435 \u044f \u0443\u0447\u0443\u0441\u044c \u0432\u00a0\u043e\u043d\u043b\u0430\u0439\u043d \u043c\u0430\u0433\u0438\u0441\u0442\u0440\u0430\u0442\u0443\u0440\u0435 \u043d\u0430 \u0431\u0430\u0437\u0435 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0438\u0442\u0435\u0442\u0430 \u0418\u0422\u041c\u041e\u00a0<a class=\"mention\" href=\"\/users\/ai-talent\">@ai-talent<\/a>.<\/p>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0445\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 ortools \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0438\u0437\u0430\u0446\u0438\u0438 \u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0440\u0442\u043d\u044b\u0445 \u0441\u0440\u0435\u0434\u0441\u0442\u0432 \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438 \u0433\u0440\u0443\u0437\u043e\u043f\u043e\u0434\u044a\u0435\u043c\u043d\u043e\u0441\u0442\u0438 (CVRPTW).<\/p>\n<p>\u0418 \u0441\u0430\u043c\u043e\u0435 \u0432\u0430\u0436\u043d\u043e \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u043f\u0430\u0440\u043e\u0439 \u0432\u0430\u0436\u043d\u044b\u0445 \u0444\u0438\u0447\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432\u044b \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u0442\u0435 \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438.<\/p>\n<h2>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 VRP \u0438 CVRPTW?<\/h2>\n<p>VRP (Vehicle Routing Problem) &#8212; \u044d\u0442\u043e \u043e\u0434\u043d\u0430 \u0438\u0437 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0437\u0430\u0434\u0430\u0447 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0432 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u043a\u0438, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u0430\u044f \u0441 \u043f\u043e\u0438\u0441\u043a\u043e\u043c \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0445 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u043e\u0432 \u0434\u043b\u044f \u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0440\u0442\u043d\u044b\u0445 \u0441\u0440\u0435\u0434\u0441\u0442\u0432 \u0441 \u0446\u0435\u043b\u044c\u044e \u0434\u043e\u0441\u0442\u0430\u0432\u043a\u0438 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u043a\u043b\u0438\u0435\u043d\u0442\u0430\u043c \u0438\u043b\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0434\u0440\u0443\u0433\u0438\u0445 \u0437\u0430\u0434\u0430\u0447 \u0441 \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0437\u0430\u0442\u0440\u0430\u0442. \u041a\u043e\u0433\u0434\u0430 \u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0440\u0442\u043d\u044b\u0435 \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430 \u043e\u0431\u043b\u0430\u0434\u0430\u044e\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u043e\u0439 \u0433\u0440\u0443\u0437\u043e\u043f\u043e\u0434\u044a\u0435\u043c\u043d\u043e\u0441\u0442\u044c\u044e, \u0430 \u0443 \u0437\u0430\u043a\u0430\u0437\u0447\u0438\u043a\u043e\u0432 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u044b \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0430\u0432\u043a\u0438, \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0437\u0430\u0434\u0430\u0447\u0430 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0438\u0437\u0430\u0446\u0438\u0438 \u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0440\u0442\u0430, \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0449\u0430\u044f \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438 \u0433\u0440\u0443\u0437\u043e\u043f\u043e\u0434\u044a\u0435\u043c\u043d\u043e\u0441\u0442\u0438 (CVRPTW).<\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u043e\u0431\u0441\u0443\u0434\u0438\u043c, \u043a\u0430\u043a \u0440\u0435\u0448\u0438\u0442\u044c CVRPTW, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0431\u044b\u0441\u0442\u0440\u043e\u0435 \u0438 \u043d\u0430\u0434\u0435\u0436\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 ortools. <\/p>\n<h2>\u041f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438 <\/h2>\n<p>\u0412 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 VRP \u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0440\u0442\u043d\u044b\u0435 \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430 (\u0434\u0430\u043b\u0435\u0435 \u0422\u0421) \u0441\u0442\u0430\u0440\u0442\u0443\u044e\u0442 \u0438\u0437 \u043e\u0434\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 &#8212; \u0434\u0435\u043f\u043e \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u0435\u0440\u043d\u0443\u0442\u044c\u0441\u044f \u0432 \u043d\u0435\u0433\u043e \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u0441\u0435\u0449\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0437\u0430\u043a\u0430\u0437\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b \u0437\u0430\u0440\u0430\u043d\u0435\u0435. <\/p>\n<p>\u041c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443. \u041f\u0443\u0441\u0442\u044c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441 \u043f\u0430\u0441\u0441\u0430\u0436\u0438\u0440\u0441\u043a\u0438\u0445 \u043f\u0435\u0440\u0435\u0432\u043e\u0437\u043e\u043a. \u0418\u043c\u0435\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f:<\/p>\n<ol>\n<li>\n<p>\u0417\u0430\u0440\u0430\u043d\u0435\u0435 \u0432\u0441\u0435 \u0442\u043e\u0447\u043a\u0438 \u0437\u0430\u043a\u0430\u0437\u043e\u0432 \u043d\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b, \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0437\u0430\u043d\u043e\u0432\u043e \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u0430\u0441\u0441\u0430\u0436\u0438\u0440\u0430;<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u0440\u0430\u0441\u0447\u0435\u0442\u043e\u0432 \u0432\u043e\u0437\u044c\u043c\u0435\u043c 2 \u0422\u0421 \u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c\u044e 8 \u0447\u0435\u043b\u043e\u0432\u0435\u043a;<\/p>\n<\/li>\n<li>\n<p>\u0423 \u043f\u0430\u0441\u0441\u0430\u0436\u0438\u0440\u043e\u0432 \u0435\u0441\u0442\u044c \u0441\u0442\u0440\u043e\u0433\u0438\u0435 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b \u043f\u043e\u0441\u0430\u0434\u043a\u0438 \u0438 \u0432\u044b\u0441\u0430\u0434\u043a\u0438 (\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043e\u043a\u043d\u0430). \u0414\u043b\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u0430\u0441\u0441\u0430\u0436\u0438\u0440\u0430, \u0442\u0430\u043a\u0436\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u044e\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043d\u0430 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435 = 30 \u043c\u0438\u043d\u0443\u0442 \u0438 \u043d\u0430 \u0432\u0440\u0435\u043c\u044f \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f + \u0432\u0440\u0435\u043c\u044f \u0432 \u043f\u0443\u0442\u0438 =  45 \u043c\u0438\u043d\u0443\u0442;<\/p>\n<\/li>\n<li>\n<p>\u0422\u043e\u0447\u043a\u0430 \u0441\u0442\u0430\u0440\u0442\u0430 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0430 &#8212; \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0422\u0421 (\u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0434\u0435\u043f\u043e \u0432 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435);<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435 \u0442\u043e\u0447\u043a\u0438 \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044f \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0430 \u0422\u0421.<\/p>\n<\/li>\n<\/ol>\n<h2>\u041c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438<\/h2>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u0441\u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u0443\u0435\u043c \u0437\u0430\u0434\u0430\u0447\u0443 \u043a\u0430\u043a \u0441\u043c\u0435\u0448\u0430\u043d\u043d\u0443\u044e \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u0443\u044e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443. \u0417\u0430\u0442\u0435\u043c \u0440\u0435\u0448\u0430\u0435\u043c \u0437\u0430\u0434\u0430\u0447\u0443 \u0434\u043b\u044f \u0440\u044f\u0434\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u0433\u0440\u0443\u0437\u043e\u0432\u0438\u043a\u043e\u0432, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0445 \u0434\u0430\u043d\u043d\u0443\u044e \u0444\u043e\u0440\u043c\u0443\u043b\u0443. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 CVRPTW \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f NP-\u0441\u043b\u043e\u0436\u043d\u044b\u043c, \u043c\u044b \u043e\u0436\u0438\u0434\u0430\u0435\u043c, \u0447\u0442\u043e \u0432\u0440\u0435\u043c\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043c\u043e\u0434\u0435\u043b\u0438 \u0431\u0443\u0434\u0435\u0442 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u043e \u043c\u0435\u0440\u0435 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u0433\u0440\u0443\u0437\u043e\u0432\u0438\u043a\u043e\u0432 \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u0442\u0441\u044f.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\textbf{\u041c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430:} \\\\ \\begin{align*} &amp; N \\text{ = \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0432\u0441\u0435\u0445 \u0443\u0437\u043b\u043e\u0432 (\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0435 \u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0435 \u0442\u043e\u0447\u043a\u0438)} \\\\ &amp; P \\text{ = \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0442\u043e\u0447\u0435\u043a \u043f\u043e\u0441\u0430\u0434\u043a\u0438 \u0438 \u0432\u044b\u0441\u0430\u0434\u043a\u0438} \\\\ &amp; D \\text{ = \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0442\u043e\u0447\u0435\u043a \u0440\u0430\u0437\u0440\u044b\u0432\u0430} \\\\ &amp; K \\text{ = \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0422\u0421 } \\end{align*}\" alt=\"\\textbf{\u041c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430:} \\\\ \\begin{align*} &amp; N \\text{ = \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0432\u0441\u0435\u0445 \u0443\u0437\u043b\u043e\u0432 (\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0435 \u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0435 \u0442\u043e\u0447\u043a\u0438)} \\\\ &amp; P \\text{ = \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0442\u043e\u0447\u0435\u043a \u043f\u043e\u0441\u0430\u0434\u043a\u0438 \u0438 \u0432\u044b\u0441\u0430\u0434\u043a\u0438} \\\\ &amp; D \\text{ = \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0442\u043e\u0447\u0435\u043a \u0440\u0430\u0437\u0440\u044b\u0432\u0430} \\\\ &amp; K \\text{ = \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0422\u0421 } \\end{align*}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/851\/f93\/90e\/851f9390e6fc520ff7121c9ed52b895b.svg\" width=\"697\" height=\"149\"\/><img class=\"formula\" source=\"\\textbf{\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:} \\\\  \\begin{align*} &amp; c_{ij} \\text{ = \u0432\u0440\u0435\u043c\u044f \u0432 \u043f\u0443\u0442\u0438 \u043c\u0435\u0436\u0434\u0443 \u0443\u0437\u043b\u0430\u043c\u0438 } i \\text{ \u0438 } j, c_{ij} \\geq 0 \\\\  &amp; q_i \\text{ = \u0441\u043f\u0440\u043e\u0441 \u043d\u0430 \u0443\u0437\u043b\u0435 } i,  -Q_k \\leq q_i  \\leq Q_k \\\\  &amp; Q_k \\text{ = \u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c \u0422\u0421 } k, Q_k > 0 \\\\  &amp; TW_i \\text{ = \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0434\u043b\u044f \u0443\u0437\u043b\u0430 } i, TW_i \\geq 0 \\\\  &amp; O_i \\text{ = \u0443\u0437\u0435\u043b } i \\text{ \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u0435\u043d \u0434\u043b\u044f \u0422\u0421 } k, O_i \\in K \\\\  &amp; T_i \\text{ = \u0442\u0438\u043f \u0443\u0437\u043b\u0430 } i \\text{ (start, onboard, pickup, delivery, finish)} \\\\  &amp; R_k \\text{ = \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u0430\u0440\u0448\u0440\u0443\u0442 \u0434\u043b\u044f \u0422\u0421 } k \\\\ &amp; p \\text{ = \u0448\u0442\u0440\u0430\u0444 \u0437\u0430 \u043d\u0435\u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0443\u0437\u043b\u0430 \u0432 \u043c\u0430\u0440\u0448\u0440\u0443\u0442 } \\end{align*}&#187; alt=&#187;\\textbf{\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:} \\\\  \\begin{align*} &amp; c_{ij} \\text{ = \u0432\u0440\u0435\u043c\u044f \u0432 \u043f\u0443\u0442\u0438 \u043c\u0435\u0436\u0434\u0443 \u0443\u0437\u043b\u0430\u043c\u0438 } i \\text{ \u0438 } j, c_{ij} \\geq 0 \\\\  &amp; q_i \\text{ = \u0441\u043f\u0440\u043e\u0441 \u043d\u0430 \u0443\u0437\u043b\u0435 } i,  -Q_k \\leq q_i  \\leq Q_k \\\\  &amp; Q_k \\text{ = \u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c \u0422\u0421 } k, Q_k > 0 \\\\  &amp; TW_i \\text{ = \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0434\u043b\u044f \u0443\u0437\u043b\u0430 } i, TW_i \\geq 0 \\\\  &amp; O_i \\text{ = \u0443\u0437\u0435\u043b } i \\text{ \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u0435\u043d \u0434\u043b\u044f \u0422\u0421 } k, O_i \\in K \\\\  &amp; T_i \\text{ = \u0442\u0438\u043f \u0443\u0437\u043b\u0430 } i \\text{ (start, onboard, pickup, delivery, finish)} \\\\  &amp; R_k \\text{ = \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u0430\u0440\u0448\u0440\u0443\u0442 \u0434\u043b\u044f \u0422\u0421 } k \\\\ &amp; p \\text{ = \u0448\u0442\u0440\u0430\u0444 \u0437\u0430 \u043d\u0435\u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0443\u0437\u043b\u0430 \u0432 \u043c\u0430\u0440\u0448\u0440\u0443\u0442 } \\end{align*}&#187; src=&#187;https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ea6\/b59\/57c\/ea6b5957c63b433452993885b80c81f7.svg&#187; width=&#187;697&#8243; height=&#187;268&#8243;\/><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\textbf{\u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f:} \\\\ \\begin{align*} &amp; x_{ijk} \\text{ = \u0431\u0438\u043d\u0430\u0440\u043d\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f, \u0440\u0430\u0432\u043d\u0430\u044f 1, \u0435\u0441\u043b\u0438 \u0422\u0421 } k \\text{ \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0435\u0442\u0441\u044f \u0438\u0437 \u0443\u0437\u043b\u0430 } i \\text{ \u0432 \u0443\u0437\u0435\u043b } j, \\text{ \u0438\u043d\u0430\u0447\u0435 0} \\\\ &amp; u_{ik} \\text{ = \u043d\u0430\u043a\u043e\u043f\u043b\u0435\u043d\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f, \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0435 \u0422\u0421 } k \\text{ \u043f\u0440\u0438 \u0432\u044b\u0435\u0437\u0434\u0435 \u0438\u0437 \u0443\u0437\u043b\u0430 } i \\\\ &amp; y_{ik} \\text{ = \u0431\u0438\u043d\u0430\u0440\u043d\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f, \u0440\u0430\u0432\u043d\u0430\u044f 1, \u0435\u0441\u043b\u0438 \u0422\u0421 } k \\text{ \u043f\u043e\u0441\u0435\u0449\u0430\u0435\u0442 \u0443\u0437\u0435\u043b } i, \\text{ \u0438\u043d\u0430\u0447\u0435 0} \\end{align*}\" alt=\"\\textbf{\u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f:} \\\\ \\begin{align*} &amp; x_{ijk} \\text{ = \u0431\u0438\u043d\u0430\u0440\u043d\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f, \u0440\u0430\u0432\u043d\u0430\u044f 1, \u0435\u0441\u043b\u0438 \u0422\u0421 } k \\text{ \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0435\u0442\u0441\u044f \u0438\u0437 \u0443\u0437\u043b\u0430 } i \\text{ \u0432 \u0443\u0437\u0435\u043b } j, \\text{ \u0438\u043d\u0430\u0447\u0435 0} \\\\ &amp; u_{ik} \\text{ = \u043d\u0430\u043a\u043e\u043f\u043b\u0435\u043d\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f, \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0435 \u0422\u0421 } k \\text{ \u043f\u0440\u0438 \u0432\u044b\u0435\u0437\u0434\u0435 \u0438\u0437 \u0443\u0437\u043b\u0430 } i \\\\ &amp; y_{ik} \\text{ = \u0431\u0438\u043d\u0430\u0440\u043d\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f, \u0440\u0430\u0432\u043d\u0430\u044f 1, \u0435\u0441\u043b\u0438 \u0422\u0421 } k \\text{ \u043f\u043e\u0441\u0435\u0449\u0430\u0435\u0442 \u0443\u0437\u0435\u043b } i, \\text{ \u0438\u043d\u0430\u0447\u0435 0} \\end{align*}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/2be\/610\/53c\/2be61053cc87b975bb874baa5990d7c3.svg\" width=\"697\" height=\"119\"\/><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\" \\textbf{\u0426\u0435\u043b\u0435\u0432\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f:} \\\\ \\begin{equation*}  \\text{Minimize} \\quad \\sum_{k=1}^{K} \\sum_{i=1}^N \\sum_{j=1}^N c_{ij} \\cdot x_{ijk} + \\sum_{i}^{D} (1 - y_{ik}) \\cdot p  \\end{equation*}\" alt=\" \\textbf{\u0426\u0435\u043b\u0435\u0432\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f:} \\\\ \\begin{equation*}  \\text{Minimize} \\quad \\sum_{k=1}^{K} \\sum_{i=1}^N \\sum_{j=1}^N c_{ij} \\cdot x_{ijk} + \\sum_{i}^{D} (1 - y_{ik}) \\cdot p  \\end{equation*}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/6e6\/1f5\/854\/6e61f585429362dbc2928502d6d6affd.svg\" width=\"697\" height=\"95\"\/><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\textbf{\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f:} \\\\ \\begin{align*} &amp; \\text{1. \u041a\u0430\u0436\u0434\u044b\u0439 \u0443\u0437\u0435\u043b \u043f\u043e\u0441\u0435\u0449\u0430\u0435\u0442\u0441\u044f \u0440\u043e\u0432\u043d\u043e \u043e\u0434\u0438\u043d \u0440\u0430\u0437:} \\quad \\sum_{i=1}^N \\sum_{k=1}^{K} y_{ik} = 1, \\quad \\forall i \\in N \\\\ &amp; \\text{2. \u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438 \u0422\u0421:} \\quad \\sum_{i=1}^N  q_i \\cdot y_{ik} \\leq Q_k, \\quad \\forall k \\\\ &amp; \\text{3. \u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u043e\u043a\u043d\u0430:} \\quad TW_i \\leq u_{ik} \\leq TW_i, \\quad \\forall i \\in N, \\forall k \\\\ &amp; \\text{4. \u041f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0441\u0430\u0434\u043a\u0438 \u0438 \u0432\u044b\u0441\u0430\u0434\u043a\u0438:} \\quad \\sum_{i}^P y_{ik} = 2 \\cdot \\sum_{(i,j)\\in P}  x_{ijk}, , \\quad \\forall k \\\\ &amp; \\text{5. \u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0443\u0437\u043b\u043e\u0432:} \\quad \\sum_{i}^{D} y_{ik} \\leq 1, \\quad \\forall i\\in D, \\forall k \\end{align*}\" alt=\"\\textbf{\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f:} \\\\ \\begin{align*} &amp; \\text{1. \u041a\u0430\u0436\u0434\u044b\u0439 \u0443\u0437\u0435\u043b \u043f\u043e\u0441\u0435\u0449\u0430\u0435\u0442\u0441\u044f \u0440\u043e\u0432\u043d\u043e \u043e\u0434\u0438\u043d \u0440\u0430\u0437:} \\quad \\sum_{i=1}^N \\sum_{k=1}^{K} y_{ik} = 1, \\quad \\forall i \\in N \\\\ &amp; \\text{2. \u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438 \u0422\u0421:} \\quad \\sum_{i=1}^N  q_i \\cdot y_{ik} \\leq Q_k, \\quad \\forall k \\\\ &amp; \\text{3. \u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u043e\u043a\u043d\u0430:} \\quad TW_i \\leq u_{ik} \\leq TW_i, \\quad \\forall i \\in N, \\forall k \\\\ &amp; \\text{4. \u041f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0441\u0430\u0434\u043a\u0438 \u0438 \u0432\u044b\u0441\u0430\u0434\u043a\u0438:} \\quad \\sum_{i}^P y_{ik} = 2 \\cdot \\sum_{(i,j)\\in P}  x_{ijk}, , \\quad \\forall k \\\\ &amp; \\text{5. \u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0443\u0437\u043b\u043e\u0432:} \\quad \\sum_{i}^{D} y_{ik} \\leq 1, \\quad \\forall i\\in D, \\forall k \\end{align*}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/6ff\/2cd\/828\/6ff2cd828bd7483288a6571efecb97cc.svg\" width=\"697\" height=\"316\"\/><\/p>\n<h2>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0434\u0430\u0442\u044b<\/h2>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447\u0438.<\/p>\n<pre><code class=\"python\">def create_data_model():     data = {}     data[\"time_matrix\"] = [         [0, 6, 0, 6, 5, 6, 7, 6, 8, 2, 9, 2, 4, 9, 9, 4, 9, 9],         [6, 0, 6, 0, 2, 2, 2, 1, 3, 3, 4, 3, 7, 11, 4, 4, 12, 12],         [0, 6, 0, 6, 5, 6, 7, 6, 8, 2, 9, 2, 4, 9, 9, 4, 9, 9],         [6, 0, 6, 0, 2, 2, 2, 1, 3, 3, 4, 3, 7, 11, 4, 4, 12, 12],         [6, 0, 6, 0, 0, 2, 3, 2, 4, 4, 5, 3, 7, 10, 5, 3, 12, 12],         [9, 4, 9, 4, 3, 0, 1, 2, 1, 6, 3, 6, 9, 12, 3, 6, 14, 14],         [8, 4, 8, 4, 3, 2, 0, 1, 2, 5, 2, 5, 9, 12, 2, 5, 14, 14],         [7, 2, 7, 2, 2, 0, 1, 0, 1, 4, 3, 4, 8, 11, 3, 4, 13, 13],         [9, 4, 9, 4, 4, 2, 0, 2, 0, 6, 2, 6, 10, 13, 2, 6, 14, 14],         [2, 5, 2, 5, 5, 4, 5, 4, 5, 0, 7, 3, 3, 10, 7, 6, 11, 11],         [8, 4, 8, 4, 3, 2, 0, 1, 2, 5, 0, 5, 9, 12, 0, 5, 14, 14],         [3, 4, 3, 4, 4, 4, 5, 4, 6, 2, 7, 0, 5, 9, 7, 3, 10, 10],         [1, 7, 1, 7, 6, 6, 7, 6, 7, 2, 9, 4, 0, 9, 9, 5, 9, 9],         [10, 11, 10, 11, 11, 13, 14, 13, 14, 10, 16, 10, 11, 0, 16, 9, 6, 6],         [8, 4, 8, 4, 3, 2, 0, 1, 2, 5, 0, 5, 9, 12, 0, 5, 14, 14],         [7, 5, 7, 5, 4, 6, 6, 5, 7, 5, 8, 4, 9, 9, 8, 0, 10, 10],         [10, 12, 10, 12, 12, 14, 15, 14, 14, 10, 17, 10, 12, 4, 17, 10, 0, 0],         [10, 12, 10, 12, 12, 14, 15, 14, 14, 10, 17, 10, 12, 4, 17, 10, 0, 0],     ]     data[\"num_vehicles\"] = 2     data[\"starts\"] = [0, 1]     data[\"ends\"] = [16, 17]     data[\"pickups_deliveries\"] = [(10, 11), (12, 13), (14, 15)]     data[\"obligations\"] = [         0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, None, None, 0, 1     ]     data[\"demands\"] = [         0, 0, 3, 3, -1, -1, -1, -1, -1, -1, 1, -1, 1, -1, 1, -1, 0, 0     ]     data[\"vehicle_capacities\"] = [8, 8]     data[\"point_types\"] = [         \"start\", \"start\", \"onboard\", \"onboard\", \"delivery\", \"delivery\",         \"delivery\", \"delivery\", \"delivery\", \"delivery\", \"pickup\", \"delivery\",         \"pickup\", \"delivery\", \"pickup\", \"delivery\", \"finish\", \"finish\",     ]     data[\"time_windows\"] = [         (0, 0), (0, 0), (0, 0), (0, 0), (0, 9), (0, 11), (0, 11), (0, 4),          (0, 4), (0, 10), (8, 15), (0, 23), (9, 17), (0, 32), (4, 30), (9, 45),         (0, 79), (0, 119),     ]     data[\"disjunction\"] = [(14, 15)]     data[\"initial_routes\"] = [[2, 4, 6, 5, 10, 11], [3, 8, 7, 9, 12, 13]]     return data <\/code><\/pre>\n<p>\u0413\u0434\u0435:<\/p>\n<ul>\n<li>\n<p>time_matrix: \u041c\u0430\u0441\u0441\u0438\u0432 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043c\u0435\u0436\u0434\u0443 \u043b\u043e\u043a\u0430\u0446\u0438\u044f\u043c\u0438 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445;<\/p>\n<\/li>\n<li>\n<p>num_vehicles: \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0422\u0421 \u0432 \u0430\u0432\u0442\u043e\u043f\u0430\u0440\u043a\u0435;<\/p>\n<\/li>\n<li>\n<p>starts: \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0443\u0437\u043b\u043e\u0432, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0422\u0421 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442 \u043c\u0430\u0440\u0448\u0440\u0443\u0442;<\/p>\n<\/li>\n<li>\n<p>ends: \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0443\u0437\u043b\u043e\u0432, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0422\u0421 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u044e\u0442 \u043c\u0430\u0440\u0448\u0440\u0443\u0442;<\/p>\n<\/li>\n<li>\n<p>pickups_deliveries: \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0443\u0437\u043b\u043e\u0432, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0437\u0430\u0434\u0430\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 &#8212; \u043f\u043e\u0441\u0430\u0434\u043a\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0440\u0430\u043d\u044c\u0448\u0435 \u0432\u044b\u0441\u0430\u0434\u043a\u0438 \u043f\u0430\u0441\u0441\u0430\u0436\u0438\u0440\u0430;<\/p>\n<\/li>\n<li>\n<p>obligation: \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0422\u0421 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0443\u0437\u043b\u0430 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0430 (\u0434\u043b\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u0430\u0441\u0441\u0430\u0436\u0438\u0440\u0430 = None);<\/p>\n<\/li>\n<li>\n<p>demands: \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438 \u0422\u0421 \u043f\u0440\u0438 \u043f\u043e\u0441\u0435\u0449\u0435\u043d\u0438\u0438 \u0443\u0437\u043b\u0430;<\/p>\n<\/li>\n<li>\n<p>vehicle_capacities: \u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c \u0422\u0421;<\/p>\n<\/li>\n<li>\n<p>point_types: \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440, \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u0442\u0438\u043f \u0443\u0437\u043b\u0430;<\/p>\n<\/li>\n<li>\n<p>time_windows: \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0441\u0435\u0442\u0438\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u0443\u0437\u0435\u043b \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0430;<\/p>\n<\/li>\n<li>\n<p>disjunction: \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0443\u0437\u043b\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u0431\u0440\u0430\u0442\u044c \u0438\u0437 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u044f \u0441\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u044f;<\/p>\n<\/li>\n<li>\n<p>initial_routes: \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u044b \u0422\u0421 \u0434\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<\/li>\n<\/ul>\n<h2>Python \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/h2>\n<p>\u041d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0441 \u0432\u044b\u0437\u043e\u0432\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0437\u0434\u0430\u0435\u0442 data.<\/p>\n<pre><code class=\"python\">data = create_data_model()<\/code><\/pre>\n<p>\u041e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u043c <strong>\u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432<\/strong> (manager) \u0438 <strong>\u043c\u043e\u0434\u0435\u043b\u044c \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u043b\u0438 \u0441\u043e\u043b\u0432\u0435\u0440<\/strong> (routing).<\/p>\n<pre><code class=\"python\">manager = pywrapcp.RoutingIndexManager(     len(data[\"time_matrix\"]), data[\"num_vehicles\"], data[\"starts\"], data[\"ends\"] ) routing = pywrapcp.RoutingModel(manager)<\/code><\/pre>\n<p><strong>\u041c\u0435\u043d\u0435\u0434\u0436\u0435\u0440 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432<\/strong> \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c, \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0432\u0435\u0441\u0442\u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0435 \u0432 data \u0432 \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0441\u043e\u043b\u0432\u0435\u0440\u0430. \u041c\u0435\u043d\u0435\u0434\u0436\u0435\u0440 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<ol>\n<li>\n<p>\u0423\u0437\u043b\u044b, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0422\u0421 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442 \u043c\u0430\u0440\u0448\u0440\u0443\u0442;<\/p>\n<\/li>\n<li>\n<p>\u0412\u0441\u0435 \u0434\u0440\u0443\u0433\u0438\u0435 \u0443\u0437\u043b\u044b;<\/p>\n<\/li>\n<li>\n<p>\u0423\u0437\u043b\u044b, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0422\u0421 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442 \u043c\u0430\u0440\u0448\u0440\u0443\u0442.<\/p>\n<\/li>\n<\/ol>\n<p>\u041c\u044b \u0441 \u0432\u0430\u043c\u0438 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0438\u043b\u0438 \u0443\u0437\u043b\u044b \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0438\u043d\u0434\u0435\u043a\u0441\u044b, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0435 \u0432 data \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u043b\u0438 \u0441 \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u043c\u0438 \u0441\u043e\u043b\u0432\u0435\u0440\u0430.<\/p>\n<h3>\u041e\u0431\u0440\u0430\u0442\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 (callback)<\/h3>\n<p>\u0427\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u043b\u0432\u0435\u0440 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0438\u0437\u0430\u0446\u0438\u0438, \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c\u00a0<strong>\u043e\u0431\u0440\u0430\u0442\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 (callback) \u0432\u0440\u0435\u043c\u0435\u043d\u0438 (\u0438\u043b\u0438 \u0442\u0440\u0430\u043d\u0437\u0438\u0442\u0430)<\/strong>\u00a0&#8212; \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043b\u044e\u0431\u0443\u044e \u043f\u0430\u0440\u0443 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 \u0443\u0437\u043b\u043e\u0432 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0432\u0440\u0435\u043c\u044f \u0442\u0440\u0430\u043d\u0437\u0438\u0442\u0430 \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438. <br \/>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0441\u043e\u0437\u0434\u0430\u0435\u0442 callback \u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u0435\u0433\u043e \u0432 \u0440\u0435\u0448\u0430\u0442\u0435\u043b\u0435 \u043a\u0430\u043a\u00a0<strong>transit_callback_index<\/strong>. \u0418 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u0443\u044e \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u0442\u0440\u0430\u043d\u0437\u0438\u0442\u0430 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043c\u0430\u0448\u0438\u043d.<\/p>\n<pre><code class=\"python\">def time_callback(from_index, to_index):     from_node = manager.IndexToNode(from_index)     to_node = manager.IndexToNode(to_index)     return data[\"time_matrix\"][from_node][to_node]  transit_callback_index = routing.RegisterTransitCallback(time_callback) routing.SetArcCostEvaluatorOfAllVehicles(transit_callback_index)<\/code><\/pre>\n<h3>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0435 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u0435:<\/h3>\n<p>\u0414\u0430\u043d\u043d\u044b\u0435 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043b\u044f \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043e\u043a\u043e\u043d.<\/p>\n<pre><code class=\"python\">routing.AddDimension(     evaluator_index=transit_callback_index,     slack_max=8 * 60,  # allow waiting time     capacity=8 * 60,  # maximum time per vehicle     fix_start_cumul_to_zero=False,     name=\"Time\", ) time_dimension = routing.GetDimensionOrDie(\"Time\")<\/code><\/pre>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b AddDimension:<\/p>\n<ul>\n<li>\n<p>slack_max &#8212; \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043f\u0440\u0438\u0431\u044b\u0442\u0438\u044f \u0432 \u0443\u0437\u0435\u043b \u0440\u0430\u043d\u044c\u0448\u0435 \u043b\u0435\u0432\u043e\u0439 \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u043e\u043a\u043d\u0430; <\/p>\n<\/li>\n<li>\n<p>capacity &#8212; \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438<\/p>\n<\/li>\n<li>\n<p>fix_start_cumul_to_zero &#8212; \u0415\u0441\u043b\u0438 True \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u044b\u0439 \u0443\u0437\u0435\u043b \u043e\u0431\u044f\u0437\u0430\u043d \u0438\u043c\u0435\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 0. <\/p>\n<\/li>\n<\/ul>\n<h3>\u0412\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043e\u043a\u043d\u0430<\/h3>\n<h4>\u0424\u0438\u0447\u0430 \u21161<\/h4>\n<p>\u041d\u0430\u0437\u043e\u0432\u0435\u043c \u044d\u0442\u043e \u043d\u0435 \u0431\u0430\u0433, \u0430 \u0444\u0438\u0447\u0430. \u0414\u043b\u044f \u0442\u043e\u0447\u0435\u043a \u0444\u0438\u043d\u0438\u0448\u0430 \u0422\u0421 <strong>manager.NodeToIndex(ind) <\/strong>\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 -1, \u0430 \u043a\u0430\u043a \u0432\u044b \u0443\u0436\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442\u0435 \u0443\u0437\u043b\u0430 \u0441 \u0442\u0430\u043a\u0438\u043c \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c \u043d\u0435\u0442. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u0437 \u0441\u043b\u043e\u0436\u0438\u0432\u0448\u0435\u0439\u0441\u044f \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0439\u0442\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <strong>routing.End(obligations[ind])<\/strong>. \u0414\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0432\u0435\u0440\u043d\u0435\u0442 \u0438\u043d\u0434\u0435\u043a\u0441 \u0443\u0437\u043b\u0430 \u0444\u0438\u043d\u0438\u0448\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u0422\u0421.<\/p>\n<pre><code class=\"python\">def get_index(     manager: RoutingIndexManager,     ind: int,     routing: RoutingModel,     obligations: list[int | None], ) -> int:     if manager.NodeToIndex(ind) != -1:         index_node = manager.NodeToIndex(ind)     else:         index_node = routing.End(obligations[ind])     return index_node<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043e\u043a\u043d\u0430:<\/p>\n<p>\u0422\u0430\u043a \u0437\u0430\u0434\u0430\u044e\u0442\u0441\u044f \u0436\u0435\u0441\u0442\u043a\u0438\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043d\u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043e\u043a\u043d\u0430. \u0412 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0445\u043e\u0442\u044c \u043e\u0434\u043d\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043d\u0430\u0440\u0443\u0448\u0430\u0435\u0442\u0441\u044f, \u0442\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0435 \u0441\u0445\u043e\u0434\u0438\u0442\u0441\u044f. \u0410 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u044d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u043e \u0432\u0432\u0438\u0434\u0443 \u043e\u043f\u043e\u0437\u0434\u0430\u043d\u0438\u0439 \u0422\u0421.<\/p>\n<pre><code class=\"python\">def time_window_constr(     data: dict[str, Any],     manager: RoutingIndexManager,     routing: RoutingModel,     time_dimension: RoutingDimension, ) -> None:     for ind, (pt, tw) in enumerate(data[\"time_windows\"]):         index = get_index(manager, ind, routing, data[\"obligations\"])         time_dimension.CumulVar(index).SetRange(tw[0], tw[1])<\/code><\/pre>\n<h4>\u0424\u0438\u0447\u0430 \u21162<\/h4>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0441 \u0432\u0430\u043c\u0438 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u043c\u044f\u0433\u043a\u0438\u0435 \u043e\u043a\u043d\u0430. \u041e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0436\u0435\u0441\u0442\u043a\u0438\u0445 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u0440\u0438 \u043d\u0430\u0440\u0443\u0448\u0435\u043d\u0438\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0432 \u0446\u0435\u043b\u0435\u0432\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0448\u0442\u0440\u0430\u0444 \u0437\u0430 \u043a\u0430\u0436\u0434\u0443\u044e \u0435\u0434\u0438\u043d\u0438\u0446\u0443, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u043f\u0440\u0435\u0432\u044b\u0441\u0438\u043b\u0438 \u043f\u043e\u0440\u043e\u0433\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435.<\/p>\n<ul>\n<li>\n<p>\u0414\u043b\u044f \u0432\u0435\u0440\u0445\u043d\u0435\u0439 \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u043e\u043a\u043d\u0430: <em>cost = <\/em>penalty<em> * (cumulVar &#8212; upper_bound)<\/em><\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u043b\u0435\u0432\u043e\u0439 \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u043e\u043a\u043d\u0430:  <em>cost = coefficient * (lower_bound &#8212; cumulVar)<\/em><\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"python\">def time_window_constr(     data: dict[str, Any],     manager: RoutingIndexManager,     routing: RoutingModel,     time_dimension: RoutingDimension,     penalty: int = 10000 ) -> None:     for ind, (pt, tw) in enumerate(zip(data[\"point_types\"], data[\"time_windows\"])):         index = get_index(manager, ind, routing, data[\"obligations\"])         if pt not in (\"delivery\", \"finish\"):             time_dimension.SetCumulVarSoftLowerBound(index, tw[0], int(10e6))         time_dimension.SetCumulVarSoftUpperBound(index, tw[1], penalty * 2)<\/code><\/pre>\n<h4>\u0424\u0438\u0447\u0430 \u21163<\/h4>\n<p>\u0421\u043e\u043b\u0432\u0435\u0440 \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 ortools \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u043d \u043f\u043e\u043f\u0430\u0441\u0442\u044c \u0432 \u043a\u0430\u0436\u0434\u044b\u0439 \u0443\u0437\u0435\u043b \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u043b\u0438\u0436\u0435 \u043a \u043b\u0435\u0432\u043e\u0439 \u0433\u0440\u0430\u043d\u0438\u0446\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u043e\u043a\u043d\u0430. \u041e\u043d \u043b\u0438\u0448\u044c \u043e\u0431\u044f\u0437\u0443\u0435\u0442\u0441\u044f \u043d\u0435 \u0432\u044b\u0445\u043e\u0434\u0438\u0442\u044c \u0437\u0430 \u0440\u0430\u043c\u043a\u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u043e\u043a\u043d\u0430. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0448\u0442\u0440\u0430\u0444:<\/p>\n<pre><code class=\"python\">span_coef = 100 time_dimension.SetSpanCostCoefficientForAllVehicles(span_coef)<\/code><\/pre>\n<p><em>span_cost = <\/em>span_coef<em> * (dimension end value &#8212; dimension start value)<\/em><\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, <em>span_cost <\/em>\u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0432 \u0446\u0435\u043b\u0435\u0432\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438 \u0441\u043e\u043b\u0432\u0435\u0440 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u0435\u0449\u0430\u0442\u044c \u0443\u0437\u043b\u044b \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u043b\u0438\u0436\u0435 \u043a \u043b\u0435\u0432\u043e\u0439 \u0433\u0440\u0430\u043d\u0438\u0446\u0435.<\/p>\n<h3>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0443\u0437\u043b\u043e\u0432<\/h3>\n<p>\u0427\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u0438\u0437-\u0437\u0430 \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u0430\u0441\u0441\u0430\u0436\u0438\u0440\u0430 \u043d\u0435 \u0441\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f? \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e, \u0435\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u0443\u0431\u0440\u0430\u0442\u044c \u0438\u0437 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438. \u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e AddDisjunction.<\/p>\n<pre><code class=\"python\">def disjunction_constr(     data: dict[str, Any],     manager: RoutingIndexManager,     routing: RoutingModel,     penalty: int = 10000 ) -> None:     for pickup, delivery in data[\"disjunction\"]:         node_ids = [manager.NodeToIndex(pickup), manager.NodeToIndex(delivery)]         routing.AddDisjunction(node_ids, penalty, 2)<\/code><\/pre>\n<p>\u0412 AddDisjunction &#8212; \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0432 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044e \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0442\u0441\u044f \u043b\u0438\u0431\u043e \u043e\u0431\u0430 \u0443\u0437\u043b\u0430 \u043b\u0438\u0431\u043e \u043d\u0438 \u043e\u0434\u0438\u043d \u0438\u0437 \u043d\u0438\u0445. \u041e\u0434\u043d\u0430\u043a\u043e \u0437\u0430 \u043d\u0435\u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0432 \u043c\u0430\u0440\u0448\u0440\u0443\u0442 \u044d\u0442\u0438\u0445 \u0443\u0437\u043b\u043e\u0432 \u0432 \u0446\u0435\u043b\u0435\u0432\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0448\u0442\u0440\u0430\u0444 \u0440\u0430\u0432\u043d\u044b\u0439  <em>penalty * \u043a\u043e\u043b-\u0432\u043e \u0432\u044b\u043a\u0438\u043d\u0443\u0442\u044b\u0445 \u0443\u0437\u043b\u043e\u0432. <\/em>\u042d\u0442\u043e \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u043c\u044f\u0433\u043a\u0438\u043c\u0438 \u043e\u043a\u043d\u0430\u043c\u0438, \u0442\u0430\u043a \u043a\u0430\u043a \u0443 \u043d\u0438\u0445 \u0437\u0430 \u043f\u0440\u0435\u0432\u044b\u0448\u0435\u043d\u0438\u0435 \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u043e\u043a\u043d\u0430 \u043d\u0430 \u043e\u0434\u043d\u0443 \u0435\u0434\u0438\u043d\u0438\u0446\u0443 \u043d\u0430\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u0447\u043d\u043e \u0442\u0430\u043a\u043e\u0439 \u0436\u0435 \u0448\u0442\u0440\u0430\u0444. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440 \u0432\u043a\u043b\u044e\u0447\u0438\u0442 \u0432 \u043c\u0430\u0440\u0448\u0440\u0443\u0442 \u043d\u043e\u0432\u044b\u0439 \u0437\u0430\u043a\u0430\u0437 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u043d\u0435 \u043d\u0430\u0440\u0443\u0448\u0430\u0435\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043e\u043a\u043d\u0430.<\/p>\n<h3>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 AddPickupAndDelivery <\/h3>\n<pre><code class=\"python\">def pickup_delivery_constr(     data: dict[str, Any],     manager: RoutingIndexManager,     routing: RoutingModel,     time_dimension: RoutingDimension, ) -> None:     for pickup, delivery in data[\"pickups_deliveries\"]:         pickup_index = get_index(manager, pickup, routing, data[\"obligations\"])         delivery_index = get_index(manager, delivery, routing, data[\"obligations\"])         # \u0423\u0441\u043a\u043e\u0440\u044f\u0435\u0442 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044e         routing.AddPickupAndDelivery(pickup_index, delivery_index)         # pickup \u0438 delivery \u043d\u0430 \u043e\u0434\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u0435 \u0438 \u0430\u043a\u0442\u0438\u0432\u043d\u044b         routing.solver().Add(             routing.ActiveVar(pickup_index) * routing.VehicleVar(pickup_index)             == routing.ActiveVar(delivery_index) * routing.VehicleVar(delivery_index)         )         # pickup \u043c\u0435\u043d\u044c\u0448\u0435 \u0438\u043b\u0438 \u0440\u0430\u0432\u0435\u043d delivery \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438         routing.solver().Add(             time_dimension.CumulVar(pickup_index)             &lt;= time_dimension.CumulVar(delivery_index)         ) <\/code><\/pre>\n<h3>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 \u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c \u0422\u0421<\/h3>\n<pre><code class=\"python\">def capacity_constr(data: dict, manager: RoutingIndexManager, routing: RoutingModel) -> None:     def demand_callback(from_index):         from_node = manager.IndexToNode(from_index)         return data[\"demands\"][from_node]      demand_callback_index = routing.RegisterUnaryTransitCallback(demand_callback)     routing.AddDimensionWithVehicleCapacity(         evaluator_index=demand_callback_index,         slack_max=0,  # null capacity slack         vehicle_capacities=data[\"vehicle_capacities\"],  # vehicle maximum capacities         fix_start_cumul_to_zero=True,  # start cumul to zero         name=\"Capacity\",     )<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c callback \u043d\u0430 \u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c. \u041d\u0430\u043f\u043e\u043c\u043d\u0438\u043c \u0432\u0430\u043c \u043a\u0430\u043a \u043e\u043d \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"python\">data[\"demands\"] = [     0, 0, 3, 3, -1, -1, -1, -1, -1, -1, 1, -1, 1, -1, 1, -1, 0, 0 ] data[\"point_types\"] = [     \"start\", \"start\", \"onboard\", \"onboard\", \"delivery\", \"delivery\",     \"delivery\", \"delivery\", \"delivery\", \"delivery\", \"pickup\", \"delivery\",     \"pickup\", \"delivery\", \"pickup\", \"delivery\", \"finish\", \"finish\", ] data[\"vehicle_capacities\"] = [8, 8]<\/code><\/pre>\n<h4>\u0424\u0438\u0447\u0430 \u21164<\/h4>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 2 \u0443\u0437\u043b\u0430 \u0441 \u0442\u0438\u043f\u043e\u043c &#171;onboard&#187;. \u0414\u043b\u044f \u0447\u0435\u0433\u043e \u043e\u043d\u0438 \u043d\u0443\u0436\u043d\u044b? \u0421\u043d\u043e\u0432\u0430 \u043d\u0435 \u0431\u0430\u0433, \u0430 \u0444\u0438\u0447\u0430.<\/p>\n<p>\u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0443\u0447\u0435\u0441\u0442\u044c \u0432 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0438 \u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438 \u0442\u0435\u0445 \u043f\u0430\u0441\u0441\u0430\u0436\u0438\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u0436\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u0422\u0421. \u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u0442\u0435, \u0434\u0430\u043d\u043d\u044b\u0439 demand \u043a \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u044b\u043c \u0443\u0437\u043b\u0430\u043c, \u0442\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0432\u044b\u0441\u0430\u0434\u043a\u0443 \u043f\u0430\u0441\u0441\u0430\u0436\u0438\u0440\u043e\u0432 (demand = -1). \u041e\u0434\u043d\u0430\u043a\u043e \u0432\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0444\u0438\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u0443\u0437\u043b\u043e\u0432,  \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u0442\u0441\u044f demand, \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0440\u0435\u0448\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u0443\u044e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443, \u0438 \u0434\u0430\u0435\u0442 \u043d\u0430\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u044b.<\/p>\n<h3>\u0417\u0430\u043a\u0440\u0435\u043f\u043b\u0435\u043d\u0438\u0435 \u0443\u0437\u043b\u043e\u0432 \u0437\u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u043c \u0422\u0421 <\/h3>\n<p>\u0418\u0442\u0430\u043a, \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0437\u0430\u043a\u0440\u0435\u043f\u043b\u044f\u0435\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0443\u0437\u0435\u043b \u0437\u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u043c \u0422\u0421.<\/p>\n<pre><code class=\"python\">def obligation_constr(     data: dict[str, Any],     manager: RoutingIndexManager,     routing: RoutingModel ) -> None:     for node_idx, obligation in enumerate(data[\"obligations\"]):         index = get_index(manager, node_idx, routing, data[\"obligations\"])         if obligation is not None:             routing.VehicleVar(index).SetValue(obligation)<\/code><\/pre>\n<p>\u0414\u043b\u044f \u0447\u0435\u0433\u043e \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0443\u0436\u043d\u043e? \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043a\u0440\u0435\u043f\u0438\u0442\u044c \u0443\u0437\u043b\u044b \u043f\u0430\u0441\u0441\u0430\u0436\u0438\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u0422\u0421. \u041f\u0440\u0430\u0432\u0434\u0430, \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u0437\u0430\u043a\u0440\u0435\u043f\u043b\u044f\u0435\u043c \u0443\u0437\u043b\u044b \u0432\u0441\u0435\u0445 \u043f\u0430\u0441\u0441\u0430\u0436\u0438\u0440\u043e\u0432 \u0437\u0430 \u043a\u0430\u043a\u0438\u043c-\u043b\u0438\u0431\u043e \u0422\u0421, \u043a\u0440\u043e\u043c\u0435 \u043d\u043e\u0432\u043e\u0433\u043e.<\/p>\n<h3>\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043f\u043e\u0438\u0441\u043a\u0430<\/h3>\n<p>\u041e\u0431\u044a\u044f\u0432\u0438\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043f\u043e\u0438\u0441\u043a\u0430:<\/p>\n<ul>\n<li>\n<p>8 (PARALLEL_CHEAPEST_INSERTION) \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/p>\n<\/li>\n<li>\n<p>2 (GUIDEDLOCALSEARCH) \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f \u0434\u043b\u044f \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/p>\n<\/li>\n<li>\n<p>500 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439<\/p>\n<\/li>\n<li>\n<p>3 \u0441\u0435\u043a\u0443\u043d\u0434\u044b \u043d\u0430 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044e<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"python\">def get_search_params() -> DefaultRoutingSearchParameters:     search_parameters = pywrapcp.DefaultRoutingSearchParameters()     search_parameters.first_solution_strategy = 8     search_parameters.local_search_metaheuristic = 2     search_parameters.solution_limit = 500     search_parameters.time_limit.seconds = 3     return search_parameters<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432\u0435\u0441\u044c \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0439 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e <a href=\"https:\/\/developers.google.com\/optimization\/routing\/routing_options\" rel=\"noopener noreferrer nofollow\">\u0442\u0443\u0442<\/a>.<\/p>\n<h4>\u041f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u0432\u0441\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/h4>\n<pre><code class=\"python\">routing.CloseModelWithParameters(search_parameters)<\/code><\/pre>\n<h3>\u041d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435<\/h3>\n<p>\u041a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u0434\u043b\u044f \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0431\u0435\u0437 \u043d\u043e\u0432\u044b\u0445 \u043f\u0430\u0441\u0441\u0430\u0436\u0438\u0440\u043e\u0432.<\/p>\n<pre><code class=\"python\">initial_solution = routing.ReadAssignmentFromRoutes(     data[\"initial_routes\"], True )<\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u0441\u043e\u043b\u0432\u0435\u0440 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043f\u043e\u0438\u0441\u043a\u0430 \u0438 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435.<\/p>\n<h3>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/h3>\n<pre><code class=\"python\">def print_solution(data, manager, routing, solution):     print(f\"Objective: {solution.ObjectiveValue()}\")     max_route_duration = 0      for vehicle_id in range(data[\"num_vehicles\"]):         plan_output = f\"Route for vehicle {vehicle_id}:\\n\"         index = routing.Start(vehicle_id)         route_duration = 0         while not routing.IsEnd(index):             plan_output += f\" {manager.IndexToNode(index)} -> \"             next_index = solution.Value(routing.NextVar(index))             route_duration += data[\"time_matrix\"][index][next_index]             index = next_index         plan_output += f\"{manager.IndexToNode(next_index)}\\n\"         plan_output += f\"Time of the route: {route_duration} minutes \\n\"         max_route_duration = max(route_duration, max_route_duration)         print(plan_output)      print(f\"Maximum of the route: {max_route_duration} minutes\")<\/code><\/pre>\n<h2>\u0418\u0442\u043e\u0433<\/h2>\n<details class=\"spoiler\">\n<summary>\u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">from typing import Any  from ortools.constraint_solver import pywrapcp from ortools.constraint_solver.pywrapcp import (     DefaultRoutingSearchParameters, RoutingDimension, RoutingIndexManager,     RoutingModel, )   def create_data_model():     data = {}     data[\"time_matrix\"] = [         [0, 6, 0, 6, 5, 6, 7, 6, 8, 2, 9, 2, 4, 9, 9, 4, 9, 9],         [6, 0, 6, 0, 2, 2, 2, 1, 3, 3, 4, 3, 7, 11, 4, 4, 12, 12],         [0, 6, 0, 6, 5, 6, 7, 6, 8, 2, 9, 2, 4, 9, 9, 4, 9, 9],         [6, 0, 6, 0, 2, 2, 2, 1, 3, 3, 4, 3, 7, 11, 4, 4, 12, 12],         [6, 0, 6, 0, 0, 2, 3, 2, 4, 4, 5, 3, 7, 10, 5, 3, 12, 12],         [9, 4, 9, 4, 3, 0, 1, 2, 1, 6, 3, 6, 9, 12, 3, 6, 14, 14],         [8, 4, 8, 4, 3, 2, 0, 1, 2, 5, 2, 5, 9, 12, 2, 5, 14, 14],         [7, 2, 7, 2, 2, 0, 1, 0, 1, 4, 3, 4, 8, 11, 3, 4, 13, 13],         [9, 4, 9, 4, 4, 2, 0, 2, 0, 6, 2, 6, 10, 13, 2, 6, 14, 14],         [2, 5, 2, 5, 5, 4, 5, 4, 5, 0, 7, 3, 3, 10, 7, 6, 11, 11],         [8, 4, 8, 4, 3, 2, 0, 1, 2, 5, 0, 5, 9, 12, 0, 5, 14, 14],         [3, 4, 3, 4, 4, 4, 5, 4, 6, 2, 7, 0, 5, 9, 7, 3, 10, 10],         [1, 7, 1, 7, 6, 6, 7, 6, 7, 2, 9, 4, 0, 9, 9, 5, 9, 9],         [10, 11, 10, 11, 11, 13, 14, 13, 14, 10, 16, 10, 11, 0, 16, 9, 6, 6],         [8, 4, 8, 4, 3, 2, 0, 1, 2, 5, 0, 5, 9, 12, 0, 5, 14, 14],         [7, 5, 7, 5, 4, 6, 6, 5, 7, 5, 8, 4, 9, 9, 8, 0, 10, 10],         [10, 12, 10, 12, 12, 14, 15, 14, 14, 10, 17, 10, 12, 4, 17, 10, 0, 0],         [10, 12, 10, 12, 12, 14, 15, 14, 14, 10, 17, 10, 12, 4, 17, 10, 0, 0],     ]     data[\"num_vehicles\"] = 2     data[\"starts\"] = [0, 1]     data[\"ends\"] = [16, 17]     data[\"pickups_deliveries\"] = [(10, 11), (12, 13), (14, 15)]     data[\"obligations\"] = [         0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, None, None, 0, 1     ]     data[\"demands\"] = [         0, 0, 3, 3, -1, -1, -1, -1, -1, -1, 1, -1, 1, -1, 1, -1, 0, 0     ]     data[\"vehicle_capacities\"] = [8, 8]     data[\"point_types\"] = [         \"start\", \"start\", \"onboard\", \"onboard\", \"delivery\", \"delivery\",         \"delivery\", \"delivery\", \"delivery\", \"delivery\", \"pickup\", \"delivery\",         \"pickup\", \"delivery\", \"pickup\", \"delivery\", \"finish\", \"finish\",     ]     data[\"time_windows\"] = [         (0, 0), (0, 0), (0, 0), (0, 0), (0, 9), (0, 11), (0, 11), (0, 4),         (0, 4), (0, 10), (8, 15), (0, 23), (9, 17), (0, 32), (4, 30), (9, 45),         (0, 79), (0, 119),     ]     data[\"disjunction\"] = [(14, 15)]     data[\"initial_routes\"] = [[2, 4, 6, 5, 10, 11], [3, 8, 7, 9, 12, 13]]     return data  def add_time_dimension(     data: dict[str, Any], manager: RoutingIndexManager, routing: RoutingModel ) -> RoutingDimension:     def time_callback(from_index, to_index):         from_node = manager.IndexToNode(from_index)         to_node = manager.IndexToNode(to_index)         return data[\"time_matrix\"][from_node][to_node]      transit_callback_index = routing.RegisterTransitCallback(time_callback)     routing.AddDimension(         evaluator_index=transit_callback_index,         slack_max=8 * 60,  # allow waiting time         capacity=8 * 60,  # maximum time per vehicle         fix_start_cumul_to_zero=False,  # force start cumul to zero         name=\"Time\",     )     time_dimension = routing.GetDimensionOrDie(\"Time\")     routing.SetArcCostEvaluatorOfAllVehicles(transit_callback_index)     time_dimension.SetSpanCostCoefficientForAllVehicles(100)     return time_dimension  def get_index(     manager: RoutingIndexManager,     ind: int,     routing: RoutingModel,     obligations: list[int | None], ) -> int:     if manager.NodeToIndex(ind) != -1:         index_node = manager.NodeToIndex(ind)     else:         index_node = routing.End(obligations[ind])     return index_node  def time_window_constr(     data: dict[str, Any],     manager: RoutingIndexManager,     routing: RoutingModel,     time_dimension: RoutingDimension,     penalty: int = 10000 ) -> None:     for ind, (pt, tw) in enumerate(zip(data[\"point_types\"], data[\"time_windows\"])):         index = get_index(manager, ind, routing, data[\"obligations\"])         if pt not in (\"delivery\", \"finish\"):             time_dimension.SetCumulVarSoftLowerBound(index, tw[0], int(10e6))         time_dimension.SetCumulVarSoftUpperBound(index, tw[1], penalty * 2)   def disjunction_constr(     data: dict[str, Any],     manager: RoutingIndexManager,     routing: RoutingModel,     penalty: int = 10000 ) -> None:     for pickup, delivery in data[\"disjunction\"]:         node_ids = [manager.NodeToIndex(pickup), manager.NodeToIndex(delivery)]         routing.AddDisjunction(node_ids, penalty, 2)   def pickup_delivery_constr(     data: dict[str, Any],     manager: RoutingIndexManager,     routing: RoutingModel,     time_dimension: RoutingDimension, ) -> None:     for pickup, delivery in data[\"pickups_deliveries\"]:         pickup_index = get_index(manager, pickup, routing, data[\"obligations\"])         delivery_index = get_index(manager, delivery, routing, data[\"obligations\"])         # \u0423\u0441\u043a\u043e\u0440\u044f\u0435\u0442 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044e         routing.AddPickupAndDelivery(pickup_index, delivery_index)         # pickup \u0438 delivery \u043d\u0430 \u043e\u0434\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u0435 \u0438 \u0430\u043a\u0442\u0438\u0432\u043d\u044b         routing.solver().Add(             routing.ActiveVar(pickup_index) * routing.VehicleVar(pickup_index)             == routing.ActiveVar(delivery_index) * routing.VehicleVar(delivery_index)         )         # pickup \u043c\u0435\u043d\u044c\u0448\u0435 \u0438\u043b\u0438 \u0440\u0430\u0432\u0435\u043d delivery \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438         routing.solver().Add(             time_dimension.CumulVar(pickup_index)             &lt;= time_dimension.CumulVar(delivery_index)         )  def capacity_constr(     data: dict[str, Any],     manager: RoutingIndexManager,     routing: RoutingModel ) -> None:     def demand_callback(from_index):         from_node = manager.IndexToNode(from_index)         return data[\"demands\"][from_node]      demand_callback_index = routing.RegisterUnaryTransitCallback(demand_callback)     routing.AddDimensionWithVehicleCapacity(         evaluator_index=demand_callback_index,         slack_max=0,  # null capacity slack         vehicle_capacities=data[\"vehicle_capacities\"],  # vehicle maximum capacities         fix_start_cumul_to_zero=True,  # start cumul to zero         name=\"Capacity\",     )   def obligation_constr(     data: dict[str, Any],     manager: RoutingIndexManager,     routing: RoutingModel ) -> None:     for node_idx, obligation in enumerate(data[\"obligations\"]):         index = get_index(manager, node_idx, routing, data[\"obligations\"])         if obligation is not None:             routing.VehicleVar(index).SetValue(obligation)   def get_search_params() -> DefaultRoutingSearchParameters:     search_parameters = pywrapcp.DefaultRoutingSearchParameters()     search_parameters.first_solution_strategy = 8     search_parameters.local_search_metaheuristic = 2     search_parameters.solution_limit = 500     search_parameters.time_limit.seconds = 3     return search_parameters   def print_solution(data, manager, routing, solution):     print(f\"Objective: {solution.ObjectiveValue()}\")     max_route_duration = 0      for vehicle_id in range(data[\"num_vehicles\"]):         plan_output = f\"Route for vehicle {vehicle_id}:\\n\"         index = routing.Start(vehicle_id)         route_duration = 0         while not routing.IsEnd(index):             plan_output += f\" {manager.IndexToNode(index)} -> \"             next_index = solution.Value(routing.NextVar(index))             route_duration += data[\"time_matrix\"][index][next_index]             index = next_index         plan_output += f\"{manager.IndexToNode(next_index)}\\n\"         plan_output += f\"Time of the route: {route_duration} minutes \\n\"         max_route_duration = max(route_duration, max_route_duration)         print(plan_output)      print(f\"Maximum of the route: {max_route_duration} minutes\")     if __name__ == \"__main__\":     data = create_data_model()     manager = pywrapcp.RoutingIndexManager(         len(data[\"time_matrix\"]), data[\"num_vehicles\"], data[\"starts\"], data[\"ends\"]     )     routing = pywrapcp.RoutingModel(manager)      # constraints     time_dimension = add_time_dimension(data=data, manager=manager, routing=routing)     time_window_constr(         data=data,         manager=manager,         routing=routing,         time_dimension=time_dimension,     )      pickup_delivery_constr(         data=data, manager=manager, routing=routing, time_dimension=time_dimension     )     capacity_constr(data=data, manager=manager, routing=routing)     obligation_constr(data=data, manager=manager, routing=routing)     disjunction_constr(data=data, manager=manager, routing=routing)      # solutions     search_parameters = get_search_params()     # \u041f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u0432\u0441\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u044f     routing.CloseModelWithParameters(search_parameters)     initial_solution = routing.ReadAssignmentFromRoutes(         data[\"initial_routes\"], True     )     assignment = routing.SolveFromAssignmentWithParameters(         initial_solution, search_parameters     )     print_solution(data, manager, routing, assignment)<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<pre><code class=\"python\">Objective: 5454 Route for vehicle 0:  0 ->  2 ->  4 ->  5 ->  6 ->  14 ->  10 ->  11 ->  15 -> 16 Time of the route: 28 minutes   Route for vehicle 1:  1 ->  3 ->  7 ->  8 ->  9 ->  12 ->  13 -> 17 Time of the route: 26 minutes   Maximum of the route: 28 minutes<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0438\u0442\u043e\u0433, \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043d\u043e\u0432\u044b\u0439 \u0437\u0430\u043a\u0430\u0437 \u0441 \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u043c\u0438 \u0443\u0437\u043b\u043e\u0432 14 \u0438 15 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0441\u044f \u0432 0 \u0422\u0421.<\/p>\n<hr\/>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0443 \u043c\u0435\u043d\u044f \u0432\u0441\u0435, \u0441\u043f\u0430\u0441\u0438\u0431\u043e, \u0447\u0442\u043e \u0434\u043e\u0447\u0438\u0442\u0430\u043b\u0438 \u0434\u043e \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u043c\u0435\u043d\u0442\u0430. \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u043e\u043a\u0430\u0437\u0430\u043b\u0441\u044f \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u043c.<\/p>\n<p>\u0421\u0441\u044b\u043b\u043a\u0438:<\/p>\n<ol>\n<li>\n<p><a href=\"https:\/\/developers.google.com\/optimization\/routing\/tsp\" rel=\"noopener noreferrer nofollow\"><u>\u041e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f ortools<\/u><\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/google\/or-tools\" rel=\"noopener noreferrer nofollow\">Git ortools<\/a><\/p>\n<\/li>\n<\/ol>\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\/articles\/783754\/\"> https:\/\/habr.com\/ru\/articles\/783754\/<\/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! \u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0418\u043b\u044c\u044f \u041d\u0430\u0431\u0430\u0442\u0447\u0438\u043a\u043e\u0432, \u044f MLE \u0432 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 Kamaz Digital. \u0422\u0430\u043a\u0436\u0435 \u044f \u0443\u0447\u0443\u0441\u044c \u0432\u00a0\u043e\u043d\u043b\u0430\u0439\u043d \u043c\u0430\u0433\u0438\u0441\u0442\u0440\u0430\u0442\u0443\u0440\u0435 \u043d\u0430 \u0431\u0430\u0437\u0435 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0438\u0442\u0435\u0442\u0430 \u0418\u0422\u041c\u041e\u00a0<a class=\"mention\" href=\"\/users\/ai-talent\">@ai-talent<\/a>.<\/p>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0445\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 ortools \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0438\u0437\u0430\u0446\u0438\u0438 \u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0440\u0442\u043d\u044b\u0445 \u0441\u0440\u0435\u0434\u0441\u0442\u0432 \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438 \u0433\u0440\u0443\u0437\u043e\u043f\u043e\u0434\u044a\u0435\u043c\u043d\u043e\u0441\u0442\u0438 (CVRPTW).<\/p>\n<p>\u0418 \u0441\u0430\u043c\u043e\u0435 \u0432\u0430\u0436\u043d\u043e \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u043f\u0430\u0440\u043e\u0439 \u0432\u0430\u0436\u043d\u044b\u0445 \u0444\u0438\u0447\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432\u044b \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u0442\u0435 \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438.<\/p>\n<h2>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 VRP \u0438 CVRPTW?<\/h2>\n<p>VRP (Vehicle Routing Problem) &#8212; \u044d\u0442\u043e \u043e\u0434\u043d\u0430 \u0438\u0437 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0437\u0430\u0434\u0430\u0447 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0432 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u043a\u0438, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u0430\u044f \u0441 \u043f\u043e\u0438\u0441\u043a\u043e\u043c \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0445 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u043e\u0432 \u0434\u043b\u044f \u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0440\u0442\u043d\u044b\u0445 \u0441\u0440\u0435\u0434\u0441\u0442\u0432 \u0441 \u0446\u0435\u043b\u044c\u044e \u0434\u043e\u0441\u0442\u0430\u0432\u043a\u0438 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u043a\u043b\u0438\u0435\u043d\u0442\u0430\u043c \u0438\u043b\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0434\u0440\u0443\u0433\u0438\u0445 \u0437\u0430\u0434\u0430\u0447 \u0441 \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0437\u0430\u0442\u0440\u0430\u0442. \u041a\u043e\u0433\u0434\u0430 \u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0440\u0442\u043d\u044b\u0435 \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430 \u043e\u0431\u043b\u0430\u0434\u0430\u044e\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u043e\u0439 \u0433\u0440\u0443\u0437\u043e\u043f\u043e\u0434\u044a\u0435\u043c\u043d\u043e\u0441\u0442\u044c\u044e, \u0430 \u0443 \u0437\u0430\u043a\u0430\u0437\u0447\u0438\u043a\u043e\u0432 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u044b \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0430\u0432\u043a\u0438, \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0437\u0430\u0434\u0430\u0447\u0430 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0438\u0437\u0430\u0446\u0438\u0438 \u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0440\u0442\u0430, \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0449\u0430\u044f \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438 \u0433\u0440\u0443\u0437\u043e\u043f\u043e\u0434\u044a\u0435\u043c\u043d\u043e\u0441\u0442\u0438 (CVRPTW).<\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u043e\u0431\u0441\u0443\u0434\u0438\u043c, \u043a\u0430\u043a \u0440\u0435\u0448\u0438\u0442\u044c CVRPTW, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0431\u044b\u0441\u0442\u0440\u043e\u0435 \u0438 \u043d\u0430\u0434\u0435\u0436\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 ortools. <\/p>\n<h2>\u041f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438 <\/h2>\n<p>\u0412 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 VRP \u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0440\u0442\u043d\u044b\u0435 \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430 (\u0434\u0430\u043b\u0435\u0435 \u0422\u0421) \u0441\u0442\u0430\u0440\u0442\u0443\u044e\u0442 \u0438\u0437 \u043e\u0434\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 &#8212; \u0434\u0435\u043f\u043e \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u0435\u0440\u043d\u0443\u0442\u044c\u0441\u044f \u0432 \u043d\u0435\u0433\u043e \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u0441\u0435\u0449\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0437\u0430\u043a\u0430\u0437\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b \u0437\u0430\u0440\u0430\u043d\u0435\u0435. <\/p>\n<p>\u041c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443. \u041f\u0443\u0441\u0442\u044c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441 \u043f\u0430\u0441\u0441\u0430\u0436\u0438\u0440\u0441\u043a\u0438\u0445 \u043f\u0435\u0440\u0435\u0432\u043e\u0437\u043e\u043a. \u0418\u043c\u0435\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f:<\/p>\n<ol>\n<li>\n<p>\u0417\u0430\u0440\u0430\u043d\u0435\u0435 \u0432\u0441\u0435 \u0442\u043e\u0447\u043a\u0438 \u0437\u0430\u043a\u0430\u0437\u043e\u0432 \u043d\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b, \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0437\u0430\u043d\u043e\u0432\u043e \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u0430\u0441\u0441\u0430\u0436\u0438\u0440\u0430;<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u0440\u0430\u0441\u0447\u0435\u0442\u043e\u0432 \u0432\u043e\u0437\u044c\u043c\u0435\u043c 2 \u0422\u0421 \u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c\u044e 8 \u0447\u0435\u043b\u043e\u0432\u0435\u043a;<\/p>\n<\/li>\n<li>\n<p>\u0423 \u043f\u0430\u0441\u0441\u0430\u0436\u0438\u0440\u043e\u0432 \u0435\u0441\u0442\u044c \u0441\u0442\u0440\u043e\u0433\u0438\u0435 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b \u043f\u043e\u0441\u0430\u0434\u043a\u0438 \u0438 \u0432\u044b\u0441\u0430\u0434\u043a\u0438 (\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043e\u043a\u043d\u0430). \u0414\u043b\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u0430\u0441\u0441\u0430\u0436\u0438\u0440\u0430, \u0442\u0430\u043a\u0436\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u044e\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043d\u0430 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435 = 30 \u043c\u0438\u043d\u0443\u0442 \u0438 \u043d\u0430 \u0432\u0440\u0435\u043c\u044f \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f + \u0432\u0440\u0435\u043c\u044f \u0432 \u043f\u0443\u0442\u0438 =  45 \u043c\u0438\u043d\u0443\u0442;<\/p>\n<\/li>\n<li>\n<p>\u0422\u043e\u0447\u043a\u0430 \u0441\u0442\u0430\u0440\u0442\u0430 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0430 &#8212; \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0422\u0421 (\u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0434\u0435\u043f\u043e \u0432 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435);<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435 \u0442\u043e\u0447\u043a\u0438 \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044f \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0430 \u0422\u0421.<\/p>\n<\/li>\n<\/ol>\n<h2>\u041c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438<\/h2>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u0441\u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u0443\u0435\u043c \u0437\u0430\u0434\u0430\u0447\u0443 \u043a\u0430\u043a \u0441\u043c\u0435\u0448\u0430\u043d\u043d\u0443\u044e \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u0443\u044e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443. \u0417\u0430\u0442\u0435\u043c \u0440\u0435\u0448\u0430\u0435\u043c \u0437\u0430\u0434\u0430\u0447\u0443 \u0434\u043b\u044f \u0440\u044f\u0434\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u0433\u0440\u0443\u0437\u043e\u0432\u0438\u043a\u043e\u0432, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0445 \u0434\u0430\u043d\u043d\u0443\u044e \u0444\u043e\u0440\u043c\u0443\u043b\u0443. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 CVRPTW \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f NP-\u0441\u043b\u043e\u0436\u043d\u044b\u043c, \u043c\u044b \u043e\u0436\u0438\u0434\u0430\u0435\u043c, \u0447\u0442\u043e \u0432\u0440\u0435\u043c\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043c\u043e\u0434\u0435\u043b\u0438 \u0431\u0443\u0434\u0435\u0442 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u043e \u043c\u0435\u0440\u0435 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u0433\u0440\u0443\u0437\u043e\u0432\u0438\u043a\u043e\u0432 \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u0442\u0441\u044f.<\/p>\n<p> 0 \\\\  &amp; TW_i \\text{ = \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0434\u043b\u044f \u0443\u0437\u043b\u0430 } i, TW_i \\geq 0 \\\\  &amp; O_i \\text{ = \u0443\u0437\u0435\u043b } i \\text{ \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u0435\u043d \u0434\u043b\u044f \u0422\u0421 } k, O_i \\in K \\\\  &amp; T_i \\text{ = \u0442\u0438\u043f \u0443\u0437\u043b\u0430 } i \\text{ (start, onboard, pickup, delivery, finish)} \\\\  &amp; R_k \\text{ = \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u0430\u0440\u0448\u0440\u0443\u0442 \u0434\u043b\u044f \u0422\u0421 } k \\\\ &amp; p \\text{ = \u0448\u0442\u0440\u0430\u0444 \u0437\u0430 \u043d\u0435\u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0443\u0437\u043b\u0430 \u0432 \u043c\u0430\u0440\u0448\u0440\u0443\u0442 } \\end{align*}&#187; alt=&#187;\\textbf{\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:} \\\\  \\begin{align*} &amp; c_{ij} \\text{ = \u0432\u0440\u0435\u043c\u044f \u0432 \u043f\u0443\u0442\u0438 \u043c\u0435\u0436\u0434\u0443 \u0443\u0437\u043b\u0430\u043c\u0438 } i \\text{ \u0438 } j, c_{ij} \\geq 0 \\\\  &amp; q_i \\text{ = \u0441\u043f\u0440\u043e\u0441 \u043d\u0430 \u0443\u0437\u043b\u0435 } i,  -Q_k \\leq q_i  \\leq Q_k \\\\  &amp; Q_k \\text{ = \u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c \u0422\u0421 } k, Q_k > 0 \\\\  &amp; TW_i \\text{ = \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0434\u043b\u044f \u0443\u0437\u043b\u0430 } i, TW_i \\geq 0 \\\\  &amp; O_i \\text{ = \u0443\u0437\u0435\u043b } i \\text{ \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u0435\u043d \u0434\u043b\u044f \u0422\u0421 } k, O_i \\in K \\\\  &amp; T_i \\text{ = \u0442\u0438\u043f \u0443\u0437\u043b\u0430 } i \\text{ (start, onboard, pickup, delivery, finish)} \\\\  &amp; R_k \\text{ = \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u0430\u0440\u0448\u0440\u0443\u0442 \u0434\u043b\u044f \u0422\u0421 } k \\\\ &amp; p \\text{ = \u0448\u0442\u0440\u0430\u0444 \u0437\u0430 \u043d\u0435\u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0443\u0437\u043b\u0430 \u0432 \u043c\u0430\u0440\u0448\u0440\u0443\u0442 } \\end{align*}&#187; src=&#187;https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ea6\/b59\/57c\/ea6b5957c63b433452993885b80c81f7.svg&#187; width=&#187;697&#8243; height=&#187;268&#8243;\/><\/p>\n<h2>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0434\u0430\u0442\u044b<\/h2>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447\u0438.<\/p>\n<pre><code class=\"python\">def create_data_model():     data = {}     data[\"time_matrix\"] = [         [0, 6, 0, 6, 5, 6, 7, 6, 8, 2, 9, 2, 4, 9, 9, 4, 9, 9],         [6, 0, 6, 0, 2, 2, 2, 1, 3, 3, 4, 3, 7, 11, 4, 4, 12, 12],         [0, 6, 0, 6, 5, 6, 7, 6, 8, 2, 9, 2, 4, 9, 9, 4, 9, 9],         [6, 0, 6, 0, 2, 2, 2, 1, 3, 3, 4, 3, 7, 11, 4, 4, 12, 12],         [6, 0, 6, 0, 0, 2, 3, 2, 4, 4, 5, 3, 7, 10, 5, 3, 12, 12],         [9, 4, 9, 4, 3, 0, 1, 2, 1, 6, 3, 6, 9, 12, 3, 6, 14, 14],         [8, 4, 8, 4, 3, 2, 0, 1, 2, 5, 2, 5, 9, 12, 2, 5, 14, 14],         [7, 2, 7, 2, 2, 0, 1, 0, 1, 4, 3, 4, 8, 11, 3, 4, 13, 13],         [9, 4, 9, 4, 4, 2, 0, 2, 0, 6, 2, 6, 10, 13, 2, 6, 14, 14],         [2, 5, 2, 5, 5, 4, 5, 4, 5, 0, 7, 3, 3, 10, 7, 6, 11, 11],         [8, 4, 8, 4, 3, 2, 0, 1, 2, 5, 0, 5, 9, 12, 0, 5, 14, 14],         [3, 4, 3, 4, 4, 4, 5, 4, 6, 2, 7, 0, 5, 9, 7, 3, 10, 10],         [1, 7, 1, 7, 6, 6, 7, 6, 7, 2, 9, 4, 0, 9, 9, 5, 9, 9],         [10, 11, 10, 11, 11, 13, 14, 13, 14, 10, 16, 10, 11, 0, 16, 9, 6, 6],         [8, 4, 8, 4, 3, 2, 0, 1, 2, 5, 0, 5, 9, 12, 0, 5, 14, 14],         [7, 5, 7, 5, 4, 6, 6, 5, 7, 5, 8, 4, 9, 9, 8, 0, 10, 10],         [10, 12, 10, 12, 12, 14, 15, 14, 14, 10, 17, 10, 12, 4, 17, 10, 0, 0],         [10, 12, 10, 12, 12, 14, 15, 14, 14, 10, 17, 10, 12, 4, 17, 10, 0, 0],     ]     data[\"num_vehicles\"] = 2     data[\"starts\"] = [0, 1]     data[\"ends\"] = [16, 17]     data[\"pickups_deliveries\"] = [(10, 11), (12, 13), (14, 15)]     data[\"obligations\"] = [         0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, None, None, 0, 1     ]     data[\"demands\"] = [         0, 0, 3, 3, -1, -1, -1, -1, -1, -1, 1, -1, 1, -1, 1, -1, 0, 0     ]     data[\"vehicle_capacities\"] = [8, 8]     data[\"point_types\"] = [         \"start\", \"start\", \"onboard\", \"onboard\", \"delivery\", \"delivery\",         \"delivery\", \"delivery\", \"delivery\", \"delivery\", \"pickup\", \"delivery\",         \"pickup\", \"delivery\", \"pickup\", \"delivery\", \"finish\", \"finish\",     ]     data[\"time_windows\"] = [         (0, 0), (0, 0), (0, 0), (0, 0), (0, 9), (0, 11), (0, 11), (0, 4),          (0, 4), (0, 10), (8, 15), (0, 23), (9, 17), (0, 32), (4, 30), (9, 45),         (0, 79), (0, 119),     ]     data[\"disjunction\"] = [(14, 15)]     data[\"initial_routes\"] = [[2, 4, 6, 5, 10, 11], [3, 8, 7, 9, 12, 13]]     return data <\/code><\/pre>\n<p>\u0413\u0434\u0435:<\/p>\n<ul>\n<li>\n<p>time_matrix: \u041c\u0430\u0441\u0441\u0438\u0432 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043c\u0435\u0436\u0434\u0443 \u043b\u043e\u043a\u0430\u0446\u0438\u044f\u043c\u0438 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445;<\/p>\n<\/li>\n<li>\n<p>num_vehicles: \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0422\u0421 \u0432 \u0430\u0432\u0442\u043e\u043f\u0430\u0440\u043a\u0435;<\/p>\n<\/li>\n<li>\n<p>starts: \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0443\u0437\u043b\u043e\u0432, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0422\u0421 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442 \u043c\u0430\u0440\u0448\u0440\u0443\u0442;<\/p>\n<\/li>\n<li>\n<p>ends: \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0443\u0437\u043b\u043e\u0432, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0422\u0421 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u044e\u0442 \u043c\u0430\u0440\u0448\u0440\u0443\u0442;<\/p>\n<\/li>\n<li>\n<p>pickups_deliveries: \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0443\u0437\u043b\u043e\u0432, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0437\u0430\u0434\u0430\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 &#8212; \u043f\u043e\u0441\u0430\u0434\u043a\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0440\u0430\u043d\u044c\u0448\u0435 \u0432\u044b\u0441\u0430\u0434\u043a\u0438 \u043f\u0430\u0441\u0441\u0430\u0436\u0438\u0440\u0430;<\/p>\n<\/li>\n<li>\n<p>obligation: \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0422\u0421 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0443\u0437\u043b\u0430 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0430 (\u0434\u043b\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u0430\u0441\u0441\u0430\u0436\u0438\u0440\u0430 = None);<\/p>\n<\/li>\n<li>\n<p>demands: \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438 \u0422\u0421 \u043f\u0440\u0438 \u043f\u043e\u0441\u0435\u0449\u0435\u043d\u0438\u0438 \u0443\u0437\u043b\u0430;<\/p>\n<\/li>\n<li>\n<p>vehicle_capacities: \u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c \u0422\u0421;<\/p>\n<\/li>\n<li>\n<p>point_types: \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440, \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u0442\u0438\u043f \u0443\u0437\u043b\u0430;<\/p>\n<\/li>\n<li>\n<p>time_windows: \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0441\u0435\u0442\u0438\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u0443\u0437\u0435\u043b \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0430;<\/p>\n<\/li>\n<li>\n<p>disjunction: \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0443\u0437\u043b\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u0431\u0440\u0430\u0442\u044c \u0438\u0437 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u044f \u0441\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u044f;<\/p>\n<\/li>\n<li>\n<p>initial_routes: \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u044b \u0422\u0421 \u0434\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<\/li>\n<\/ul>\n<h2>Python \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/h2>\n<p>\u041d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0441 \u0432\u044b\u0437\u043e\u0432\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0437\u0434\u0430\u0435\u0442 data.<\/p>\n<pre><code class=\"python\">data = create_data_model()<\/code><\/pre>\n<p>\u041e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u043c <strong>\u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432<\/strong> (manager) \u0438 <strong>\u043c\u043e\u0434\u0435\u043b\u044c \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u043b\u0438 \u0441\u043e\u043b\u0432\u0435\u0440<\/strong> (routing).<\/p>\n<pre><code class=\"python\">manager = pywrapcp.RoutingIndexManager(     len(data[\"time_matrix\"]), data[\"num_vehicles\"], data[\"starts\"], data[\"ends\"] ) routing = pywrapcp.RoutingModel(manager)<\/code><\/pre>\n<p><strong>\u041c\u0435\u043d\u0435\u0434\u0436\u0435\u0440 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432<\/strong> \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c, \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0432\u0435\u0441\u0442\u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0435 \u0432 data \u0432 \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0441\u043e\u043b\u0432\u0435\u0440\u0430. \u041c\u0435\u043d\u0435\u0434\u0436\u0435\u0440 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<ol>\n<li>\n<p>\u0423\u0437\u043b\u044b, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0422\u0421 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442 \u043c\u0430\u0440\u0448\u0440\u0443\u0442;<\/p>\n<\/li>\n<li>\n<p>\u0412\u0441\u0435 \u0434\u0440\u0443\u0433\u0438\u0435 \u0443\u0437\u043b\u044b;<\/p>\n<\/li>\n<li>\n<p>\u0423\u0437\u043b\u044b, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0422\u0421 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442 \u043c\u0430\u0440\u0448\u0440\u0443\u0442.<\/p>\n<\/li>\n<\/ol>\n<p>\u041c\u044b \u0441 \u0432\u0430\u043c\u0438 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0438\u043b\u0438 \u0443\u0437\u043b\u044b \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0438\u043d\u0434\u0435\u043a\u0441\u044b, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0435 \u0432 data \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u043b\u0438 \u0441 \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u043c\u0438 \u0441\u043e\u043b\u0432\u0435\u0440\u0430.<\/p>\n<h3>\u041e\u0431\u0440\u0430\u0442\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 (callback)<\/h3>\n<p>\u0427\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u043b\u0432\u0435\u0440 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0438\u0437\u0430\u0446\u0438\u0438, \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c\u00a0<strong>\u043e\u0431\u0440\u0430\u0442\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 (callback) \u0432\u0440\u0435\u043c\u0435\u043d\u0438 (\u0438\u043b\u0438 \u0442\u0440\u0430\u043d\u0437\u0438\u0442\u0430)<\/strong>\u00a0&#8212; \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043b\u044e\u0431\u0443\u044e \u043f\u0430\u0440\u0443 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 \u0443\u0437\u043b\u043e\u0432 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0432\u0440\u0435\u043c\u044f \u0442\u0440\u0430\u043d\u0437\u0438\u0442\u0430 \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438. <br \/>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0441\u043e\u0437\u0434\u0430\u0435\u0442 callback \u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u0435\u0433\u043e \u0432 \u0440\u0435\u0448\u0430\u0442\u0435\u043b\u0435 \u043a\u0430\u043a\u00a0<strong>transit_callback_index<\/strong>. \u0418 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u0443\u044e \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u0442\u0440\u0430\u043d\u0437\u0438\u0442\u0430 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043c\u0430\u0448\u0438\u043d.<\/p>\n<pre><code class=\"python\">def time_callback(from_index, to_index):     from_node = manager.IndexToNode(from_index)     to_node = manager.IndexToNode(to_index)     return data[\"time_matrix\"][from_node][to_node]  transit_callback_index = routing.RegisterTransitCallback(time_callback) routing.SetArcCostEvaluatorOfAllVehicles(transit_callback_index)<\/code><\/pre>\n<h3>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0435 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u0435:<\/h3>\n<p>\u0414\u0430\u043d\u043d\u044b\u0435 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043b\u044f \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043e\u043a\u043e\u043d.<\/p>\n<pre><code class=\"python\">routing.AddDimension(     evaluator_index=transit_callback_index,     slack_max=8 * 60,  # allow waiting time     capacity=8 * 60,  # maximum time per vehicle     fix_start_cumul_to_zero=False,     name=\"Time\", ) time_dimension = routing.GetDimensionOrDie(\"Time\")<\/code><\/pre>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b AddDimension:<\/p>\n<ul>\n<li>\n<p>slack_max &#8212; \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043f\u0440\u0438\u0431\u044b\u0442\u0438\u044f \u0432 \u0443\u0437\u0435\u043b \u0440\u0430\u043d\u044c\u0448\u0435 \u043b\u0435\u0432\u043e\u0439 \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u043e\u043a\u043d\u0430; <\/p>\n<\/li>\n<li>\n<p>capacity &#8212; \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438<\/p>\n<\/li>\n<li>\n<p>fix_start_cumul_to_zero &#8212; \u0415\u0441\u043b\u0438 True \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u044b\u0439 \u0443\u0437\u0435\u043b \u043e\u0431\u044f\u0437\u0430\u043d \u0438\u043c\u0435\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 0. <\/p>\n<\/li>\n<\/ul>\n<h3>\u0412\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043e\u043a\u043d\u0430<\/h3>\n<h4>\u0424\u0438\u0447\u0430 \u21161<\/h4>\n<p>\u041d\u0430\u0437\u043e\u0432\u0435\u043c \u044d\u0442\u043e \u043d\u0435 \u0431\u0430\u0433, \u0430 \u0444\u0438\u0447\u0430. \u0414\u043b\u044f \u0442\u043e\u0447\u0435\u043a \u0444\u0438\u043d\u0438\u0448\u0430 \u0422\u0421 <strong>manager.NodeToIndex(ind) <\/strong>\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 -1, \u0430 \u043a\u0430\u043a \u0432\u044b \u0443\u0436\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442\u0435 \u0443\u0437\u043b\u0430 \u0441 \u0442\u0430\u043a\u0438\u043c \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c \u043d\u0435\u0442. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u0437 \u0441\u043b\u043e\u0436\u0438\u0432\u0448\u0435\u0439\u0441\u044f \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0439\u0442\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <strong>routing.End(obligations[ind])<\/strong>. \u0414\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0432\u0435\u0440\u043d\u0435\u0442 \u0438\u043d\u0434\u0435\u043a\u0441 \u0443\u0437\u043b\u0430 \u0444\u0438\u043d\u0438\u0448\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u0422\u0421.<\/p>\n<pre><code class=\"python\">def get_index(     manager: RoutingIndexManager,     ind: int,     routing: RoutingModel,     obligations: list[int | None], ) -> int:     if manager.NodeToIndex(ind) != -1:         index_node = manager.NodeToIndex(ind)     else:         index_node = routing.End(obligations[ind])     return index_node<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043e\u043a\u043d\u0430:<\/p>\n<p>\u0422\u0430\u043a \u0437\u0430\u0434\u0430\u044e\u0442\u0441\u044f \u0436\u0435\u0441\u0442\u043a\u0438\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043d\u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043e\u043a\u043d\u0430. \u0412 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0445\u043e\u0442\u044c \u043e\u0434\u043d\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043d\u0430\u0440\u0443\u0448\u0430\u0435\u0442\u0441\u044f, \u0442\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0435 \u0441\u0445\u043e\u0434\u0438\u0442\u0441\u044f. \u0410 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u044d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u043e \u0432\u0432\u0438\u0434\u0443 \u043e\u043f\u043e\u0437\u0434\u0430\u043d\u0438\u0439 \u0422\u0421.<\/p>\n<pre><code class=\"python\">def time_window_constr(     data: dict[str, Any],     manager: RoutingIndexManager,     routing: RoutingModel,     time_dimension: RoutingDimension, ) -> None:     for ind, (pt, tw) in enumerate(data[\"time_windows\"]):         index = get_index(manager, ind, routing, data[\"obligations\"])         time_dimension.CumulVar(index).SetRange(tw[0], tw[1])<\/code><\/pre>\n<h4>\u0424\u0438\u0447\u0430 \u21162<\/h4>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0441 \u0432\u0430\u043c\u0438 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u043c\u044f\u0433\u043a\u0438\u0435 \u043e\u043a\u043d\u0430. \u041e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0436\u0435\u0441\u0442\u043a\u0438\u0445 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u0440\u0438 \u043d\u0430\u0440\u0443\u0448\u0435\u043d\u0438\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0432 \u0446\u0435\u043b\u0435\u0432\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0448\u0442\u0440\u0430\u0444 \u0437\u0430 \u043a\u0430\u0436\u0434\u0443\u044e \u0435\u0434\u0438\u043d\u0438\u0446\u0443, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u043f\u0440\u0435\u0432\u044b\u0441\u0438\u043b\u0438 \u043f\u043e\u0440\u043e\u0433\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435.<\/p>\n<ul>\n<li>\n<p>\u0414\u043b\u044f \u0432\u0435\u0440\u0445\u043d\u0435\u0439 \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u043e\u043a\u043d\u0430: <em>cost = <\/em>penalty<em> * (cumulVar &#8212; upper_bound)<\/em><\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u043b\u0435\u0432\u043e\u0439 \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u043e\u043a\u043d\u0430:  <em>cost = coefficient * (lower_bound &#8212; cumulVar)<\/em><\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"python\">def<\/code><\/pre>\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-364243","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/364243","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=364243"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/364243\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=364243"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=364243"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=364243"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}