help-glpk
[Top][All Lists]
Advanced

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

[Help-glpk] Help


From: stilak1
Subject: [Help-glpk] Help
Date: Sat, 28 Aug 2004 20:50:47 -0400 (EDT)
User-agent: SquirrelMail/1.4.2

Hi Everyone,

I am new in this area and trying glpk for the first time.
I am trying to work on the following problem:

Max phi

s.t.
    4a+9b+6c+8d+7e+11f-6phi >= 0
    2a+4b+3c+6d+5e+8f-3phi >= 0
    2a+7b+6c+5d+8e+6f =< 6
    3a+5b+7c+8d+4e+6f <= 7

    a,b,c,d,e,f >= 0, phi is free


I get following answer:

!     0:   objval =   0.000000000e+00   infeas =   0.000000000e+00
OPTIMAL SOLUTION FOUND
Z:0 l1:0 l2:0 l3:0 l4:0 l5:0 l6:0 ph:0


Is there something wrong with my code, or simplex is not the right method
for this problem ? Any help would be great...

I have writetn the following code.

#include <stdio.h>
#include <stdlib.h>
#include "glpk.h"

int main(void)
{
  LPX* lp;
  int rn[1+26],cn[1+26];
  double a[1+26],Z,l1,l2,l3,l4,l5,l6,ph;

  lp = lpx_create_prob();
  lpx_set_prob_name(lp,"ex2");

  lpx_add_rows(lp,4);

  lpx_set_row_name(lp,1,"p");
  lpx_set_row_bnds(lp,1,LPX_LO,0.0,0.0);

  lpx_set_row_name(lp,2,"q");
  lpx_set_row_bnds(lp,2,LPX_LO,0.0,0.0);

  lpx_set_row_name(lp,3,"r");
  lpx_set_row_bnds(lp,3,LPX_UP,0.0,6.0);

  lpx_set_row_name(lp,4,"s");
  lpx_set_row_bnds(lp,4,LPX_UP,0.0,7.0);

  lpx_add_cols(lp,7);

  lpx_set_col_name(lp,1,"l1");
  lpx_set_col_bnds(lp,1,LPX_LO,0.0,0.0);
  lpx_set_col_name(lp,2,"l2");
  lpx_set_col_bnds(lp,2,LPX_LO,0.0,0.0);

  lpx_set_col_name(lp,3,"l3");
  lpx_set_col_bnds(lp,3,LPX_LO,0.0,0.0);
  lpx_set_col_name(lp,4,"l4");
  lpx_set_col_bnds(lp,4,LPX_LO,0.0,0.0);

  lpx_set_col_name(lp,5,"l5");
  lpx_set_col_bnds(lp,5,LPX_LO,0.0,0.0);
  lpx_set_col_name(lp,6,"l6");
  lpx_set_col_bnds(lp,6,LPX_LO,0.0,0.0);

  lpx_set_col_name(lp,7,"ph");

  rn[1] = 1, cn[1] = 1, a[1] = 4.0;
  rn[2] = 1, cn[2] = 2, a[2] = 9.0;
  rn[3] = 1, cn[3] = 3, a[3] = 6.0;
  rn[4] = 1, cn[4] = 4, a[4] = 8.0;
  rn[5] = 1, cn[5] = 5, a[5] = 7.0;
  rn[6] = 1, cn[6] = 6, a[6] = 11.0;
  rn[7] = 1, cn[7] = 7, a[7] = -6.0;


  rn[8] = 2, cn[8] = 1, a[8] = 2.0;
  rn[9] = 2, cn[9] = 2, a[9] = 4.0;
  rn[10] = 2, cn[10] = 3, a[10] = 3.0;
  rn[11] = 2, cn[11] = 4, a[11] = 6.0;
  rn[12] = 2, cn[12] = 5, a[12] = 5.0;
  rn[13] = 2, cn[13] = 6, a[13] = 8.0;
  rn[14] = 2, cn[14] = 7, a[14] = -3.0;


  rn[15] = 3, cn[15] = 1, a[15] = 2.0;
  rn[16] = 3, cn[16] = 2, a[16] = 7.0;
  rn[17] = 3, cn[17] = 3, a[17] = 6.0;
  rn[18] = 3, cn[18] = 4, a[18] = 5.0;
  rn[19] = 3, cn[19] = 5, a[19] = 8.0;
  rn[20] = 3, cn[20] = 6, a[20] = 6.0;
  //  rn[21] = 3, cn[21] = 7, a[21] = 0.0;

  rn[21] = 4, cn[21] = 1, a[21] = 3.0;
  rn[22] = 4, cn[22] = 2, a[22] = 5.0;
  rn[23] = 4, cn[23] = 3, a[23] = 7.0;
  rn[24] = 4, cn[24] = 4, a[24] = 8.0;
  rn[25] = 4, cn[25] = 5, a[25] = 4.0;
  rn[26] = 4, cn[26] = 6, a[26] = 6.0;
  //  rn[28] = 4, cn[28] = 7, a[28] = 0.0;


  lpx_load_mat3(lp,26,rn,cn,a);

  lpx_set_obj_dir(lp,LPX_MAX);

  lpx_set_col_coef(lp,1,0.0);
  lpx_set_col_coef(lp,2,0.0);
  lpx_set_col_coef(lp,3,0.0);
  lpx_set_col_coef(lp,4,0.0);
  lpx_set_col_coef(lp,5,0.0);
  lpx_set_col_coef(lp,6,0.0);
  lpx_set_col_coef(lp,7,1.0);


  lpx_simplex(lp);

  Z = lpx_get_obj_val(lp);

  lpx_get_col_info(lp,1,NULL,&l1,NULL);
  lpx_get_col_info(lp,2,NULL,&l2,NULL);
  lpx_get_col_info(lp,3,NULL,&l3,NULL);
  lpx_get_col_info(lp,4,NULL,&l4,NULL);
  lpx_get_col_info(lp,5,NULL,&l5,NULL);
  lpx_get_col_info(lp,6,NULL,&l6,NULL);
  lpx_get_col_info(lp,7,NULL,&ph,NULL);

  printf("Z:%g l1:%g l2:%g l3:%g l4:%g l5:%g l6:%g ph:%g\n",
         Z,l1,l2,l3,l4,l5,l6,ph);

  lpx_delete_prob(lp);

 return 0;

}






reply via email to

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