{"id":5954,"date":"2023-09-20T16:23:39","date_gmt":"2023-09-20T15:23:39","guid":{"rendered":"http:\/\/mosaic-modeling.de\/?page_id=5954"},"modified":"2025-09-26T00:54:47","modified_gmt":"2025-09-25T23:54:47","slug":"use-of-optimization-iv-milp-example","status":"publish","type":"page","link":"https:\/\/mosaic-modeling.de\/?page_id=5954","title":{"rendered":"Use of Optimization IV &#8211; MILP Example"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">On this page<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/mosaic-modeling.de\/?page_id=5954\/#Model-description\" >Model description<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/mosaic-modeling.de\/?page_id=5954\/#Modeling-Workflow\" >Modeling Workflow<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/mosaic-modeling.de\/?page_id=5954\/#Notation-of-equation-system\" >Notation of equation system<\/a><ul class='ez-toc-list-level-5' ><li class='ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/mosaic-modeling.de\/?page_id=5954\/#Base-names\" >Base names<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/mosaic-modeling.de\/?page_id=5954\/#Indices\" >Indices<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/mosaic-modeling.de\/?page_id=5954\/#Equations\" >Equations<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/mosaic-modeling.de\/?page_id=5954\/#Equation-system\" >Equation system<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/mosaic-modeling.de\/?page_id=5954\/#Simulation-workflow\" >Simulation workflow<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/mosaic-modeling.de\/?page_id=5954\/#Optimization-workflow\" >Optimization workflow<\/a><\/li><\/ul><\/nav><\/div>\n<p>This tutorial explains how a simple mixed-integer linear programming problem can be set up and solved.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Model-description\"><\/span>Model description<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>This example is governed by the following equations:<\/p>\n<p class=\"ql-left-displayed-equation\" style=\"line-height: 242px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/mosaic-modeling.de\/wp-content\/ql-cache\/quicklatex.com-cba203709d29dec6eb65b1a4b4f0acf2_l3.png\" height=\"242\" width=\"308\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#98;&#101;&#103;&#105;&#110;&#123;&#97;&#108;&#105;&#103;&#110;&#42;&#125; &#38;&#92;&#109;&#105;&#110;&#95;&#123;&#120;&#95;&#105;&#125;&#32;&#92;&#80;&#104;&#105;&#32;&#61;&#32;&#45;&#50;&#48;&#32;&#120;&#95;&#123;&#105;&#61;&#49;&#125;&#32;&#45;&#32;&#54;&#32;&#120;&#95;&#123;&#105;&#61;&#50;&#125;&#32;&#45;&#32;&#56;&#32;&#120;&#95;&#123;&#105;&#61;&#51;&#125;&#92;&#92;&#91;&#51;&#101;&#120;&#93; &#92;&#109;&#97;&#116;&#104;&#114;&#109;&#123;&#115;&#46;&#92;&#44;&#116;&#46;&#92;&#113;&#117;&#97;&#100;&#125;&#32;&#38;&#48;&#46;&#56;&#32;&#120;&#95;&#123;&#105;&#61;&#49;&#125;&#32;&#43;&#32;&#48;&#46;&#50;&#32;&#120;&#95;&#123;&#105;&#61;&#50;&#125;&#32;&#43;&#32;&#48;&#46;&#51;&#32;&#120;&#95;&#123;&#105;&#61;&#51;&#125;&#32;&#92;&#108;&#101;&#113;&#32;&#50;&#48;&#44;&#32;&#92;&#92;&#91;&#50;&#101;&#120;&#93; &#92;&#112;&#104;&#97;&#110;&#116;&#111;&#109;&#123;&#92;&#109;&#97;&#116;&#104;&#114;&#109;&#123;&#115;&#46;&#92;&#44;&#116;&#46;&#92;&#44;&#125;&#125;&#32;&#38;&#48;&#46;&#52;&#32;&#120;&#95;&#123;&#105;&#61;&#49;&#125;&#32;&#43;&#32;&#48;&#46;&#51;&#32;&#120;&#95;&#123;&#105;&#61;&#50;&#125;&#32;&#92;&#108;&#101;&#113;&#32;&#49;&#48;&#44;&#32;&#92;&#92;&#91;&#50;&#101;&#120;&#93; &#92;&#112;&#104;&#97;&#110;&#116;&#111;&#109;&#123;&#92;&#109;&#97;&#116;&#104;&#114;&#109;&#123;&#115;&#46;&#92;&#44;&#116;&#46;&#92;&#44;&#125;&#125;&#32;&#38;&#48;&#46;&#50;&#32;&#120;&#95;&#123;&#105;&#61;&#49;&#125;&#32;&#43;&#32;&#48;&#46;&#49;&#32;&#120;&#95;&#123;&#105;&#61;&#51;&#125;&#32;&#92;&#108;&#101;&#113;&#32;&#53;&#44;&#32;&#92;&#92;&#91;&#50;&#101;&#120;&#93; &#92;&#112;&#104;&#97;&#110;&#116;&#111;&#109;&#123;&#92;&#109;&#97;&#116;&#104;&#114;&#109;&#123;&#115;&#46;&#92;&#44;&#116;&#46;&#92;&#44;&#125;&#125;&#32;&#38;&#48;&#32;&#92;&#108;&#101;&#113;&#32;&#120;&#95;&#105;&#32;&#92;&#108;&#101;&#113;&#32;&#92;&#105;&#110;&#102;&#116;&#121;&#44;&#32;&#92;&#92;&#91;&#50;&#101;&#120;&#93; &#92;&#112;&#104;&#97;&#110;&#116;&#111;&#109;&#123;&#92;&#109;&#97;&#116;&#104;&#114;&#109;&#123;&#115;&#46;&#92;&#44;&#116;&#46;&#92;&#44;&#125;&#125;&#32;&#38;&#120;&#95;&#105;&#32;&#92;&#105;&#110;&#32;&#92;&#109;&#97;&#116;&#104;&#98;&#98;&#123;&#78;&#125;&#46; &#92;&#101;&#110;&#100;&#123;&#97;&#108;&#105;&#103;&#110;&#42;&#125;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p>\n<p>The example is taken from <a href=\"http:\/\/homepages.ed.ac.uk\/jwp\/newMSOcopy\/section5\/milp.html\">here<\/a>.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Modeling-Workflow\"><\/span>Modeling Workflow<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4><span class=\"ez-toc-section\" id=\"Notation-of-equation-system\"><\/span>Notation of equation system<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>For the notation of the equation, we need to set up all base names, superscripts, and indices that appear in the equations, i.e.<\/p>\n<h5><span class=\"ez-toc-section\" id=\"Base-names\"><\/span>Base names<span class=\"ez-toc-section-end\"><\/span><\/h5>\n<ul>\n<li><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/mosaic-modeling.de\/wp-content\/ql-cache\/quicklatex.com-21f36758b04341c7980aa18b13ced720_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#80;&#104;&#105;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"12\" style=\"vertical-align: 0px;\"\/>, objective function value<\/li>\n<li><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/mosaic-modeling.de\/wp-content\/ql-cache\/quicklatex.com-7e5fbfa0bbbd9f3051cd156a0f1b5e31_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#120;\" title=\"Rendered by QuickLaTeX.com\" height=\"8\" width=\"10\" style=\"vertical-align: 0px;\"\/>, variable<\/li>\n<\/ul>\n<h5><span class=\"ez-toc-section\" id=\"Indices\"><\/span>Indices<span class=\"ez-toc-section-end\"><\/span><\/h5>\n<ul>\n<li><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/mosaic-modeling.de\/wp-content\/ql-cache\/quicklatex.com-31318c5dcb226c69e0818e5f7d2422b5_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#105;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"6\" style=\"vertical-align: 0px;\"\/>, variable index 1..NI<\/li>\n<\/ul>\n<p>The resulting notation has ID 186252.<\/p>\n<h4><span class=\"ez-toc-section\" id=\"Equations\"><\/span>Equations<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>Next, we can define the equations of the model. Therefore, we open the equation editor, load the notation we just created, and enter the equations as stated above in the model description. The formulated equations are available with the IDs 186253, 186255, and 186256. The objective function has ID 186260.<\/p>\n<h4><span class=\"ez-toc-section\" id=\"Equation-system\"><\/span>Equation system<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>Now we are able to construct our equation system:<\/p>\n<ol>\n<li>Go to &#8220;Equation System&#8221; and load the notation for the equations<\/li>\n<li>Add the eleven constraints and the objective function to your system in the Connected Elements tab<\/li>\n<li>Save your equation system<\/li>\n<\/ol>\n<p>This equation system is available with ID 186261.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Simulation-workflow\"><\/span>Simulation workflow<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Your model is now complete and you can move on to the &#8220;Simulation&#8221; section of MOSAICmodeling.<\/p>\n<ol>\n<li>Enter a suitable description<\/li>\n<li>Select the tab Equation System and load the system created in the previous steps. Assign the maximum values for NI = 3 and click on Confirm Index Data<\/li>\n<li>Select the tab Specifications. In the list ALL VARIABLES, you will find the variables as defined in your model notation.<\/li>\n<li>Classify the variables as design variables and iteration values, respectively, by selecting the category from the dropdown menu in the Type column.<\/li>\n<\/ol>\n<p>You can save the variable specification and then the simulation. The simulation is available in MOSAICmodeling with ID 186262. The respective variable specification that may serve as initialization for the optimization has ID 186263.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Optimization-workflow\"><\/span>Optimization workflow<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Go to the &#8220;Optimization&#8221; section of MOSAICmodeling and load the simulation from above. Go to the Variable Specification, select the <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/mosaic-modeling.de\/wp-content\/ql-cache\/quicklatex.com-dad27a9703483183e1afd245f5232b83_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#120;&#95;&#105;\" title=\"Rendered by QuickLaTeX.com\" height=\"11\" width=\"15\" style=\"vertical-align: -3px;\"\/> as OPTIMIZATION_VAR and <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/mosaic-modeling.de\/wp-content\/ql-cache\/quicklatex.com-21f36758b04341c7980aa18b13ced720_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#80;&#104;&#105;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"12\" style=\"vertical-align: 0px;\"\/> as OBJECTIVE_VAR. Check the field Integer for the <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/mosaic-modeling.de\/wp-content\/ql-cache\/quicklatex.com-dad27a9703483183e1afd245f5232b83_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#120;&#95;&#105;\" title=\"Rendered by QuickLaTeX.com\" height=\"11\" width=\"15\" style=\"vertical-align: -3px;\"\/>.<\/p>\n<p>Now, we would like to export the model and solve it. However, many MILP solvers simply expect matrices and vectors for lower and upper bounds of constraints. MOSAICmodeling is not capable of providing that &#8211; even with UDLS capabilities &#8211; because the software does not understand structures such as matrices and vectors. Instead, the constraints are exported as is. Therefore, obtaining a matrix structure as typically used in software, such as Matlab, is not straightforward with MOSAICmodeling. However, other software packages do not require a matrix formulation.<\/p>\n<p>Due to these reasons, we solve our models with GAMS or AMPL. To this end, we go to the tab Code Generation &amp; Execution and connect to the NEOS server (tab Code Generation &amp; Execution on NEOS Server). Here, the user must accept the Terms of Use, select Mixed Integer Linear Programming as Category, choose a solver from the list, and select the preferred language. Then, click on Generate Code &amp; Submit and inspect the results in the tab History. The following solution is obtained with CBC and AMPL:<\/p>\n<ul>\n<li><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/mosaic-modeling.de\/wp-content\/ql-cache\/quicklatex.com-f74e449d82b3e4bf444ecf9ab0f2d5de_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#120;&#95;&#123;&#105;&#61;&#49;&#125;&#32;&#61;&#32;&#48;\" title=\"Rendered by QuickLaTeX.com\" height=\"15\" width=\"66\" style=\"vertical-align: -3px;\"\/><\/li>\n<li><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/mosaic-modeling.de\/wp-content\/ql-cache\/quicklatex.com-7c4e8591cb2493115d1f64f2a1acab02_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#120;&#95;&#123;&#105;&#61;&#50;&#125;&#32;&#61;&#32;&#51;&#49;\" title=\"Rendered by QuickLaTeX.com\" height=\"15\" width=\"74\" style=\"vertical-align: -3px;\"\/><\/li>\n<li><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/mosaic-modeling.de\/wp-content\/ql-cache\/quicklatex.com-f94857839092a663dd379166aa960db8_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#120;&#95;&#123;&#105;&#61;&#51;&#125;&#32;&#61;&#32;&#52;&#54;\" title=\"Rendered by QuickLaTeX.com\" height=\"15\" width=\"75\" style=\"vertical-align: -3px;\"\/><\/li>\n<li><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/mosaic-modeling.de\/wp-content\/ql-cache\/quicklatex.com-237905d14c50f2f29e7585fb0b865408_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#80;&#104;&#105;&#32;&#61;&#32;&#45;&#53;&#53;&#52;\" title=\"Rendered by QuickLaTeX.com\" height=\"13\" width=\"77\" style=\"vertical-align: 0px;\"\/><\/li>\n<\/ul>\n<p>The optimization is available with ID 186264, the variable specification modified for optimization with ID 186265.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial explains how a simple mixed-integer linear programming problem can be set up and solved. Model description This example is governed by the following equations: &nbsp; &nbsp; The example is taken from here. Modeling Workflow Notation of equation system For the notation of the equation, we need to set up all base names, superscripts, [&hellip;]<\/p>\n","protected":false},"author":252,"featured_media":0,"parent":5203,"menu_order":3,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-5954","page","type-page","status-publish","czr-hentry"],"_links":{"self":[{"href":"https:\/\/mosaic-modeling.de\/index.php?rest_route=\/wp\/v2\/pages\/5954","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mosaic-modeling.de\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/mosaic-modeling.de\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/mosaic-modeling.de\/index.php?rest_route=\/wp\/v2\/users\/252"}],"replies":[{"embeddable":true,"href":"https:\/\/mosaic-modeling.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5954"}],"version-history":[{"count":17,"href":"https:\/\/mosaic-modeling.de\/index.php?rest_route=\/wp\/v2\/pages\/5954\/revisions"}],"predecessor-version":[{"id":6233,"href":"https:\/\/mosaic-modeling.de\/index.php?rest_route=\/wp\/v2\/pages\/5954\/revisions\/6233"}],"up":[{"embeddable":true,"href":"https:\/\/mosaic-modeling.de\/index.php?rest_route=\/wp\/v2\/pages\/5203"}],"wp:attachment":[{"href":"https:\/\/mosaic-modeling.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5954"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}