{"id":180,"date":"2026-07-03T21:25:26","date_gmt":"2026-07-03T21:25:26","guid":{"rendered":"https:\/\/www.kindsonthegenius.com\/data-science\/?p=180"},"modified":"2026-07-03T21:26:24","modified_gmt":"2026-07-03T21:26:24","slug":"solving-an-optimization-problem-with-python-step-by-step","status":"publish","type":"post","link":"https:\/\/kindsonthegenius.com\/data-science\/solving-an-optimization-problem-with-python-step-by-step\/","title":{"rendered":"Solving an Optimization Problem with Python &#8211; Step by Step"},"content":{"rendered":"<p>In this example, we are going to solve a typical Constraint Optimization problem. In the previous tutorial, we tool a <a href=\"https:\/\/kindsonthegenius.com\/data-science\/2021\/01\/20\/solving-constraints-optimization-problem-with-python\/\">simple example <\/a>of just one constraint.<\/p>\n<p><strong>Example 1: Maximize the function 2x + 2y + 3z with respect to the following constraints:<\/strong><\/p>\n<table style=\"width: 60%; font-family: 'Times New Roman';\" border=\"0\">\n<tbody>\n<tr>\n<td><em>x<\/em>\u00a0+\u00a0<sup>7<\/sup>\u2044<sub>2<\/sub>\u00a0<em>y<\/em>\u00a0+\u00a0<sup>3<\/sup>\u2044<sub>2<\/sub>\u00a0<em>z<\/em><\/td>\n<td>\u2264<\/td>\n<td>25<\/td>\n<\/tr>\n<tr>\n<td>3<em>x<\/em>\u00a0&#8211; 5<em>y<\/em>\u00a0+ 7<em>z<\/em><\/td>\n<td>\u2264<\/td>\n<td>45<\/td>\n<\/tr>\n<tr>\n<td>5<em>x<\/em>\u00a0+ 2<em>y<\/em>\u00a0&#8211; 6<em>z<\/em><\/td>\n<td>\u2264<\/td>\n<td>37<\/td>\n<\/tr>\n<tr>\n<td><em>x<\/em>,\u00a0<em>y<\/em>,\u00a0<em>z<\/em><\/td>\n<td>\u2265<\/td>\n<td>0<\/td>\n<\/tr>\n<tr>\n<td colspan=\"3\"><em>x<\/em>,\u00a0<em>y<\/em>,\u00a0<em>z<\/em>\u00a0integers<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Note:<\/strong> Since we are performing integer optimization, we must make sure the coefficients of the first constraint are all integer. We can achieve this by multiplying through by 2.<\/p>\n<p>So let&#8217;s now take the steps<\/p>\n<p><strong>Step 1:<\/strong> Declare the model<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"> <span style=\"color: #888888;\"># Declare the Model<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">from<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">ortools.sat.python<\/span> <span style=\"color: #008800; font-weight: bold;\">import<\/span> cp_model\r\nmodel <span style=\"color: #333333;\">=<\/span> cp_model<span style=\"color: #333333;\">.<\/span>CpModel()\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 2:<\/strong> Define the variables<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\"># Define the variables<\/span>\r\nnum_vars <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">3<\/span>\r\nx <span style=\"color: #333333;\">=<\/span> model<span style=\"color: #333333;\">.<\/span>NewIntVar(<span style=\"color: #0000dd; font-weight: bold;\">0<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">50<\/span>, <span style=\"background-color: #fff0f0;\">'x'<\/span>)\r\ny <span style=\"color: #333333;\">=<\/span> model<span style=\"color: #333333;\">.<\/span>NewIntVar(<span style=\"color: #0000dd; font-weight: bold;\">0<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">50<\/span>, <span style=\"background-color: #fff0f0;\">'y'<\/span>)\r\nz <span style=\"color: #333333;\">=<\/span> model<span style=\"color: #333333;\">.<\/span>NewIntVar(<span style=\"color: #0000dd; font-weight: bold;\">0<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">50<\/span>, <span style=\"background-color: #fff0f0;\">'z'<\/span>)\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 3:<\/strong> Create the constraints<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\"># Set up the constraints<\/span>\r\nmodel<span style=\"color: #333333;\">.<\/span>Add(<span style=\"color: #0000dd; font-weight: bold;\">2<\/span><span style=\"color: #333333;\">*<\/span>x <span style=\"color: #333333;\">+<\/span> <span style=\"color: #0000dd; font-weight: bold;\">7<\/span><span style=\"color: #333333;\">*<\/span>y <span style=\"color: #333333;\">+<\/span> <span style=\"color: #0000dd; font-weight: bold;\">3<\/span><span style=\"color: #333333;\">*<\/span>z <span style=\"color: #333333;\">&lt;=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">50<\/span>)\r\nmodel<span style=\"color: #333333;\">.<\/span>Add(<span style=\"color: #0000dd; font-weight: bold;\">3<\/span><span style=\"color: #333333;\">*<\/span>x <span style=\"color: #333333;\">-<\/span> <span style=\"color: #0000dd; font-weight: bold;\">5<\/span><span style=\"color: #333333;\">*<\/span>y <span style=\"color: #333333;\">+<\/span> <span style=\"color: #0000dd; font-weight: bold;\">7<\/span><span style=\"color: #333333;\">*<\/span>z <span style=\"color: #333333;\">&lt;=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">45<\/span>)\r\nmodel<span style=\"color: #333333;\">.<\/span>Add(<span style=\"color: #0000dd; font-weight: bold;\">5<\/span><span style=\"color: #333333;\">*<\/span>x <span style=\"color: #333333;\">+<\/span> <span style=\"color: #0000dd; font-weight: bold;\">2<\/span><span style=\"color: #333333;\">*<\/span>y <span style=\"color: #333333;\">-<\/span> <span style=\"color: #0000dd; font-weight: bold;\">6<\/span><span style=\"color: #333333;\">*<\/span>z <span style=\"color: #333333;\">&lt;=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">37<\/span>)\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 4:<\/strong> Define the cost function<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\"># Define the objective function 2x + 2y + 3z<\/span>\r\nmodel<span style=\"color: #333333;\">.<\/span>Maximize(<span style=\"color: #0000dd; font-weight: bold;\">2<\/span><span style=\"color: #333333;\">*<\/span>x <span style=\"color: #333333;\">+<\/span> <span style=\"color: #0000dd; font-weight: bold;\">2<\/span><span style=\"color: #333333;\">*<\/span>y <span style=\"color: #333333;\">+<\/span> <span style=\"color: #0000dd; font-weight: bold;\">3<\/span><span style=\"color: #333333;\">*<\/span>z)\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 5:<\/strong> Invoke the solver<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\"># Invoke the solver<\/span>\r\nsolver <span style=\"color: #333333;\">=<\/span> cp_model<span style=\"color: #333333;\">.<\/span>CpSolver()\r\nstatus <span style=\"color: #333333;\">=<\/span> solver<span style=\"color: #333333;\">.<\/span>Solve(model)\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 6:<\/strong> Display the results<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\"># Display the results<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">if<\/span> status <span style=\"color: #333333;\">==<\/span> cp_model<span style=\"color: #333333;\">.<\/span>OPTIMAL:\r\n    <span style=\"color: #007020;\">print<\/span>(<span style=\"background-color: #fff0f0;\">'Value of objective function: %i'<\/span> <span style=\"color: #333333;\">%<\/span> solver<span style=\"color: #333333;\">.<\/span>ObjectiveValue())\r\n    <span style=\"color: #007020;\">print<\/span>(<span style=\"background-color: #fff0f0;\">'x = %i'<\/span> <span style=\"color: #333333;\">%<\/span>solver<span style=\"color: #333333;\">.<\/span>Value(x))\r\n    <span style=\"color: #007020;\">print<\/span>(<span style=\"background-color: #fff0f0;\">'y = %i'<\/span> <span style=\"color: #333333;\">%<\/span>solver<span style=\"color: #333333;\">.<\/span>Value(y))\r\n    <span style=\"color: #007020;\">print<\/span>(<span style=\"background-color: #fff0f0;\">'z = %i'<\/span> <span style=\"color: #333333;\">%<\/span>solver<span style=\"color: #333333;\">.<\/span>Value(z))\r\n<\/pre>\n<p>The output would be as shown below:<br \/>\n<!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\">Value of objective function: 35\r\nx = 7\r\ny = 3\r\nz = 5\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Complete program is given below:<\/p>\n<figure id=\"attachment_187\" aria-describedby=\"caption-attachment-187\" style=\"width: 895px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/kindsonthegenius.com\/data-science\/wp-content\/uploads\/2021\/01\/Screenshot-2021-01-21-at-12.43.08.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-187 size-full\" src=\"https:\/\/kindsonthegenius.com\/data-science\/wp-content\/uploads\/2021\/01\/Screenshot-2021-01-21-at-12.43.08.png\" alt=\"Constraint Optimization Problem in Python\" width=\"895\" height=\"848\" srcset=\"https:\/\/kindsonthegenius.com\/data-science\/wp-content\/uploads\/2021\/01\/Screenshot-2021-01-21-at-12.43.08.png 895w, https:\/\/kindsonthegenius.com\/data-science\/wp-content\/uploads\/2021\/01\/Screenshot-2021-01-21-at-12.43.08-300x284.png 300w, https:\/\/kindsonthegenius.com\/data-science\/wp-content\/uploads\/2021\/01\/Screenshot-2021-01-21-at-12.43.08-768x728.png 768w\" sizes=\"auto, (max-width: 895px) 100vw, 895px\" \/><\/a><figcaption id=\"caption-attachment-187\" class=\"wp-caption-text\">Constraint Optimization Problem in Python<\/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\/solving-constraints-optimization-problem-with-python\/\">Solving Constraints Optimization  Problem with Python<\/a><\/p>\n<p><strong>Next:<\/strong> <a href=\"https:\/\/kindsonthegenius.com\/data-science\/solving-cryparithetic-puzzle-in-python\/\">Solving Cryparithetic Puzzle in 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 this example, we are going to solve a typical Constraint Optimization problem. In the previous tutorial, we tool a simple example of just one &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":[29],"tags":[],"class_list":["post-180","post","type-post","status-publish","format-standard","hentry","category-constraint-optimization"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Solving an Optimization Problem with Python &#8211; Step by Step | Data Science Tutorials<\/title>\n<meta name=\"description\" content=\"Walk through a complete optimization problem in Python \u2014 from problem definition to solver setup and interpreting results. Step-by-step guide for practitioners.\" \/>\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\/solving-an-optimization-problem-with-python-step-by-step\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Solving an Optimization Problem with Python &#8211; Step by Step | Data Science Tutorials\" \/>\n<meta property=\"og:description\" content=\"Walk through a complete optimization problem in Python \u2014 from problem definition to solver setup and interpreting results. Step-by-step guide for practitioners.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/kindsonthegenius.com\/data-science\/solving-an-optimization-problem-with-python-step-by-step\/\" \/>\n<meta property=\"og:site_name\" content=\"Data Science Tutorials\" \/>\n<meta property=\"article:published_time\" content=\"2026-07-03T21:25:26+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-07-03T21:26:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/kindsonthegenius.com\/data-science\/wp-content\/uploads\/2021\/01\/Screenshot-2021-01-21-at-12.43.08.png\" \/>\n\t<meta property=\"og:image:width\" content=\"895\" \/>\n\t<meta property=\"og:image:height\" content=\"848\" \/>\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=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/solving-an-optimization-problem-with-python-step-by-step\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/solving-an-optimization-problem-with-python-step-by-step\\\/\"},\"author\":{\"name\":\"kindsonthegenius\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/#\\\/schema\\\/person\\\/31dd138b160587ab3ea3c4746c59bfbc\"},\"headline\":\"Solving an Optimization Problem with Python &#8211; Step by Step\",\"datePublished\":\"2026-07-03T21:25:26+00:00\",\"dateModified\":\"2026-07-03T21:26:24+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/solving-an-optimization-problem-with-python-step-by-step\\\/\"},\"wordCount\":187,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/solving-an-optimization-problem-with-python-step-by-step\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/Screenshot-2021-01-21-at-12.43.08.png\",\"articleSection\":[\"Constraint Optimization\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/solving-an-optimization-problem-with-python-step-by-step\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/solving-an-optimization-problem-with-python-step-by-step\\\/\",\"url\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/solving-an-optimization-problem-with-python-step-by-step\\\/\",\"name\":\"Solving an Optimization Problem with Python &#8211; Step by Step | Data Science Tutorials\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/solving-an-optimization-problem-with-python-step-by-step\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/solving-an-optimization-problem-with-python-step-by-step\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/Screenshot-2021-01-21-at-12.43.08.png\",\"datePublished\":\"2026-07-03T21:25:26+00:00\",\"dateModified\":\"2026-07-03T21:26:24+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/#\\\/schema\\\/person\\\/31dd138b160587ab3ea3c4746c59bfbc\"},\"description\":\"Walk through a complete optimization problem in Python \u2014 from problem definition to solver setup and interpreting results. Step-by-step guide for practitioners.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/solving-an-optimization-problem-with-python-step-by-step\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/solving-an-optimization-problem-with-python-step-by-step\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/solving-an-optimization-problem-with-python-step-by-step\\\/#primaryimage\",\"url\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/Screenshot-2021-01-21-at-12.43.08.png\",\"contentUrl\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/Screenshot-2021-01-21-at-12.43.08.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/solving-an-optimization-problem-with-python-step-by-step\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/kindsonthegenius.com\\\/data-science\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Solving an Optimization Problem with Python &#8211; Step by Step\"}]},{\"@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":"Solving an Optimization Problem with Python &#8211; Step by Step | Data Science Tutorials","description":"Walk through a complete optimization problem in Python \u2014 from problem definition to solver setup and interpreting results. Step-by-step guide for practitioners.","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\/solving-an-optimization-problem-with-python-step-by-step\/","og_locale":"en_US","og_type":"article","og_title":"Solving an Optimization Problem with Python &#8211; Step by Step | Data Science Tutorials","og_description":"Walk through a complete optimization problem in Python \u2014 from problem definition to solver setup and interpreting results. Step-by-step guide for practitioners.","og_url":"https:\/\/kindsonthegenius.com\/data-science\/solving-an-optimization-problem-with-python-step-by-step\/","og_site_name":"Data Science Tutorials","article_published_time":"2026-07-03T21:25:26+00:00","article_modified_time":"2026-07-03T21:26:24+00:00","og_image":[{"width":895,"height":848,"url":"https:\/\/kindsonthegenius.com\/data-science\/wp-content\/uploads\/2021\/01\/Screenshot-2021-01-21-at-12.43.08.png","type":"image\/png"}],"author":"kindsonthegenius","twitter_card":"summary_large_image","twitter_misc":{"Written by":"kindsonthegenius","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/kindsonthegenius.com\/data-science\/solving-an-optimization-problem-with-python-step-by-step\/#article","isPartOf":{"@id":"https:\/\/kindsonthegenius.com\/data-science\/solving-an-optimization-problem-with-python-step-by-step\/"},"author":{"name":"kindsonthegenius","@id":"https:\/\/kindsonthegenius.com\/data-science\/#\/schema\/person\/31dd138b160587ab3ea3c4746c59bfbc"},"headline":"Solving an Optimization Problem with Python &#8211; Step by Step","datePublished":"2026-07-03T21:25:26+00:00","dateModified":"2026-07-03T21:26:24+00:00","mainEntityOfPage":{"@id":"https:\/\/kindsonthegenius.com\/data-science\/solving-an-optimization-problem-with-python-step-by-step\/"},"wordCount":187,"commentCount":0,"image":{"@id":"https:\/\/kindsonthegenius.com\/data-science\/solving-an-optimization-problem-with-python-step-by-step\/#primaryimage"},"thumbnailUrl":"https:\/\/kindsonthegenius.com\/data-science\/wp-content\/uploads\/2021\/01\/Screenshot-2021-01-21-at-12.43.08.png","articleSection":["Constraint Optimization"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/kindsonthegenius.com\/data-science\/solving-an-optimization-problem-with-python-step-by-step\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/kindsonthegenius.com\/data-science\/solving-an-optimization-problem-with-python-step-by-step\/","url":"https:\/\/kindsonthegenius.com\/data-science\/solving-an-optimization-problem-with-python-step-by-step\/","name":"Solving an Optimization Problem with Python &#8211; Step by Step | Data Science Tutorials","isPartOf":{"@id":"https:\/\/kindsonthegenius.com\/data-science\/#website"},"primaryImageOfPage":{"@id":"https:\/\/kindsonthegenius.com\/data-science\/solving-an-optimization-problem-with-python-step-by-step\/#primaryimage"},"image":{"@id":"https:\/\/kindsonthegenius.com\/data-science\/solving-an-optimization-problem-with-python-step-by-step\/#primaryimage"},"thumbnailUrl":"https:\/\/kindsonthegenius.com\/data-science\/wp-content\/uploads\/2021\/01\/Screenshot-2021-01-21-at-12.43.08.png","datePublished":"2026-07-03T21:25:26+00:00","dateModified":"2026-07-03T21:26:24+00:00","author":{"@id":"https:\/\/kindsonthegenius.com\/data-science\/#\/schema\/person\/31dd138b160587ab3ea3c4746c59bfbc"},"description":"Walk through a complete optimization problem in Python \u2014 from problem definition to solver setup and interpreting results. Step-by-step guide for practitioners.","breadcrumb":{"@id":"https:\/\/kindsonthegenius.com\/data-science\/solving-an-optimization-problem-with-python-step-by-step\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/kindsonthegenius.com\/data-science\/solving-an-optimization-problem-with-python-step-by-step\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/kindsonthegenius.com\/data-science\/solving-an-optimization-problem-with-python-step-by-step\/#primaryimage","url":"https:\/\/kindsonthegenius.com\/data-science\/wp-content\/uploads\/2021\/01\/Screenshot-2021-01-21-at-12.43.08.png","contentUrl":"https:\/\/kindsonthegenius.com\/data-science\/wp-content\/uploads\/2021\/01\/Screenshot-2021-01-21-at-12.43.08.png"},{"@type":"BreadcrumbList","@id":"https:\/\/kindsonthegenius.com\/data-science\/solving-an-optimization-problem-with-python-step-by-step\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/kindsonthegenius.com\/data-science\/"},{"@type":"ListItem","position":2,"name":"Solving an Optimization Problem with Python &#8211; Step by Step"}]},{"@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\/180","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=180"}],"version-history":[{"count":5,"href":"https:\/\/kindsonthegenius.com\/data-science\/wp-json\/wp\/v2\/posts\/180\/revisions"}],"predecessor-version":[{"id":316,"href":"https:\/\/kindsonthegenius.com\/data-science\/wp-json\/wp\/v2\/posts\/180\/revisions\/316"}],"wp:attachment":[{"href":"https:\/\/kindsonthegenius.com\/data-science\/wp-json\/wp\/v2\/media?parent=180"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/data-science\/wp-json\/wp\/v2\/categories?post=180"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/data-science\/wp-json\/wp\/v2\/tags?post=180"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}