Find out the right WooCommerce WordPress Themes for your online business store

Are you looking for a WooCommerce Themes that best suits your business? But confused in choosing the right theme among the bunch of themes available in the market?. Fact is that not all WordPress…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




A primer on the Operations Research libraries in Python and Julia

As a user of Medium for the past two years, I must say that the community has been wonderful thus far. A gigantic community of like minded individuals, relentless in the pursuit of knowledge.

Being somebody who has benefited tremendously from posts written by fellow authors, I feel encouraged to do the same.

If synthesizing the material from a dozen disparate sources into a single post here, allows the shortening of the learning journey of even one other person, I think that itself constitutes a worthwhile endeavour.

It also serves as a sanity check for me to ensure, that I have actually understood what i’ve been reading.

After all, if I lack the ability to document and explain my knowledge here in a cogent manner, it must mean my mastery is lacking.

With that said, let’s jump right in.

Operations Research, and Optimization. These are two terms are used fairly interchangeably in the academic and commercial realms.

They can broadly be be seen as using the tools of mathematics to find the most suitable courses of action, out of an astronomically large number of possible paths.

While the vernacular may sound intimidating, the field is vast and there are plenty of possible uses of Operations Research that may be understood just fine, even without a rigorous technical grounding.

Take for instance, the following; The Grey Wolf Optimization algorithm.

It finds its origins in the population dynamics of wolves and their prey.

A plot of the Rastrigin function in the GWO algorithm

The key task in Operation Research is the maximising (or minimizing), of the objective function. And that would depend on how we frame the problem.

It is also called the loss or cost function in different literature.

In the coloured plot of the Rastrigin function, we can see the local maxima and minima of the function, given by the dark red, and dark blue pointed features.

For the subsequent section, I will be walking through a simple example to demonstrate a start to end process of an optimization problem. From formulating the problem, to solving it to obtain the desired values.

For the Python version, we make use of the the Google Operation Research Toolkit [Google OR-Tools]. It contains a whole suite of optimization libraries made open source by Google.

One of the examples given in OR-tools is listed here.

A problem of 3 variables, and 4 constraints.

Or technically, we could say 5 constraints, or even up to 7. Considering that we are confining all 3 variables to integer values.

A typical problem in constraint optimization.

*Note*

The CP model used in this toolkit is specifically designed to work with integers, in order to increase computational speed.

Hence if we encounter fractions in our problem, we need to convert them into integers through multiplication by another number.

Hence we transform the first equation from a to b, leaving it functionally the same.

Next we need to declare our variables, as well as constraints.

The values 50, 45, 37 denote the state space that the objective function can exist.

And the integer values that our variables are constrained to take are denoted via the function: “NewIntVar”. Shorthand for ‘new integer variable”.

Add in the remaining constraints and call the solver.

The Julia implementation comes from the JuMP Library in Julia

The reason why i’m including it, is that Julia has made tremendous strides in recent years, and is hot on the heels of Python in terms of ease of use.

My Julia command line

Declare the optimization model. The model used here is the Coin Branch and Cut (Cbc).

The good thing about Julia is that it allows you to view the objectives you have declared in a manner that is far closer to human intuition. This allows muche easier proofreading.

Extract our solution from the solver

And this shall be the end of this post, where we have demonstrated passing constraints optimization problems to various solvers in both the Python and Julia language.

Add a comment

Related posts:

You Can Smell The Whistle Blow

I recently posted a poem in response to a Cooking prompt on Medium. It turned into a full-blown recipe with photos of vegetables, lentils, coconuts, a coconut scraper, and whatnot. I asked the reader…

Carl Rogers on Resolving Inner Conflict

The following members’ newsletter went out on 23rd August. If you want to get it the day it’s published, subscribe here. Our existence is dichotomous and paradoxical and our job, I believe, is not…

Decentralized Bitcoin ETF

The article was created as an idea to expand the scope of tBTC. In the article I will consider the creation of a decentralized Bitcoin ETF based on tBTC also baskets with other tokens (ETH, DAI). You…