1#!/usr/bin/env bash
2#* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
3#*                                                                           *
4#*                  This file is part of the program and library             *
5#*         SCIP --- Solving Constraint Integer Programs                      *
6#*                                                                           *
7#*    Copyright (C) 2002-2021 Konrad-Zuse-Zentrum                            *
8#*                            fuer Informationstechnik Berlin                *
9#*                                                                           *
10#*  SCIP is distributed under the terms of the ZIB Academic License.         *
11#*                                                                           *
12#*  You should have received a copy of the ZIB Academic License              *
13#*  along with SCIP; see the file COPYING. If not email to scip@zib.de.      *
14#*                                                                           *
15#* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
16
17### resets and fills a batch file TMPFILE to run CPLEX with
18### sets correct limits, reads in settings, and controls
19### display of the solving process
20
21# environment variables passed as arguments
22INSTANCE=${1}        #  instance name to solve
23SCIPPATH=${2}        # - path to working directory for test (usually, the check subdirectory)
24TMPFILE=${3}         # - the batch file to control XPRESS
25SETNAME=${4}         # - specified basename of settings-file, or 'default'
26SETFILE=${5}         # - instance/settings specific set-file
27THREADS=${6}         # - the number of LP solver threads to use
28SETCUTOFF=${7}       # - should optimal instance value be used as objective limit (0 or 1)?
29FEASTOL=${8}         # - feasibility tolerance, or 'default'
30TIMELIMIT=${9}       # - time limit for the solver
31MEMLIMIT=${10}     # - memory limit for the solver
32NODELIMIT=${11}    # - node limit for the solver
33LPS=${12}          # - LP solver to use
34DISPFREQ=${13}     # - display frequency for chronological output table
35REOPT=${14}        # - true if we use reoptimization, i.e., using a difflist file instead if an instance file
36OPTCOMMAND=${15}   # - command that should per executed after reading the instance, e.g. optimize, presolve or count
37CLIENTTMPDIR=${16} # - directory for temporary files
38SOLBASENAME=${17}  # - base name for solution file
39VISUALIZE=${18}    # - true, if the branch-and-bound search should be visualized
40SOLUFILE=${19}     # - solu file, only necessary if ${SETCUTOFF} is 1
41
42#args=("$@")
43#for ((i=0; i < $#; i++)) {
44#   echo "argument $((i+1)): ${args[${i}]}"
45#}
46
47# new environment variables after running this script
48# -None
49
50#set solfile
51SOLFILE=${CLIENTTMPDIR}/${USER}-tmpdir/${SOLBASENAME}.sol
52
53# reset TMPFILE
54echo > ${TMPFILE}
55echo ""                              > ${TMPFILE}
56
57# read in settings (even when using default, see bugzilla 600)
58SETTINGS=${SCIPPATH}/../settings/${SETNAME}.prm
59if test ${SETNAME} != "default"
60then
61    echo read ${SETTINGS}                  >> ${TMPFILE}
62    echo disp settings changed           >> ${TMPFILE}
63fi
64
65# set non-default feasibility tolerance
66if test ${FEASTOL} != "default"
67then
68    echo set simplex tolerances feas ${FEASTOL}    >> ${TMPFILE}
69    echo set mip tolerances integrality ${FEASTOL} >> ${TMPFILE}
70fi
71
72# if permutation counter is positive add permutation seed (0 = default)
73if test ${p} -gt 0
74then
75    echo "Warning: CPlex configuration currently cannot handle instance permutation"
76    exit 1
77fi
78
79if test "${REOPT}" = true
80then
81    # exit because reoptimization feature is not supported here
82    echo "Warning: CPlex configuration currently cannot handle reoptimization"
83    exit 1
84fi
85
86if test "${VISUALIZE}" = true
87then
88    # exit because visualization feature is not supported here
89    echo "Warning: CPlex configuration currently cannot handle visualization"
90    exit 1
91fi
92
93# set objective limit: optimal solution value from solu file, if existent
94if test "${SETCUTOFF}" = 1 || test "${SETCUTOFF}" = true
95then
96    # TODO setting cutoff requires knowledge about whether the objective sense is minimization or maximization
97    echo "Warning: Setting a cutoff is currently not supported for Cplex configuration"
98    exit 1
99fi
100
101echo "set timelimit ${TIMELIMIT}"            >> "${TMPFILE}"
102echo "set clocktype 0"                       >> "${TMPFILE}"
103echo "set mip display 3"                     >> "${TMPFILE}"
104echo "set mip interval ${DISPFREQ}"          >> "${TMPFILE}"
105echo "set mip tolerances mipgap 0.0"         >> "${TMPFILE}"
106echo "set mip limits nodes ${NODELIMIT}"     >> "${TMPFILE}"
107echo "set mip limits treememory ${MEMLIMIT}" >> "${TMPFILE}"
108echo "set threads ${THREADS}"                >> "${TMPFILE}"
109echo "set parallel 1"                        >> "${TMPFILE}"
110echo "set lpmethod 4"                        >> "${TMPFILE}"
111echo "set barrier crossover -1"              >> "${TMPFILE}"
112echo "read ${INSTANCE}"                      >> "${TMPFILE}"
113echo "display problem stats"                 >> "${TMPFILE}"
114echo "${OPTCOMMAND}"                         >> "${TMPFILE}"
115echo "display solution quality"              >> "${TMPFILE}"
116echo "quit"                                  >> "${TMPFILE}"
117
118# currently, the solution checker only supports .mps-files.
119# compare instance name (without .gz) to instance name stripped by .mps.
120#if they are unequal, we have an mps-file
121# TMPINSTANCE=$(basename "${INSTANCE}" .gz)
122# TMPINSTANCEB=$(basename "${TMPINSTANCE}" .mps)
123# if test "${TMPINSTANCEB}" != "${TMPINSTANCE}"
124# then
125# TODO Solution checker implementation for CPLEX
126#echo "write ${SOLFILE}"                     >> "${TMPFILE}"
127# fi
128echo "quit"                                 >> "${TMPFILE}"
129