public SolverResult BranchAndCut(bool messageFlg = true, int timeLimit = 315360000) { Simplex(false); glp_iocp iocp = new glp_iocp(); GLPK.glp_init_iocp(iocp); if (!messageFlg) { iocp.msg_lev = GLPK.GLP_MSG_OFF; } iocp.tm_lim = timeLimit * 1000; return((SolverResult)GLPK.glp_intopt(problem, iocp)); }
/** * Solves a linear ordering problem. * * @param inFile input file * @param outFile output file */ private void solve(String inFile, String outFile) { glp_iocp iocp; GlpkCallback.addListener(this); read_data(inFile); build_mip(); GLPK.glp_adv_basis(prob, 0); GLPK.glp_simplex(prob, null); iocp = new glp_iocp(); GLPK.glp_init_iocp(iocp); GLPK.glp_intopt(prob, iocp); GLPK.glp_print_mip(prob, outFile); GlpkCallback.removeListener(this); GLPK.glp_delete_prob(prob); }
/// <summary> /// Résout le problème /// </summary> /// <returns>Borne inférieure</returns> private double _solve() { GLPK.glp_term_out(GLPK.GLP_OFF); glp_iocp iocp; GlpkCallback.addListener(this); buildProblem(); //On construit le problème GLPK.glp_adv_basis(problem, 0); GLPK.glp_simplex(problem, null); //On résout double val = GLPK.glp_get_obj_val(problem); iocp = new glp_iocp(); GLPK.glp_init_iocp(iocp); GLPK.glp_intopt(problem, iocp); //On cherche la solution entière optimale GlpkCallback.removeListener(this); GLPK.glp_delete_prob(problem); return(GLPK.glp_get_obj_val(problem)); }
private Route _solve() { glp_iocp iocp; GlpkCallback.addListener(this); buildProblem(); GLPK.glp_adv_basis(problem, 0); GLPK.glp_simplex(problem, null); iocp = new glp_iocp(); GLPK.glp_init_iocp(iocp); GLPK.glp_intopt(problem, iocp); List <Route> res = getSubroutes(true); GlpkCallback.removeListener(this); GLPK.glp_delete_prob(problem); return(res[0]); }
public void solve(string[] arg) { glp_prob lp; glp_tran tran; glp_iocp iocp; String fname; int skip = 0; int ret; // listen to callbacks GlpkCallback.addListener(this); // listen to terminal output GlpkTerminal.addListener(this); try { // create problem lp = GLPK.glp_create_prob(); // allocate workspace tran = GLPK.glp_mpl_alloc_wksp(); // read model fname = arg [0]; ret = GLPK.glp_mpl_read_model(tran, fname, skip); if (ret != 0) { GLPK.glp_mpl_free_wksp(tran); GLPK.glp_delete_prob(lp); throw new ApplicationException("Model file not valid: " + fname); } // generate model ret = GLPK.glp_mpl_generate(tran, null); if (ret != 0) { GLPK.glp_mpl_free_wksp(tran); GLPK.glp_delete_prob(lp); throw new ApplicationException("Cannot generate model: " + fname); } // build model GLPK.glp_mpl_build_prob(tran, lp); // set solver parameters iocp = new glp_iocp(); GLPK.glp_init_iocp(iocp); iocp.presolve = GLPK.GLP_ON; // do not listen to output anymore GlpkTerminal.removeListener(this); // solve model ret = GLPK.glp_intopt(lp, iocp); // postsolve model if (ret == 0) { GLPK.glp_mpl_postsolve(tran, lp, GLPK.GLP_MIP); } // free memory GLPK.glp_mpl_free_wksp(tran); GLPK.glp_delete_prob(lp); } catch (org.gnu.glpk.GlpkException e) { Console.Error.WriteLine("An error inside the GLPK library occured."); Console.Error.WriteLine(e.Message); } catch (ApplicationException e) { Console.Error.WriteLine(e.Message); } // do not listen for callbacks anymore GlpkCallback.removeListener(this); // check that the terinal hook function has been used if (!hookUsed) { throw new ApplicationException( "The terminal output hook was not used."); } }
/** * Build a model with one column * * @return error error occurred */ private bool run() { glp_prob lp; glp_iocp iocp; SWIGTYPE_p_int ind; SWIGTYPE_p_double val; bool ret = false; try { // Create problem lp = GLPK.glp_create_prob (); Console.WriteLine ("Problem created"); GLPK.glp_set_prob_name (lp, "myProblem"); // Define columns GLPK.glp_add_cols (lp, 2); GLPK.glp_set_col_name (lp, 1, "x1"); GLPK.glp_set_col_kind (lp, 1, GLPK.GLP_IV); GLPK.glp_set_col_bnds (lp, 1, GLPK.GLP_LO, 0, 0); GLPK.glp_set_col_name (lp, 2, "x2"); GLPK.glp_set_col_kind (lp, 2, GLPK.GLP_IV); GLPK.glp_set_col_bnds (lp, 2, GLPK.GLP_LO, 0, 0); // Create constraints GLPK.glp_add_rows (lp, 2); GLPK.glp_set_row_name (lp, 1, "c1"); GLPK.glp_set_row_bnds (lp, 1, GLPK.GLP_UP, 0, 40); ind = GLPK.new_intArray (3); GLPK.intArray_setitem (ind, 1, 1); GLPK.intArray_setitem (ind, 2, 2); val = GLPK.new_doubleArray (3); GLPK.doubleArray_setitem (val, 1, 10); GLPK.doubleArray_setitem (val, 2, 7); GLPK.glp_set_mat_row (lp, 1, 2, ind, val); GLPK.delete_intArray (ind); GLPK.delete_doubleArray (val); ind = GLPK.new_intArray (3); GLPK.intArray_setitem (ind, 1, 1); GLPK.intArray_setitem (ind, 2, 2); val = GLPK.new_doubleArray (3); GLPK.glp_set_row_name (lp, 2, "c2"); GLPK.glp_set_row_bnds (lp, 2, GLPK.GLP_UP, 0, 5); GLPK.doubleArray_setitem (val, 1, 1); GLPK.doubleArray_setitem (val, 2, 1); GLPK.glp_set_mat_row (lp, 2, 2, ind, val); GLPK.delete_intArray (ind); GLPK.delete_doubleArray (val); // Define objective GLPK.glp_set_obj_name (lp, "obj"); GLPK.glp_set_obj_dir (lp, GLPK.GLP_MAX); GLPK.glp_set_obj_coef (lp, 0, 0); GLPK.glp_set_obj_coef (lp, 1, 17); GLPK.glp_set_obj_coef (lp, 2, 12); // solve model iocp = new glp_iocp (); GLPK.glp_init_iocp (iocp); iocp.presolve = GLPK.GLP_ON; iocp.msg_lev = GLPK.GLP_MSG_OFF; GLPK.glp_intopt (lp, iocp); // free memory GLPK.glp_delete_prob (lp); } catch (GlpkException ex) { Console.WriteLine (ex.Message); ret = true; } return ret; }
public void solve(string[] arg) { glp_prob lp; glp_tran tran; glp_iocp iocp; String fname; int skip = 0; int ret; // listen to callbacks GlpkCallback.addListener (this); // listen to terminal output GlpkTerminal.addListener (this); try { // create problem lp = GLPK.glp_create_prob (); // allocate workspace tran = GLPK.glp_mpl_alloc_wksp (); // read model fname = arg [0]; ret = GLPK.glp_mpl_read_model (tran, fname, skip); if (ret != 0) { GLPK.glp_mpl_free_wksp (tran); GLPK.glp_delete_prob (lp); throw new ApplicationException ("Model file not valid: " + fname); } // generate model ret = GLPK.glp_mpl_generate (tran, null); if (ret != 0) { GLPK.glp_mpl_free_wksp (tran); GLPK.glp_delete_prob (lp); throw new ApplicationException ("Cannot generate model: " + fname); } // build model GLPK.glp_mpl_build_prob (tran, lp); // set solver parameters iocp = new glp_iocp (); GLPK.glp_init_iocp (iocp); iocp.presolve = GLPK.GLP_ON; // do not listen to output anymore GlpkTerminal.removeListener (this); // solve model ret = GLPK.glp_intopt (lp, iocp); // postsolve model if (ret == 0) { GLPK.glp_mpl_postsolve (tran, lp, GLPK.GLP_MIP); } // free memory GLPK.glp_mpl_free_wksp (tran); GLPK.glp_delete_prob (lp); } catch (org.gnu.glpk.GlpkException e) { Console.Error.WriteLine ("An error inside the GLPK library occured."); Console.Error.WriteLine (e.Message); } catch (ApplicationException e) { Console.Error.WriteLine (e.Message); } // do not listen for callbacks anymore GlpkCallback.removeListener (this); // check that the terinal hook function has been used if (!hookUsed) { throw new ApplicationException ( "The terminal output hook was not used."); } }
/** * Build a model with one column * * @return error error occurred */ private bool run() { glp_prob lp; glp_iocp iocp; SWIGTYPE_p_int ind; SWIGTYPE_p_double val; bool ret = false; try { // Create problem lp = GLPK.glp_create_prob(); Console.WriteLine("Problem created"); GLPK.glp_set_prob_name(lp, "myProblem"); // Define columns GLPK.glp_add_cols(lp, 2); GLPK.glp_set_col_name(lp, 1, "x1"); GLPK.glp_set_col_kind(lp, 1, GLPK.GLP_IV); GLPK.glp_set_col_bnds(lp, 1, GLPK.GLP_LO, 0, 0); GLPK.glp_set_col_name(lp, 2, "x2"); GLPK.glp_set_col_kind(lp, 2, GLPK.GLP_IV); GLPK.glp_set_col_bnds(lp, 2, GLPK.GLP_LO, 0, 0); // Create constraints GLPK.glp_add_rows(lp, 2); GLPK.glp_set_row_name(lp, 1, "c1"); GLPK.glp_set_row_bnds(lp, 1, GLPK.GLP_UP, 0, 40); ind = GLPK.new_intArray(3); GLPK.intArray_setitem(ind, 1, 1); GLPK.intArray_setitem(ind, 2, 2); val = GLPK.new_doubleArray(3); GLPK.doubleArray_setitem(val, 1, 10); GLPK.doubleArray_setitem(val, 2, 7); GLPK.glp_set_mat_row(lp, 1, 2, ind, val); GLPK.delete_intArray(ind); GLPK.delete_doubleArray(val); ind = GLPK.new_intArray(3); GLPK.intArray_setitem(ind, 1, 1); GLPK.intArray_setitem(ind, 2, 2); val = GLPK.new_doubleArray(3); GLPK.glp_set_row_name(lp, 2, "c2"); GLPK.glp_set_row_bnds(lp, 2, GLPK.GLP_UP, 0, 5); GLPK.doubleArray_setitem(val, 1, 1); GLPK.doubleArray_setitem(val, 2, 1); GLPK.glp_set_mat_row(lp, 2, 2, ind, val); GLPK.delete_intArray(ind); GLPK.delete_doubleArray(val); // Define objective GLPK.glp_set_obj_name(lp, "obj"); GLPK.glp_set_obj_dir(lp, GLPK.GLP_MAX); GLPK.glp_set_obj_coef(lp, 0, 0); GLPK.glp_set_obj_coef(lp, 1, 17); GLPK.glp_set_obj_coef(lp, 2, 12); // solve model iocp = new glp_iocp(); GLPK.glp_init_iocp(iocp); iocp.presolve = GLPK.GLP_ON; iocp.msg_lev = GLPK.GLP_MSG_OFF; GLPK.glp_intopt(lp, iocp); // free memory GLPK.glp_delete_prob(lp); } catch (GlpkException ex) { Console.WriteLine(ex.Message); ret = true; } return(ret); }