<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Daniel Godard on Medium]]></title>
        <description><![CDATA[Stories by Daniel Godard on Medium]]></description>
        <link>https://medium.com/@daniel.godard_53172?source=rss-57b331d9562c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*BrdB_Y3lvfVtX1kE</url>
            <title>Stories by Daniel Godard on Medium</title>
            <link>https://medium.com/@daniel.godard_53172?source=rss-57b331d9562c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 00:50:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@daniel.godard_53172/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Using CPLEX Scala Library with Decision Optimization Center 4.0]]></title>
            <link>https://medium.com/decisionbrain/using-cplex-scala-library-with-decision-optimization-center-4-0-daf4758a71f0?source=rss-57b331d9562c------2</link>
            <guid isPermaLink="false">https://medium.com/p/daf4758a71f0</guid>
            <category><![CDATA[optimization]]></category>
            <category><![CDATA[analytics]]></category>
            <category><![CDATA[cplex]]></category>
            <category><![CDATA[scala]]></category>
            <category><![CDATA[developer]]></category>
            <dc:creator><![CDATA[Daniel Godard]]></dc:creator>
            <pubDate>Mon, 01 Jun 2020 08:01:00 GMT</pubDate>
            <atom:updated>2020-06-09T09:20:24.533Z</atom:updated>
            <content:encoded><![CDATA[<p>The CPLEX Scala Library <a href="https://github.com/decisionbrain/cplex-scala"><strong>cplex-scala</strong></a><strong> </strong>is an open-source library written in Scala to build optimization models for CPLEX. It is available on GitHub. This library combines functional programming, mathematical programming, and constraint programming allowing to model optimization problems with a syntax that is close to the standard presentation of these problems in textbooks and scientific papers. For instance, the following constraint:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/164/0*fnrPWTpAu9J-w4XK.gif" /></figure><p>can be written as:</p><p>model.add(sum (for (i &lt;- 1 to n) yield a(i) * x(i)) &lt;= c(j))</p><p>where <strong><em>a</em></strong><em> </em>and <strong><em>x</em></strong> are respectively an array of constants (e.g. floating-point values) and an array of decision variables i.e. the unknowns of the mathematical equations.</p><p>This tiny example is a good illustration of how the syntax is concise and very close to what OR practitioners are used to.</p><p>The <a href="https://github.com/decisionbrain/cplex-scala"><strong>cplex-scala</strong></a> library allows us to build both mathematical programming models and constraint programming models.</p><h3>Why Scala?</h3><p>Scala is a general-purpose language like Java or C#. In a <a href="https://www.linkedin.com/pulse/optimization-aka-prescriptive-analytics-should-we-write-fleischer/?trk=pulse_spock-articles">post</a>, <a href="https://medium.com/u/a44bf0e3dd54">Alex Fleischer</a> gives some pros and cons of a Domain Specific Language (DSL) like OPL versus a General Programming Language (GPL) such as Java or C#. With Scala, there is no need to choose anymore: programmers can <a href="https://scalac.io/encog-dsl-scala-part1/">create their own DSL</a>, and this is what we did in the cplex-scala library.</p><p>In Scala you have similar constructs as in Python:</p><ul><li>Map and filtering</li><li>Tuples</li><li>Dictionaries and Sets</li><li>Slicing</li><li>List comprehensions</li><li>Generators</li><li>Operator overloading</li><li>…</li></ul><p><strong>But unlike Python, Scala is very fast.</strong> The other main advantage of Scala compared to Python is it is a statically typed language. This is specifically important for building robust and industrial applications, while at the same time, type inference makes you <a href="https://www.artima.com/weblogs/viewpost.jsp?thread=328540">feel it is dynamic</a>.</p><p>Having said that, Scala has a longer learning curve than Python. Fortunately, Scala is a JVM language, any Java developer can learn Scala and use it gradually. First step would be to write Scala programs similar to a Java program and become gradually more proficient in functional programming.</p><p>There are excellent MOOC available in Scala. My recommendation is the one from Coursera <a href="https://www.coursera.org/specializations/scala"><strong>Functional Programming in Scala Specialization</strong></a><strong> </strong>from the Ecole Polytechnique Fédérale de Lausanne. Any Java developer should consider attending the first course of the specialization <em>Functional Programming Principles in Scala</em>.</p><p>There are plenty of resources available on the internet; however, I would start with this: <a href="https://www.scala-lang.org/">https://www.scala-lang.org</a></p><p>Scala with CPLEX is a perfect combo for building a powerful optimization modeling language.</p><h3>CPLEX Scala Library available as GitHub Packages</h3><p>Since 1.7.0, to use the <a href="https://github.com/decisionbrain/cplex-scala"><strong>cplex-scala</strong></a> library in your project, you have three options:</p><ul><li>Check out the Git repository and build the library as described in the <a href="https://github.com/decisionbrain/cplex-scala/blob/master/README.md">README</a> file.</li><li>Download the libraries from the section <em>assets </em>of the release page on GitHub:</li><li>Use <a href="https://github.com/features/packages">GitHub Package</a>: this is a recent feature of GitHub which makes it even simpler to use in your projects</li></ul><figure><img alt="GitHub Package Description" src="https://cdn-images-1.medium.com/max/1024/1*2Kfhf5E5xK-HRGc1W-2veg.png" /><figcaption>GitHub Package Description</figcaption></figure><p>In the remaining section, we will give details on how to use GitHub Package and how to <em>install </em>the package using Maven or Gradle.</p><p>Firstly you will need to create a personal access token as described <a href="https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line">here</a>. To install a public repo, the important scope and permission to specify when creating the token through is <strong><em>read:packages</em>:</strong></p><figure><img alt="GitHub Personal Access Token" src="https://cdn-images-1.medium.com/max/1024/1*Rm_h5WS93N-toGTTrtu0Hw.png" /><figcaption>GitHub Personal Access Token</figcaption></figure><h3>How to configure your DOC projects with Gradle</h3><p>Now you have created your personal access token, you need to update the <em>build.gradle </em>files of your DOC project.</p><h3>Adding GitHub Package Repository in Gradle</h3><p>The first step is to add GitHub Package repository in the list of repositories to scan when a dependency is missing. To do so, search for the section <em>allProjects</em> in the <em>build.gradle</em> file in the root directory of your DOC 4.0 project and add a <em>maven </em>entry (see <em>GitHubPackages </em>below):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d9def49920a2db8955703e711fcc834e/href">https://medium.com/media/d9def49920a2db8955703e711fcc834e/href</a></iframe><p><strong><em>Note:</em></strong><em> you can have more than one maven section here.</em></p><p>The above declaration makes use of two Gradle properties (notice the $ sign):</p><ul><li><em>GITHUB_USER</em></li><li><em>GITHUB_TOKEN</em></li></ul><p>The values must be specified in a file <em>gradle.properties. </em>This<em> </em>file is either in the root directory of the project or in the directory <em>.gradle</em> in your home directory. Here is an example of a <em>gradle.properties</em> file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2c0dcbc4571141a216877a58edebdbd9/href">https://medium.com/media/2c0dcbc4571141a216877a58edebdbd9/href</a></iframe><p>Specify for these properties:</p><ul><li><em>GITHUB_USER = </em>GitHub email address associated with your login</li><li><em>GITHUB_TOKEN = </em>personal access token created in your account.</li></ul><p>The next step is to specify the dependencies to the cplex-scala library for your Gradle projects.</p><h3>Adding Dependency to CPLEX Scala Library in Gradle</h3><p>Now that the GitHub Package repository for <a href="https://github.com/decisionbrain/cplex-scala"><strong>cplex-scala</strong></a> has been specified, the next step is to update the file <em>build.gradle</em> of your optimization model.</p><p>In a DOC 4.0 application, after the project scaffolding, you get the typical file structure below:</p><figure><img alt="A Typical DOC 4.0 Project Structure" src="https://cdn-images-1.medium.com/max/459/1*Y_hSGUbbHqPb_Sll5-zhGA.png" /><figcaption>A Typical DOC 4.0 Project Structure</figcaption></figure><p>Here the name of the DOC 4.0 project is <em>aircraft-maintenance.</em></p><p>Open the file <em>build.gradle</em> in your <em>&lt;your-project-name&gt;-libs/engine </em>and add the dependency to <a href="https://github.com/decisionbrain/cplex-scala"><strong>cplex-scala</strong></a> library:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c6da83bf51830ed5613f28eb2cd4b1ba/href">https://medium.com/media/c6da83bf51830ed5613f28eb2cd4b1ba/href</a></iframe><p>The version of the <a href="https://github.com/decisionbrain/cplex-scala"><strong>cplex-scala</strong></a> library can be specified above directly instead of using a Gradle property. In the case above, it is defined in the file <em>versions.gradle </em>in directory <em>gradle/template </em>of your DOC project:</p><figure><img alt="Versions in Gradle" src="https://cdn-images-1.medium.com/max/394/1*M3SeWO-FGdIqNPne2NlY-A.png" /><figcaption>Versions in Gradle</figcaption></figure><p>For instance, the version of the <a href="https://github.com/decisionbrain/cplex-scala"><strong>cplex-scala</strong></a> library used in the DOC 4.0 project is version 1.7.0:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/858eebf38c2fe7026b6c8f08f0a3433d/href">https://medium.com/media/858eebf38c2fe7026b6c8f08f0a3433d/href</a></iframe><p>If you are using IntelliJ, refresh your Gradle project and you will now see the <a href="https://github.com/decisionbrain/cplex-scala"><strong>cplex-scala</strong></a> library in the list of <em>External Libraries:</em></p><figure><img alt="External Libraries in IntelliJ" src="https://cdn-images-1.medium.com/max/514/1*Q3-adjMZF3aOzncHAgC6kw.png" /><figcaption>External Libraries in IntelliJ</figcaption></figure><p>That’s it, you are ready to start implementing your optimization model using the <a href="https://github.com/decisionbrain/cplex-scala"><strong>cplex-scala</strong></a><strong> </strong>library. As a bonus, you have access to the CPLEX Scala documentation right at your fingertips. With IntelliJ select either a method, a class, an object… and type <em>CTRL-Q</em> to get the corresponding documentation:</p><figure><img alt="Quick Documentation View in IntelliJ" src="https://cdn-images-1.medium.com/max/1024/1*XKQVEDG8YADb61giGrZA_A.png" /><figcaption>Quick Documentation View in IntelliJ</figcaption></figure><p>If you have any feedback and ideas on how to improve the <a href="https://github.com/decisionbrain/cplex-scala"><strong>cplex-scala</strong></a> library, please create an <a href="https://github.com/decisionbrain/cplex-scala/issues">issue </a>on GitHub. You are also welcome to contribute to this library by creating a <a href="https://github.com/decisionbrain/cplex-scala/pulls">pull request</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=daf4758a71f0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/decisionbrain/using-cplex-scala-library-with-decision-optimization-center-4-0-daf4758a71f0">Using CPLEX Scala Library with Decision Optimization Center 4.0</a> was originally published in <a href="https://medium.com/decisionbrain">Decision Optimization Center</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>