Did you miss the ability to double-click on an LP file in your file manager, and have CPLEX read it? This is now possible with version 12.7.1 of CPLEX Optimization Studio.
In this version, both CPLEX Interactive and CP Optimizer Interactive feature a new
-i option on the command line. That option instructs the Interactive to keep accepting commands after it has executed the ones specified on the command line (using
-c) or in a file (using
If you associate an LP file with the command
cplex -i -c "read [myfile]" CPLEX will launch, read the file, and then wait for your commands at the prompt. You can then set parameters, start a solve, a
tools runseeds, or anything else you wish.
The detailed instructions below were tested on Windows 10, OS X El Capitan and Ubuntu 14. They should work on other versions of these operating systems.
Create a file named
Open_instance_with_CPLEX.reg, with the following content:
Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\Classes\.mps] @="CPLEX.instance" [HKEY_CURRENT_USER\Software\Classes\.lp] @="CPLEX.instance" [HKEY_CURRENT_USER\Software\Classes\.sav] @="CPLEX.instance" [HKEY_CURRENT_USER\Software\Classes\CPLEX.instance] [HKEY_CURRENT_USER\Software\Classes\CPLEX.instance\shell] [HKEY_CURRENT_USER\Software\Classes\CPLEX.instance\shell\open] [HKEY_CURRENT_USER\Software\Classes\CPLEX.instance\shell\open\command] @="\"C:\\Program Files\\IBM\\ILOG\\CPLEX_Studio1271\\cplex\\bin\\x64_win64\\cplex.exe\" -i -c \"read \\\"%1\\\"\"" [HKEY_CURRENT_USER\Software\Classes\.cpo] @="CPOptimizer.instance" [HKEY_CURRENT_USER\Software\Classes\CPOptimizer.instance] [HKEY_CURRENT_USER\Software\Classes\CPOptimizer.instance\shell] [HKEY_CURRENT_USER\Software\Classes\CPOptimizer.instance\shell\open] [HKEY_CURRENT_USER\Software\Classes\CPOptimizer.instance\shell\open\command] @="\"C:\\Program Files\\IBM\\ILOG\\CPLEX_Studio1271\\cpoptimizer\\bin\\x64_win64\\cpoptimizer.exe\" -i -c \"read \\\"%1\\\"\""
Double-click this file, accept the prompts. That’s it.
From now on, double-clicking an LP file will open the CPLEX Interactive in a console.
Ubuntu 14, using Nautilus
$HOME/.local/share/applications/cplex.desktop with the following content:
[Desktop Entry] Name=CPLEX interactive optimizer GenericName=CPLEX interactive optimizer Comment=Solve optimization models Exec=/opt/ibm/ILOG/CPLEX_Studio1271/cplex/bin/x86-64_linux/cplex -i -c 'read %f' Terminal=true Type=Application Icon=/opt/ibm/ILOG/CPLEX_Studio1271/doc/html/en-US/images/IBM_logo_pdf_default.png
Restart your environment (log out, then back in; or restart Nautilus:
nautilus &). Right-click an LP file. Choose Properties, then the tab Open With. In the Other Applications section, select CPLEX Interactive Optimizer and click Set as default.
Double-click your LP file, et voilà…
OS X El Capitan
- Open the Script Editor application, located in the Other group of the Launchpad.
- Select File -> New
- Paste the following in the top part of the window, and update the path to include your user name:
-- This routine processes the dropped item(s) on open theDroppedItems repeat with i from 1 to the count of theDroppedItems set aDroppedItem to item i of theDroppedItems processItem(aDroppedItem) end repeat end open -- This routine processes an item on processItem(anItemToProcess) set pathUnix to POSIX path of anItemToProcess set commandToRun to "/Users/[username]/Applications/IBM/ILOG/CPLEX_Studio1271/cplex/bin/x86-64_osx/cplex -i -c \"read \\\"" & pathUnix & "\\\"\"" -- Let’s run this command in a Terminal set commandToRun to commandToRun & ";exit" tell application "Terminal" do script commandToRun activate end tell -- An alternative is iTerm, which I personally prefer -- Pick one or the other! -- tell application "iTerm" -- create window with default profile command commandToRun -- end tell end processItem
- Select File -> Save… Complete the dialog with the following information:
Save As: OpenCPLEX
File Format: Application Other.
- Double-click an LP file
- Choose Open With… and Other.
- Navigate to your OpenCPLEX application, which is located in the global ‘Application’ folder.
The CPLEX Interactive will be launched in a Terminal, it will read your model, and wait for your commands.