{"id":3069,"date":"2021-12-29T10:10:29","date_gmt":"2021-12-29T01:10:29","guid":{"rendered":"https:\/\/gri.jp\/media\/?p=3069"},"modified":"2021-12-28T22:39:12","modified_gmt":"2021-12-28T13:39:12","slug":"python%e3%81%a7%e6%95%b0%e7%90%86%e6%9c%80%e9%81%a9%e5%8c%96%e3%82%84%e3%81%a3%e3%81%a6%e3%81%bf%e3%81%9f%e3%80%82%e3%80%90%e8%b6%85%e5%85%a5%e9%96%80%e3%83%ac%e3%83%99%e3%83%ab%ef%bc%9a%e4%b8%ad","status":"publish","type":"post","link":"https:\/\/gri.jp\/media\/entry\/3069","title":{"rendered":"Python\u3067\u6570\u7406\u6700\u9069\u5316\u3084\u3063\u3066\u307f\u305f\u3002\u3010\u8d85\u5165\u9580\u30ec\u30d9\u30eb\uff1a\u4e2d\u5b66\u6570\u5b66\uff081\u6b21\u65b9\u7a0b\u5f0f\u30fb\u9023\u7acb1\u6b21\u65b9\u7a0b\u5f0f\uff09\u3011"},"content":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\u3002<br \/>\n\u6700\u8fd1\u3001\u6570\u7406\u6700\u9069\u5316\u3092\u3086\u308b\u3086\u308b\u3068\u52c9\u5f37\u3057\u59cb\u3081\u305f\u5206\u6790\u5b98\u306e\u671b\u6708\u3067\u3059\u3002<\/p>\n<p>\u81ea\u5206\u306e\u5b66\u3093\u3060\u3053\u3068\u3092\u5b9a\u7740\u3055\u305b\u308b\u305f\u3081\u306b\u3082\u30a2\u30a6\u30c8\u30d7\u30c3\u30c8\u3057\u3066\u3044\u304f\u306e\u304c\u826f\u3044\u306a\u3068\u601d\u3044\u307e\u3057\u305f\u306e\u3067\u3001\u3053\u306e\u5834\u3092\u4f7f\u3063\u3066\u4e0d\u5b9a\u671f\u3067\u307e\u3068\u3081\u3066\u3044\u304d\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u521d\u56de\u306f\u3056\u3063\u304f\u308a\u6570\u7406\u6700\u9069\u5316\u3068\u306f\uff1f\u3068\u3044\u3046\u3068\u3053\u308d\u304b\u3089Python\u3067\u6570\u7406\u6700\u9069\u5316\u3092\u6271\u3046\u305f\u3081\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3068\u305d\u306e\u4f7f\u3044\u65b9\u3092\u7c21\u5358\u306a\u4f8b\u3092\u3082\u3068\u306b\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<h4>\u6570\u7406\u6700\u9069\u5316\u3068\u306f\uff1f<\/h4>\n<p>\u3056\u3063\u304f\u308a\u8a00\u3046\u3068\u300c\u4e0e\u3048\u3089\u308c\u305f\u6761\u4ef6\u306e\u4e2d\u3067\u3001\u6700\u9069\u306a\u9078\u629e\u3092\u898b\u3064\u3051\u308b\u305f\u3081\u306e\u8a08\u7b97\u6280\u8853\u300d\u3067\u3059\u3002<br \/>\n\u6709\u540d\u306a\u4f8b\u3068\u3057\u3066\u306f<a href=\"https:\/\/gri.jp\/report\/data-science\/10980\">\u30ca\u30c3\u30d7\u30b6\u30c3\u30af\u554f\u984c<\/a>\u306a\u3069\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<h4>\u4f7f\u7528\u3059\u308bPython\u30e9\u30a4\u30d6\u30e9\u30ea<\/h4>\n<p>\u4eca\u56de\u306f<a href=\"https:\/\/coin-or.github.io\/pulp\/\" target=\"_blank\" rel=\"noopener\">PuLP<\/a>\u3068\u3044\u3046\u6570\u7406\u6700\u9069\u5316\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u5229\u7528\u3057\u3066\u6570\u7406\u6700\u9069\u5316\u554f\u984c\u3092\u89e3\u3044\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<h4>\u53d6\u308a\u6271\u3046\u554f\u984c<\/h4>\n<p>\u4eca\u56de\u306f\u8d85\u5165\u9580\u30ec\u30d9\u30eb\u3068\u3044\u3046\u3053\u3068\u306a\u306e\u3067\u4e2d\u5b66\u6570\u5b66\u3067\u7fd2\u3046<\/p>\n<ul>\n<li>1\u6b21\u65b9\u7a0b\u5f0f<\/li>\n<li>\u9023\u7acb1\u6b21\u65b9\u7a0b\u5f0f<\/li>\n<\/ul>\n<p>\u3092PuLP\u3092\u4f7f\u3063\u3066\u89e3\u3044\u3066\u307f\u307e\u3059\u3002<\/p>\n<h4>1\u6b21\u65b9\u7a0b\u5f0f\u3092\u89e3\u3044\u3066\u307f\u308b<\/h4>\n<p>1\u6b21\u65b9\u7a0b\u5f0f2x+5=11\u3092\u89e3\u3044\u3066\u3044\u304d\u307e\u3059\u3002<br \/>\n\u30b3\u30fc\u30c9\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\u3002<\/p>\n<pre class=\"language-python\"><code># 0.\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u30a4\u30f3\u30dd\u30fc\u30c8\r\nimport pulp\r\n\r\n# 1.\u6570\u7406\u30e2\u30c7\u30eb\u306e\u5b9a\u7fa9\r\nproblem_LE = pulp.LpProblem('Linear_Equation', pulp.LpMaximize)\r\n\r\n# 2.\u5909\u6570\u306e\u5b9a\u7fa9\r\nx = pulp.LpVariable('x', cat='Continuous')\r\n\r\n# 3.1\u6b21\u65b9\u7a0b\u5f0f\u306e\u5b9a\u7fa9\r\nproblem_LE += 2 * x + 5 == 11\r\n\r\n# 4.\u5b9a\u7fa9\u3057\u305f\u554f\u984c\u3092\u89e3\u304f\r\nstatus = problem_LE.solve()\r\n\r\n# 5.\u6700\u9069\u5316\u8a08\u7b97\u306e\u7d50\u679c\r\nprint(pulp.LpStatus[status])\r\nprint('x=', x.value())\r\n<\/code><\/pre>\n<h5>1.\u6570\u7406\u30e2\u30c7\u30eb\u306e\u5b9a\u7fa9<\/h5>\n<p>pulp.LpProblem\u3067\u6570\u7406\u30e2\u30c7\u30eb\u3092\u5b9a\u7fa9\u3057\u307e\u3059\u3002<br \/>\n\u7b2c\u4e00\u5f15\u6570\u306f\u4efb\u610f\u306e\u540d\u524d\u3001\u7b2c\u4e8c\u5f15\u6570\u306f\u3069\u3046\u3044\u3063\u305f\u554f\u984c\u3092\u89e3\u304f\u304b\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<br \/>\n\u3053\u3053\u3067\u306fpulp.LpMaximize\uff08\u6700\u5927\u5316\uff09\u3068\u3057\u3066\u3044\u307e\u3059\u304c\u3001\u4eca\u56de\u306f1\u6b21\u65b9\u7a0b\u5f0f\u3092\u89e3\u304f\u305f\u3081\u7279\u306b\u610f\u5473\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<h5>2.\u5909\u6570\u306e\u5b9a\u7fa9<\/h5>\n<p>pulp.LpVariable\u3067\u5909\u6570x\u3092\u5b9a\u7fa9\u3057\u307e\u3059\u3002<br \/>\n\u7b2c\u4e00\u5f15\u6570\u306f\u4efb\u610f\u306e\u540d\u524d\u3001\u7b2c\u4e8c\u5f15\u6570\u306f\u5909\u6570\u306e\u7a2e\u5225\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<br \/>\n\u3053\u3053\u3067\u306f\u9023\u7d9a\u5024&#8221;Continuous&#8221;\u3068\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<h5>3.1\u6b21\u65b9\u7a0b\u5f0f\u306e\u5b9a\u7fa9<\/h5>\n<p>\u4ee3\u5165\u6f14\u7b97\u5b50&#8221;+=&#8221;\u3092\u7528\u3044\u30661\u6b21\u65b9\u7a0b\u5f0f\u3092\u5b9a\u7fa9\u3057\u307e\u3059\u3002<\/p>\n<h5>4.\u5b9a\u7fa9\u3057\u305f\u554f\u984c\u3092\u89e3\u304f<\/h5>\n<p>problem_LE.solve()\u3067\u305d\u306e\u524d\u307e\u3067\u306b\u5b9a\u7fa9\u3057\u305f\u554f\u984c\u3092\u89e3\u304d\u307e\u3059\u3002<br \/>\n\u89e3\u3051\u305f\u304b\u3069\u3046\u304b\u306e\u60c5\u5831\u304cstatus\u306b\u5165\u308a\u307e\u3059\u3002<\/p>\n<h5>5.\u6700\u9069\u5316\u8a08\u7b97\u306e\u7d50\u679c<\/h5>\n<p>pulp.LpStatus[status]\u3067\u89e3\u3051\u305f\u304b\u3069\u3046\u304b\u78ba\u8a8d\u3057\u307e\u3059\u3002<br \/>\n\u6700\u9069\u89e3\u304c\u5f97\u3089\u308c\u305f\u5834\u5408\u306f&#8221;Optimal&#8221;\u3068\u306a\u308a\u307e\u3059\u3002<br \/>\n\u307e\u305f\u3001x.value()\u3067\u89e3\u3092\u78ba\u8a8d\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-3113 size-full\" src=\"https:\/\/gri.jp\/media\/wp\/wp-content\/uploads\/2021\/12\/opt_01.png\" alt=\"\" width=\"569\" height=\"357\" \/><br \/>\nx=3\u304c\u5c0e\u304d\u51fa\u3055\u308c\u305f\u3053\u3068\u304c\u78ba\u8a8d\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<h4>\u9023\u7acb1\u6b21\u65b9\u7a0b\u5f0f\u3092\u89e3\u3044\u3066\u307f\u308b<\/h4>\n<p>\u7d9a\u3044\u3066\u9023\u7acb1\u6b21\u65b9\u7a0b\u5f0f-3x+4y=45, x+y=20\u3092\u89e3\u3044\u3066\u3044\u304d\u307e\u3059\u3002<br \/>\n\u30b3\u30fc\u30c9\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\u3002<\/p>\n<pre class=\"language-python\"><code># \u6570\u7406\u30e2\u30c7\u30eb\u306e\u5b9a\u7fa9\r\nproblem_SLE = pulp.LpProblem('simultaneous linear equations', pulp.LpMaximize)\r\n\r\n# \u5909\u6570\u306e\u5b9a\u7fa9\r\nx = pulp.LpVariable('x', cat='Continuous')\r\ny = pulp.LpVariable('y', cat='Continuous')\r\n\r\n# \u9023\u7acb1\u6b21\u65b9\u7a0b\u5f0f\u306e\u5b9a\u7fa9\r\nproblem_SLE += -3 * x + 4 * y == 45\r\nproblem_SLE += x + y == 20\r\n\r\n# \u5b9a\u7fa9\u3057\u305f\u554f\u984c\u3092\u89e3\u304f\r\nstatus = problem_SLE.solve()\r\n\r\n# \u6700\u9069\u5316\u8a08\u7b97\u306e\u7d50\u679c\r\nprint(pulp.LpStatus[status])\r\nprint('x=', x.value(), 'y=', y.value())\r\n<\/code><\/pre>\n<p>\u5909\u6570\u30922\u3064\u5b9a\u7fa9\u3057\u3066\u4ee3\u5165\u6f14\u7b97\u5b50\u3067\u65b9\u7a0b\u5f0f\u30922\u3064\u52a0\u3048\u308b\u3068\u3053\u308d\u4ee5\u5916\u306f1\u6b21\u65b9\u7a0b\u5f0f\u3068\u540c\u69d8\u3067\u3059\u3002\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-3114 size-full\" src=\"https:\/\/gri.jp\/media\/wp\/wp-content\/uploads\/2021\/12\/opt_02.png\" alt=\"\" width=\"566\" height=\"340\" \/><br \/>\nx=5, y=15\u304c\u5c0e\u304d\u51fa\u3055\u308c\u305f\u3053\u3068\u304c\u78ba\u8a8d\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<h4>\u307e\u3068\u3081<\/h4>\n<p>\u4eca\u56de\u306fPuLP\u3092\u7528\u3044\u30661\u6b21\u65b9\u7a0b\u5f0f, \u9023\u7acb1\u6b21\u65b9\u7a0b\u5f0f\u3092\u89e3\u3044\u3066\u307f\u307e\u3057\u305f\u3002<br \/>\n\u6b21\u56de\u306f\u5c11\u3057\u30ec\u30d9\u30eb\u30a2\u30c3\u30d7\u3057\u3066\u9ad8\u6821\u6570\u5b66\u306e\u7bc4\u56f2\u3067\u3042\u308b\u9818\u57df\u306b\u304a\u3051\u308b\u6700\u5927\u30fb\u6700\u5c0f\u554f\u984c\u3092\u6271\u3044\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<h4>\u53c2\u8003\u66f8\u7c4d<\/h4>\n<p><a href=\"https:\/\/www.ohmsha.co.jp\/book\/9784274227356\/\" target=\"_blank\" rel=\"noopener\">Python\u3067\u306f\u3058\u3081\u308b\u6570\u7406\u6700\u9069\u5316 \u30b1\u30fc\u30b9\u30b9\u30bf\u30c7\u30a3\u3067\u30e2\u30c7\u30ea\u30f3\u30b0\u306e\u30b9\u30ad\u30eb\u3092\u8eab\u306b\u3064\u3051\u3088\u3046\uff08\u30aa\u30fc\u30e0\u793e\uff09<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\u3002 \u6700\u8fd1\u3001\u6570\u7406\u6700\u9069\u5316\u3092\u3086\u308b\u3086\u308b\u3068\u52c9\u5f37\u3057\u59cb\u3081\u305f\u5206\u6790\u5b98\u306e\u671b\u6708\u3067\u3059\u3002 \u81ea\u5206\u306e\u5b66\u3093\u3060\u3053\u3068\u3092\u5b9a\u7740\u3055\u305b\u308b\u305f\u3081\u306b\u3082\u30a2\u30a6\u30c8\u30d7\u30c3\u30c8\u3057\u3066\u3044\u304f\u306e\u304c\u826f\u3044\u306a\u3068\u601d\u3044\u307e\u3057\u305f\u306e\u3067\u3001\u3053\u306e\u5834\u3092\u4f7f\u3063\u3066\u4e0d\u5b9a\u671f\u3067\u307e\u3068\u3081\u3066\u3044\u304d\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002 \u521d\u56de\u306f\u3056\u3063<\/p>\n","protected":false},"author":10,"featured_media":3911,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[144],"tags":[],"class_list":["post-3069","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python"],"acf":[],"meta_field":{"_edit_lock":["1640699054:26"],"_edit_last":["26"],"hidden_toppage":["0"],"_hidden_toppage":["field_61933136630d2"],"note_url":[""],"_note_url":["field_61243c8278b90"],"_thumbnail_id":["3911"],"_pv_count":["a:24:{i:20;i:85;i:15;i:182;i:11;i:148;i:9;i:131;i:16;i:209;i:5;i:57;i:18;i:134;i:12;i:103;i:8;i:63;i:19;i:114;i:0;i:57;i:17;i:163;i:10;i:151;i:2;i:183;i:23;i:85;i:7;i:43;i:13;i:191;i:21;i:103;i:14;i:202;i:22;i:86;i:1;i:91;i:3;i:115;i:6;i:35;i:4;i:79;}"],"pv_count":["2810"]},"_links":{"self":[{"href":"https:\/\/gri.jp\/media\/wp-json\/wp\/v2\/posts\/3069","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gri.jp\/media\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gri.jp\/media\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gri.jp\/media\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/gri.jp\/media\/wp-json\/wp\/v2\/comments?post=3069"}],"version-history":[{"count":45,"href":"https:\/\/gri.jp\/media\/wp-json\/wp\/v2\/posts\/3069\/revisions"}],"predecessor-version":[{"id":4599,"href":"https:\/\/gri.jp\/media\/wp-json\/wp\/v2\/posts\/3069\/revisions\/4599"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gri.jp\/media\/wp-json\/wp\/v2\/media\/3911"}],"wp:attachment":[{"href":"https:\/\/gri.jp\/media\/wp-json\/wp\/v2\/media?parent=3069"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gri.jp\/media\/wp-json\/wp\/v2\/categories?post=3069"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gri.jp\/media\/wp-json\/wp\/v2\/tags?post=3069"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}