help-glpk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-glpk] Maximize using MPS file called from C


From: Banik
Subject: [Help-glpk] Maximize using MPS file called from C
Date: Thu, 5 Nov 2009 17:05:38 +0300

Hi :-)

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.








reply via email to

[Prev in Thread] Current Thread [Next in Thread]