long GenModelCplex::SetParam(string param, int whichparam, string type, string message, bool implemented) { printf("Setting param: %s \n", param); bool notimplmessage = boolParam.count("throw_on_unimplemeted_option") > 0 && boolParam["throw_on_unimplemeted_option"]; if (type == "dbl") { if (dblParam.count(param) > 0 && implemented) SetDirectParam(whichparam, dbl2param(dblParam[param]), type, message); else if (notimplmessage && !implemented && dblParam.count(param) > 0) throw (string("Parameter ") + param + " not implemented in GenModelOsi"); } else if (type == "long") { if (longParam.count(param) > 0 && implemented) SetDirectParam(whichparam, long2param(longParam[param]), type, message); else if (notimplmessage && !implemented && longParam.count(param) > 0) throw (string("Parameter ") + param + " not implemented in GenModelOsi"); } else if (type == "str") { if (strParam.count(param) > 0 && implemented) SetDirectParam(whichparam, str2param(strParam[param]), type, message); else if (notimplmessage && !implemented && strParam.count(param) > 0) throw (string("Parameter ") + param + " not implemented in GenModelOsi"); } else if (type == "bool") { if (boolParam.count(param) > 0 && implemented) { if (boolParam[param]) SetDirectParam(whichparam, long2param(CPX_ON), "long", message); else SetDirectParam(whichparam, long2param(CPX_OFF), "long", message); } else if (notimplmessage && !implemented && boolParam.count(param) > 0) throw (string("Parameter ") + param + " not implemented in GenModelOsi"); } return 0; }
long GenModelCplex::Init(string name) { //strParam.count("log_file") //dblParam.count("relative_mip_gap_tolerance") //dblParam.count("absolute_mip_gap_tolerance") //dblParam.count("time_limit") //dblParam.count("bounds_feasibility_tolerance") //dblParam.count("optimality_tolerance") //dblParam.count("markowitz_tolerance")) //longParam.count("threads") //longParam.count("cutpass") //longParam.count("pumplevel") //longParam.count("mipemphasis") //longParam.count("probinglevel") //longParam.count("max_iteration_limit"); //boolParam.count("preprocoff") : turn on/off preprocessing //boolParam.count("datacheckoff") //boolParam.count("screen_output") //boolParam.count("usecutcb") if(solverdata == NULL) solverdata = new CplexData(); else { static_cast<CplexData*>(solverdata)->Delete(); static_cast<CplexData*>(solverdata)->Reset(); } CplexData* d = static_cast<CplexData*>(solverdata); int status = 0; d->env = CPXopenCPLEX (&status); // If an error occurs if ( d->env == NULL ) return ThrowError(getcplexerror(d->env, status)+string(". ")+string("Could not open CPLEX environment")); hassolution = false; // Log file if(strParam.count("log_file") > 0) { d->cpxfileptr = CPXfopen(strParam["log_file"].c_str(), "w"); status = CPXsetlogfile(d->env, d->cpxfileptr); if ( status ) return ThrowError(getcplexerror(d->env, status)+string(". ")+string("Failure to set the log file")); } // General settings boolParam["log_output_stdout"] = true; SetParam("log_output_stdout", CPX_PARAM_SCRIND, "bool", "Failure to turn on/off log output to stdout"); SetParam("log_level", CPX_PARAM_MIPDISPLAY, "long", "Failure to set log level"); SetParam("use_data_checking", CPX_PARAM_DATACHECK, "bool", "Failure to turn on/off data checking"); SetParam("nb_threads", CPX_PARAM_THREADS, "long", "Failure to set the number of threads"); if(boolParam.count("use_preprocessor") > 0 && !boolParam["use_preprocessor"]) { SetDirectParam(CPX_PARAM_AGGFILL, long2param(0), "long", "Failure to use preprocessor (CPX_PARAM_AGGFILL)"); SetDirectParam(CPX_PARAM_PREPASS, long2param(0), "long", "Failure to use preprocessor (CPX_PARAM_PREPASS)"); SetDirectParam(CPX_PARAM_AGGIND, long2param(CPX_OFF), "long", "Failure to use preprocessor (CPX_PARAM_AGGIND)"); SetDirectParam(CPX_PARAM_DEPIND, long2param(0), "long", "Failure to use preprocessor (CPX_PARAM_DEPIND)"); SetDirectParam(CPX_PARAM_PRELINEAR, long2param(0), "long", "Failure to use preprocessor (CPX_PARAM_PRELINEAR)"); SetDirectParam(CPX_PARAM_PREDUAL, long2param(-1), "long", "Failure to use preprocessor (CPX_PARAM_PREDUAL)"); SetDirectParam(CPX_PARAM_REDUCE, long2param(0), "long", "Failure to use preprocessor (CPX_PARAM_REDUCE)"); SetDirectParam(CPX_PARAM_PREIND, long2param(CPX_OFF), "long", "Failure to use preprocessor (CPX_PARAM_PREIND)"); } // MIP settings SetParam("nb_cut_pass", CPX_PARAM_CUTPASS, "long", "Failure to set the number of cut pass"); SetParam("feasibility_pump_level", CPX_PARAM_FPHEUR, "long", "Failure to set the feasibility pump level"); SetParam("probing_level", CPX_PARAM_PROBE, "long", "Failure to set the probing level"); SetParam("mip_emphasis", CPX_PARAM_MIPEMPHASIS, "long", "Failure to set the MIP emphasis"); SetParam("mip_search", CPX_PARAM_MIPSEARCH, "long", "Failure to set the MIP search strategy"); SetParam("starting_algo", CPX_PARAM_STARTALG, "long", "Failure to set the starting algo parameter"); SetParam("node_algo", CPX_PARAM_SUBALG, "long", "Failure to set the node algo parameter"); if(boolParam.count("use_cut_callback") > 0 && boolParam["use_cut_callback"]) { SetDirectParam(CPX_PARAM_PRELINEAR, long2param(0), "long", "Failure to use cut callback (CPX_PARAM_PRELINEAR)"); SetDirectParam(CPX_PARAM_MIPCBREDLP, long2param(0), "long", "Failure to use cut callback (CPX_PARAM_MIPCBREDLP)"); } // Tolerance and limits SetParam("time_limit", CPX_PARAM_TILIM, "dbl", "Failure to set time limit"); SetParam("max_iteration_limit", CPX_PARAM_ITLIM, "long", "Failure to set the maximal number of simplex iterations"); SetParam("bounds_feasibility_tolerance", CPX_PARAM_EPRHS, "dbl", "Failure to set bounds feasibility tolerance"); SetParam("optimality_tolerance", CPX_PARAM_EPOPT, "dbl", "Failure to set optimality tolerance"); SetParam("markowitz_tolerance", CPX_PARAM_EPMRK, "dbl", "Failure to set Markowitz tolerance"); SetParam("absolute_mip_gap_tolerance", CPX_PARAM_EPAGAP, "dbl", "Failure to set absolute gap tolerance"); SetParam("relative_mip_gap_tolerance", CPX_PARAM_EPGAP, "dbl", "Failure to set relative gap tolerance"); if(boolParam.count("maximize") > 0 && boolParam["maximize"]) SetParam("lp_objective_limit", CPX_PARAM_OBJULIM, "dbl", "Failure to set lp objective limit"); else SetParam("lp_objective_limit", CPX_PARAM_OBJLLIM, "dbl", "Failure to set lp objective limit"); // MIP Emphasis if(longParam.count("mipemphasis")) { status = CPXsetintparam (d->env, CPX_PARAM_MIPEMPHASIS, longParam["mipemphasis"]); } // Probing level if(longParam.count("probinglevel")) { status = CPXsetintparam (d->env, CPX_PARAM_PROBE, longParam["probinglevel"]); } if ( status ) { fprintf (stderr, "Failure to set cut callback parameters, error %d->\n", status); return 1; } binit = true; if(dblParam.count("feastol")) status = CPXsetdblparam (d->env, CPX_PARAM_EPRHS, dblParam["feastol"]); if ( status ) { fprintf (stderr, "Failure to change feasibility tolerance, error %d->\n", status); return 1; } if(dblParam.count("opttol")) status = CPXsetdblparam (d->env, CPX_PARAM_EPOPT, dblParam["opttol"]); if ( status ) { fprintf (stderr, "Failure to change optimality tolerance, error %d->\n", status); return 1; } if(dblParam.count("marktol")) status = CPXsetdblparam (d->env, CPX_PARAM_EPMRK, dblParam["marktol"]); if ( status ) { fprintf (stderr, "Failure to change Markowitz tolerance, error %d->\n", status); return 1; } if(longParam.count("threads")) { printf("Threads: %ld\n", longParam["threads"]); status = CPXsetintparam (d->env, CPX_PARAM_THREADS, longParam["threads"]); if ( status ) { fprintf (stderr, "Failure to change the number of threads, error %d->\n", status); return 1; } } // Turn off preprocessing if(boolParam.count("preprocoff") > 0 && boolParam["preprocoff"]) { status = CPXsetintparam (d->env, CPX_PARAM_AGGFILL, 0); status = status && CPXsetintparam (d->env, CPX_PARAM_PREPASS, 0); status = status && CPXsetintparam (d->env, CPX_PARAM_AGGIND, CPX_OFF); status = status && CPXsetintparam (d->env, CPX_PARAM_DEPIND, 0); status = status && CPXsetintparam (d->env, CPX_PARAM_PRELINEAR, 0); status = status && CPXsetintparam (d->env, CPX_PARAM_PREDUAL, -1); status = status && CPXsetintparam (d->env, CPX_PARAM_REDUCE, 0); status = status && CPXsetintparam (d->env, CPX_PARAM_PREIND, CPX_OFF); } if ( status ) { fprintf (stderr, "Failure to turn off preprocessing, error %d->\n", status); return 1; } // Turn on data checking if(boolParam.count("datacheckoff") > 0 && boolParam["datacheckoff"]) status = CPXsetintparam (d->env, CPX_PARAM_DATACHECK, CPX_OFF); else status = CPXsetintparam (d->env, CPX_PARAM_DATACHECK, CPX_ON); if ( status ) { fprintf (stderr, "Failure to turn on data checking, error %d->\n", status); return 1; } // Sets a relative tolerance on the gap between the best integer objective and the objective of the best node remaining (between 0.0 and 1.0) if(dblParam.count("epgap")) { //printf("setting epgap\n"); status = CPXsetdblparam (d->env, CPX_PARAM_EPGAP, dblParam["epgap"]); if ( status ) { fprintf (stderr, "Failure to set relative gap tolerance, error %d->\n", status); return 1; } } // Create the problem d->lp = CPXcreateprob (d->env, &status, name.c_str()); if ( d->lp == NULL ) { fprintf (stderr, "Failed to create LP.\n"); return 1; } fflush(stdout); return 0; }
long GenModelCplex::Init(string name) { //strParam.count("log_file") //dblParam.count("relative_mip_gap_tolerance") //dblParam.count("absolute_mip_gap_tolerance") //dblParam.count("time_limit") //dblParam.count("bounds_feasibility_tolerance") //dblParam.count("optimality_tolerance") //dblParam.count("markowitz_tolerance")) //longParam.count("threads") //longParam.count("cutpass") //longParam.count("pumplevel") //longParam.count("mipemphasis") //longParam.count("probinglevel") //longParam.count("max_iteration_limit"); //boolParam.count("preprocoff") : turn on/off preprocessing //boolParam.count("datacheckoff") //boolParam.count("screen_output") //boolParam.count("usecutcb") if(solverdata == NULL) solverdata = new CplexData(); else { static_cast<CplexData*>(solverdata)->Delete(); static_cast<CplexData*>(solverdata)->Reset(); } CplexData* d = static_cast<CplexData*>(solverdata); int status = 0; d->env = CPXopenCPLEX (&status); // If an error occurs if ( d->env == NULL ) return ThrowError(getcplexerror(d->env, status)+string(". ")+string("Could not open CPLEX environment")); hassolution = false; // Log file if(strParam.count("log_file") > 0) { d->cpxfileptr = CPXfopen(strParam["log_file"].c_str(), "w"); status = CPXsetlogfile(d->env, d->cpxfileptr); if ( status ) return ThrowError(getcplexerror(d->env, status)+string(". ")+string("Failure to set the log file")); } // General settings boolParam["log_output_stdout"] = true; SetParam("log_output_stdout", CPX_PARAM_SCRIND, "bool", "Failure to turn on/off log output to stdout"); SetParam("log_level", 0, "long", "Failure to set log level", false); SetParam("use_data_checking", CPX_PARAM_DATACHECK, "bool", "Failure to turn on/off data checking"); SetParam("nb_threads", CPX_PARAM_THREADS, "long", "Failure to set the number of threads"); if(boolParam.count("use_preprocessor") > 0 && !boolParam["use_preprocessor"]) { SetDirectParam(CPX_PARAM_AGGFILL, long2param(0), "long", "Failure to use preprocessor (CPX_PARAM_AGGFILL)"); SetDirectParam(CPX_PARAM_PREPASS, long2param(0), "long", "Failure to use preprocessor (CPX_PARAM_PREPASS)"); SetDirectParam(CPX_PARAM_AGGIND, long2param(CPX_OFF), "long", "Failure to use preprocessor (CPX_PARAM_AGGIND)"); SetDirectParam(CPX_PARAM_DEPIND, long2param(0), "long", "Failure to use preprocessor (CPX_PARAM_DEPIND)"); SetDirectParam(CPX_PARAM_PRELINEAR, long2param(0), "long", "Failure to use preprocessor (CPX_PARAM_PRELINEAR)"); SetDirectParam(CPX_PARAM_PREDUAL, long2param(-1), "long", "Failure to use preprocessor (CPX_PARAM_PREDUAL)"); SetDirectParam(CPX_PARAM_REDUCE, long2param(0), "long", "Failure to use preprocessor (CPX_PARAM_REDUCE)"); SetDirectParam(CPX_PARAM_PREIND, long2param(CPX_OFF), "long", "Failure to use preprocessor (CPX_PARAM_PREIND)"); } // MIP settings SetParam("nb_cut_pass", CPX_PARAM_CUTPASS, "long", "Failure to set the number of cut pass"); SetParam("feasibility_pump_level", CPX_PARAM_FPHEUR, "long", "Failure to set the feasibility pump level"); SetParam("probing_level", CPX_PARAM_PROBE, "long", "Failure to set the probing level"); SetParam("mip_emphasis", CPX_PARAM_MIPEMPHASIS, "long", "Failure to set the MIP emphasis"); if(boolParam.count("use_cut_callback") > 0 && boolParam["use_cut_callback"]) { SetDirectParam(CPX_PARAM_PRELINEAR, long2param(0), "long", "Failure to use cut callback (CPX_PARAM_PRELINEAR)"); SetDirectParam(CPX_PARAM_MIPCBREDLP, long2param(0), "long", "Failure to use cut callback (CPX_PARAM_MIPCBREDLP)"); } // Tolerance and limits SetParam("time_limit", CPX_PARAM_TILIM, "dbl", "Failure to set time limit"); SetParam("max_iteration_limit", CPX_PARAM_ITLIM, "long", "Failure to set the maximal number of simplex iterations"); SetParam("bounds_feasibility_tolerance", CPX_PARAM_EPRHS, "dbl", "Failure to set bounds feasibility tolerance"); SetParam("optimality_tolerance", CPX_PARAM_EPOPT, "dbl", "Failure to set optimality tolerance"); SetParam("markowitz_tolerance", CPX_PARAM_EPMRK, "dbl", "Failure to set Markowitz tolerance"); SetParam("absolute_mip_gap_tolerance", CPX_PARAM_EPAGAP, "dbl", "Failure to set absolute gap tolerance"); SetParam("relative_mip_gap_tolerance", CPX_PARAM_EPGAP, "dbl", "Failure to set relative gap tolerance"); if(boolParam.count("maximize") > 0 && boolParam["maximize"]) SetParam("lp_objective_limit", CPX_PARAM_OBJULIM, "dbl", "Failure to set lp objective limit"); else SetParam("lp_objective_limit", CPX_PARAM_OBJLLIM, "dbl", "Failure to set lp objective limit"); // Create the problem d->lp = CPXcreateprob (d->env, &status, name.c_str()); if ( d->lp == NULL ) return ThrowError(getcplexerror(d->env, status)+string(". ")+string("Failure to create Cplex optimization problem")); binit = true; return 0; }