{"id":164,"date":"2026-07-03T21:25:31","date_gmt":"2026-07-03T21:25:31","guid":{"rendered":"https:\/\/www.kindsonthegenius.com\/data-science\/?p=164"},"modified":"2026-07-03T21:26:21","modified_gmt":"2026-07-03T21:26:21","slug":"an-mip-problem-with-python-with-constraints-define-with-arrays","status":"publish","type":"post","link":"https:\/\/kindsonthegenius.com\/data-science\/an-mip-problem-with-python-with-constraints-define-with-arrays\/","title":{"rendered":"An MIP Problem with Python with Constraints Define with Arrays"},"content":{"rendered":"<p>In the previous tutorial, we learnt how to solve a Mixed Integer Program(MIP) problem in Python. In that example there were very few constraints and so we manually specified them.<\/p>\n<p>We would now look at situation where there are many constraints such that they have to be represented as an array. Let&#8217;s take an example:<\/p>\n<p><strong>Example 1 &#8211; Maximize the function<em> 7x<sub>1<\/sub>\u00a0+ 8x<sub>2<\/sub>\u00a0+ 2x<sub>3<\/sub>\u00a0+ 9x<sub>4<\/sub>\u00a0+ 6x<sub>5<\/sub><\/em> with respect to the following constraints:<\/strong><\/p>\n<table border=\"0\">\n<tbody>\n<tr>\n<td>5<em>x<sub>1<\/sub><\/em><\/td>\n<td>+<\/td>\n<td>7<em>x<sub>2<\/sub><\/em><\/td>\n<td>+<\/td>\n<td>9<em>x<sub>3<\/sub><\/em><\/td>\n<td>+<\/td>\n<td>2<em>x<sub>4<\/sub><\/em><\/td>\n<td>+<\/td>\n<td>1<em>x<sub>5<\/sub><\/em><\/td>\n<td>\u2264<\/td>\n<td>250<\/td>\n<\/tr>\n<tr>\n<td>18<em>x<sub>1<\/sub><\/em><\/td>\n<td>+<\/td>\n<td>4<em>x<sub>2<\/sub><\/em><\/td>\n<td>&#8211;<\/td>\n<td>9<em>x<sub>3<\/sub><\/em><\/td>\n<td>+<\/td>\n<td>10<em>x<sub>4<\/sub><\/em><\/td>\n<td>+<\/td>\n<td>12<em>x<sub>5<\/sub><\/em><\/td>\n<td>\u2264<\/td>\n<td>285<\/td>\n<\/tr>\n<tr>\n<td>4<em>x<sub>1<\/sub><\/em><\/td>\n<td>+<\/td>\n<td>7<em>x<sub>2<\/sub><\/em><\/td>\n<td>+<\/td>\n<td>3<em>x<sub>3<\/sub><\/em><\/td>\n<td>+<\/td>\n<td>8<em>x<sub>4<\/sub><\/em><\/td>\n<td>+<\/td>\n<td>5<em>x<sub>5<\/sub><\/em><\/td>\n<td>\u2264<\/td>\n<td>211<\/td>\n<\/tr>\n<tr>\n<td>5<em>x<sub>1<\/sub><\/em><\/td>\n<td>+<\/td>\n<td>13<em>x<sub>2<\/sub><\/em><\/td>\n<td>+<\/td>\n<td>16<em>x<sub>3<\/sub><\/em><\/td>\n<td>+<\/td>\n<td>3<em>x<sub>4<\/sub><\/em><\/td>\n<td>&#8211;<\/td>\n<td>7<em>x<sub>5<\/sub><\/em><\/td>\n<td>\u2264<\/td>\n<td>315<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Also <em>x<sub>1<\/sub><\/em>, <em>x<sub>2<\/sub><\/em>, <em>x<sub>3<\/sub><\/em>, <em>x<sub>4<\/sub><\/em>, <em>x<sub>5 <\/sub><\/em>are integers<\/p>\n<p><strong>Solution:<\/strong><\/p>\n<p>We would follow the same 5 step procedure we followed previously<\/p>\n<p>First let&#8217;s represent the given problem using the following:<\/p>\n<ul>\n<li>a 2-d array of coefficients &#8211; coefs<\/li>\n<li>array of the maximums(right-hand-side) &#8211; maxs<\/li>\n<li>array of unknowns (x1, x2,&#8230;, x5) &#8211; unknowns<\/li>\n<li>array of cost function coefficients &#8211; cost_fn<\/li>\n<\/ul>\n<p>All these are clearly shown below:<br \/>\n<!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\">coefs <span style=\"color: #333333;\">=<\/span> [[<span style=\"color: #0000dd; font-weight: bold;\">5<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">7<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">9<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">2<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">1<\/span>],\r\n        [<span style=\"color: #0000dd; font-weight: bold;\">18<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">4<\/span>, <span style=\"color: #333333;\">-<\/span><span style=\"color: #0000dd; font-weight: bold;\">9<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">10<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">12<\/span>],\r\n        [<span style=\"color: #0000dd; font-weight: bold;\">4<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">7<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">3<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">8<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">5<\/span>],\r\n        [<span style=\"color: #0000dd; font-weight: bold;\">5<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">13<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">15<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">3<\/span>, <span style=\"color: #333333;\">-<\/span><span style=\"color: #0000dd; font-weight: bold;\">7<\/span>]]\r\n\r\nmaxs <span style=\"color: #333333;\">=<\/span> [<span style=\"color: #0000dd; font-weight: bold;\">250<\/span>,  <span style=\"color: #0000dd; font-weight: bold;\">285<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">211<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">315<\/span>] \r\n\r\nunknowns <span style=\"color: #333333;\">=<\/span> [<span style=\"background-color: #fff0f0;\">'x1'<\/span>,<span style=\"background-color: #fff0f0;\">'x2'<\/span>,<span style=\"background-color: #fff0f0;\">'x3'<\/span>,<span style=\"background-color: #fff0f0;\">'x4'<\/span>,<span style=\"background-color: #fff0f0;\">'x5'<\/span>]\r\n\r\ncost_fn <span style=\"color: #333333;\">=<\/span> [<span style=\"color: #0000dd; font-weight: bold;\">7<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">8<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">2<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">9<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">6<\/span>]\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 1<\/strong> &#8211; Create the Solver<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\"># IMPORT THE SOLVER<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">from<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">ortools.linear_solver<\/span> <span style=\"color: #008800; font-weight: bold;\">import<\/span> pywraplp\r\nsolver <span style=\"color: #333333;\">=<\/span> pywraplp<span style=\"color: #333333;\">.<\/span>Solver<span style=\"color: #333333;\">.<\/span>CreateSolver(<span style=\"background-color: #fff0f0;\">'SCIP'<\/span>)\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 2<\/strong> &#8211; Declare the variables<\/p>\n<p>To do this, we loop through the unknown and populate the variables array as shown below:<br \/>\n<!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\"># DECLARE THE VARIABLES<\/span>\r\nvariables <span style=\"color: #333333;\">=<\/span> [[]] <span style=\"color: #333333;\">*<\/span> <span style=\"color: #007020;\">len<\/span>(unknowns)\r\n<span style=\"color: #008800; font-weight: bold;\">for<\/span> i <span style=\"color: #000000; font-weight: bold;\">in<\/span> <span style=\"color: #007020;\">range<\/span>(<span style=\"color: #0000dd; font-weight: bold;\">0<\/span>, <span style=\"color: #007020;\">len<\/span>(unknowns)):\r\n    variables[i] <span style=\"color: #333333;\">=<\/span> solver<span style=\"color: #333333;\">.<\/span>IntVar(<span style=\"color: #0000dd; font-weight: bold;\">0<\/span>, solver<span style=\"color: #333333;\">.<\/span>infinity(), unknowns[i])\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 3<\/strong> &#8211; Create the contraints.<\/p>\n<p>We do this by looping\u00a0 through the constraints with an outer loop. Then, for each iteration, create a new constraint. Then we use an inner loop to iterate through the coefficients and assign the coefficients of each variable.<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\"># CREATE THE CONSTRAINT 0 &lt;= f(x,y) &lt;= 17.5<\/span>\r\nconstraints <span style=\"color: #333333;\">=<\/span> [<span style=\"color: #0000dd; font-weight: bold;\">0<\/span>] <span style=\"color: #333333;\">*<\/span> <span style=\"color: #007020;\">len<\/span>(coefs)\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">for<\/span> i <span style=\"color: #000000; font-weight: bold;\">in<\/span> <span style=\"color: #007020;\">range<\/span>(<span style=\"color: #0000dd; font-weight: bold;\">0<\/span>, <span style=\"color: #007020;\">len<\/span>(coefs)):\r\n    constraints[i] <span style=\"color: #333333;\">=<\/span> solver<span style=\"color: #333333;\">.<\/span>Constraint(<span style=\"color: #0000dd; font-weight: bold;\">0<\/span>, maxs[i])\r\n    <span style=\"color: #008800; font-weight: bold;\">for<\/span> j <span style=\"color: #000000; font-weight: bold;\">in<\/span> <span style=\"color: #007020;\">range<\/span>(<span style=\"color: #0000dd; font-weight: bold;\">0<\/span>, <span style=\"color: #007020;\">len<\/span>(coefs[i])):\r\n        constraints[i]<span style=\"color: #333333;\">.<\/span>SetCoefficient(variables[j], coefs[i][j])\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 4<\/strong> &#8211; Setup the Objective function<\/p>\n<p>To do this, we loop through the cost_fn array and assign coefficients to the corresponding variable<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\"># DEFINE THE OBJECTIVE FUNCTION 7x1\u00a0+ 8x2\u00a0+ 2x3\u00a0+ 9x4\u00a0+ 6x5<\/span>\r\nobj <span style=\"color: #333333;\">=<\/span> solver<span style=\"color: #333333;\">.<\/span>Objective()\r\n<span style=\"color: #008800; font-weight: bold;\">for<\/span> i <span style=\"color: #000000; font-weight: bold;\">in<\/span> <span style=\"color: #007020;\">range<\/span>(<span style=\"color: #0000dd; font-weight: bold;\">0<\/span>, <span style=\"color: #007020;\">len<\/span>(cost_fn)):\r\n    obj<span style=\"color: #333333;\">.<\/span>SetCoefficient(variables[i], cost_fn[i])\r\n\r\nobj<span style=\"color: #333333;\">.<\/span>SetMaximization() <span style=\"color: #888888;\"># set the problem goal as maximization<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 5<\/strong> &#8211; Call the Solver() and print the result<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\"># CALL THE SOLVER AND SHOW THE RESULT<\/span>\r\nstatus <span style=\"color: #333333;\">=<\/span> solver<span style=\"color: #333333;\">.<\/span>Solve()\r\n<span style=\"color: #008800; font-weight: bold;\">print<\/span>(<span style=\"background-color: #fff0f0;\">'Objective value = '<\/span>, obj<span style=\"color: #333333;\">.<\/span>Value())\r\n\r\n<span style=\"color: #888888;\"># PRINT THE RESULTS<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">for<\/span> i <span style=\"color: #000000; font-weight: bold;\">in<\/span> <span style=\"color: #007020;\">range<\/span>(<span style=\"color: #0000dd; font-weight: bold;\">0<\/span>, <span style=\"color: #007020;\">len<\/span>(unknowns)):\r\n    <span style=\"color: #008800; font-weight: bold;\">print<\/span>(<span style=\"background-color: #fff0f0;\">'<\/span><span style=\"background-color: #eeeeee;\">%s<\/span><span style=\"background-color: #fff0f0;\"> = <\/span><span style=\"background-color: #eeeeee;\">%f<\/span><span style=\"background-color: #fff0f0;\">'<\/span> <span style=\"color: #333333;\">%<\/span>(unknowns[i], variables[i]<span style=\"color: #333333;\">.<\/span>solution_value()))\r\n<\/pre>\n<p>The output of the program is given below:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">Objective value =  260.0000000000009\r\nx1 = 8.000000\r\nx2 = 21.000000\r\nx3 = 0.000000\r\nx4 = 2.000000\r\nx5 = 3.000000\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>The complete program is given below:<\/p>\n<figure id=\"attachment_174\" aria-describedby=\"caption-attachment-174\" style=\"width: 876px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/kindsonthegenius.com\/data-science\/wp-content\/uploads\/2021\/01\/Screenshot-2021-01-20-at-15.24.18.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-174 size-full\" src=\"https:\/\/kindsonthegenius.com\/data-science\/wp-content\/uploads\/2021\/01\/Screenshot-2021-01-20-at-15.24.18.png\" alt=\"MIP Linear Program with Python using Array\" width=\"876\" height=\"843\" srcset=\"https:\/\/kindsonthegenius.com\/data-science\/wp-content\/uploads\/2021\/01\/Screenshot-2021-01-20-at-15.24.18.png 876w, https:\/\/kindsonthegenius.com\/data-science\/wp-content\/uploads\/2021\/01\/Screenshot-2021-01-20-at-15.24.18-300x289.png 300w, https:\/\/kindsonthegenius.com\/data-science\/wp-content\/uploads\/2021\/01\/Screenshot-2021-01-20-at-15.24.18-768x739.png 768w\" sizes=\"auto, (max-width: 876px) 100vw, 876px\" \/><\/a><figcaption id=\"caption-attachment-174\" class=\"wp-caption-text\">MIP Linear Program with Python using Array<\/figcaption><\/figure>\n<p><!-- ktg-series-nav --><\/p>\n<nav class=\"ktg-series-nav\" aria-label=\"OR tutorial navigation\">\n<p><strong>Previous:<\/strong> <a href=\"https:\/\/kindsonthegenius.com\/data-science\/integer-optimization-mixed-integer-programmip-with-python\/\">Integer Optimization &#8211; Mixed Integer Program(MIP) with Python<\/a><\/p>\n<p><strong>Next:<\/strong> <a href=\"https:\/\/kindsonthegenius.com\/data-science\/solving-constraints-optimization-problem-with-python\/\">Solving Constraints Optimization  Problem with Python<\/a><\/p>\n<\/nav>\n<p><!-- ktg-alkademy-cta --><\/p>\n<div class=\"ktg-alkademy-cta\" style=\"margin:2em 0;padding:1.25em;border-left:4px solid #2563eb;background:#f8fafc;\">\n<p><strong>Want live data science classes?<\/strong> Join <a href=\"https:\/\/www.alkademy.com\/courses\" target=\"_blank\" rel=\"noopener noreferrer\">Alkademy<\/a> for instructor-led data science and Python courses with hands-on projects.<\/p>\n<\/div>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>In the previous tutorial, we learnt how to solve a Mixed Integer Program(MIP) problem in Python. In that example there were very few constraints and &hellip; <!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-164","post","type-post","status-publish","format-standard","hentry","category-linear-programming"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>An MIP Problem with Python with Constraints Define with Arrays | Data Science Tutorials<\/title>\n<meta name=\"description\" content=\"Define MIP constraints with NumPy arrays in Python. Practical example for building scalable optimization models. Free tutorial with runnable Python code.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/kindsonthegenius.com\/data-science\/an-mip-problem-with-python-with-constraints-define-with-arrays\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"An MIP Problem with Python with Constraints Define with Arrays | Data Science Tutorials\" \/>\n<meta property=\"og:description\" content=\"Define MIP constraints with NumPy arrays in Python. Practical example for building scalable optimization models. Free tutorial with runnable Python code.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/kindsonthegenius.com\/data-science\/an-mip-problem-with-python-with-constraints-define-with-arrays\/\" \/>\n<meta property=\"og:site_name\" content=\"Data Science Tutorials\" \/>\n<meta property=\"article:published_time\" content=\"2026-07-03T21:25:31+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-07-03T21:26:21+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/kindsonthegenius.com\/data-science\/wp-content\/uploads\/2021\/01\/Screenshot-2021-01-20-at-15.24.18.png\" \/>\n\t<meta property=\"og:image:width\" content=\"876\" \/>\n\t<meta property=\"og:image:height\" content=\"843\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"kindsonthegenius\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"kindsonthegenius\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/an-mip-problem-with-python-with-constraints-define-with-arrays\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/an-mip-problem-with-python-with-constraints-define-with-arrays\\\/\"},\"author\":{\"name\":\"kindsonthegenius\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/#\\\/schema\\\/person\\\/31dd138b160587ab3ea3c4746c59bfbc\"},\"headline\":\"An MIP Problem with Python with Constraints Define with Arrays\",\"datePublished\":\"2026-07-03T21:25:31+00:00\",\"dateModified\":\"2026-07-03T21:26:21+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/an-mip-problem-with-python-with-constraints-define-with-arrays\\\/\"},\"wordCount\":338,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/an-mip-problem-with-python-with-constraints-define-with-arrays\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/Screenshot-2021-01-20-at-15.24.18.png\",\"articleSection\":[\"Linear Programming\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/an-mip-problem-with-python-with-constraints-define-with-arrays\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/an-mip-problem-with-python-with-constraints-define-with-arrays\\\/\",\"url\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/an-mip-problem-with-python-with-constraints-define-with-arrays\\\/\",\"name\":\"An MIP Problem with Python with Constraints Define with Arrays | Data Science Tutorials\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/an-mip-problem-with-python-with-constraints-define-with-arrays\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/an-mip-problem-with-python-with-constraints-define-with-arrays\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/Screenshot-2021-01-20-at-15.24.18.png\",\"datePublished\":\"2026-07-03T21:25:31+00:00\",\"dateModified\":\"2026-07-03T21:26:21+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/#\\\/schema\\\/person\\\/31dd138b160587ab3ea3c4746c59bfbc\"},\"description\":\"Define MIP constraints with NumPy arrays in Python. Practical example for building scalable optimization models. Free tutorial with runnable Python code.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/an-mip-problem-with-python-with-constraints-define-with-arrays\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/an-mip-problem-with-python-with-constraints-define-with-arrays\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/an-mip-problem-with-python-with-constraints-define-with-arrays\\\/#primaryimage\",\"url\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/Screenshot-2021-01-20-at-15.24.18.png\",\"contentUrl\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/Screenshot-2021-01-20-at-15.24.18.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/an-mip-problem-with-python-with-constraints-define-with-arrays\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"An MIP Problem with Python with Constraints Define with Arrays\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/#website\",\"url\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/\",\"name\":\"Data Science Tutorials\",\"description\":\"Data Science and Machine Learning in Python and R\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/#\\\/schema\\\/person\\\/31dd138b160587ab3ea3c4746c59bfbc\",\"name\":\"kindsonthegenius\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=wavatar&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=wavatar&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=wavatar&r=g\",\"caption\":\"kindsonthegenius\"},\"url\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/author\\\/kindsonthegenius-3\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"An MIP Problem with Python with Constraints Define with Arrays | Data Science Tutorials","description":"Define MIP constraints with NumPy arrays in Python. Practical example for building scalable optimization models. Free tutorial with runnable Python code.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/kindsonthegenius.com\/data-science\/an-mip-problem-with-python-with-constraints-define-with-arrays\/","og_locale":"en_US","og_type":"article","og_title":"An MIP Problem with Python with Constraints Define with Arrays | Data Science Tutorials","og_description":"Define MIP constraints with NumPy arrays in Python. Practical example for building scalable optimization models. Free tutorial with runnable Python code.","og_url":"https:\/\/kindsonthegenius.com\/data-science\/an-mip-problem-with-python-with-constraints-define-with-arrays\/","og_site_name":"Data Science Tutorials","article_published_time":"2026-07-03T21:25:31+00:00","article_modified_time":"2026-07-03T21:26:21+00:00","og_image":[{"width":876,"height":843,"url":"https:\/\/kindsonthegenius.com\/data-science\/wp-content\/uploads\/2021\/01\/Screenshot-2021-01-20-at-15.24.18.png","type":"image\/png"}],"author":"kindsonthegenius","twitter_card":"summary_large_image","twitter_misc":{"Written by":"kindsonthegenius","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/kindsonthegenius.com\/data-science\/an-mip-problem-with-python-with-constraints-define-with-arrays\/#article","isPartOf":{"@id":"https:\/\/kindsonthegenius.com\/data-science\/an-mip-problem-with-python-with-constraints-define-with-arrays\/"},"author":{"name":"kindsonthegenius","@id":"https:\/\/kindsonthegenius.com\/data-science\/#\/schema\/person\/31dd138b160587ab3ea3c4746c59bfbc"},"headline":"An MIP Problem with Python with Constraints Define with Arrays","datePublished":"2026-07-03T21:25:31+00:00","dateModified":"2026-07-03T21:26:21+00:00","mainEntityOfPage":{"@id":"https:\/\/kindsonthegenius.com\/data-science\/an-mip-problem-with-python-with-constraints-define-with-arrays\/"},"wordCount":338,"commentCount":0,"image":{"@id":"https:\/\/kindsonthegenius.com\/data-science\/an-mip-problem-with-python-with-constraints-define-with-arrays\/#primaryimage"},"thumbnailUrl":"https:\/\/kindsonthegenius.com\/data-science\/wp-content\/uploads\/2021\/01\/Screenshot-2021-01-20-at-15.24.18.png","articleSection":["Linear Programming"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/kindsonthegenius.com\/data-science\/an-mip-problem-with-python-with-constraints-define-with-arrays\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/kindsonthegenius.com\/data-science\/an-mip-problem-with-python-with-constraints-define-with-arrays\/","url":"https:\/\/kindsonthegenius.com\/data-science\/an-mip-problem-with-python-with-constraints-define-with-arrays\/","name":"An MIP Problem with Python with Constraints Define with Arrays | Data Science Tutorials","isPartOf":{"@id":"https:\/\/kindsonthegenius.com\/data-science\/#website"},"primaryImageOfPage":{"@id":"https:\/\/kindsonthegenius.com\/data-science\/an-mip-problem-with-python-with-constraints-define-with-arrays\/#primaryimage"},"image":{"@id":"https:\/\/kindsonthegenius.com\/data-science\/an-mip-problem-with-python-with-constraints-define-with-arrays\/#primaryimage"},"thumbnailUrl":"https:\/\/kindsonthegenius.com\/data-science\/wp-content\/uploads\/2021\/01\/Screenshot-2021-01-20-at-15.24.18.png","datePublished":"2026-07-03T21:25:31+00:00","dateModified":"2026-07-03T21:26:21+00:00","author":{"@id":"https:\/\/kindsonthegenius.com\/data-science\/#\/schema\/person\/31dd138b160587ab3ea3c4746c59bfbc"},"description":"Define MIP constraints with NumPy arrays in Python. Practical example for building scalable optimization models. Free tutorial with runnable Python code.","breadcrumb":{"@id":"https:\/\/kindsonthegenius.com\/data-science\/an-mip-problem-with-python-with-constraints-define-with-arrays\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/kindsonthegenius.com\/data-science\/an-mip-problem-with-python-with-constraints-define-with-arrays\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/kindsonthegenius.com\/data-science\/an-mip-problem-with-python-with-constraints-define-with-arrays\/#primaryimage","url":"https:\/\/kindsonthegenius.com\/data-science\/wp-content\/uploads\/2021\/01\/Screenshot-2021-01-20-at-15.24.18.png","contentUrl":"https:\/\/kindsonthegenius.com\/data-science\/wp-content\/uploads\/2021\/01\/Screenshot-2021-01-20-at-15.24.18.png"},{"@type":"BreadcrumbList","@id":"https:\/\/kindsonthegenius.com\/data-science\/an-mip-problem-with-python-with-constraints-define-with-arrays\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/kindsonthegenius.com\/data-science\/"},{"@type":"ListItem","position":2,"name":"An MIP Problem with Python with Constraints Define with Arrays"}]},{"@type":"WebSite","@id":"https:\/\/kindsonthegenius.com\/data-science\/#website","url":"https:\/\/kindsonthegenius.com\/data-science\/","name":"Data Science Tutorials","description":"Data Science and Machine Learning in Python and R","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/kindsonthegenius.com\/data-science\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/kindsonthegenius.com\/data-science\/#\/schema\/person\/31dd138b160587ab3ea3c4746c59bfbc","name":"kindsonthegenius","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=wavatar&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=wavatar&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=wavatar&r=g","caption":"kindsonthegenius"},"url":"https:\/\/kindsonthegenius.com\/data-science\/author\/kindsonthegenius-3\/"}]}},"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/kindsonthegenius.com\/data-science\/wp-json\/wp\/v2\/posts\/164","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kindsonthegenius.com\/data-science\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kindsonthegenius.com\/data-science\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/data-science\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/data-science\/wp-json\/wp\/v2\/comments?post=164"}],"version-history":[{"count":3,"href":"https:\/\/kindsonthegenius.com\/data-science\/wp-json\/wp\/v2\/posts\/164\/revisions"}],"predecessor-version":[{"id":314,"href":"https:\/\/kindsonthegenius.com\/data-science\/wp-json\/wp\/v2\/posts\/164\/revisions\/314"}],"wp:attachment":[{"href":"https:\/\/kindsonthegenius.com\/data-science\/wp-json\/wp\/v2\/media?parent=164"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/data-science\/wp-json\/wp\/v2\/categories?post=164"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/data-science\/wp-json\/wp\/v2\/tags?post=164"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}