Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Interactive Optimizer - Batch Processing

    Posted 12/28/09 01:50 PM

    Originally posted by: bademhan


    Hello,

    I have 100 Integer Programming Problems in lp files. I want to use the Interactive Optimizer (Cplex 9.1) to solve them and store the result of each problem (time, # branch and bound nodes and solution if a problem is feasible) into a text file. Can I do batch processing with Interactive Optimizer? If so, can you please tell me what code to use to:

    -solve all 100 problems that are stored in lp files (names of the files are: file1.lp,file2.lp,...,file100.lp);
    -put a time limit of 3 hours for each problem;
    -store the result for each problem.

    Thanks in advance for your help.
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Interactive Optimizer - Batch Processing

    Posted 12/28/09 04:52 PM

    Originally posted by: SystemAdmin


    Do you have a reasonable shell you can use? I use the interactive optimizer in batch-like mode
    every day. For example, using bash I would do something like this (untested code)
    #!/bin/bash
    i=0
    while [ $i -lt 100 ]; do
       i=`expr $i + 1`
       cat <<EOF | cplex | tee $i.log
    set log *
    read $i.lp
    set timelimit 10800
    opt
    write $i.sol
    write $i.mst
    disp sol var -
    EOF
    done
    

    In fact you would need only one of 'write $i.sol', 'write $i.mst' and 'disp sol var -'.
    'write $i.sol' would be the preferred choice but is not available in CPLEX 9.1.
    'write $i.mst' writes out a MIP start for the solution.
    'disp sol var -' displays all non-zero solution values on the screen (and I redirected
    them to $i.log).
    What output suits you best depends on the tools you will use to analyze the solution.
    What always works is parsing the log file :-)
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Interactive Optimizer - Batch Processing

    Posted 12/28/09 05:01 PM

    Originally posted by: SystemAdmin


    In case you opt for the 'disp sol var -' variant then you may want
    to do it like this
    x rm -f $i.nzs
    set log $i.nzs
    disp sol var -
    set log *
    

    so that you don't have too much garbage in the solution file. Note
    that I delete the output file before setting it as log file as
    CPLEX always appends its log messages if the respective files
    already exist.
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Interactive Optimizer - Batch Processing

    Posted 08/07/10 08:43 AM

    Originally posted by: JimDan


    I am facing a similar issue also under Windows 7...I have problem one.lp, two.lp, three.lp, ..., ten.lp.

    Is there a way I can automate using the DOS prompt the otherwise tedious task of: read one.lp, optimize,..., read two.lp, optimize,...

    and then read the solution from a log file?

    Thanks.
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Interactive Optimizer - Batch Processing

    Posted 08/07/10 12:43 PM

    Originally posted by: SystemAdmin


    To run the models I suppose you could put the commands you mentioned into a file and then execute a command like:
    c:\ilog\cplex_studio122\cplex\bin\x86_win32\cplex.exe < foo
    where "foo" is the file of commands.

    But to then parse the log file, looking for instance for the lines of output like:
    MIP - Integer optimal solution: Objective = 2.0000000000e+001
    I just don't know what kinds of tools exist in the DOS environment.

    Unix-style commands (e.g. "grep") seem called for. You might consider installing Cygwin on top of Windows and see if that meets your need.

    But really, even though the use you propose is pretty straightforward, the degree of automation you want suggests to me that you should consider using a true programming interface (API). CPLEX offers several. The programmatic control plus interactivity that Python offers might be right, for instance.
    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Interactive Optimizer - Batch Processing

    Posted 08/16/10 12:00 PM

    Originally posted by: SystemAdmin


    Here is a batch script that I used in past. It might not be perfect but AFAIR it worked. It should be saved to a file called runcpx.bat.
    @ECHO OFF
     
    REM Running multiple problems through CPLEX.
    REM Command line syntax:
    REM    runcpx.bat cplex list [timelimit]
    REM    runcpx.bat cplex single problem [timelimit]
    REM CPLEX      is the CPLEX binary to test
    REM LIST       is a file with problems to be run (one per line)
    REM PROBLEM    is a single problem file to be run
    REM TIMELIMIT  optional time limit
     
    IF "%1"=="" GOTO Usage
    IF "%1"=="/help" GOTO Usage
    IF "%1"=="--help" GOTO Usage
    IF "%2"=="" GOTO Usage
     
    IF "%2"=="single" GOTO Single
     
    :List
    REM ---------- Read list of models from file.
    IF "%2"=="" GOTO Usage
     
    SET TIMELIMIT=%3
    IF "%3"=="" SET TIMELIMIT=1e75
     
    FOR /F "tokens=1 delims= " %%A IN ('TYPE %2') DO (
            %0 %1 single %%A %TIMELIMIT%
    )
     
    GOTO End
     
    :Single
    REM ---------- Run the model file specified on the command line.
    IF "%3"=="" GOTO Usage
     
    SET TIMELIMIT=%4
    IF "%4"=="" SET TIMELIMIT=1e75
     
    REM Generate input script
    ECHO set timelimit %TIMELIMIT% >input
    ECHO read %3 >>input
    ECHO.  >>input
    ECHO optimize >>input
     
    REM Run cplex
    %1 < input
     
    GOTO End
     
    :Usage
     
    ECHO Usage: %0 CPLEX problem-list [timelimit]
    ECHO        %0 CPLEX single problem-file [timelimit]
     
    :End
    


    Assuming you have a file called problems.lst that lists the problems to be solved (one per line) you can do
    runcpx.bat cplex problems.lst 1e10
    

    where the last argument is the time limit and is optional.
    The script should also be easy to modify to execute extra commands etc.
    For analyzing the log/output files you would or course need extra tools/scripts, just as John already pointed out.
    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Interactive Optimizer - Batch Processing

    Posted 08/17/10 04:41 AM

    Originally posted by: JimDan


    Thanks...John's suggestion did the trick.
    #CPLEXOptimizers
    #DecisionOptimization