|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
Maximize using MPS file called from CHi :-) I am currently working on maximizing a cost function, I have used the MPS form to define the problem, rows, columns and so on, it looks like this: ----------------------------------------------------------------------- NAME SLLP ROWS N Z L P L Q L R L S COLUMNS X10 Z 100.0 P 100.0 X10 Q 1.0 R 1.0 X11 Z 70.0 P 70.0 X11 Q 1.0 R 1.0 X12 Z 50.0 P 50.0 X12 Q 1.0 R 1.0 X20 Z 200.0 P 100.0 X20 Q 1.0 S 1.0 X21 Z 140.0 P 70.0 X21 Q 1.0 S 1.0 X22 Z 100.0 P 50.0 X22 Q 1.0 S 1.0 RHS RHS1 P 400.0 Q 2.0 RHS1 R 1.0 S 1.0 BOUNDS UP BND1 X10 1.0 UP BND1 X11 1.0 UP BND1 X12 1.0 UP BND1 X20 1.0 UP BND1 X21 1.0 UP BND1 X22 1.0 ENDATA --------------------------------------------------------------------- I know one can not specify the optimization direction explicitly in MPS format and I know that by default it always MIN the objective function, so I though that by defining the direction in the C file that calls this MPS file the problems would be solved, my C file looks like this: -------------------------------------------------------------------- /* sllp.c */ #include <stdio.h> #include <stdlib.h> #include <glpk.h> int main(void) { glp_prob *P; P = glp_create_prob(); glp_set_obj_dir(P, GLP_MAX); glp_read_mps(P, GLP_MPS_FILE, NULL, "sllp.mps"); glp_simplex(P, NULL); lpx_print_sol(P, "sllp.txt"); glp_write_sol(P, "sllpsol.txt"); glp_delete_prob(P); return 0; } /* eof */ ------------------------------------------------------------------------------ But still the solver MIN all the time, by the way I do not use the glpsol, I always compile from the terminal with: >gcc -c sllp.c >gcc sllp.o -lglpk -lm The answer that I get is: ----------------------------------------------------------------------- glp_read_mps: reading problem data from `sllp.mps'... glp_read_mps: problem SLLP glp_read_mps: 5 rows, 6 columns, 24 non-zeros glp_read_mps: 34 records were read * 0: obj = 0.000000000e+00 infeas = 0.000e+00 (0) OPTIMAL SOLUTION FOUND lpx_print_sol: writing LP problem solution to `sllp.txt'... glp_write_sol: writing basic solution to `sllpsol.txt'... glp_write_sol: 13 lines were written ----------------------------------------------------------------------- Could somebody please give me a hint on how to define MAX so that I can MAX my problem defined using the MPS format? Thanks for the help :working: -- View this message in context: http://old.nabble.com/Maximize-using-MPS-file-called-from-C-tp26213652p26213652.html Sent from the Gnu - GLPK - Help mailing list archive at Nabble.com. _______________________________________________ Help-glpk mailing list Help-glpk@... http://lists.gnu.org/mailman/listinfo/help-glpk |
|
|
Re: Maximize using MPS file called from C> /* sllp.c */
> #include <stdio.h> > #include <stdlib.h> > #include <glpk.h> > int main(void) > { glp_prob *P; > P = glp_create_prob(); > glp_set_obj_dir(P, GLP_MAX); > glp_read_mps(P, GLP_MPS_FILE, NULL, "sllp.mps"); > glp_simplex(P, NULL); > lpx_print_sol(P, "sllp.txt"); > glp_write_sol(P, "sllpsol.txt"); > glp_delete_prob(P); > return 0; > } > /* eof */ Glp_read_mps calls glp_erase_prob, which discards all data stored in the problem object. Therefore you should call glp_set_obj_dir *after* glp_read_mps. _______________________________________________ Help-glpk mailing list Help-glpk@... http://lists.gnu.org/mailman/listinfo/help-glpk |
| Free embeddable forum powered by Nabble | Forum Help |