[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-glpk] Question SImplex
From: |
Jonata Goulart |
Subject: |
[Help-glpk] Question SImplex |
Date: |
Fri, 19 Apr 2002 13:21:53 +0000 |
I don't know what is happening with my model.
I need to specify binarie (0, 1) variables but on the solution they are not
integer. The model is simple (Set Covering problem). Each row has to be
covered by at least one column.
Look what I made and the result:
Z = 4; x1 = 0; x2 = 0; x3 = 0.5; x4 = 0; x5 = 0; x6 = 0.5; x7 = 0.5
x8 = 1
thanks.
#include <stdio.h>
#include <stdlib.h>
#include "glpk.h"
int main(void)
{ LPI *lp;
double Z, valx, dx, x1, x2, x3, x4, x5, x6, x7, x8;
int i, tagx;
s1: lp = glp_create_prob("scp1");
s2: glp_new_col(lp, "x1"), glp_set_obj_coef(lp, 1, 1.0);
s3: glp_new_col(lp, "x2"), glp_set_obj_coef(lp, 2, 2.0);
s4: glp_new_col(lp, "x3"), glp_set_obj_coef(lp, 3, 2.0);
s5: glp_new_col(lp, "x4"), glp_set_obj_coef(lp, 4, 2.0);
s6: glp_new_col(lp, "x5"), glp_set_obj_coef(lp, 5, 1.0);
s7: glp_new_col(lp, "x6"), glp_set_obj_coef(lp, 6, 1.0);
s8: glp_new_col(lp, "x7"), glp_set_obj_coef(lp, 7, 1.0);
s9: glp_new_col(lp, "x8"), glp_set_obj_coef(lp, 8, 2.0);
for (i = 1; i <= 8; i ++) {
s105: glp_set_col_kind(lp, i, 'I');
s10: glp_set_col_bnds(lp, i, 'D', 0, 1);
}
s11: glp_new_row(lp, "p");
s12: glp_set_row_bnds(lp, 1, 'L', 1.0, 0.0);
s13: glp_new_aij(lp, 1, 1, 0.0);
s14: glp_new_aij(lp, 1, 2, 0.0);
s15: glp_new_aij(lp, 1, 3, 0.0);
s16: glp_new_aij(lp, 1, 4, 0.0);
s17: glp_new_aij(lp, 1, 5, 1.0);
s18: glp_new_aij(lp, 1, 6, 1.0);
s19: glp_new_aij(lp, 1, 7, 1.0);
s20: glp_new_aij(lp, 1, 8, 0.0);
s21: glp_new_row(lp, "q");
s22: glp_set_row_bnds(lp, 2, 'L', 1.0, 0.0);
s23: glp_new_aij(lp, 2, 1, 1.0);
s24: glp_new_aij(lp, 2, 2, 0.0);
s25: glp_new_aij(lp, 2, 3, 0.0);
s26: glp_new_aij(lp, 2, 4, 0.0);
s27: glp_new_aij(lp, 2, 5, 0.0);
s28: glp_new_aij(lp, 2, 6, 1.0);
s29: glp_new_aij(lp, 2, 7, 0.0);
s30: glp_new_aij(lp, 2, 8, 1.0);
s31: glp_new_row(lp, "r");
s32: glp_set_row_bnds(lp, 3, 'L', 1.0, 0.0);
s33: glp_new_aij(lp, 3, 1, 0.0);
s34: glp_new_aij(lp, 3, 2, 0.0);
s35: glp_new_aij(lp, 3, 3, 1.0);
s36: glp_new_aij(lp, 3, 4, 0.0);
s37: glp_new_aij(lp, 3, 5, 0.0);
s38: glp_new_aij(lp, 3, 6, 0.0);
s39: glp_new_aij(lp, 3, 7, 1.0);
s40: glp_new_aij(lp, 3, 8, 0.0);
s41: glp_new_row(lp, "s");
s42: glp_set_row_bnds(lp, 4, 'L', 1.0, 0.0);
s43: glp_new_aij(lp, 4, 1, 1.0);
s44: glp_new_aij(lp, 4, 2, 1.0);
s45: glp_new_aij(lp, 4, 3, 0.0);
s46: glp_new_aij(lp, 4, 4, 0.0);
s47: glp_new_aij(lp, 4, 5, 1.0);
s48: glp_new_aij(lp, 4, 6, 1.0);
s49: glp_new_aij(lp, 4, 7, 0.0);
s50: glp_new_aij(lp, 4, 8, 1.0);
s51: glp_new_row(lp, "t");
s52: glp_set_row_bnds(lp, 5, 'L', 1.0, 0.0);
s53: glp_new_aij(lp, 5, 1, 0.0);
s54: glp_new_aij(lp, 5, 2, 0.0);
s55: glp_new_aij(lp, 5, 3, 0.0);
s56: glp_new_aij(lp, 5, 4, 0.0);
s57: glp_new_aij(lp, 5, 5, 0.0);
s58: glp_new_aij(lp, 5, 6, 0.0);
s59: glp_new_aij(lp, 5, 7, 0.0);
s60: glp_new_aij(lp, 5, 8, 1.0);
s61: glp_new_row(lp, "u");
s62: glp_set_row_bnds(lp, 6, 'L', 1.0, 0.0);
s63: glp_new_aij(lp, 6, 1, 0.0);
s64: glp_new_aij(lp, 6, 2, 0.0);
s65: glp_new_aij(lp, 6, 3, 1.0);
s66: glp_new_aij(lp, 6, 4, 1.0);
s67: glp_new_aij(lp, 6, 5, 1.0);
s68: glp_new_aij(lp, 6, 6, 1.0);
s69: glp_new_aij(lp, 6, 7, 0.0);
s70: glp_new_aij(lp, 6, 8, 0.0);
s71: glp_new_row(lp, "v");
s72: glp_set_row_bnds(lp, 7, 'L', 1.0, 0.0);
s73: glp_new_aij(lp, 7, 1, 0.0);
s74: glp_new_aij(lp, 7, 2, 0.0);
s75: glp_new_aij(lp, 7, 3, 1.0);
s76: glp_new_aij(lp, 7, 4, 0.0);
s77: glp_new_aij(lp, 7, 5, 1.0);
s78: glp_new_aij(lp, 7, 6, 0.0);
s79: glp_new_aij(lp, 7, 7, 1.0);
s80: glp_new_aij(lp, 7, 8, 0.0);
s81: glp_new_row(lp, "x");
s82: glp_set_row_bnds(lp, 8, 'L', 1.0, 0.0);
s83: glp_new_aij(lp, 8, 1, 1.0);
s84: glp_new_aij(lp, 8, 2, 0.0);
s85: glp_new_aij(lp, 8, 3, 1.0);
s86: glp_new_aij(lp, 8, 4, 0.0);
s87: glp_new_aij(lp, 8, 5, 1.0);
s88: glp_new_aij(lp, 8, 6, 0.0);
s89: glp_new_aij(lp, 8, 7, 1.0);
s90: glp_new_aij(lp, 8, 8, 0.0);
s91: glp_set_obj_sense(lp, '-');
s92: glp_simplex2(lp, NULL);
s93: Z = glp_get_obj_val(lp);
s94: glp_get_col_soln(lp, 1, NULL, &x1, NULL);
s95: glp_get_col_soln(lp, 2, NULL, &x2, NULL);
s96: glp_get_col_soln(lp, 3, NULL, &x3, NULL);
s97: glp_get_col_soln(lp, 4, NULL, &x4, NULL);
s98: glp_get_col_soln(lp, 5, NULL, &x5, NULL);
s99: glp_get_col_soln(lp, 6, NULL, &x6, NULL);
s100: glp_get_col_soln(lp, 7, NULL, &x7, NULL);
s101: glp_get_col_soln(lp, 8, NULL, &x8, NULL);
s102: printf("\nZ = %g; x1 = %g; x2 = %g; x3 = %g; x4 = %g; x5 = %g; x6 =
%g; x7 = %g x8 = %g\n", Z, x1, x2, x3, x4, x5, x6, x7, x8);
s104: glp_delete_prob(lp);
return 0;
}
/* eof */
_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com
- [Help-glpk] Question SImplex,
Jonata Goulart <=