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.
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.
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.
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:
Within scripting you can use
You can do any kind of computation:
And use the debugger from the IDE
And let's not forget codeassist that is available in both the CPLEX IDE and WatsonStudio in CloudPakForData
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.
Through external python call you can get any file from the web to your machine.
What else ?
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.
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.
Senior Machine Learning Engineer at BigData Republic | ML-Engineer @ IMG
3 年And Rust #rustlang has bindings now as well right? Yeaah for it!