help-glpk
[Top][All Lists]
Advanced

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

Re: [Help-glpk] GLPK Problem


From: vijay patil
Subject: Re: [Help-glpk] GLPK Problem
Date: Mon, 16 Jul 2007 19:09:15 +0530

Miguel,

Following are some of the mistakes in your program.

lpx_set_row_name(lp,1,"p");
lpx_set_row_bnds(lp,1, LPX_UP , 0.0 , 100.0);
lpx_set_row_name(lp,1,"q");
 lpx_set_row_bnds(lp,1, LPX_UP , 0.0 , 600.0);

[1]. You are not incrementing row index, in both cases its 1. There
are similar mistake elsewhere in the program. Make sure that you
increment row index and column index.

 lpx_set_row_bnds(lp,1, LPX_FX , 0.0 , 400.0);

[2]. Here both lower bound and upper bound should be 400.0. Refer GLPK
documentation and see usage of above function.

I hope you will be able to fix the program. You can print and verify
the LP model using function :

        /* Verify LP file. */
        lpx_write_cpxlp(lp, "output.lp");

I had some spare time, so I wrote the complete program, see
attachment, but only after you try fixing it yourselves first.



On 7/15/07, miguel montoya <address@hidden> wrote:
Hello everybody, i want to solve the following problem

Maximize Z=10x1+6x2+4x3
Subject to
x1+x2+x3+<=100
10x1+4x2+5x3<=600
2x1+2x2+6x3<=300
8x1+3x2+5x3=400
5x1+4x2+8x3=600

where all variables are non-negative

this is the routine in C

LPX *lp
int ia[1+1000], ja[1+1000];
double ar[1+1000],Z,x1,x2,x3;
lp=lpx_create_prob();
lpx_set_obj_dir(lp,LPX_MAX),
lpx_add_rows(lp,5);
lpx_set_row_name(lp,1,"p");
lpx_set_row_bnds(lp,1, LPX_UP , 0.0 , 100.0);
lpx_set_row_name(lp,1,"q");
 lpx_set_row_bnds(lp,1, LPX_UP , 0.0 , 600.0);
lpx_set_row_name(lp,1,"r");
 lpx_set_row_bnds(lp,1, LPX_UP , 0.0 , 300.0);
lpx_set_row_name(lp,1,"s");
 lpx_set_row_bnds(lp,1, LPX_FX , 0.0 , 400.0);
lpx_set_row_name(lp,1,"t");
 lpx_set_row_bnds(lp,1, LPX_FX , 0.0 , 600.0);
lpx_add_cols(lp,3);
lpx_set_col_name(lp,1,"x1");
lpx_set_col_bnds(lp,1,LPX_LO, 0.0, 0.0);
lpx_set_obj_coef(lp,1,10.0);
lpx_set_col_name(lp,2,"x2");
 lpx_set_col_bnds(lp,2,LPX_LO, 0.0, 0.0);
 lpx_set_obj_coef(lp,1,6.0);
lpx_set_col_name(lp,3,"x3");
 lpx_set_col_bnds(lp,3,LPX_LO, 0.0, 0.0);
 lpx_set_obj_coef(lp,3,4.0);
ia[1]=1, ja=[1]=1, ar[1]=1.0;
ia[2]=1, ja=[2]=2, ar[2]=1.0 ;
ia[3]=1, ja=[3]=3, ar[3]=1.0 ;
......................................
.....................................
......................................
........................................
lpx_load_matrix(lp,12,ia,ja,ar);

I want to know if the routine in C is right ????????????

Thanks

--


_______________________________________________
Help-glpk mailing list
address@hidden
http://lists.gnu.org/mailman/listinfo/help-glpk




--
Vijay Patil

Attachment: mm-main.c
Description: Text document


reply via email to

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