Command line for optimization in the IBM Cloud

Alex Fleischer
4 min readJun 5, 2020

--

Command line to call OPL CPLEX model in IBM Cloud Watson Machine Learning / Serverless optimization / Cloudbursting optimization

Optimization is simply doing more with less.

CPLEX is the IBM Optimization tool and OPL is a high level modeling language within CPLEX.

In this article we will see how we can very simply use command line (CLI) and OPL and have CPLEX optimization run in the cloud.

Calling optimization in the cloud and through command line means that on any machine you can call optimization on any machine without installing anything but Python, which means that you can benefit from cloud elasticity and serverless optimization and you can even start for free!

This also means if you are already using OPL and CPLEX that you could benefit from cloud bursting. (In Peak usage situations, optimization intensive computations will happen in the elastic cloud and not on your limited device or server)

IBM ILOG CPLEX Optimization Studio is a prescriptive analytics solution that enables rapid development and deployment of decision optimization models using mathematical and constraint programming.

Many languages and API are available to call CPLEX

I ran many surveys and OPL won each time.

The easiest and most popular language is OPL, which is an algebraic modeling language.

To build, test, and maintain models, CPLEX provides a very convenient IDE (Integrated Development Environment)

CPLEX OPL IDE on MacOS

To run an OPL CPLEX model you may use the IDE, but when in production in deployment mode, you need more.

You may use C++/Java/.NET/Python APIs that call OPL but what is even easier is to use OPL CPLEX in command line mode (CLI) and call a tool provided within CPLEX: oplrun.

CPLEX can run on a machine or in the cloud. (within IBM WML / Watson Machine Learning)

Local: oplrun calls OPL CPLEX models in command line

Cloud : IBM Watson Machine Learning can solve OPL CPLEX models

input and output for WML

Now in 2021 how can you easily call OPL CPLEX in the cloud (WML) with an oplrun-like command line ? (On your machine you can use command line oplrun for that)

Here

See github from my colleague and friend AlainChabrier

For instance if we use the zoo example again:

300 kids need to travel to the London zoo.The school may rent 40 seats and 30 seats buses for $500 and $400 . How many buses of each size do you use to minimize cost?

zoodat.mod

int nbKids=...;
float costBus40=...;
float costBus30=...;

dvar int+ nbBus40;
dvar int+ nbBus30;

minimize
costBus40*nbBus40 +nbBus30*costBus30;

subject to
{
40*nbBus40+nbBus30*30>=nbKids;
}

execute DISPLAY_After_SOLVE
{
writeln("The minimum cost is ",cplex.getObjValue());
writeln("We will use ",nbBus40," 40 seats buses and ",nbBus30," 30 seats buses ");
}

tuple solution
{
int bus40;
int bus30;
}

{solution} theSolution={<nbBus40,nbBus30>};

zoodat.dat

nbKids=300;
costBus40=500;
costBus30=400;

we get solution.json with the result

{
"theSolution" : [ {
"bus40" : 6,
"bus30" : 2
} ]
}

and in the log we see

The minimum cost is 3900
We will use 640 seats buses and 2 30 seats buses

if we change

‘oaas.resultsFormat’: ‘JSON’

into

‘oaas.resultsFormat’: ‘TEXT’

then we get solution.txt

nbBus40 = 6;
nbBus30 = 2;
theSolution = {<6 2>};

This is a very easy way to call OPL CPLEX models in the cloud IBM Watson Machine Learning from command line when you do not have CPLEX in your machine

You may also use this to call many OPL CPLEX models in parallel in the cloud through “How to call many OPL models in parallel ?”in https://www.linkedin.com/pulse/how-opl-alex-fleischer/

That way you may mix cplex on your machine and elasticity provided by IBM Watson Machine Learning

This is very helpful for simulation, random seed tests and tuning.
Instead of waiting because of limited CPU capacity, elasticity can bring very fast response time.

More WML posts that could be useful:

DO for WML throughput and latency

Custom Decision Optimization for WML Monitoring User Interface

Use DO on different WML locations

Nota Bene:

With some slight changes, we can also cloud WML within Cloudpak For Data.

--

--

Alex Fleischer

Optimization Expert at IBM Europe. His expertise is in computer science, mathematics, artificial intelligence and Optimization. Sup Aéro graduate 1996.