/** * 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]); }
private double _solve() { GLPK.glp_term_out(GLPK.GLP_OFF); GlpkCallback.addListener(this); buildProblem(); GLPK.glp_adv_basis(problem, 0); GLPK.glp_simplex(problem, null); double val = GLPK.glp_get_obj_val(problem); /*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(GLPK.glp_get_obj_val(problem)); }
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."); } }