| 1128 | cpdef solver_parameter(self, name, value = None): |
| 1129 | """ |
| 1130 | Returns or defines a solver parameter. |
| 1131 | |
| 1132 | For a list of parameters and associated values, please refer to Gurobi's |
| 1133 | reference manual |
| 1134 | `<http://www.gurobi.com/documentation/5.5/reference-manual/node798>`_. |
| 1135 | |
| 1136 | INPUT: |
| 1137 | |
| 1138 | - ``name`` (string) -- the parameter |
| 1139 | |
| 1140 | - ``value`` -- the parameter's value if it is to be defined, |
| 1141 | or ``None`` (default) to obtain its current value. |
| 1142 | |
| 1143 | EXAMPLES:: |
| 1144 | |
| 1145 | sage: p = MixedIntegerLinearProgram(solver="Gurobi") # optional - Gurobi |
| 1146 | |
| 1147 | An integer parameter:: |
| 1148 | |
| 1149 | sage: p.solver_parameter("VarBranch") # optional - Gurobi |
| 1150 | -1 |
| 1151 | sage: p.solver_parameter("VarBranch", 1) # optional - Gurobi |
| 1152 | sage: p.solver_parameter("VarBranch") # optional - Gurobi |
| 1153 | 1 |
| 1154 | |
| 1155 | A double parameter:: |
| 1156 | |
| 1157 | sage: p.solver_parameter("TimeLimit") # optional - Gurobi |
| 1158 | 1e+100 |
| 1159 | sage: p.solver_parameter("TimeLimit", 10) # optional - Gurobi |
| 1160 | sage: p.solver_parameter("TimeLimit") # optional - Gurobi |
| 1161 | 10.0 |
| 1162 | |
| 1163 | A string parameter:: |
| 1164 | |
| 1165 | sage: p.solver_parameter("LogFile") # optional - Gurobi |
| 1166 | '' |
| 1167 | sage: p.solver_parameter("LogFile", "/dev/null") # optional - Gurobi |
| 1168 | sage: p.solver_parameter("LogFile") # optional - Gurobi |
| 1169 | '/dev/null' |
| 1170 | |
| 1171 | """ |
| 1172 | cdef int tmp_int[1] |
| 1173 | cdef double tmp_dbl[1] |
| 1174 | cdef char tmp_str[25500] |
| 1175 | cdef char * c_name |
| 1176 | c_name = tmp_str |
| 1177 | |
| 1178 | if name == "timelimit": |
| 1179 | name = "TimeLimit" |
| 1180 | |
| 1181 | try: |
| 1182 | t = parameters_type[name] |
| 1183 | except KeyError: |
| 1184 | raise ValueError("This parameter is not available. "+ |
| 1185 | "Enabling it may not be so hard, though.") |
| 1186 | |
| 1187 | if t == "int": |
| 1188 | if value is None: |
| 1189 | check(self.env, GRBgetintparam(self.env, name, tmp_int)) |
| 1190 | return tmp_int[0] |
| 1191 | else: |
| 1192 | check(self.env, GRBsetintparam(self.env, name, value)) |
| 1193 | elif t == "double": |
| 1194 | if value is None: |
| 1195 | check(self.env, GRBgetdblparam(self.env, name, tmp_dbl)) |
| 1196 | return tmp_dbl[0] |
| 1197 | else: |
| 1198 | check(self.env, GRBsetdblparam(self.env, name, value)) |
| 1199 | elif t == "string": |
| 1200 | if value is None: |
| 1201 | check(self.env, GRBgetstrparam(self.env, name, c_name)) |
| 1202 | return str(c_name) |
| 1203 | else: |
| 1204 | check(self.env, GRBsetstrparam(self.env, name, value)) |
| 1205 | else: |
| 1206 | raise RuntimeError("This should not happen.") |
| 1207 | |
| 1248 | cdef dict parameters_type = { |
| 1249 | "AggFill" : "int", |
| 1250 | "Aggregate" : "int", |
| 1251 | "BarConvTol" : "double", |
| 1252 | "BarCorrectors" : "int", |
| 1253 | "BarHomogeneous" : "int", |
| 1254 | "BarOrder" : "int", |
| 1255 | "BarQCPConvTol" : "double", |
| 1256 | "BarIterLimit" : "int", |
| 1257 | "BranchDir" : "int", |
| 1258 | "CliqueCuts" : "int", |
| 1259 | "CoverCuts" : "int", |
| 1260 | "Crossover" : "int", |
| 1261 | "CrossoverBasis" : "int", |
| 1262 | "Cutoff" : "double", |
| 1263 | "CutAggPasses" : "int", |
| 1264 | "CutPasses" : "int", |
| 1265 | "Cuts" : "int", |
| 1266 | "DisplayInterval" : "int", |
| 1267 | "DualReductions" : "int", |
| 1268 | "FeasibilityTol" : "double", |
| 1269 | "FeasRelaxBigM" : "double", |
| 1270 | "FlowCoverCuts" : "int", |
| 1271 | "FlowPathCuts" : "int", |
| 1272 | "GomoryPasses" : "int", |
| 1273 | "GUBCoverCuts" : "int", |
| 1274 | "Heuristics" : "double", |
| 1275 | "IISMethod" : "int", |
| 1276 | "ImpliedCuts" : "int", |
| 1277 | "ImproveStartGap" : "double", |
| 1278 | "ImproveStartNodes" : "double", |
| 1279 | "ImproveStartTime" : "double", |
| 1280 | "InfUnbdInfo" : "int", |
| 1281 | "InputFile" : "string", |
| 1282 | "IntFeasTol" : "double", |
| 1283 | "IterationLimit" : "double", |
| 1284 | "LogFile" : "string", |
| 1285 | "LogToConsole" : "int", |
| 1286 | "MarkowitzTol" : "double", |
| 1287 | "Method" : "int", |
| 1288 | "MinRelNodes" : "int", |
| 1289 | "MIPFocus" : "int", |
| 1290 | "MIPGap" : "double", |
| 1291 | "MIPGapAbs" : "double", |
| 1292 | "MIPSepCuts" : "int", |
| 1293 | "MIQCPMethod" : "int", |
| 1294 | "MIRCuts" : "int", |
| 1295 | "ModKCuts" : "int", |
| 1296 | "NetworkCuts" : "int", |
| 1297 | "NodefileDir" : "string", |
| 1298 | "NodefileStart" : "double", |
| 1299 | "NodeLimit" : "double", |
| 1300 | "NodeMethod" : "int", |
| 1301 | "NormAdjust" : "int", |
| 1302 | "ObjScale" : "double", |
| 1303 | "OptimalityTol" : "double", |
| 1304 | "OutputFlag" : "int", |
| 1305 | "PerturbValue" : "double", |
| 1306 | "PreCrush" : "int", |
| 1307 | "PreDepRow" : "int", |
| 1308 | "PreDual" : "int", |
| 1309 | "PrePasses" : "int", |
| 1310 | "PreQLinearize" : "int", |
| 1311 | "Presolve" : "int", |
| 1312 | "PreSparsify" : "int", |
| 1313 | "PSDTol" : "double", |
| 1314 | "PumpPasses" : "int", |
| 1315 | "QCPDual" : "int", |
| 1316 | "Quad" : "int", |
| 1317 | "ResultFile" : "string", |
| 1318 | "RINS" : "int", |
| 1319 | "ScaleFlag" : "int", |
| 1320 | "Seed" : "int", |
| 1321 | "Sifting" : "int", |
| 1322 | "SiftMethod" : "int", |
| 1323 | "SimplexPricing" : "int", |
| 1324 | "SolutionLimit" : "int", |
| 1325 | "SolutionNumber" : "int", |
| 1326 | "SubMIPCuts" : "int", |
| 1327 | "SubMIPNodes" : "int", |
| 1328 | "Symmetry" : "int", |
| 1329 | "Threads" : "int", |
| 1330 | "TimeLimit" : "double", |
| 1331 | "VarBranch" : "int", |
| 1332 | "ZeroHalfCuts" : "int", |
| 1333 | "ZeroObjNodes" : "int" |
| 1334 | } |
| 1335 | |