├── .gitattributes ├── Factory-planning.pdf ├── Factory-planning ├── factoryPlanning.mod └── factoryPlanning.xlsx ├── LICENSE.txt ├── Production-plan.pdf ├── Production-plan ├── production_cloud.dat ├── production_cloud.mod └── production_data.mod ├── README.md ├── Warehouse-location ├── warehouse_cloud.dat ├── warehouse_cloud.mod └── warehouse_data.mod ├── info.json └── warehouse.pdf /.gitattributes: -------------------------------------------------------------------------------- 1 | *.mod linguist-language=OPL 2 | *.dat linguist-language=OPL 3 | -------------------------------------------------------------------------------- /Factory-planning.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBMDecisionOptimization/Decision-Optimization-with-OPL-CPLEX-samples/de1c6f1d7737f3215d38c47cb2accdc2113941aa/Factory-planning.pdf -------------------------------------------------------------------------------- /Factory-planning/factoryPlanning.mod: -------------------------------------------------------------------------------- 1 | // -------------------------------------------------------------------------- 2 | // Licensed Materials - Property of IBM 3 | // 4 | // 5725-A06 5725-A29 5724-Y48 5724-Y49 5724-Y54 5724-Y55 5 | // Copyright IBM Corporation 1998, 2013. All Rights Reserved. 6 | // 7 | // Note to U.S. Government Users Restricted Rights: 8 | // Use, duplication or disclosure restricted by GSA ADP Schedule 9 | // Contract with IBM Corp. 10 | // -------------------------------------------------------------------------- 11 | 12 | // Problem 3 from Model Building in Mathematical Programming, 3rd ed. 13 | // by HP Williams 14 | // Factory Planning 15 | // This model is described in the documentation. 16 | // See "Samples" in the Documentation home page. 17 | 18 | tuple TProduct { 19 | key string name; 20 | float profit; 21 | } 22 | {TProduct} Products = ...; 23 | 24 | /// 25 | /// months are integer from 1 to nbMonths 26 | /// number of work hours per month is a float 27 | /// calendar-related data are in a single-row table Calendar 28 | tuple TCalendar { 29 | int nbMonths; 30 | float hoursPerMonth; 31 | } 32 | TCalendar Calendar = ...; 33 | 34 | /// 35 | /// Inventory data: 36 | /// - initial & final quantity (hard constraints) 37 | /// - maximum quantity held in stock for each period (month) 38 | /// - cost incurred for each unit in stock. 39 | /// 40 | /// Cost data are stored in a single-row table Inventory 41 | 42 | tuple TInventoryData { 43 | float initialQuantity; 44 | float finalQuantity; 45 | float maxQuantity; 46 | float costPerUnit; 47 | } 48 | TInventoryData Inventory = ...; 49 | 50 | /// 51 | /// A process is a resource (a machine) identified by its name. 52 | tuple TProcess { 53 | key string name; 54 | } 55 | {TProcess} Processes = ...; 56 | 57 | /// 58 | /// This table stores, for each process type and month, 59 | /// the number of available machines. 60 | /// As this could be an average, it is modeled as a float. 61 | tuple TProcessNum { 62 | key string process; 63 | key int month; 64 | float num; 65 | } 66 | {TProcessNum} NumProcessPerMonth = ...; 67 | 68 | /// 69 | /// This table stores the quantity of process r required by product p. 70 | tuple TProcessProduct { 71 | key string process; 72 | key string product; 73 | float required; 74 | } 75 | {TProcessProduct} ProcessPerProduct = ...; 76 | 77 | /// 78 | /// This table stores an upper bound on the quantity of product 79 | /// that can be sold in agiven month. 80 | tuple TProductForecastPerMonth { 81 | key string product; 82 | key int month; 83 | float forecast; 84 | } 85 | {TProductForecastPerMonth} MarketForecastPerMonth = ...; 86 | 87 | 88 | /// Output Table 89 | /// The output is a set of tuples, indicating, for each (product, mpnth) 90 | /// which quantities are produced, sold, and held in stock. 91 | tuple TPlan { 92 | key string product; 93 | key int month; 94 | float make; 95 | float sell; 96 | float hold; 97 | } 98 | 99 | /// --- 100 | /// Internal modeling Data 101 | /// for convenience, we transform table data into OPL arrays 102 | /// ---- 103 | int NbMonths = Calendar.nbMonths; 104 | range Months = 1..NbMonths; 105 | 106 | 107 | float forecasts[p in Products][m in Months] = sum(f in MarketForecastPerMonth: f.month==m && f.product == p.name) f.forecast; 108 | float processUsages[ r in Processes][p in Products] = sum(u in ProcessPerProduct: u.process == r.name && u.product==p.name) u.required; 109 | float processCapacities[ r in Processes][m in Months] = sum(np in NumProcessPerMonth : np.process == r.name && m == np.month) np.num; 110 | 111 | dvar float+ Make[Products][Months]; 112 | 113 | /// REMARK: Hold variable range from 0, not 1 as we take into account initial stock 114 | dvar float+ Hold[Products][0..NbMonths] in 0..Inventory.maxQuantity; 115 | dvar float+ Sell[p in Products][m in Months] in 0..forecasts[p][m]; 116 | 117 | dexpr float totalProfit = 118 | sum (p in Products, m in Months) p.profit * Sell[p][m]; 119 | dexpr float totalInventoryCost = 120 | sum (p in Products, m in Months) Inventory.costPerUnit * Hold[p][m]; 121 | 122 | maximize totalProfit - totalInventoryCost; 123 | 124 | subject to { 125 | // Limits on process capacity 126 | forall(m in Months, r in Processes) 127 | ctCapacity: 128 | sum(p in Products) processUsages[r][p] * Make[p][m] 129 | <= processCapacities[r][m] * Calendar.hoursPerMonth; 130 | 131 | // Inventory balance 132 | forall(p in Products, m in Months) 133 | ct_inventory_balance: 134 | Hold[p][m-1] + Make[p][m] == Sell[p][m] + Hold[p][m]; 135 | 136 | // Initial and final inventories are fixed 137 | forall(p in Products) { 138 | ct_initial_inventory: 139 | Hold[p][0] == Inventory.initialQuantity; 140 | ct_final_inventory: 141 | Hold[p][NbMonths] == Inventory.finalQuantity; 142 | } 143 | } 144 | 145 | {TPlan} plan; /// to be filled in post-processing. 146 | 147 | /// 148 | /// This block fills the output table. 149 | /// 150 | execute POSTPROCESS { 151 | for(var m in Months) { 152 | for(var p in Products) { 153 | plan.addOnly(p.name, m, Make[p][m], Sell[p][m], Hold[p][m]); 154 | writeln(" plan[",m,", ",p.name,"] = "); 155 | }//for 156 | }//for 157 | } 158 | 159 | /* 160 | // solution (optimal) with objective 93715.1785714286 161 | plan[1][Prod1] = 162 | plan[1][Prod2] = 163 | plan[1][Prod3] = 164 | plan[1][Prod4] = 165 | plan[1][Prod5] = 166 | plan[1][Prod6] = 167 | plan[1][Prod7] = 168 | plan[2][Prod1] = 169 | plan[2][Prod2] = 170 | plan[2][Prod3] = 171 | plan[2][Prod4] = 172 | plan[2][Prod5] = 173 | plan[2][Prod6] = 174 | plan[2][Prod7] = 175 | plan[3][Prod1] = 176 | plan[3][Prod2] = 177 | plan[3][Prod3] = 178 | plan[3][Prod4] = 179 | plan[3][Prod5] = 180 | plan[3][Prod6] = 181 | plan[3][Prod7] = 182 | plan[4][Prod1] = 183 | plan[4][Prod2] = 184 | plan[4][Prod3] = 185 | plan[4][Prod4] = 186 | plan[4][Prod5] = 187 | plan[4][Prod6] = 188 | plan[4][Prod7] = 189 | plan[5][Prod1] = 190 | plan[5][Prod2] = 191 | plan[5][Prod3] = 192 | plan[5][Prod4] = 193 | plan[5][Prod5] = 194 | plan[5][Prod6] = 195 | plan[5][Prod7] = 196 | plan[6][Prod1] = 197 | plan[6][Prod2] = 198 | plan[6][Prod3] = 199 | plan[6][Prod4] = 200 | plan[6][Prod5] = 201 | plan[6][Prod6] = 202 | plan[6][Prod7] = 203 | */ 204 | -------------------------------------------------------------------------------- /Factory-planning/factoryPlanning.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBMDecisionOptimization/Decision-Optimization-with-OPL-CPLEX-samples/de1c6f1d7737f3215d38c47cb2accdc2113941aa/Factory-planning/factoryPlanning.xlsx -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [2015] [IBM Corporation] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /Production-plan.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBMDecisionOptimization/Decision-Optimization-with-OPL-CPLEX-samples/de1c6f1d7737f3215d38c47cb2accdc2113941aa/Production-plan.pdf -------------------------------------------------------------------------------- /Production-plan/production_cloud.dat: -------------------------------------------------------------------------------- 1 | // -------------------------------------------------------------------------- 2 | // Licensed Materials - Property of IBM 3 | // 4 | // 5725-A06 5725-A29 5724-Y48 5724-Y49 5724-Y54 5724-Y55 5 | // Copyright IBM Corporation 1998, 2013. All Rights Reserved. 6 | // 7 | // Note to U.S. Government Users Restricted Rights: 8 | // Use, duplication or disclosure restricted by GSA ADP Schedule 9 | // Contract with IBM Corp. 10 | // -------------------------------------------------------------------------- 11 | 12 | Products= 13 | { 14 | <"kluski" , 100 , 0.6, 0.8 > 15 | <"capellini" , 200 , 0.8, 0.9 > 16 | <"fettucine" , 300 , 0.3, 0.4 > 17 | }; 18 | 19 | Resources = 20 | { 21 | <"flour" 20> 22 | <"eggs" 40> 23 | }; 24 | 25 | Consumptions = 26 | { 27 | <"kluski" "flour" 0.5> 28 | <"kluski" "eggs" 0.2> 29 | 30 | <"capellini" "flour" 0.4> 31 | <"capellini" "eggs" 0.4> 32 | 33 | <"fettucine" "flour" 0.3> 34 | <"fettucine" "eggs" 0.6> 35 | }; 36 | 37 | 38 | -------------------------------------------------------------------------------- /Production-plan/production_cloud.mod: -------------------------------------------------------------------------------- 1 | // -------------------------------------------------------------------------- 2 | // Licensed Materials - Property of IBM 3 | // 4 | // 5725-A06 5725-A29 5724-Y48 5724-Y49 5724-Y54 5724-Y55 5 | // Copyright IBM Corporation 1998, 2013. All Rights Reserved. 6 | // 7 | // Note to U.S. Government Users Restricted Rights: 8 | // Use, duplication or disclosure restricted by GSA ADP Schedule 9 | // Contract with IBM Corp. 10 | // -------------------------------------------------------------------------- 11 | 12 | include "production_data.mod"; 13 | 14 | /// variables. 15 | dvar float+ Inside [Products]; 16 | dvar float+ Outside[Products]; 17 | 18 | dexpr float totalInsideCost = sum(p in Products) p.insideCost * Inside[p]; 19 | dexpr float totalOutsideCost = sum(p in Products) p.outsideCost * Outside[p]; 20 | 21 | minimize 22 | totalInsideCost + totalOutsideCost; 23 | 24 | subject to { 25 | forall( r in Resources ) 26 | ctCapacity: 27 | sum( k in Consumptions, p in Products 28 | : k.resourceId == r.name && p.name == k.productId ) 29 | k.consumption* Inside[p] <= r.capacity; 30 | 31 | forall(p in Products) 32 | ctDemand: 33 | Inside[p] + Outside[p] >= p.demand; 34 | } 35 | 36 | {TPlannedProduction} plan; 37 | 38 | execute PRINT_SOLUTION { 39 | plan.clear(); 40 | for (var p in Products) { 41 | writeln(" product: ", p.name, ", in=", Inside[p], ", out=", Outside[p]); 42 | // store results in output table. 43 | plan.addOnly(p.name, Inside[p], Outside[p]); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Production-plan/production_data.mod: -------------------------------------------------------------------------------- 1 | // -------------------------------------------------------------------------- 2 | // Licensed Materials - Property of IBM 3 | // 4 | // 5725-A06 5725-A29 5724-Y48 5724-Y49 5724-Y54 5724-Y55 5 | // Copyright IBM Corporation 1998, 2013. All Rights Reserved. 6 | // 7 | // Note to U.S. Government Users Restricted Rights: 8 | // Use, duplication or disclosure restricted by GSA ADP Schedule 9 | // Contract with IBM Corp. 10 | // -------------------------------------------------------------------------- 11 | 12 | tuple TProduct { 13 | key string name; 14 | float demand; 15 | float insideCost; 16 | float outsideCost; 17 | }; 18 | 19 | tuple TResource { 20 | key string name; 21 | float capacity; 22 | }; 23 | 24 | tuple TConsumption { 25 | key string productId; 26 | key string resourceId; 27 | float consumption; 28 | } 29 | 30 | {TProduct} Products = ...; 31 | {TResource} Resources = ...; 32 | {TConsumption} Consumptions = ...; 33 | 34 | /// solution 35 | tuple TPlannedProduction { 36 | key string productId; 37 | float insideProduction; 38 | float outsideProduction; 39 | } 40 | 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # IBM® Decision Optimization Modeling with OPL and CPLEX 2 | 3 | Welcome to IBM® Decision Optimization Modeling with OPL and CPLEX on IBM® Decision Optimization on Cloud (DOcplexcloud) 4 | 5 | This library contains various model examples with different file types. Brief descriptions of these models are provided later in this file. For each sample you can find the: 6 | * **documentation** - a pdf file describing the optimization problem and the OPL model 7 | * **model and data files** - a folder containing the .mod, .dat or .xls files 8 | 9 | 10 | You can solve OPL models with CPLEX on DOcplexcloud by 11 | 12 | - uploading a MOD file with optional JSON file(s) and/or zero or more DAT file(s) and/or zero or more Excel files. 13 | - uploading an OPLPROJECT file with a default run configuration, one or more MOD file(s), zero or more DAT file(s), and an optional OPS file. 14 | 15 | An OPL project can have only one default run configuration. 16 | 17 | All files must be in the same root directory; uploads containing multiple directories are not supported. Problem files cannot connect to an external data source. You cannot drag and drop files directly from an archive viewer into the DropSolve interface. All files must be dropped on the DropSolve interface simultaneously. 18 | 19 | Solving with the IBM Decision Optimization on Cloud service (DOcplexcloud) requires that you 20 | [Register for a DropSolve account](https://dropsolve-oaas.docloud.ibmcloud.com/software/analytics/docloud). You can register for the DOcplexcloud free trial and use it free for 30 days. 21 | 22 | ## Model descriptions 23 | ### Factory-planning 24 | How do you find the optimal way to use your factory to increase your profits? 25 | 26 | This sample shows how to find the optimal mix of products to manufacture, given production capacities and marketing limitations. You have a factory that makes seven different types of metal products. You use five different machines to process the products and each product requires the use of certain machine processes for varying lengths of time. Some products are more profitable than others, but these often require greater utilization of the machinery. There are marketing limits to the products as well. You will not be able to sell more of certain products during certain months, even if you can manufacture more. Finally, the machines used in some processes will be down for maintenance during certain months. 27 | 28 | This is an example of a multi-period production problem. A single-period production problem just evaluates the best manufacturing decisions for each month separately. However, in this model, it's possible to store certain products. So, you want to create a model that links all the months and takes into account the amounts of products held in storage. 29 | 30 | This sample shows how to make a six-month plan that optimizes your factory's profits. 31 | 32 | This sample uses a Microsoft **Excel** file as a data source. 33 | 34 | ### Production-plan 35 | How does a company decide what proportion of its products to produce inside the company and what to buy from outside the company? 36 | 37 | To meet the demands of its customers, a company manufactures products in its own factories (inside production) or buys them from other companies (outside production). The problem is to determine how much of each product should be produced inside the company and how much outside, while minimizing the overall production cost, meeting the demand, and satisfying the resource constraints. 38 | 39 | The model minimizes the production cost for a number of products while satisfying customer demand. Each product can be produced either inside the company, or outside at a higher cost. The inside production is constrained by the company's resources, while outside production is considered unlimited. 40 | 41 | The model first declares the products and the resources. The data consists of a description of the products, that is, the demand, the inside and outside costs, the resource consumption, and the capacity of the various resources. The variables for this problem are the inside and outside production for each product. 42 | 43 | A production planning problem exists because there are limited production resources that cannot be stored from period to period. Choices must be made as to which resources to include and how to model their capacity, their consumption, and their costs. 44 | 45 | This production problem uses Mixed Integer-Linear Programming (MILP), which includes both integer and real variables. 46 | 47 | ### Warehouse-location 48 | Where is the best location to build a warehouse so that it can supply its existing stores at a minimal cost? 49 | 50 | A retail company is considering a number of locations for building warehouses to supply existing stores. Each possible warehouse has a fixed maintenance cost and a maximum capacity specifying how many stores it can support. In addition, each store can be supplied by only one warehouse and the supply cost to the store differs according to the warehouse selected. 51 | 52 | The problem consists of choosing which warehouses to build and which of them should supply the various stores while minimizing the total cost, that is, the sum of the fixed and supply costs. 53 | 54 | Warehouse location is a typical discrete optimization problem that uses Integer Programming (IP). Integer Programming is the class of problems defined as the optimization of a linear function, subject to linear constraints over integer variables. IP programs are generally harder to solve than linear programs and, to be solved efficiently, need to be smaller than linear programs. 55 | 56 | 57 | ## License 58 | 59 | This library is delivered under the Apache License Version 2.0, January 2004 (see LICENSE.txt). 60 | -------------------------------------------------------------------------------- /Warehouse-location/warehouse_cloud.dat: -------------------------------------------------------------------------------- 1 | // -------------------------------------------------------------------------- 2 | // Licensed Materials - Property of IBM 3 | // 4 | // 5725-A06 5725-A29 5724-Y48 5724-Y49 5724-Y54 5724-Y55 5 | // Copyright IBM Corporation 1998, 2013. All Rights Reserved. 6 | // 7 | // Note to U.S. Government Users Restricted Rights: 8 | // Use, duplication or disclosure restricted by GSA ADP Schedule 9 | // Contract with IBM Corp. 10 | // -------------------------------------------------------------------------- 11 | 12 | // 10 stores to be opened. 13 | plan = <10>; 14 | 15 | warehouses = 16 | { 17 | 18 | , 19 | , 20 | , 21 | , 22 | }; 23 | 24 | supplyCosts = 25 | { 26 | 27 | , 28 | , 29 | , 30 | , 31 | , 32 | , 33 | , 34 | , 35 | , 36 | // 37 | , 38 | , 39 | , 40 | , 41 | , 42 | , 43 | , 44 | , 45 | , 46 | , 47 | // 48 | , 49 | , 50 | , 51 | , 52 | , 53 | , 54 | , 55 | , 56 | , 57 | , 58 | // 59 | , 60 | , 61 | , 62 | , 63 | , 64 | , 65 | , 66 | , 67 | , 68 | , 69 | // 70 | , 71 | , 72 | , 73 | , 74 | , 75 | , 76 | , 77 | , 78 | , 79 | , 80 | 81 | }; 82 | -------------------------------------------------------------------------------- /Warehouse-location/warehouse_cloud.mod: -------------------------------------------------------------------------------- 1 | // -------------------------------------------------------------------------- 2 | // Licensed Materials - Property of IBM 3 | // 4 | // 5725-A06 5725-A29 5724-Y48 5724-Y49 5724-Y54 5724-Y55 5 | // Copyright IBM Corporation 1998, 2013. All Rights Reserved. 6 | // 7 | // Note to U.S. Government Users Restricted Rights: 8 | // Use, duplication or disclosure restricted by GSA ADP Schedule 9 | // Contract with IBM Corp. 10 | // -------------------------------------------------------------------------- 11 | 12 | include "warehouse_data.mod"; 13 | 14 | 15 | range stores = 1..plan.nbStores; 16 | 17 | dvar boolean Open[ warehouses ]; 18 | dvar boolean Supply[ stores ][ warehouses ]; 19 | 20 | // expression 21 | dexpr float totalOpeningCost = sum( w in warehouses ) w.fixedCost * Open[w]; 22 | dexpr float totalSupplyCost = sum( w in warehouses , s in stores, k in supplyCosts : k.storeId == s && k.warehouseName == w.name ) 23 | Supply[s][w] * k.cost; 24 | 25 | minimize 26 | totalOpeningCost + totalSupplyCost; 27 | 28 | subject to { 29 | forall( s in stores ) 30 | ctEachStoreHasOneWarehouse: 31 | sum( w in warehouses ) Supply[s][w] == 1; 32 | 33 | forall( w in warehouses, s in stores ) 34 | ctUseOpenWarehouses: 35 | Supply[s][w] <= Open[w]; 36 | 37 | forall( w in warehouses ) 38 | ctMaxUseOfWarehouse: 39 | sum( s in stores) Supply[s][w] <= w.capacity; 40 | } 41 | 42 | 43 | {int} StoresSupplied[w in warehouses] = { s | s in stores : Supply[s][w] == 1 }; 44 | {string} OpenWarehouses = { w.name | w in warehouses : Open[w] == 1 }; 45 | tuple TSuppliedStore { 46 | string warehouseName; 47 | int storeId; 48 | } 49 | {TSuppliedStore} network; 50 | 51 | execute DISPLAY_RESULTS{ 52 | network.clear(); 53 | writeln("* Open Warehouses=", OpenWarehouses); 54 | for ( var w in warehouses) { 55 | if ( Open[w] ==1) { 56 | writeln("* stores supplied by ", w.name, ": ", StoresSupplied[w]); 57 | for (var s in stores) { 58 | if (Supply[s][w] == 1) { 59 | network.addOnly(w.name, s); 60 | } 61 | } 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Warehouse-location/warehouse_data.mod: -------------------------------------------------------------------------------- 1 | 2 | tuple TWarehouse { 3 | key string name; 4 | int capacity; 5 | float fixedCost; 6 | } 7 | 8 | tuple TSupplyCost { 9 | key string warehouseName; 10 | key int storeId; 11 | float cost; 12 | } 13 | 14 | tuple TPlan { 15 | int nbStores; 16 | } 17 | 18 | TPlan plan = ...; 19 | {TWarehouse} warehouses = ...; 20 | {TSupplyCost} supplyCosts = ...; -------------------------------------------------------------------------------- /info.json: -------------------------------------------------------------------------------- 1 | { 2 | "provider": ["IBM"], 3 | "name": "Decision Optimisation with OPL-CPLEX samples", 4 | "model": ["CPLEX", "OPL"], 5 | "development": [""], 6 | "category": [{ 7 | "MODELING": ["ADVANCED MODELING"] 8 | }], 9 | "industry": ["Operational research"], 10 | "abstract": "OPL models, with different file types, for solution with CPLEX using DOcplexcloud." 11 | } -------------------------------------------------------------------------------- /warehouse.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBMDecisionOptimization/Decision-Optimization-with-OPL-CPLEX-samples/de1c6f1d7737f3215d38c47cb2accdc2113941aa/warehouse.pdf --------------------------------------------------------------------------------