Javascript within OPL CPLEX
https://fossbytes.com/best-programming-languages/

Javascript within OPL CPLEX

With very popular Python, Java and C# you can either model directly with CPLEX or call OPL. With very popular Javascript, it's different. Javascript is part of OPL CPLEX.

No alt text provided for this image

Optimization (Prescriptive analytics, Operations Research, Decision Optimization) is doing more with less. Which is why most of the time, this makes sense. In a few posts I tried to show the way:

Then I gave some tricks and examples but nothing happened, well not much. Then came 2018 and I tried a very simple story.

No alt text provided for this image

This got some impact and got translated into 23 languages (English included) because this was very simple. In Freakonomics, Nobel Prize 2017 Richard Thaler said : "If you want to get people to do something, make it easy. Remove the barriers."

In most examples I have shared and the IBM Research Ponder This I have solved I have focused on the 2 engines within CPLEX and the modeling part within OPL.

No alt text provided for this image

But here I will spend more time on the scripting part either called ILOGscript, ECMA or javascript. As an interpreted language this is not as fast as OPL modeling part but this language that is part of OPL is very useful. Plus Javascript is a very common and standard language, which is very good for OPL CPLEX adoption.

Javascript is behind node.js, typescript and many other dialects like the one in OPL.

In OPL we can use scripting for preprocessing and postprocessing,for flow control, but also within the data file .dat to process data.

Some simple examples:

No alt text provided for this image

No alt text provided for this image


Within scripting you can use

No alt text provided for this image

No alt text provided for this image

No alt text provided for this image

No alt text provided for this image

No alt text provided for this image

No alt text provided for this image

No alt text provided for this image

You can do any kind of computation:

And use the debugger from the IDE

No alt text provided for this image

And let's not forget codeassist that is available in both the CPLEX IDE and WatsonStudio in CloudPakForData

No alt text provided for this image
Code Assist in CPLEX IDE


No alt text provided for this image
Code Assist in Watson Studio


In the IDE you can also run any new scripts after running the model and that helps when running the model again takes time. We call this interactive scripting.

No alt text provided for this image
Interactive scripting


Through external python call you can get any file from the web to your machine.

What else ?

No alt text provided for this image

No alt text provided for this image


  • split a string with values into an array

In Scripting you may use brute force too. For the zoo example, brute force in scripting even if not as efficient as brute force in the OPL modeling part

NB:

Scripting is much slower than OPL modeling part. So not to be used in huge loops. Here some figures with OPL and python.

  1. OPL computation : 14.652
  2. OPL scripting : 109.809
  3. python expression :?12.402294158935547
  4. python loop :?17.183008909225464

Nourredine Hail

Senior operations research and data scientist

3 年

Thanks a lot for sharing Alex Fleischer. The main challenge that I face during my 15 years of experience with OPL is that IT standards could refrain our enthusiasm in using a promising language over more conventional ones. I remember that I was very excited to when I built a generic flow control in python using DOOPL python library, however our IT department was not ready to promote CPLEX models into production via python. Thanks again Alex.

回复
Willem Hendriks

Senior Machine Learning Engineer at BigData Republic | ML-Engineer @ IMG

3 年

And Rust #rustlang has bindings now as well right? Yeaah for it!

回复

要查看或添加评论,请登录

社区洞察

其他会员也浏览了